MacroMath
Architecture

App services

The service layer — the classes that talk to AI, auth, food data, devices and billing.

The app's data/services/ layer centralizes every interaction with the outside world. Each service is a focused class; the UI never talks to an external API directly. State is managed with BLoC (flutter_bloc), wired through get_it for dependency injection, with go_router handling navigation.

The services

ServiceResponsibility
AiServiceThe single entry point to Gemini. Builds the NutritionContext, sends prompts, parses action markers and runs the deterministic normaliser. See AI and automation.
AuthServiceEmail/password sign-up and login, OTP verification, password reset and session persistence.
BiometricServiceFace ID / Touch ID / fingerprint unlock via local_auth.
EmailServiceSends transactional email (OTP) through the send-email Edge Function.
FatsecretServiceFood search and barcode lookups through the secure fatsecret Edge Function.
OpenfoodfactsServiceGlobal barcode fallback against Open Food Facts.
OcrServiceReads shopping receipts with ML Kit text recognition.
NotificationServiceSchedules timezone-aware local reminders (meals, hydration, weekly summary).
SubscriptionServiceTracks Premium state, drives the paywall and talks to Stripe.

Food data, three ways

FatsecretService, OpenfoodfactsService and the bundled PortugueseFoodsDatabase datasource together implement the three-source strategy in Food sources: local first for national accuracy, FatSecret and Open Food Facts for global coverage.

Why a service layer

Keeping all I/O behind services makes the app testable and keeps secrets on the server (the Gemini, FatSecret and Stripe calls go through Edge Functions). It also means a source or provider can be swapped without touching the screens.

On this page