Food sources
The hybrid three-source nutritional data architecture and the canonical identifier.
To reconcile national accuracy with international coverage, MacroMath orchestrates three nutritional data sources, in priority order. The system is resilient: if one fails, it degrades gracefully to the next.
The three sources
Priority and resilience
- Text search — combines the three sources to maximize the chance of finding the right food, favoring the local database.
- Barcode — FatSecret is queried first; Open Food Facts acts as a global fallback.
- FatSecret Edge Function failure — search degrades to the local database and Open Food Facts, without compromising operation.
Canonical food identifier
To ensure referential integrity between the Pantry, the Diet and Foods, the system
uses a canonical identifier stored in the food_ref_id field, whose prefix indicates
its provenance:
off:<barcode> → Open Food Facts product (international)
local:<slug> → national catalog itemThis universal identifier lets the same food be recognized consistently across all modules. See Data model.
Photo recognition
When there's no exact match — or for composite dishes — MacroAI estimates the macros from a photo. It's a complement to the sources above, not a substitute: always confirm the values before saving.
No database is perfect. For specific clinical needs, confirm the values against the product packaging or with a health professional.