# bhumii23/cal-ai architecture

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

- Interactive diagram: https://gitdiagram.com/bhumii23/cal-ai
- Repository: https://github.com/bhumii23/cal-ai

## Overview

Cal AI is a nutrition-tracking web app. Users authenticate, review a dashboard, log meals (including a photo-analysis workflow), and manage nutrition goals and profile settings; history provides a separate tracking view. Authentication and nutrition data use Supabase when configured, with local-storage fallback for app data. The major unsampled pages and analysis endpoint are represented from the tree, but their internal calls are not inferred. The README is a generic Next.js starter and documents no additional product capabilities.

Main entry points: [`src/lib/db.ts`](https://github.com/bhumii23/cal-ai/blob/master/src/lib/db.ts) (Nutrition data), [`src/lib/auth.ts`](https://github.com/bhumii23/cal-ai/blob/master/src/lib/auth.ts) (Auth logic), [`src/app/auth/page.tsx`](https://github.com/bhumii23/cal-ai/blob/master/src/app/auth/page.tsx) (Sign in), [`src/app/profile/page.tsx`](https://github.com/bhumii23/cal-ai/blob/master/src/app/profile/page.tsx) (Profile settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_auth_page["Sign in<br/>[page.tsx]"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_profile["Profile settings<br/>[page.tsx]"]
end

subgraph group_nutrition["Nutrition workflows"]
  node_diary["Food diary<br/>[page.tsx]"]
  node_analysis_api["Meal analysis<br/>[route.ts]"]
  node_history["Nutrition history<br/>[page.tsx]"]
  node_goals["Goal tracking<br/>[page.tsx]"]
end

subgraph group_identity["Identity and persistence"]
  node_auth_logic["Auth logic<br/>[auth.ts]"]
  node_middleware["Route auth gate<br/>[middleware.ts]"]
  node_data_access["Nutrition data<br/>[db.ts]"]
  node_supabase_client["Supabase client<br/>[supabaseClient.ts]"]
end

subgraph group_platform["External services"]
  node_local_storage[("Browser storage")]
  node_supabase[("Supabase")]
  node_analysis_provider["AI analysis provider"]
end

node_user(("User"))

node_user -->|"signs in"| node_auth_page
node_user -->|"tracks nutrition"| node_dashboard
node_user -->|"logs meals"| node_diary
node_user -.->|"reviews history"| node_history
node_user -.->|"sets goals"| node_goals
node_user -->|"edits profile"| node_profile
node_auth_page -->|"calls auth"| node_auth_logic
node_auth_page -->|"checks setup"| node_supabase_client
node_middleware -->|"checks session"| node_supabase
node_dashboard -->|"loads and adds"| node_data_access
node_diary -->|"loads and edits"| node_data_access
node_profile -->|"reads and updates"| node_auth_logic
node_profile -->|"loads and saves"| node_data_access
node_history -.->|"loads nutrition data"| node_data_access
node_goals -.->|"loads and saves goals"| node_data_access
node_diary -.->|"requests analysis"| node_analysis_api
node_analysis_api -.->|"requests estimates"| node_analysis_provider
node_auth_logic -->|"creates client"| node_supabase_client
node_data_access -->|"gets session scope"| node_auth_logic
node_data_access -->|"creates client"| node_supabase_client
node_auth_logic -->|"stores fallback auth"| node_local_storage
node_data_access -->|"stores fallback data"| node_local_storage
node_auth_logic -->|"uses auth"| node_supabase
node_data_access -->|"reads and writes"| node_supabase

click node_auth_page "https://github.com/bhumii23/cal-ai/blob/master/src/app/auth/page.tsx"
click node_dashboard "https://github.com/bhumii23/cal-ai/blob/master/src/app/page.tsx"
click node_diary "https://github.com/bhumii23/cal-ai/blob/master/src/app/diary/page.tsx"
click node_analysis_api "https://github.com/bhumii23/cal-ai/blob/master/src/app/api/analyze/route.ts"
click node_history "https://github.com/bhumii23/cal-ai/blob/master/src/app/history/page.tsx"
click node_goals "https://github.com/bhumii23/cal-ai/blob/master/src/app/goals/page.tsx"
click node_profile "https://github.com/bhumii23/cal-ai/blob/master/src/app/profile/page.tsx"
click node_auth_logic "https://github.com/bhumii23/cal-ai/blob/master/src/lib/auth.ts"
click node_middleware "https://github.com/bhumii23/cal-ai/blob/master/middleware.ts"
click node_data_access "https://github.com/bhumii23/cal-ai/blob/master/src/lib/db.ts"
click node_supabase_client "https://github.com/bhumii23/cal-ai/blob/master/src/lib/supabaseClient.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_auth_page,node_dashboard,node_profile,node_user toneBlue
class node_diary,node_analysis_api,node_history,node_goals toneAmber
class node_auth_logic,node_middleware,node_data_access,node_supabase_client toneMint
class node_local_storage,node_supabase,node_analysis_provider toneRose
```

## Components

### User experience

- [Sign in](https://github.com/bhumii23/cal-ai/blob/master/src/app/auth/page.tsx): `src/app/auth/page.tsx`
- [Dashboard](https://github.com/bhumii23/cal-ai/blob/master/src/app/page.tsx): `src/app/page.tsx`
- [Profile settings](https://github.com/bhumii23/cal-ai/blob/master/src/app/profile/page.tsx): `src/app/profile/page.tsx`

### Nutrition workflows

- [Food diary](https://github.com/bhumii23/cal-ai/blob/master/src/app/diary/page.tsx): `src/app/diary/page.tsx`
- [Meal analysis](https://github.com/bhumii23/cal-ai/blob/master/src/app/api/analyze/route.ts): `src/app/api/analyze/route.ts`
- [Nutrition history](https://github.com/bhumii23/cal-ai/blob/master/src/app/history/page.tsx): `src/app/history/page.tsx`
- [Goal tracking](https://github.com/bhumii23/cal-ai/blob/master/src/app/goals/page.tsx): `src/app/goals/page.tsx`

### Identity and persistence

- [Auth logic](https://github.com/bhumii23/cal-ai/blob/master/src/lib/auth.ts): `src/lib/auth.ts`
- [Route auth gate](https://github.com/bhumii23/cal-ai/blob/master/middleware.ts): `middleware.ts`
- [Nutrition data](https://github.com/bhumii23/cal-ai/blob/master/src/lib/db.ts): `src/lib/db.ts`
- [Supabase client](https://github.com/bhumii23/cal-ai/blob/master/src/lib/supabaseClient.ts): `src/lib/supabaseClient.ts`

### External services

- **Browser storage**
- **Supabase**
- **AI analysis provider**

### Other components

- **User**

## Connections

- User → Sign in: signs in (evidence: `src/app/auth/page.tsx`)
- User → Dashboard: tracks nutrition (evidence: `src/app/page.tsx`)
- User → Food diary: logs meals (evidence: `src/app/diary/page.tsx`)
- User → Nutrition history: reviews history
- User → Goal tracking: sets goals
- User → Profile settings: edits profile (evidence: `src/app/profile/page.tsx`)
- Sign in → Auth logic: calls auth (evidence: `src/app/auth/page.tsx`)
- Sign in → Supabase client: checks setup (evidence: `src/app/auth/page.tsx`)
- Route auth gate → Supabase: checks session (evidence: `middleware.ts`)
- Dashboard → Nutrition data: loads and adds (evidence: `src/app/page.tsx`)
- Food diary → Nutrition data: loads and edits (evidence: `src/app/diary/page.tsx`)
- Profile settings → Auth logic: reads and updates (evidence: `src/app/profile/page.tsx`)
- Profile settings → Nutrition data: loads and saves (evidence: `src/app/profile/page.tsx`)
- Nutrition history → Nutrition data: loads nutrition data
- Goal tracking → Nutrition data: loads and saves goals
- Food diary → Meal analysis: requests analysis
- Meal analysis → AI analysis provider: requests estimates
- Auth logic → Supabase client: creates client (evidence: `src/lib/auth.ts`)
- Nutrition data → Auth logic: gets session scope (evidence: `src/lib/db.ts`)
- Nutrition data → Supabase client: creates client (evidence: `src/lib/db.ts`)
- Auth logic → Browser storage: stores fallback auth (evidence: `src/lib/auth.ts`)
- Nutrition data → Browser storage: stores fallback data (evidence: `src/lib/db.ts`)
- Auth logic → Supabase: uses auth (evidence: `src/lib/auth.ts`)
- Nutrition data → Supabase: reads and writes (evidence: `src/lib/db.ts`)
