# san2003m/telegram-calrorie-bot architecture

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

- Interactive diagram: https://gitdiagram.com/san2003m/telegram-calrorie-bot
- Repository: https://github.com/san2003m/telegram-calrorie-bot

## Overview

A personal Telegram food and calorie logger. Users scan or search packaged foods, look up Korean food-database entries or restaurant menus, enter recipes or manual nutrition, confirm candidates, choose portions, and save intake; they can then review totals and history in Telegram or a private dashboard. The map includes the documented barcode, AI, recipe, and web branches. README-described flows fill gaps where implementation excerpts were unavailable; unsampled internal calls are not inferred.

Main entry points: [`app/telegram.py`](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/telegram.py) (Bot workflows), [`app/web_api.py`](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/web_api.py) (Dashboard API), [`app/health.py`](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/health.py) (Health and web server), [`app/mfds_catalog.py`](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/mfds_catalog.py) (Food database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Food capture"]
  node_handlers["Bot workflows<br/>[telegram.py]"]
  node_barcode["Barcode reader<br/>[barcode.py]"]
  node_image_tools["Image preparation<br/>[image_tools.py]"]
end

subgraph group_nutrition["Nutrition lookup"]
  node_product_lookup["Product lookup<br/>[catalog.py]"]
  node_recognizer["Label recognition<br/>[ai_recognition.py]"]
  node_food_lookup["Food database<br/>[mfds_catalog.py]"]
  node_food_estimator["Food estimation"]
  node_menu_search["Menu search<br/>[menu_ai.py]"]
  node_recipe_parser["Recipe parsing<br/>[recipe_ai.py]"]
  node_recipe_calc["Recipe calculation<br/>[recipe.py]"]
end

subgraph group_records["Records and storage"]
  node_portion["Portion conversion<br/>[portion.py]"]
  node_nutrition_rules["Nutrition normalization<br/>[nutrition.py]"]
  node_repository["Record repository<br/>[repository.py]"]
  node_models["Data models<br/>[models.py]"]
  node_database[("Database engine<br/>[db.py]")]
end

subgraph group_interfaces["User interfaces"]
  node_web_api["Dashboard API<br/>[web_api.py]"]
  node_web_auth["Web authorization<br/>[web_auth.py]"]
  node_dashboard["Dashboard view<br/>[dashboard.py]"]
  node_health["Health and web server<br/>[health.py]"]
  node_main["Application startup<br/>[main.py]"]
end

node_user(("Food logger"))
node_telegram_api(("Telegram"))
node_openai(("OpenAI"))
node_off(("Open Food Facts"))
node_mfds(("MFDS API"))
node_browser(("Dashboard user"))

node_user -->|"sends input"| node_telegram_api
node_telegram_api -->|"delivers updates"| node_handlers
node_handlers -->|"decodes codes"| node_barcode
node_handlers -->|"prepares photos"| node_image_tools
node_handlers -->|"looks up products"| node_product_lookup
node_product_lookup -->|"queries fallback"| node_off
node_handlers -->|"requests recognition"| node_recognizer
node_recognizer -->|"analyzes images"| node_openai
node_handlers -->|"searches foods"| node_food_lookup
node_food_lookup -->|"queries catalog"| node_mfds
node_handlers -->|"requests estimate"| node_food_estimator
node_food_estimator -->|"estimates ingredients"| node_openai
node_handlers -->|"searches menus"| node_menu_search
node_menu_search -->|"searches official data"| node_openai
node_handlers -->|"parses recipe text"| node_recipe_parser
node_recipe_parser -->|"structures ingredients"| node_openai
node_handlers -->|"calculates recipe"| node_recipe_calc
node_recipe_calc -->|"matches ingredients"| node_food_lookup
node_handlers -->|"converts serving"| node_portion
node_handlers -->|"normalizes nutrients"| node_nutrition_rules
node_handlers -->|"saves intake"| node_repository
node_repository -->|"queries and updates"| node_models
node_database -->|"creates schema"| node_models
node_browser -->|"views totals"| node_dashboard
node_dashboard -->|"requests dashboard data"| node_web_api
node_web_api -->|"reads and changes records"| node_repository
node_web_api -->|"checks authorization"| node_web_auth
node_main -->|"registers router"| node_handlers
node_main -->|"starts server"| node_health
node_health -->|"serves dashboard"| node_dashboard
node_health -->|"routes requests"| node_web_api

click node_handlers "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/telegram.py"
click node_barcode "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/barcode.py"
click node_image_tools "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/image_tools.py"
click node_product_lookup "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/catalog.py"
click node_recognizer "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/ai_recognition.py"
click node_food_lookup "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/mfds_catalog.py"
click node_food_estimator "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/food_estimate_ai.py"
click node_menu_search "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/menu_ai.py"
click node_recipe_parser "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/recipe_ai.py"
click node_recipe_calc "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/recipe.py"
click node_portion "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/portion.py"
click node_nutrition_rules "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/nutrition.py"
click node_repository "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/repository.py"
click node_models "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/models.py"
click node_database "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/db.py"
click node_web_api "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/web_api.py"
click node_web_auth "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/web_auth.py"
click node_dashboard "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/dashboard.py"
click node_health "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/health.py"
click node_main "https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/main.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_handlers,node_barcode,node_image_tools,node_browser toneBlue
class node_product_lookup,node_recognizer,node_food_lookup,node_food_estimator,node_menu_search,node_recipe_parser,node_recipe_calc toneAmber
class node_portion,node_nutrition_rules,node_repository,node_models,node_database,node_mfds toneMint
class node_web_api,node_web_auth,node_dashboard,node_health,node_main toneRose
class node_user,node_telegram_api,node_openai,node_off toneIndigo
```

## Components

### Food capture

- [Bot workflows](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/telegram.py): `app/telegram.py`
- [Barcode reader](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/barcode.py): `app/barcode.py`
- [Image preparation](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/image_tools.py): `app/image_tools.py`

### Nutrition lookup

- [Product lookup](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/catalog.py): `app/catalog.py`
- [Label recognition](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/ai_recognition.py): `app/ai_recognition.py`
- [Food database](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/mfds_catalog.py): `app/mfds_catalog.py`
- [Food estimation](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/food_estimate_ai.py): `app/food_estimate_ai.py`
- [Menu search](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/menu_ai.py): `app/menu_ai.py`
- [Recipe parsing](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/recipe_ai.py): `app/recipe_ai.py`
- [Recipe calculation](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/recipe.py): `app/recipe.py`

### Records and storage

- [Portion conversion](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/portion.py): `app/portion.py`
- [Nutrition normalization](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/nutrition.py): `app/nutrition.py`
- [Record repository](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/repository.py): `app/repository.py`
- [Data models](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/models.py): `app/models.py`
- [Database engine](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/db.py): `app/db.py`

### User interfaces

- [Dashboard API](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/web_api.py): `app/web_api.py`
- [Web authorization](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/web_auth.py): `app/web_auth.py`
- [Dashboard view](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/dashboard.py): `app/dashboard.py`
- [Health and web server](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/health.py): `app/health.py`
- [Application startup](https://github.com/san2003m/telegram-calrorie-bot/blob/main/app/main.py): `app/main.py`

### Other components

- **Food logger**
- **Telegram**
- **OpenAI**
- **Open Food Facts**
- **MFDS API**
- **Dashboard user**

## Connections

- Food logger → Telegram: sends input (evidence: `README.md`)
- Telegram → Bot workflows: delivers updates (evidence: `README.md`)
- Bot workflows → Barcode reader: decodes codes (evidence: `app/telegram.py`)
- Bot workflows → Image preparation: prepares photos (evidence: `app/telegram.py`)
- Bot workflows → Product lookup: looks up products (evidence: `app/telegram.py`)
- Product lookup → Open Food Facts: queries fallback (evidence: `README.md`)
- Bot workflows → Label recognition: requests recognition (evidence: `app/telegram.py`)
- Label recognition → OpenAI: analyzes images (evidence: `app/ai_recognition.py`)
- Bot workflows → Food database: searches foods (evidence: `app/telegram.py`)
- Food database → MFDS API: queries catalog (evidence: `README.md`)
- Bot workflows → Food estimation: requests estimate (evidence: `app/telegram.py`)
- Food estimation → OpenAI: estimates ingredients (evidence: `app/food_estimate_ai.py`)
- Bot workflows → Menu search: searches menus (evidence: `app/telegram.py`)
- Menu search → OpenAI: searches official data (evidence: `README.md`)
- Bot workflows → Recipe parsing: parses recipe text (evidence: `app/telegram.py`)
- Recipe parsing → OpenAI: structures ingredients (evidence: `app/recipe_ai.py`)
- Bot workflows → Recipe calculation: calculates recipe (evidence: `app/telegram.py`)
- Recipe calculation → Food database: matches ingredients (evidence: `README.md`)
- Bot workflows → Portion conversion: converts serving (evidence: `app/telegram.py`)
- Bot workflows → Nutrition normalization: normalizes nutrients (evidence: `app/telegram.py`)
- Bot workflows → Record repository: saves intake (evidence: `app/telegram.py`)
- Record repository → Data models: queries and updates (evidence: `app/repository.py`)
- Database engine → Data models: creates schema (evidence: `app/db.py`)
- Dashboard user → Dashboard view: views totals (evidence: `README.md`)
- Dashboard view → Dashboard API: requests dashboard data (evidence: `app/dashboard.py`)
- Dashboard API → Record repository: reads and changes records (evidence: `app/web_api.py`)
- Dashboard API → Web authorization: checks authorization (evidence: `app/health.py`)
- Application startup → Bot workflows: registers router (evidence: `app/main.py`)
- Application startup → Health and web server: starts server (evidence: `app/main.py`)
- Health and web server → Dashboard view: serves dashboard (evidence: `app/health.py`)
- Health and web server → Dashboard API: routes requests (evidence: `app/health.py`)
