No description
  • Go 91.5%
  • CSS 8.2%
  • Makefile 0.2%
Find a file
2026-06-12 10:03:46 -04:00
cmd/coach refactor: aligned project with studio pollinator style guide 2026-06-12 10:03:46 -04:00
internal refactor: aligned project with studio pollinator style guide 2026-06-12 10:03:46 -04:00
.dockerignore added: docker 2026-04-07 23:34:14 -04:00
.gitignore initial commit 2026-03-08 22:50:10 -04:00
compose.yaml added: docker 2026-04-07 23:34:14 -04:00
Dockerfile added: docker 2026-04-07 23:34:14 -04:00
go.mod refactor: aligned project with studio pollinator style guide 2026-06-12 10:03:46 -04:00
go.sum refactor: aligned project with studio pollinator style guide 2026-06-12 10:03:46 -04:00
Makefile refactor: aligned project with studio pollinator style guide 2026-06-12 10:03:46 -04:00
README.md refactor: aligned project with studio pollinator style guide 2026-06-12 10:03:46 -04:00

Coach

Coach is a small single-binary Go web app for tracking calorie intake and body weight.

It is intentionally simple:

  • log meals with calorie counts
  • log weight entries
  • view a chronological journal
  • view a graph with cumulative calorie budget vs. actual intake
  • overlay weight on the all-time graph

The app is server-rendered with Go templates, uses HTMX for UI interactions, and stores all data in a single SQLite file.

High-Level Shape

  • cmd/coach/
    • CLI entrypoint and serve command
  • internal/server/
    • production composition root: opens the database, constructs service/api/web, mounts routes, listens
  • internal/service/
    • domain types, validation, journal assembly, chart generation, store contract
  • internal/database/
    • SQLite open/init, migrations, store implementation
  • internal/api/
    • machine-facing JSON API: DTOs, bearer auth, error mapping
  • internal/web/
    • server-rendered UI: resource-scoped handlers, view models, templates, static assets
  • internal/testutil/
    • test composition root and shared test helpers

Runtime Model

  • single process
  • single SQLite database file
  • no external services
  • no frontend build step
  • mobile-first SSR UI with HTMX-loaded modals

Optional private access gate:

  • set COACH_AUTH_TOKEN (or pass --auth-token) to require a one-field login
  • successful login sets a browser cookie used on later requests

The default local development flow uses:

  • ./bin/coach for the built binary
  • ./data/coach.sqlite3 for runtime data

Request Flow

Most interactions follow the same shape:

  1. HTTP handler parses form input or query state
  2. service layer validates and applies domain rules
  3. database layer persists or loads SQLite state
  4. web layer rebuilds view models from persisted state
  5. templates render either a full page or HTMX fragment

The server remains the source of truth after every write.

UI Model

  • pinned graph at the top of the screen
  • scrollable journal below it
  • journal header actions for adding meal and weight entries
  • chart header settings action beside the mode switch
  • modal forms for create/edit flows
  • week and all-time graph modes

Meal and weight timestamps are intentionally normalized to the hour.

Development

  • make lists the available targets
  • make build builds ./bin/coach
  • make run builds and runs against ./data/coach.sqlite3
  • make test runs the test suite
  • make lint runs go fmt and go vet
  • make clean removes build artifacts; make reset removes local runtime data

Meal Summary API

The server also exposes a JSON summary endpoint intended for LLM-friendly analysis:

  • GET /api/v1/summary/meals
  • Optional query params:
    • start_date=YYYY-MM-DD
    • end_date=YYYY-MM-DD
  • If no query params are provided, all logged meal dates are included.
  • If auth is enabled (--auth-token or COACH_AUTH_TOKEN), /api/v1/* routes require Authorization: Bearer <token>.
  • Responses use the standard envelope: {"data": {...}} on success, {"error": {"message": "..."}} on failure. The summary itself is plain text in the summary field.

Example:

curl -H "Authorization: Bearer example-password" \
  "http://127.0.0.1:8080/api/v1/summary/meals?start_date=2026-03-01&end_date=2026-03-31"

Notes For Developers

  • templates and static files are embedded into the binary
  • chart rendering is done server-side as SVG
  • persisted timestamps are stored as Unix seconds in SQLite
  • the database package implements the service-owned store interface
  • tests are in-process and exercise the app without starting a real listener