# kushal-at/nutriscanai26 architecture

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

- Interactive diagram: https://gitdiagram.com/kushal-at/nutriscanai26
- Repository: https://github.com/kushal-at/nutriscanai26

## Overview

NutraVision analyzes paired meal photos: the web client submits them to the nutrition API, which orchestrates vision-based component and portion estimation, then predicts and aggregates nutrients. The vision service combines segmentation, plate calibration, local multimodal interpretation, and density-based weight estimation; the nutrition service resolves food features and runs CatBoost models. The frontend also documents diary and dashboard capabilities, while sampled sync code shows optional Supabase authentication and cloud synchronization. Some frontend and service wiring is documented rather than fully sampled, so those links cite the README.

Main entry points: [`vision/app.py`](https://github.com/kushal-at/nutriscanai26/blob/main/vision/app.py) (Vision API), [`ML/app.py`](https://github.com/kushal-at/nutriscanai26/blob/main/ML/app.py) (Nutrition API), [`FrontEnd/script.js`](https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/script.js) (Client controller), [`ML/predictor.py`](https://github.com/kushal-at/nutriscanai26/blob/main/ML/predictor.py) (Nutrition prediction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_webui["Meal UI<br/>[index.html]"]
  node_clientapp["Client controller<br/>[script.js]"]
  node_diary["Food diary<br/>[script.js]"]
end

subgraph group_vision["Vision service"]
  node_visionapi["Vision API<br/>[app.py]"]
  node_segment["Food segmentation<br/>[segmentation.py]"]
  node_segmodel["Segmentation model<br/>[best_model.pth]"]
  node_vlm["Meal interpretation<br/>[vlm.py]"]
  node_weight["Portion estimation<br/>[estimation.py]"]
  node_density["Food density data<br/>[food_density.json]"]
end

subgraph group_nutrition["Nutrition service"]
  node_api["Nutrition API<br/>[app.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
  node_predictor["Nutrition prediction<br/>[predictor.py]"]
  node_preprocessor["Food preprocessing<br/>[preprocessor.py]"]
  node_models["CatBoost models<br/>[energy_kcal.cbm]"]
end

subgraph group_sync["Account sync"]
  node_syncengine["Sync engine<br/>[sync.js]"]
  node_syncconfig["Supabase config<br/>[supabase-config.js]"]
end

node_user(("Meal user"))
node_supabase[("Supabase")]
node_ollama["Ollama Qwen"]

node_user -->|"submits photos"| node_webui
node_webui -->|"runs interface"| node_clientapp
node_clientapp -->|"requests analysis"| node_api
node_api -->|"forwards photos"| node_visionapi
node_visionapi -->|"segments images"| node_segment
node_segment -.->|"uses weights"| node_segmodel
node_visionapi -->|"interprets meal"| node_vlm
node_vlm -->|"queries model"| node_ollama
node_visionapi -->|"estimates portions"| node_weight
node_weight -.->|"reads density"| node_density
node_visionapi -->|"returns estimates"| node_api
node_api -->|"predicts nutrients"| node_predictor
node_api -->|"validates requests"| node_schemas
node_predictor -->|"builds features"| node_preprocessor
node_predictor -->|"loads regressors"| node_models
node_syncengine -->|"reads credentials"| node_syncconfig
node_syncengine -->|"syncs account data"| node_supabase
node_clientapp -->|"manages diary"| node_diary

click node_webui "https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/index.html"
click node_clientapp "https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/script.js"
click node_diary "https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/script.js"
click node_syncengine "https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/sync.js"
click node_syncconfig "https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/supabase-config.js"
click node_api "https://github.com/kushal-at/nutriscanai26/blob/main/ML/app.py"
click node_schemas "https://github.com/kushal-at/nutriscanai26/blob/main/ML/schemas.py"
click node_visionapi "https://github.com/kushal-at/nutriscanai26/blob/main/vision/app.py"
click node_segment "https://github.com/kushal-at/nutriscanai26/blob/main/vision/segmentation.py"
click node_segmodel "https://github.com/kushal-at/nutriscanai26/blob/main/vision/models/FoodSeg103/best_model.pth"
click node_vlm "https://github.com/kushal-at/nutriscanai26/blob/main/vision/vlm.py"
click node_weight "https://github.com/kushal-at/nutriscanai26/blob/main/vision/estimation.py"
click node_density "https://github.com/kushal-at/nutriscanai26/blob/main/vision/food_density.json"
click node_predictor "https://github.com/kushal-at/nutriscanai26/blob/main/ML/predictor.py"
click node_preprocessor "https://github.com/kushal-at/nutriscanai26/blob/main/ML/preprocessor.py"
click node_models "https://github.com/kushal-at/nutriscanai26/blob/main/ML/energy_kcal.cbm"

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_webui,node_clientapp,node_diary,node_user toneBlue
class node_visionapi,node_segment,node_segmodel,node_vlm,node_weight,node_density,node_supabase toneAmber
class node_api,node_schemas,node_predictor,node_preprocessor,node_models toneMint
class node_syncengine,node_syncconfig toneRose
class node_ollama toneIndigo
```

## Components

### Web client

- [Meal UI](https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/index.html): `FrontEnd/index.html`
- [Client controller](https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/script.js): `FrontEnd/script.js`
- [Food diary](https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/script.js): `FrontEnd/script.js`

### Vision service

- [Vision API](https://github.com/kushal-at/nutriscanai26/blob/main/vision/app.py): `vision/app.py`
- [Food segmentation](https://github.com/kushal-at/nutriscanai26/blob/main/vision/segmentation.py): `vision/segmentation.py`
- [Segmentation model](https://github.com/kushal-at/nutriscanai26/blob/main/vision/models/FoodSeg103/best_model.pth): `vision/models/FoodSeg103/best_model.pth`
- [Meal interpretation](https://github.com/kushal-at/nutriscanai26/blob/main/vision/vlm.py): `vision/vlm.py`
- [Portion estimation](https://github.com/kushal-at/nutriscanai26/blob/main/vision/estimation.py): `vision/estimation.py`
- [Food density data](https://github.com/kushal-at/nutriscanai26/blob/main/vision/food_density.json): `vision/food_density.json`

### Nutrition service

- [Nutrition API](https://github.com/kushal-at/nutriscanai26/blob/main/ML/app.py): `ML/app.py`
- [API schemas](https://github.com/kushal-at/nutriscanai26/blob/main/ML/schemas.py): `ML/schemas.py`
- [Nutrition prediction](https://github.com/kushal-at/nutriscanai26/blob/main/ML/predictor.py): `ML/predictor.py`
- [Food preprocessing](https://github.com/kushal-at/nutriscanai26/blob/main/ML/preprocessor.py): `ML/preprocessor.py`
- [CatBoost models](https://github.com/kushal-at/nutriscanai26/blob/main/ML/energy_kcal.cbm): `ML/energy_kcal.cbm`

### Account sync

- [Sync engine](https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/sync.js): `FrontEnd/sync.js`
- [Supabase config](https://github.com/kushal-at/nutriscanai26/blob/main/FrontEnd/supabase-config.js): `FrontEnd/supabase-config.js`

### Other components

- **Meal user**
- **Supabase**
- **Ollama Qwen**

## Connections

- Meal user → Meal UI: submits photos (evidence: `README.md`)
- Meal UI → Client controller: runs interface (evidence: `README.md`)
- Client controller → Nutrition API: requests analysis (evidence: `README.md`)
- Nutrition API → Vision API: forwards photos (evidence: `ML/app.py`)
- Vision API → Food segmentation: segments images (evidence: `vision/app.py`)
- Food segmentation → Segmentation model: uses weights
- Vision API → Meal interpretation: interprets meal (evidence: `vision/app.py`)
- Meal interpretation → Ollama Qwen: queries model (evidence: `vision/vlm.py`)
- Vision API → Portion estimation: estimates portions (evidence: `vision/app.py`)
- Portion estimation → Food density data: reads density
- Vision API → Nutrition API: returns estimates (evidence: `README.md`)
- Nutrition API → Nutrition prediction: predicts nutrients (evidence: `ML/app.py`)
- Nutrition API → API schemas: validates requests (evidence: `ML/app.py`)
- Nutrition prediction → Food preprocessing: builds features (evidence: `ML/predictor.py`)
- Nutrition prediction → CatBoost models: loads regressors (evidence: `ML/predictor.py`)
- Sync engine → Supabase config: reads credentials (evidence: `FrontEnd/sync.js`)
- Sync engine → Supabase: syncs account data (evidence: `FrontEnd/sync.js`)
- Client controller → Food diary: manages diary (evidence: `FrontEnd/script.js`)
