# guadoesdev/kainlab architecture

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

- Interactive diagram: https://gitdiagram.com/guadoesdev/kainlab
- Repository: https://github.com/guadoesdev/kainlab

## Overview

KainLab lets users authenticate, log meals by text or food photo, and review nutrition summaries and trends. The browser sends authenticated requests to the Express API; the backend analyzes and validates meal input, then serves meal, profile, chat, and summary data. Supabase provides authentication and persistent PostgreSQL storage, while the in-memory repositories are an alternative backend store. The README documents additional dashboard and account capabilities; unsampled route details are not inferred beyond the shown wiring.

Main entry points: [`src/components/TodayScreen.tsx`](https://github.com/guadoesdev/kainlab/blob/main/src/components/TodayScreen.tsx) (Today workspace), [`server.ts`](https://github.com/guadoesdev/kainlab/blob/main/server.ts) (Express API), [`src/App.tsx`](https://github.com/guadoesdev/kainlab/blob/main/src/App.tsx) (App shell), [`src/lib/nutritionRepository.ts`](https://github.com/guadoesdev/kainlab/blob/main/src/lib/nutritionRepository.ts) (Nutrition API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web app"]
  node_app["App shell<br/>[App.tsx]"]
  node_authform["Sign-in and signup<br/>[AuthFormPanel.tsx]"]
  node_today["Today workspace<br/>[TodayScreen.tsx]"]
  node_chat["Meal chat"]
  node_camera["Food camera"]
  node_history["Meal history"]
  node_daily["Daily summary"]
  node_trend["Calorie trends"]
  node_summary["Summary dashboards<br/>[SummaryPage.tsx]"]
  node_profilepage["Profile settings<br/>[ProfilePage.tsx]"]
  node_clientdata["Nutrition API client"]
  node_csv["CSV export<br/>[csvExport.ts]"]
end

subgraph group_account["Identity and profiles"]
  node_auth["Supabase browser auth<br/>[supabaseAuth.ts]"]
  node_profiles["Profile service<br/>[profileService.ts]"]
  node_supabaseauth{{"Supabase Auth"}}
end

subgraph group_api["Nutrition API"]
  node_api["Express API<br/>[server.ts]"]
  node_authmw["JWT verification<br/>[auth.ts]"]
  node_nutrition["Nutrition service"]
  node_gemini["Gemini analysis"]
  node_geminiservice{{"Gemini API"}}
end

subgraph group_data["Nutrition data"]
  node_mealrepo["Meal ledger interface<br/>[mealRepository.ts]"]
  node_suparepo["Supabase repository"]
  node_memoryrepo["Memory repository"]
  node_postgres[("Supabase PostgreSQL<br/>[schema.sql]")]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_app -->|"renders"| node_authform
node_app -->|"renders"| node_today
node_app -->|"subscribes"| node_auth
node_app -->|"syncs profile"| node_profiles
node_authform -->|"authenticates"| node_auth
node_auth -->|"authenticates with"| node_supabaseauth
node_today -->|"renders"| node_chat
node_today -->|"renders"| node_history
node_today -->|"renders"| node_daily
node_today -->|"renders"| node_trend
node_today -->|"renders"| node_summary
node_today -->|"renders"| node_profilepage
node_today -->|"loads nutrition"| node_clientdata
node_chat -->|"opens"| node_camera
node_chat -->|"submits meals"| node_clientdata
node_summary -->|"loads summaries"| node_clientdata
node_summary -->|"exports data"| node_csv
node_profilepage -->|"updates profile"| node_profiles
node_profiles -->|"sends profile requests"| node_api
node_clientdata -->|"sends API requests"| node_api
node_api -->|"verifies requests"| node_authmw
node_api -->|"processes meal input"| node_nutrition
node_api -->|"constructs provider"| node_gemini
node_nutrition -->|"analyzes meals"| node_gemini
node_gemini -->|"requests analysis"| node_geminiservice
node_api -->|"dispatches storage"| node_suparepo
node_api -->|"dispatches storage"| node_memoryrepo
node_suparepo -->|"reads and writes"| node_postgres
node_suparepo -->|"implements interface"| node_mealrepo

click node_app "https://github.com/guadoesdev/kainlab/blob/main/src/App.tsx"
click node_authform "https://github.com/guadoesdev/kainlab/blob/main/src/components/AuthFormPanel.tsx"
click node_today "https://github.com/guadoesdev/kainlab/blob/main/src/components/TodayScreen.tsx"
click node_chat "https://github.com/guadoesdev/kainlab/blob/main/src/components/NutritionChatPanel.tsx"
click node_camera "https://github.com/guadoesdev/kainlab/blob/main/src/components/CameraCaptureModal.tsx"
click node_history "https://github.com/guadoesdev/kainlab/blob/main/src/components/MealHistoryList.tsx"
click node_daily "https://github.com/guadoesdev/kainlab/blob/main/src/components/DailySummaryCard.tsx"
click node_trend "https://github.com/guadoesdev/kainlab/blob/main/src/components/CalorieTrendChart.tsx"
click node_summary "https://github.com/guadoesdev/kainlab/blob/main/src/components/SummaryPage.tsx"
click node_profilepage "https://github.com/guadoesdev/kainlab/blob/main/src/components/ProfilePage.tsx"
click node_clientdata "https://github.com/guadoesdev/kainlab/blob/main/src/lib/nutritionRepository.ts"
click node_csv "https://github.com/guadoesdev/kainlab/blob/main/src/lib/csvExport.ts"
click node_auth "https://github.com/guadoesdev/kainlab/blob/main/src/lib/supabaseAuth.ts"
click node_profiles "https://github.com/guadoesdev/kainlab/blob/main/src/lib/profileService.ts"
click node_api "https://github.com/guadoesdev/kainlab/blob/main/server.ts"
click node_authmw "https://github.com/guadoesdev/kainlab/blob/main/server/middleware/auth.ts"
click node_nutrition "https://github.com/guadoesdev/kainlab/blob/main/server/services/nutritionService.ts"
click node_gemini "https://github.com/guadoesdev/kainlab/blob/main/server/ai/geminiNutritionProvider.ts"
click node_mealrepo "https://github.com/guadoesdev/kainlab/blob/main/server/repositories/mealRepository.ts"
click node_suparepo "https://github.com/guadoesdev/kainlab/blob/main/server/repositories/supabaseNutritionRepository.ts"
click node_memoryrepo "https://github.com/guadoesdev/kainlab/blob/main/server/repositories/memoryNutritionStore.ts"
click node_postgres "https://github.com/guadoesdev/kainlab/blob/main/supabase/schema.sql"

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_app,node_authform,node_today,node_chat,node_camera,node_history,node_daily,node_trend,node_summary,node_profilepage,node_clientdata,node_csv,node_user toneBlue
class node_auth,node_profiles,node_supabaseauth toneAmber
class node_api,node_authmw,node_nutrition,node_gemini,node_geminiservice toneMint
class node_mealrepo,node_suparepo,node_memoryrepo,node_postgres toneRose
```

## Components

### Web app

- [App shell](https://github.com/guadoesdev/kainlab/blob/main/src/App.tsx): `src/App.tsx`
- [Sign-in and signup](https://github.com/guadoesdev/kainlab/blob/main/src/components/AuthFormPanel.tsx): `src/components/AuthFormPanel.tsx`
- [Today workspace](https://github.com/guadoesdev/kainlab/blob/main/src/components/TodayScreen.tsx): `src/components/TodayScreen.tsx`
- [Meal chat](https://github.com/guadoesdev/kainlab/blob/main/src/components/NutritionChatPanel.tsx): `src/components/NutritionChatPanel.tsx`
- [Food camera](https://github.com/guadoesdev/kainlab/blob/main/src/components/CameraCaptureModal.tsx): `src/components/CameraCaptureModal.tsx`
- [Meal history](https://github.com/guadoesdev/kainlab/blob/main/src/components/MealHistoryList.tsx): `src/components/MealHistoryList.tsx`
- [Daily summary](https://github.com/guadoesdev/kainlab/blob/main/src/components/DailySummaryCard.tsx): `src/components/DailySummaryCard.tsx`
- [Calorie trends](https://github.com/guadoesdev/kainlab/blob/main/src/components/CalorieTrendChart.tsx): `src/components/CalorieTrendChart.tsx`
- [Summary dashboards](https://github.com/guadoesdev/kainlab/blob/main/src/components/SummaryPage.tsx): `src/components/SummaryPage.tsx`
- [Profile settings](https://github.com/guadoesdev/kainlab/blob/main/src/components/ProfilePage.tsx): `src/components/ProfilePage.tsx`
- [Nutrition API client](https://github.com/guadoesdev/kainlab/blob/main/src/lib/nutritionRepository.ts): `src/lib/nutritionRepository.ts`
- [CSV export](https://github.com/guadoesdev/kainlab/blob/main/src/lib/csvExport.ts): `src/lib/csvExport.ts`

### Identity and profiles

- [Supabase browser auth](https://github.com/guadoesdev/kainlab/blob/main/src/lib/supabaseAuth.ts): `src/lib/supabaseAuth.ts`
- [Profile service](https://github.com/guadoesdev/kainlab/blob/main/src/lib/profileService.ts): `src/lib/profileService.ts`
- **Supabase Auth**

### Nutrition API

- [Express API](https://github.com/guadoesdev/kainlab/blob/main/server.ts): `server.ts`
- [JWT verification](https://github.com/guadoesdev/kainlab/blob/main/server/middleware/auth.ts): `server/middleware/auth.ts`
- [Nutrition service](https://github.com/guadoesdev/kainlab/blob/main/server/services/nutritionService.ts): `server/services/nutritionService.ts`
- [Gemini analysis](https://github.com/guadoesdev/kainlab/blob/main/server/ai/geminiNutritionProvider.ts): `server/ai/geminiNutritionProvider.ts`
- **Gemini API**

### Nutrition data

- [Meal ledger interface](https://github.com/guadoesdev/kainlab/blob/main/server/repositories/mealRepository.ts): `server/repositories/mealRepository.ts`
- [Supabase repository](https://github.com/guadoesdev/kainlab/blob/main/server/repositories/supabaseNutritionRepository.ts): `server/repositories/supabaseNutritionRepository.ts`
- [Memory repository](https://github.com/guadoesdev/kainlab/blob/main/server/repositories/memoryNutritionStore.ts): `server/repositories/memoryNutritionStore.ts`
- [Supabase PostgreSQL](https://github.com/guadoesdev/kainlab/blob/main/supabase/schema.sql): `supabase/schema.sql`

### Other components

- **User**

## Connections

- User → App shell: uses (evidence: `src/App.tsx`)
- App shell → Sign-in and signup: renders (evidence: `src/App.tsx`)
- App shell → Today workspace: renders (evidence: `src/App.tsx`)
- App shell → Supabase browser auth: subscribes (evidence: `src/App.tsx`)
- App shell → Profile service: syncs profile (evidence: `src/App.tsx`)
- Sign-in and signup → Supabase browser auth: authenticates (evidence: `src/components/AuthFormPanel.tsx`)
- Supabase browser auth → Supabase Auth: authenticates with (evidence: `README.md`)
- Today workspace → Meal chat: renders (evidence: `src/components/TodayScreen.tsx`)
- Today workspace → Meal history: renders (evidence: `src/components/TodayScreen.tsx`)
- Today workspace → Daily summary: renders (evidence: `src/components/TodayScreen.tsx`)
- Today workspace → Calorie trends: renders (evidence: `src/components/TodayScreen.tsx`)
- Today workspace → Summary dashboards: renders (evidence: `src/components/TodayScreen.tsx`)
- Today workspace → Profile settings: renders (evidence: `src/components/TodayScreen.tsx`)
- Today workspace → Nutrition API client: loads nutrition (evidence: `src/components/TodayScreen.tsx`)
- Meal chat → Food camera: opens (evidence: `src/components/NutritionChatPanel.tsx`)
- Meal chat → Nutrition API client: submits meals (evidence: `src/lib/nutritionRepository.ts`)
- Summary dashboards → Nutrition API client: loads summaries (evidence: `src/components/SummaryPage.tsx`)
- Summary dashboards → CSV export: exports data (evidence: `src/components/SummaryPage.tsx`)
- Profile settings → Profile service: updates profile (evidence: `src/components/ProfilePage.tsx`)
- Profile service → Express API: sends profile requests (evidence: `src/lib/profileService.ts`)
- Nutrition API client → Express API: sends API requests (evidence: `src/lib/nutritionRepository.ts`)
- Express API → JWT verification: verifies requests (evidence: `README.md`)
- Express API → Nutrition service: processes meal input (evidence: `server.ts`)
- Express API → Gemini analysis: constructs provider (evidence: `server.ts`)
- Nutrition service → Gemini analysis: analyzes meals (evidence: `server/services/nutritionService.ts`)
- Gemini analysis → Gemini API: requests analysis (evidence: `README.md`)
- Express API → Supabase repository: dispatches storage (evidence: `server.ts`)
- Express API → Memory repository: dispatches storage (evidence: `server.ts`)
- Supabase repository → Supabase PostgreSQL: reads and writes (evidence: `server/repositories/supabaseNutritionRepository.ts`)
- Supabase repository → Meal ledger interface: implements interface (evidence: `server/repositories/supabaseNutritionRepository.ts`)
