- OCaml 67%
- HTML 24%
- CSS 7%
- Docker 2%
- Shell <1%
Health Buddy #
AI WARNING #
This is AI vibe coded!
A private, server-rendered meal and macro tracker written in OCaml. It stores readable JSON on the local filesystem and contains no browser JavaScript.
The repository also retains the original design prototype (index.html, add.html, and the other static pages). The running application is under lib/ and bin/.
Current implementation #
The first vertical slice includes:
- Today dashboard with meal and macro totals
- Manual meal logging
- Daily target editing
- Filesystem JSON persistence using temporary file,
fsync, and atomic rename - Mobile photo upload using
accept="image/*"andcapture="environment" - Multipart upload parsing, file-size limit, and image MIME sniffing
- Gemini meal estimation through OpenRouter with strict structured output
- Server-rendered estimate review and correction before logging
- Gemini model/confidence provenance on estimated meals
- Recipe-book and history read views
- No JavaScript or client-side state
Still to build: CSRF protection, persisted expiring classification drafts, recipe creation/reuse mutations, meal edit/delete, complete seven-day history, image re-encoding/orientation normalisation, per-path Async write queues, and deployment packaging.
Build #
The project uses a local opam switch:
opam switch create . ocaml-system
opam install . --deps-only --with-test
eval $(opam env)
dune runtest
dune build @all
Run #
export HEALTHBUDDY_DATA_DIR=$PWD/data
export HEALTHBUDDY_STATIC_DIR=$PWD
export OPENROUTER_API_KEY='***'
eval $(opam env)
dune exec healthbuddy
The server listens on /run/healthbuddy/http.sock.
OPENROUTER_API_KEY is only needed for photo estimation. The application uses the hardcoded google/gemini-3.7-flash model. Manual logging works without a key. Secrets are never written to JSON or rendered into HTML.
Docker #
Build the image as bayge/healthbuddy:
./docker.sh
Run it with persistent data and the OpenRouter key supplied at runtime:
sudo install -d -m 0770 -o 10001 -g 10001 /run/healthbuddy
docker run --rm \
--name healthbuddy \
-v healthbuddy-data:/data \
-v /run/healthbuddy:/run/healthbuddy \
-e OPENROUTER_API_KEY \
bayge/healthbuddy
The container runs as an unprivileged user, stores JSON beneath /data, and
contains only the compiled server, stylesheet, CA certificates, and required
runtime libraries. docker.sh forwards additional Docker build options, for
example ./docker.sh --pull.
The bind-mounted /run/healthbuddy directory must be writable by container UID
and GID 10001. The server creates http.sock there with mode 0660; arrange
the directory's ownership or setgid group so the reverse proxy can connect.
Data layout #
data/
├── meals/
│ └── YYYY-MM-DD.json
├── recipes/
├── drafts/
└── targets.json
Each durable JSON replacement is written to a same-directory temporary file, flushed with fsync, atomically renamed, and followed by a directory fsync. Malformed existing JSON fails loudly rather than being treated as empty state.
Tests #
eval $(opam env)
dune runtest --force --no-buffer
The tests cover JSON round trips and corruption handling, meal totals, safe path components, HTTP application flows, escaping/no-JavaScript rendering, Gemini response validation, image sniffing, and multipart form parsing.
See plan.html for the broader product and technical plan.