MacroMath
Reference

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

1 · Portuguese local databaseA relational repository embedded in the app, with high-consumption products from the main retail chains (Continente, Pingo Doce, Lidl, Auchan, Minipreço, among others). Instant response; covers generic foods.
2 · FatSecretAn API consumed securely through a Supabase Edge Function, which encapsulates the credentials and OAuth authentication. Covers generic foods and products from the Portuguese and Spanish markets.
3 · Open Food FactsA public, free API geared toward packaged products worldwide. Particularly relevant for barcode search.

Priority and resilience

  • Text search — combines the three sources to maximize the chance of finding the right food, favoring the local database.
  • BarcodeFatSecret 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 item

This 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.

On this page