AI Macro Identifier is a food-photo nutrition app aimed at giving users a fast, grounded estimate of calories and macros from a meal photo.
This repo is in active MVP development on the feat/mvp-foundation branch.
Current working capabilities:
- upload a food photo with instant local preview
- call an analysis API route from the UI
- render structured food candidates and macro totals
- expose ambiguity, confidence, and follow-up questions
- adjust portions and instantly recalculate totals
- validate and normalize provider output server-side
- ground detected foods toward USDA-backed macro estimates through the new grounding layer
The useful version of this product is not "take a photo and trust the number blindly."
It is:
- detect likely foods in the image
- estimate portion size with explicit uncertainty
- map foods to a nutrient database
- show calories, protein, carbs, and fat
- let the user quickly correct the result before saving it
That correction loop matters because current single-image nutrition estimation is directionally useful, but portion estimation is still the weak point.
Based on current literature and platform documentation reviewed while setting up this repo:
- General-purpose multimodal models can be decent for rough food recognition and macro estimation, but error rates are still high enough that this should not be framed as clinically precise.
- Portion size is the core problem. Food naming is easier than estimating how much food is actually present.
- Large portions tend to be systematically underestimated.
- A practical MVP should combine AI vision with a trusted nutrition database such as USDA FoodData Central.
- Confidence and user correction are product requirements, not nice-to-haves.
- Targeted follow-up questions are often a better product choice than pretending a low-confidence estimate is exact.
Detailed notes live in:
docs/research-notes-2026-04-11.mddocs/architecture/overview.mddocs/development/roadmap.mddocs/development/usda-grounding.mddocs/development/provider-setup.mddocs/development/release-checklist.mddocs/development/next-20-line-items.md
src/approute handlers and app entrypointssrc/componentsUI componentssrc/libdomain logic, provider adapters, and integrationssrc/lib/analysisanalysis-provider abstraction, schema validation, normalization, and provider factorysrc/lib/grounding.tsUSDA grounding flow for detected foods
docs/architecturesystem design notesdocs/developmentroadmap, grounding notes, and execution checklistdocs/research-notes-2026-04-11.mdresearch grounding for product decisionsscripts/dev-check.shlocal verification helper
- Next.js App Router
- single-screen analysis workbench
- image upload with local preview
- API-driven analysis state
- editable portion controls with recalculated totals
app/api/analyze/route.tsas backend-for-frontend entry point- analysis provider abstraction via
src/lib/analysis - schema validation and normalization for provider output
- current mocked provider behind a stable structured schema
- placeholder provider adapter for future live multimodal integration
- USDA search, food-details fetch, nutrient extraction, and grounding helpers
POST /api/analyze
Accepts either:
multipart/form-datawithimageapplication/jsonwithimageBase64orimageUrl
Returns a structured analysis response with:
- overall confidence
- summary
- per-food identification confidence
- per-food portion confidence
- estimated weight ranges
- ambiguity notes
- targeted follow-up questions
- macro totals derived from per-food macro estimates
- provider and pipeline-stage metadata in the route response
This richer schema is intentional. The contract is designed to survive real provider integration without forcing a UI rewrite.
USDA FoodData Central is a strong early data source because it provides public nutrient data and a documented API, but it requires a data.gov API key and has rate limits.
Recommended usage direction:
- prefer Foundation and FNDDS for common foods and mixed dishes
- use Branded as fallback for packaged food matching
- cache resolved matches to reduce repeated lookups
- normalize common food-name variants before USDA search
- ground model-detected foods against USDA when confidence and matching quality are sufficient
Create a .env.local file:
USDA_API_KEY=your_data_gov_api_key_hereA starter template exists in .env.example.
A usable MVP should do all of the following:
- accept a food photo
- call a real multimodal model
- return structured food candidates
- ground candidates against USDA data
- show calories, protein, carbs, and fat
- expose confidence and ambiguity clearly
- let the user adjust portions
- save or export a corrected result
- Replace the mocked analysis provider selected in
src/lib/analysis/factory.tswith a real multimodal provider adapter. - Map provider output into the validated analysis schema.
- Invoke USDA grounding from the analysis pipeline with clear success/failure handling.
- Add caching for repeated USDA lookups and resolved food records.
- Add persistence for meal history and corrected meals.
For a larger execution list, see docs/development/next-20-line-items.md.
npm install
npm run devThen open http://localhost:3000.
./scripts/dev-check.sh- Problem: Food-photo macro estimation is useful but uncertain, especially around portion size.
- Core capability: Image-based macro estimation with uncertainty handling and user correction loops.
- Primary stack: TypeScript app + vision/API-backed analysis pipeline.
- Status: Active MVP foundation work.