# dhruvg130/calorie-app architecture

> Architecture diagram of the GitHub repository dhruvg130/calorie-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhruvg130/calorie-app
- Repository: https://github.com/dhruvg130/calorie-app

## Overview

Calorie Tracker is a mobile nutrition and recovery app. The main flow is authenticate, choose a logging route, find or enter food, confirm servings and meal type, then save and review daily intake. Weight tracking and WHOOP-derived recovery are separate but related capabilities. The graph preserves those documented branches; source excerpts support only some client and backend links, so unsampled relationships are not asserted.

Main entry points: [`app/(tabs)/add.tsx`](https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/add.tsx) (Add food routes), [`src/services/nutrition/index.ts`](https://github.com/dhruvg130/calorie-app/blob/main/src/services/nutrition/index.ts) (Nutrition lookup), [`src/components/ServingForm.tsx`](https://github.com/dhruvg130/calorie-app/blob/main/src/components/ServingForm.tsx) (Serving and meal form), [`src/lib/supabase.ts`](https://github.com/dhruvg130/calorie-app/blob/main/src/lib/supabase.ts) (Supabase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Mobile experience"]
  node_authscreens["Sign-in and sign-up<br/>[sign-in.tsx]"]
  node_auth["Session and auth<br/>[AuthProvider.tsx]"]
  node_home["Today dashboard<br/>[index.tsx]"]
end

subgraph group_nutrition["Nutrition logging"]
  node_logroutes["Add food routes<br/>[add.tsx]"]
  node_search["Food search<br/>[search.tsx]"]
  node_barcode["Barcode lookup<br/>[scan.tsx]"]
  node_photo["Photo logging<br/>[photo.tsx]"]
  node_manual["Manual entry<br/>[manual.tsx]"]
  node_confirm["Confirm food<br/>[confirm.tsx]"]
  node_handoff["Food handoff<br/>[handoff.ts]"]
  node_nutritionlookup["Nutrition lookup<br/>[index.ts]"]
  node_serving["Serving and meal form<br/>[ServingForm.tsx]"]
end

subgraph group_tracking["Personal tracking"]
  node_entryhook["Entry queries<br/>[useEntries.ts]"]
  node_entryapi["Entry persistence<br/>[entries.ts]"]
  node_profilehook["Profile queries<br/>[useProfile.ts]"]
  node_weight["Weight tracking<br/>[weight.tsx]"]
  node_weightapi["Weight persistence<br/>[weight.ts]"]
  node_whoopui["WHOOP dashboard<br/>[whoop.tsx]"]
  node_whoophook["WHOOP queries<br/>[useWhoop.ts]"]
  node_whoopapi["WHOOP client API<br/>[whoop.ts]"]
end

subgraph group_backend["Supabase services"]
  node_foodfunction["Food search function<br/>[index.ts]"]
  node_usdafunction["USDA search function<br/>[index.ts]"]
  node_openfoodfacts["Open Food Facts<br/>[openFoodFacts.ts]"]
  node_whoopfunction["WHOOP function<br/>[index.ts]"]
  node_callback["OAuth callback<br/>[index.ts]"]
  node_database[("PostgreSQL data<br/>[database.types.ts]")]
  node_supabase["Supabase client<br/>[supabase.ts]"]
end

node_person(("User"))
node_whoopservice["WHOOP service"]
node_offservice["Open Food Facts service"]
node_usdaservice["USDA service"]

node_person -->|"signs in"| node_authscreens
node_authscreens -->|"submits credentials"| node_auth
node_auth -->|"authenticates"| node_supabase
node_home -->|"loads entries"| node_entryhook
node_home -.->|"loads goals"| node_profilehook
node_person -.->|"starts logging"| node_logroutes
node_logroutes -.->|"opens search"| node_search
node_logroutes -.->|"opens scanner"| node_barcode
node_logroutes -.->|"opens camera"| node_photo
node_logroutes -.->|"opens manual"| node_manual
node_search -->|"searches foods"| node_nutritionlookup
node_barcode -->|"looks up barcode"| node_nutritionlookup
node_search -->|"passes selection"| node_handoff
node_barcode -->|"passes selection"| node_handoff
node_nutritionlookup -->|"searches remotely"| node_foodfunction
node_nutritionlookup -.->|"queries barcode"| node_openfoodfacts
node_foodfunction -.->|"queries USDA"| node_usdaservice
node_foodfunction -.->|"queries products"| node_offservice
node_person -.->|"confirms selection"| node_confirm
node_confirm -.->|"sets serving"| node_serving
node_manual -.->|"enters food"| node_serving
node_photo -.->|"reviews food"| node_serving
node_serving -.->|"creates entry"| node_entryhook
node_entryhook -->|"calls persistence"| node_entryapi
node_entryapi -->|"reads and writes"| node_supabase
node_supabase -.->|"queries data"| node_database
node_person -.->|"records weight"| node_weight
node_weight -.->|"loads and saves"| node_weightapi
node_weightapi -->|"reads and writes"| node_supabase
node_person -.->|"views recovery"| node_whoopui
node_whoopui -.->|"loads metrics"| node_whoophook
node_whoophook -->|"requests data"| node_whoopapi
node_whoopapi -.->|"calls function"| node_whoopfunction
node_whoopfunction -.->|"fetches metrics"| node_whoopservice
node_callback -.->|"exchanges code"| node_whoopservice
node_whoopfunction -.->|"stores metrics"| node_database

click node_authscreens "https://github.com/dhruvg130/calorie-app/blob/main/app/(auth)/sign-in.tsx"
click node_auth "https://github.com/dhruvg130/calorie-app/blob/main/src/providers/AuthProvider.tsx"
click node_home "https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/index.tsx"
click node_logroutes "https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/add.tsx"
click node_search "https://github.com/dhruvg130/calorie-app/blob/main/app/log/search.tsx"
click node_barcode "https://github.com/dhruvg130/calorie-app/blob/main/app/log/scan.tsx"
click node_photo "https://github.com/dhruvg130/calorie-app/blob/main/app/log/photo.tsx"
click node_manual "https://github.com/dhruvg130/calorie-app/blob/main/app/log/manual.tsx"
click node_confirm "https://github.com/dhruvg130/calorie-app/blob/main/app/log/confirm.tsx"
click node_handoff "https://github.com/dhruvg130/calorie-app/blob/main/src/services/nutrition/handoff.ts"
click node_nutritionlookup "https://github.com/dhruvg130/calorie-app/blob/main/src/services/nutrition/index.ts"
click node_foodfunction "https://github.com/dhruvg130/calorie-app/blob/main/supabase/functions/food-search/index.ts"
click node_usdafunction "https://github.com/dhruvg130/calorie-app/blob/main/supabase/functions/usda-search/index.ts"
click node_openfoodfacts "https://github.com/dhruvg130/calorie-app/blob/main/src/services/nutrition/openFoodFacts.ts"
click node_serving "https://github.com/dhruvg130/calorie-app/blob/main/src/components/ServingForm.tsx"
click node_entryhook "https://github.com/dhruvg130/calorie-app/blob/main/src/hooks/useEntries.ts"
click node_entryapi "https://github.com/dhruvg130/calorie-app/blob/main/src/api/entries.ts"
click node_profilehook "https://github.com/dhruvg130/calorie-app/blob/main/src/hooks/useProfile.ts"
click node_weight "https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/weight.tsx"
click node_weightapi "https://github.com/dhruvg130/calorie-app/blob/main/src/api/weight.ts"
click node_whoopui "https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/whoop.tsx"
click node_whoophook "https://github.com/dhruvg130/calorie-app/blob/main/src/hooks/useWhoop.ts"
click node_whoopapi "https://github.com/dhruvg130/calorie-app/blob/main/src/api/whoop.ts"
click node_whoopfunction "https://github.com/dhruvg130/calorie-app/blob/main/supabase/functions/whoop/index.ts"
click node_callback "https://github.com/dhruvg130/calorie-app/blob/main/supabase/functions/whoop-callback/index.ts"
click node_database "https://github.com/dhruvg130/calorie-app/blob/main/src/lib/database.types.ts"
click node_supabase "https://github.com/dhruvg130/calorie-app/blob/main/src/lib/supabase.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_authscreens,node_auth,node_home,node_person toneBlue
class node_logroutes,node_search,node_barcode,node_photo,node_manual,node_confirm,node_handoff,node_nutritionlookup,node_serving toneAmber
class node_entryhook,node_entryapi,node_profilehook,node_weight,node_weightapi,node_whoopui,node_whoophook,node_whoopapi toneMint
class node_foodfunction,node_usdafunction,node_openfoodfacts,node_whoopfunction,node_callback,node_database,node_supabase toneRose
class node_whoopservice,node_offservice,node_usdaservice toneIndigo
```

## Components

### Mobile experience

- [Sign-in and sign-up](https://github.com/dhruvg130/calorie-app/blob/main/app/(auth)/sign-in.tsx): `app/(auth)/sign-in.tsx`
- [Session and auth](https://github.com/dhruvg130/calorie-app/blob/main/src/providers/AuthProvider.tsx): `src/providers/AuthProvider.tsx`
- [Today dashboard](https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/index.tsx): `app/(tabs)/index.tsx`

### Nutrition logging

- [Add food routes](https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/add.tsx): `app/(tabs)/add.tsx`
- [Food search](https://github.com/dhruvg130/calorie-app/blob/main/app/log/search.tsx): `app/log/search.tsx`
- [Barcode lookup](https://github.com/dhruvg130/calorie-app/blob/main/app/log/scan.tsx): `app/log/scan.tsx`
- [Photo logging](https://github.com/dhruvg130/calorie-app/blob/main/app/log/photo.tsx): `app/log/photo.tsx`
- [Manual entry](https://github.com/dhruvg130/calorie-app/blob/main/app/log/manual.tsx): `app/log/manual.tsx`
- [Confirm food](https://github.com/dhruvg130/calorie-app/blob/main/app/log/confirm.tsx): `app/log/confirm.tsx`
- [Food handoff](https://github.com/dhruvg130/calorie-app/blob/main/src/services/nutrition/handoff.ts): `src/services/nutrition/handoff.ts`
- [Nutrition lookup](https://github.com/dhruvg130/calorie-app/blob/main/src/services/nutrition/index.ts): `src/services/nutrition/index.ts`
- [Serving and meal form](https://github.com/dhruvg130/calorie-app/blob/main/src/components/ServingForm.tsx): `src/components/ServingForm.tsx`

### Personal tracking

- [Entry queries](https://github.com/dhruvg130/calorie-app/blob/main/src/hooks/useEntries.ts): `src/hooks/useEntries.ts`
- [Entry persistence](https://github.com/dhruvg130/calorie-app/blob/main/src/api/entries.ts): `src/api/entries.ts`
- [Profile queries](https://github.com/dhruvg130/calorie-app/blob/main/src/hooks/useProfile.ts): `src/hooks/useProfile.ts`
- [Weight tracking](https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/weight.tsx): `app/(tabs)/weight.tsx`
- [Weight persistence](https://github.com/dhruvg130/calorie-app/blob/main/src/api/weight.ts): `src/api/weight.ts`
- [WHOOP dashboard](https://github.com/dhruvg130/calorie-app/blob/main/app/(tabs)/whoop.tsx): `app/(tabs)/whoop.tsx`
- [WHOOP queries](https://github.com/dhruvg130/calorie-app/blob/main/src/hooks/useWhoop.ts): `src/hooks/useWhoop.ts`
- [WHOOP client API](https://github.com/dhruvg130/calorie-app/blob/main/src/api/whoop.ts): `src/api/whoop.ts`

### Supabase services

- [Food search function](https://github.com/dhruvg130/calorie-app/blob/main/supabase/functions/food-search/index.ts): `supabase/functions/food-search/index.ts`
- [USDA search function](https://github.com/dhruvg130/calorie-app/blob/main/supabase/functions/usda-search/index.ts): `supabase/functions/usda-search/index.ts`
- [Open Food Facts](https://github.com/dhruvg130/calorie-app/blob/main/src/services/nutrition/openFoodFacts.ts): `src/services/nutrition/openFoodFacts.ts`
- [WHOOP function](https://github.com/dhruvg130/calorie-app/blob/main/supabase/functions/whoop/index.ts): `supabase/functions/whoop/index.ts`
- [OAuth callback](https://github.com/dhruvg130/calorie-app/blob/main/supabase/functions/whoop-callback/index.ts): `supabase/functions/whoop-callback/index.ts`
- [PostgreSQL data](https://github.com/dhruvg130/calorie-app/blob/main/src/lib/database.types.ts): `src/lib/database.types.ts`
- [Supabase client](https://github.com/dhruvg130/calorie-app/blob/main/src/lib/supabase.ts): `src/lib/supabase.ts`

### Other components

- **User**
- **WHOOP service**
- **Open Food Facts service**
- **USDA service**

## Connections

- User → Sign-in and sign-up: signs in
- Sign-in and sign-up → Session and auth: submits credentials
- Session and auth → Supabase client: authenticates (evidence: `src/providers/AuthProvider.tsx`)
- Today dashboard → Entry queries: loads entries (evidence: `app/(tabs)/index.tsx`)
- Today dashboard → Profile queries: loads goals (evidence: `app/(tabs)/index.tsx`)
- User → Add food routes: starts logging
- Add food routes → Food search: opens search
- Add food routes → Barcode lookup: opens scanner
- Add food routes → Photo logging: opens camera
- Add food routes → Manual entry: opens manual
- Food search → Nutrition lookup: searches foods (evidence: `app/log/search.tsx`)
- Barcode lookup → Nutrition lookup: looks up barcode (evidence: `app/log/scan.tsx`)
- Food search → Food handoff: passes selection (evidence: `app/log/search.tsx`)
- Barcode lookup → Food handoff: passes selection (evidence: `app/log/scan.tsx`)
- Nutrition lookup → Food search function: searches remotely
- Nutrition lookup → Open Food Facts: queries barcode (evidence: `src/services/nutrition/index.ts`)
- Food search function → USDA service: queries USDA
- Food search function → Open Food Facts service: queries products
- User → Confirm food: confirms selection
- Confirm food → Serving and meal form: sets serving
- Manual entry → Serving and meal form: enters food
- Photo logging → Serving and meal form: reviews food
- Serving and meal form → Entry queries: creates entry
- Entry queries → Entry persistence: calls persistence (evidence: `src/hooks/useEntries.ts`)
- Entry persistence → Supabase client: reads and writes (evidence: `src/api/entries.ts`)
- Supabase client → PostgreSQL data: queries data (evidence: `src/lib/supabase.ts`)
- User → Weight tracking: records weight
- Weight tracking → Weight persistence: loads and saves (evidence: `app/(tabs)/weight.tsx`)
- Weight persistence → Supabase client: reads and writes (evidence: `src/api/weight.ts`)
- User → WHOOP dashboard: views recovery
- WHOOP dashboard → WHOOP queries: loads metrics
- WHOOP queries → WHOOP client API: requests data (evidence: `src/hooks/useWhoop.ts`)
- WHOOP client API → WHOOP function: calls function
- WHOOP function → WHOOP service: fetches metrics
- OAuth callback → WHOOP service: exchanges code
- WHOOP function → PostgreSQL data: stores metrics
