# mzuhaibkhan/nutritrac architecture

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

- Interactive diagram: https://gitdiagram.com/mzuhaibkhan/nutritrac
- Repository: https://github.com/mzuhaibkhan/nutritrac

## Overview

NutriTrack AI lets users log meals and workouts, review nutrition and activity trends, manage goals, and get AI coaching. The web app authenticates users, sends feature requests to Flask APIs, and presents results in dashboards and history views. Backend routes validate requests and coordinate persistence, AI analysis, scoring, and integrations. The README also documents comparison, water, streaks, social, and profile capabilities; some of these route implementations were not sampled, so their internal connections are shown only where documented or evidenced. External integrations and data-store relationships follow the README and sampled callers.

Main entry points: [`backend/app/__init__.py`](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/__init__.py) (Flask API), [`frontend/src/lib/api.ts`](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/lib/api.ts) (API client), [`backend/app/mongo_client.py`](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/mongo_client.py) (MongoDB access), [`backend/app/routes/llm.py`](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/llm.py) (AI meal analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_meal_entry["Meal logging<br/>[LogForm.tsx]"]
  node_activity_views["Activity views<br/>[page.tsx]"]
  node_goals_ui["Goal management<br/>[page.tsx]"]
  node_insights["Insights and history<br/>[page.tsx]"]
  node_compare_ui["Comparison view<br/>[page.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_identity["Identity"]
  node_auth_ui["Web authentication<br/>[AuthProvider.tsx]"]
  node_supabase_web["Supabase web client<br/>[client.ts]"]
  node_auth_middleware["JWT verification<br/>[auth.py]"]
end

subgraph group_api["Nutrition and activity APIs"]
  node_flask["Flask API<br/>[__init__.py]"]
  node_meal_analysis["AI meal analysis<br/>[llm.py]"]
  node_food_routes["Food logging<br/>[manual_food.py]"]
  node_activity_routes["Activity tracking<br/>[activities.py]"]
  node_goal_routes["Goals and meal plans<br/>[goals.py]"]
  node_analytics_routes["Nutrition analytics<br/>[analytics.py]"]
  node_compare_routes["Food comparison<br/>[compare.py]"]
  node_chat_routes["Nutrition chat<br/>[chat.py]"]
  node_profile_routes["User profile<br/>[profile.py]"]
  node_water_routes["Water tracking<br/>[water.py]"]
  node_streak_routes["Streak tracking<br/>[streaks.py]"]
  node_social_routes["Social sharing<br/>[social.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
end

subgraph group_intelligence["AI and scoring"]
  node_ml_routes["Health scoring<br/>[ml.py]"]
  node_gemini_client["AI provider client<br/>[gemini.py]"]
end

subgraph group_connections["Integrations and data"]
  node_mongo_client["MongoDB access<br/>[mongo_client.py]"]
  node_mongo[("MongoDB Atlas")]
  node_supabase_client["Supabase verifier client<br/>[supabase_client.py]"]
  node_supabase["Supabase Auth"]
  node_strava_routes["Strava sync<br/>[strava.py]"]
  node_strava["Strava API"]
  node_ai_providers["AI services"]
end

node_user(("Browser user"))

node_user -->|"views"| node_dashboard
node_user -->|"logs meals"| node_meal_entry
node_user -->|"tracks workouts"| node_activity_views
node_user -->|"sets goals"| node_goals_ui
node_meal_entry -.->|"submits data"| node_api_client
node_activity_views -.->|"requests data"| node_api_client
node_goals_ui -.->|"requests plans"| node_api_client
node_dashboard -.->|"requests summaries"| node_api_client
node_insights -.->|"requests trends"| node_api_client
node_compare_ui -.->|"requests comparison"| node_api_client
node_auth_ui -->|"uses"| node_supabase_web
node_api_client -.->|"calls API"| node_flask
node_flask -->|"registers route"| node_meal_analysis
node_flask -->|"registers route"| node_food_routes
node_flask -->|"registers route"| node_activity_routes
node_flask -->|"registers route"| node_goal_routes
node_flask -->|"registers route"| node_analytics_routes
node_flask -->|"registers route"| node_compare_routes
node_flask -->|"registers route"| node_chat_routes
node_flask -->|"registers route"| node_profile_routes
node_flask -->|"registers route"| node_water_routes
node_flask -->|"registers route"| node_streak_routes
node_flask -->|"registers route"| node_social_routes
node_meal_analysis -->|"validates with"| node_schemas
node_activity_routes -->|"validates with"| node_schemas
node_meal_analysis -->|"requests score"| node_ml_routes
node_meal_analysis -->|"analyzes meals"| node_gemini_client
node_goal_routes -->|"generates plans"| node_gemini_client
node_chat_routes -->|"generates reply"| node_gemini_client
node_gemini_client -->|"calls providers"| node_ai_providers
node_meal_analysis -->|"saves food logs"| node_mongo_client
node_activity_routes -->|"reads and writes"| node_mongo_client
node_goal_routes -->|"reads and writes"| node_mongo_client
node_compare_routes -->|"reads food data"| node_mongo_client
node_chat_routes -->|"loads user context"| node_mongo_client
node_strava_routes -->|"stores synced data"| node_mongo_client
node_mongo_client -->|"connects"| node_mongo
node_auth_middleware -->|"verifies fallback"| node_supabase_client
node_supabase_client -->|"creates client"| node_supabase
node_strava_routes -->|"syncs workouts"| node_strava
node_strava_routes -->|"protects routes"| node_auth_middleware
node_meal_analysis -->|"protects route"| node_auth_middleware
node_chat_routes -->|"protects route"| node_auth_middleware

click node_dashboard "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/dashboard/page.tsx"
click node_meal_entry "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/components/LogForm.tsx"
click node_activity_views "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/activities/page.tsx"
click node_goals_ui "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/goals/page.tsx"
click node_insights "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/insights/page.tsx"
click node_compare_ui "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/compare/page.tsx"
click node_api_client "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/lib/api.ts"
click node_auth_ui "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/components/AuthProvider.tsx"
click node_supabase_web "https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/lib/supabase/client.ts"
click node_flask "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/__init__.py"
click node_auth_middleware "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/auth.py"
click node_meal_analysis "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/llm.py"
click node_food_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/manual_food.py"
click node_activity_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/activities.py"
click node_goal_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/goals.py"
click node_analytics_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/analytics.py"
click node_compare_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/compare.py"
click node_chat_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/chat.py"
click node_profile_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/profile.py"
click node_water_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/water.py"
click node_streak_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/streaks.py"
click node_social_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/social.py"
click node_schemas "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/schemas.py"
click node_ml_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/ml.py"
click node_gemini_client "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/gemini.py"
click node_mongo_client "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/mongo_client.py"
click node_supabase_client "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/supabase_client.py"
click node_strava_routes "https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/strava.py"

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_dashboard,node_meal_entry,node_activity_views,node_goals_ui,node_insights,node_compare_ui,node_api_client,node_user toneBlue
class node_auth_ui,node_supabase_web,node_auth_middleware toneAmber
class node_flask,node_meal_analysis,node_food_routes,node_activity_routes,node_goal_routes,node_analytics_routes,node_compare_routes,node_chat_routes,node_profile_routes,node_water_routes,node_streak_routes,node_social_routes,node_schemas toneMint
class node_ml_routes,node_gemini_client toneRose
class node_mongo_client,node_mongo,node_supabase_client,node_supabase,node_strava_routes,node_strava,node_ai_providers toneIndigo
```

## Components

### Web experience

- [Dashboard](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/dashboard/page.tsx): `frontend/src/app/dashboard/page.tsx`
- [Meal logging](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/components/LogForm.tsx): `frontend/src/components/LogForm.tsx`
- [Activity views](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/activities/page.tsx): `frontend/src/app/activities/page.tsx`
- [Goal management](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/goals/page.tsx): `frontend/src/app/goals/page.tsx`
- [Insights and history](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/insights/page.tsx): `frontend/src/app/insights/page.tsx`
- [Comparison view](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/app/compare/page.tsx): `frontend/src/app/compare/page.tsx`
- [API client](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### Identity

- [Web authentication](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/components/AuthProvider.tsx): `frontend/src/components/AuthProvider.tsx`
- [Supabase web client](https://github.com/mzuhaibkhan/nutritrac/blob/main/frontend/src/lib/supabase/client.ts): `frontend/src/lib/supabase/client.ts`
- [JWT verification](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/auth.py): `backend/app/auth.py`

### Nutrition and activity APIs

- [Flask API](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/__init__.py): `backend/app/__init__.py`
- [AI meal analysis](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/llm.py): `backend/app/routes/llm.py`
- [Food logging](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/manual_food.py): `backend/app/routes/manual_food.py`
- [Activity tracking](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/activities.py): `backend/app/routes/activities.py`
- [Goals and meal plans](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/goals.py): `backend/app/routes/goals.py`
- [Nutrition analytics](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/analytics.py): `backend/app/routes/analytics.py`
- [Food comparison](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/compare.py): `backend/app/routes/compare.py`
- [Nutrition chat](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/chat.py): `backend/app/routes/chat.py`
- [User profile](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/profile.py): `backend/app/routes/profile.py`
- [Water tracking](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/water.py): `backend/app/routes/water.py`
- [Streak tracking](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/streaks.py): `backend/app/routes/streaks.py`
- [Social sharing](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/social.py): `backend/app/routes/social.py`
- [Request schemas](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### AI and scoring

- [Health scoring](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/ml.py): `backend/app/routes/ml.py`
- [AI provider client](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/gemini.py): `backend/app/gemini.py`

### Integrations and data

- [MongoDB access](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/mongo_client.py): `backend/app/mongo_client.py`
- **MongoDB Atlas**
- [Supabase verifier client](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/supabase_client.py): `backend/app/supabase_client.py`
- **Supabase Auth**
- [Strava sync](https://github.com/mzuhaibkhan/nutritrac/blob/main/backend/app/routes/strava.py): `backend/app/routes/strava.py`
- **Strava API**
- **AI services**

### Other components

- **Browser user**

## Connections

- Browser user → Dashboard: views
- Browser user → Meal logging: logs meals
- Browser user → Activity views: tracks workouts
- Browser user → Goal management: sets goals
- Meal logging → API client: submits data
- Activity views → API client: requests data
- Goal management → API client: requests plans
- Dashboard → API client: requests summaries
- Insights and history → API client: requests trends
- Comparison view → API client: requests comparison
- Web authentication → Supabase web client: uses (evidence: `frontend/src/components/AuthProvider.tsx`)
- API client → Flask API: calls API
- Flask API → AI meal analysis: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Food logging: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Activity tracking: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Goals and meal plans: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Nutrition analytics: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Food comparison: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Nutrition chat: registers route (evidence: `backend/app/__init__.py`)
- Flask API → User profile: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Water tracking: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Streak tracking: registers route (evidence: `backend/app/__init__.py`)
- Flask API → Social sharing: registers route (evidence: `backend/app/__init__.py`)
- AI meal analysis → Request schemas: validates with (evidence: `backend/app/routes/llm.py`)
- Activity tracking → Request schemas: validates with (evidence: `backend/app/routes/activities.py`)
- AI meal analysis → Health scoring: requests score (evidence: `backend/app/routes/llm.py`)
- AI meal analysis → AI provider client: analyzes meals (evidence: `backend/app/routes/llm.py`)
- Goals and meal plans → AI provider client: generates plans (evidence: `backend/app/routes/goals.py`)
- Nutrition chat → AI provider client: generates reply (evidence: `backend/app/routes/chat.py`)
- AI provider client → AI services: calls providers
- AI meal analysis → MongoDB access: saves food logs (evidence: `backend/app/routes/llm.py`)
- Activity tracking → MongoDB access: reads and writes (evidence: `backend/app/routes/activities.py`)
- Goals and meal plans → MongoDB access: reads and writes (evidence: `backend/app/routes/goals.py`)
- Food comparison → MongoDB access: reads food data (evidence: `backend/app/routes/compare.py`)
- Nutrition chat → MongoDB access: loads user context (evidence: `backend/app/routes/chat.py`)
- Strava sync → MongoDB access: stores synced data (evidence: `backend/app/routes/strava.py`)
- MongoDB access → MongoDB Atlas: connects (evidence: `backend/app/mongo_client.py`)
- JWT verification → Supabase verifier client: verifies fallback (evidence: `backend/app/auth.py`)
- Supabase verifier client → Supabase Auth: creates client (evidence: `backend/app/supabase_client.py`)
- Strava sync → Strava API: syncs workouts
- Strava sync → JWT verification: protects routes (evidence: `backend/app/routes/strava.py`)
- AI meal analysis → JWT verification: protects route (evidence: `backend/app/routes/llm.py`)
- Nutrition chat → JWT verification: protects route (evidence: `backend/app/routes/chat.py`)
