Navigation

AI + nutrition

MealPath

Meal photo to reviewed items, nutrition and a plan: AI suggests, the user confirms, exact server-side arithmetic decides.

In the demo you analyse a sample meal photo, review the items the AI was unsure about, confirm portions, and get calculated nutrition and a ranked three-day plan. Underneath: a validated AI adapter that rejects invalid output instead of repairing it, exact arithmetic with one rounding step, versioned ranking rules, and images processed in memory and never stored.

My role
Sole engineer: spec to deployment
Walkthrough
90-second guided scenario
Focus
AI behind a validated boundary

Launch guided demo (opens in a new tab)Engineering evidence

Stack: React · TypeScript · PHP/Symfony · PostgreSQL · Playwright + axe

Independently built portfolio showcase · simulated data

MealPath meal estimate after review: 546.0 kcal, 71.0 g protein, 9.2 g fat and 48.5 g carbohydrate, with the ingredient breakdown for chicken breast, brown rice, broccoli and soy sauce, the reference-data notes and the suggested 3-day plan below.

The business problem

People who plan meals around general nutrition preferences jump between disconnected steps: understanding what they eat, checking approximate nutrition, finding recipes and making a plan. MealPath connects uncertain AI food recognition to reliable reference data and deterministic recommendations, relevant to meal-kit and grocery businesses.

Try the workflow

  1. Step 1

    MealPath review screen for the sample chicken and rice bowl: the meal photo, "2 items need your review", a rice item needing a choice between brown and white, a sauce not in the catalogue, and "0 of 4 confirmed".
    Review: the AI's suggestions need a person; nothing is calculated while items are unresolved.
  2. Step 2

    MealPath recipe recommendations for "Higher protein" with dairy excluded: 6 recipes shown and 4 hidden, the top pick "Beef and sweet potato tray bake", and the 3-day plan updated with the top three recipes.
    Ranking: a registered, versioned rule orders recipes for higher protein with dairy excluded.
  3. Step 3

    MealPath saved 3-day meal plan with plan totals of 1493.9 kcal, 131.1 g protein, 53.0 g fat and 134.5 g carbohydrate, a 9-ingredient shopping list and the recipe filters below.
    Saved plan: totals and the ingredient list come from the server, not the model.
MealPath on a phone: the 3-day meal planner at the Plan step with the meal estimate of 546.0 kcal, 71.0 g protein, 9.2 g fat and 48.5 g carbohydrate.
The meal estimate on a phone (390 × 844).

Engineering invariants

Rules the system enforces whatever the user does, and where each one is proven.

InvariantWhy it mattersEvidence
Nothing is calculated until every item is matched to a catalogue food and confirmed by the user.AI output never reaches results without human review.Confirmation gate (opens in a new tab)Functional/NutritionFlowTest.php :: testUnresolvedOrUnconfirmedItemsBlockConfirmation
AI output passes size, JSON, JSON Schema and semantic checks against the catalogue. Invalid output is rejected, never repaired; after one escalation a second failure stores nothing.The model cannot inject unknown foods or malformed data.Validation pipeline (opens in a new tab)Functional/LiveAnalysisTest.php :: testTwoInvalidOutputsFailWithoutPersistingAnything
Images are re-encoded in memory with metadata stripped and discarded after analysis; oversized images are rejected before decoding.No photo, EXIF location or image URL is ever stored.Image lifecycle (ADR 0005) (opens in a new tab)Unit/Shared/ImageSanitizerTest.php :: testStripsMetadataByReencoding

System architecture

MealPath system architectureBrowser, then a React and TypeScript single-page app, then a Symfony modular monolith with the Nutrition module, then PostgreSQL: session-owned rows, deleted with the session. The backend calls an AI adapter: A vision model proposes catalogue food ids, gram estimates and uncertainty notes as structured JSON; the user confirms every item, and nutrient values come only from the reference catalogue.BrowserAnonymous demo session · guided scenarioReact + TypeScriptSingle-page app · Playwright end-to-end + axeJSON · RFC 9457 problem detailsSymfony modular monolithNutrition moduleconfirmed items · exact arithmetic · ranking rulestransactions · constraintsPostgreSQLSession-owned rows, deleted with the sessionAI adapterJSON schema + semanticvalidation · fixture modeby default · no AI numbersDocker + Caddy on a shared 4-vCPU host · synthetic data only
A vision model proposes catalogue food ids, gram estimates and uncertainty notes as structured JSON; the user confirms every item, and nutrient values come only from the reference catalogue.

Key decisions

  • Fixture-first AI: a provider-independent contract, with a fixture provider for the public demo and all tests that runs the same validation. Live calls use a fast tier with at most one escalation.

    Why: A reliable public demo and deterministic CI without API keys, at a low live cost.

    Rejected: Always using the smartest model (about 20× the cost), automatic retries, live-only.

    ADR 0003 — Fixture-first AI via OpenRouter with tiered OpenAI models

  • Ranking and filtering are registered, versioned rules with explanations.

    Why: Deterministic and explainable; saved results record rule versions.

    Rejected: LLM ranking (non-deterministic and hard to explain).

    ADR 0004 — Explicit registered rule handlers instead of a rule language

Engineering evidence

  • Tests

    PHPUnit — calculator, rules, parser, flow, live path with mocked transport

    Exact-amount, calculator, parser, image sanitiser and live-path tests (with a mocked transport) in PHPUnit.

  • End-to-end

    Playwright journey with axe

    The full journey (71.0 g protein, 546.0 kcal; reset ends the session) plus checks that unresolved items block calculation. 7/7 passing on production on 26 Nov 2026.

    Conditions: Desktop; smoke test also on Pixel 7

  • Engineering page

    “How it's engineered” in the live demo (opens in a new tab)

    The full detail: rules, data model, tests and measurements, next to the running product.

I use AI-assisted development for implementation, exploration and review. I remain responsible for architecture, business rules, code quality and deployment. Critical behaviour is verified with deterministic tests, static analysis and reproducible benchmarks.

Trade-offs and limits

  • Synthetic reference data, not real nutrition values
  • Not medical or dietary advice
  • Allergen filters use catalogue declarations only; not an allergy safety guarantee
  • Public demo uses a prepared sample analysis

My contribution

I built MealPath as an independent engineering showcase: product specification, architecture, frontend, backend, data model, automated tests and deployment.

Want to discuss the engineering behind this?

Launch demo (opens in a new tab)Get in touch

Source-code walkthroughs available on request.