# mirier1/tg_bot architecture

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

- Interactive diagram: https://gitdiagram.com/mirier1/tg_bot
- Repository: https://github.com/mirier1/tg_bot

## Overview

TG_Bot is an aiogram Telegram bot for learning about the Sustainable Development Goals (SDGs), with quizzes, mini-games, and community features. Its likely user journey starts in the bot’s menu, then branches into SDG content, quizzes or games; users can also submit questions, apply to be ambassadors, give feedback, or enter a contest. Admin handlers manage content, applications, and reporting. The README is only a title, so capabilities are inferred from the source index and excerpts; edges are limited to relationships those sources support.

Main entry points: [`bot.py`](https://github.com/mirier1/tg_bot/blob/main/bot.py) (Bot runtime), [`database.py`](https://github.com/mirier1/tg_bot/blob/main/database.py) (Database access), [`handlers/main_menu.py`](https://github.com/mirier1/tg_bot/blob/main/handlers/main_menu.py) (Main menu), [`handlers/sdg.py`](https://github.com/mirier1/tg_bot/blob/main/handlers/sdg.py) (SDG content)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Bot and profiles"]
  node_bot_runtime["Bot runtime<br/>[bot.py]"]
  node_configuration["Configuration<br/>[config.py]"]
  node_start_profile["Start and profile<br/>[start.py]"]
  node_settings["Profile settings<br/>[settings.py]"]
  node_main_menu["Main menu<br/>[main_menu.py]"]
  node_menu_keyboard["Menu keyboard<br/>[main_menu_kb.py]"]
end

subgraph group_learning["SDG learning"]
  node_sdg_content["SDG content<br/>[sdg.py]"]
  node_sdg_data["SDG constants<br/>[constants.py]"]
  node_sdg_keyboards["SDG keyboards<br/>[sdg_keyboards.py]"]
end

subgraph group_activities["Quizzes and games"]
  node_quiz_flow["Quiz flow<br/>[quizzes.py]"]
  node_quiz_questions["Quiz questions<br/>[quiz_questions.py]"]
  node_game_menu["Game menu<br/>[menu.py]"]
  node_game_handlers["Mini-games"]
  node_game_data["Game content<br/>[games_data.py]"]
  node_story_game["Story game<br/>[story.py]"]
  node_story_engine["Story rules<br/>[story_engine.py]"]
end

subgraph group_community["Community features"]
  node_questions["Expert questions<br/>[questions.py]"]
  node_ambassadors["Ambassador applications<br/>[ambassador.py]"]
  node_feedback["Feedback<br/>[feedback.py]"]
  node_contest["Video contest<br/>[contest.py]"]
end

subgraph group_platform["Data and administration"]
  node_admin["Admin operations<br/>[admin.py]"]
  node_admin_content["Content management<br/>[admin_content.py]"]
  node_admin_keyboards["Admin keyboards<br/>[admin_kb.py]"]
  node_analytics["Activity analytics<br/>[analytics.py]"]
  node_database_access["Database access<br/>[database.py]"]
  node_models["Domain models<br/>[models.py]"]
  node_game_results["Game result helper<br/>[utils.py]"]
end

node_telegram_user(("Telegram user"))

node_telegram_user -->|"sends updates"| node_bot_runtime
node_bot_runtime -->|"loads settings"| node_configuration
node_bot_runtime -->|"registers handler"| node_main_menu
node_bot_runtime -->|"registers handler"| node_sdg_content
node_bot_runtime -->|"registers handler"| node_start_profile
node_bot_runtime -->|"registers handler"| node_settings
node_bot_runtime -->|"registers handler"| node_quiz_flow
node_bot_runtime -->|"registers handler"| node_admin
node_bot_runtime -->|"registers handlers"| node_game_handlers
node_bot_runtime -->|"registers handler"| node_ambassadors
node_bot_runtime -->|"registers handler"| node_feedback
node_bot_runtime -->|"registers handler"| node_contest
node_main_menu -->|"builds menu"| node_menu_keyboard
node_main_menu -->|"routes to"| node_sdg_content
node_main_menu -->|"routes to"| node_questions
node_main_menu -->|"routes to"| node_ambassadors
node_main_menu -->|"routes to"| node_game_menu
node_sdg_content -->|"uses titles"| node_sdg_data
node_sdg_content -->|"builds choices"| node_sdg_keyboards
node_sdg_content -->|"logs activity"| node_analytics
node_quiz_flow -->|"selects questions"| node_quiz_questions
node_quiz_flow -->|"reads and saves"| node_database_access
node_quiz_flow -->|"logs activity"| node_analytics
node_game_handlers -->|"uses game content"| node_game_data
node_story_game -->|"uses story rules"| node_story_engine
node_story_game -->|"saves progress"| node_database_access
node_story_game -->|"saves results"| node_game_results
node_game_results -->|"writes scores"| node_database_access
node_questions -->|"stores questions"| node_database_access
node_ambassadors -->|"stores applications"| node_database_access
node_feedback -->|"stores feedback"| node_database_access
node_contest -->|"stores entries"| node_database_access
node_admin -->|"queries records"| node_database_access
node_admin -->|"uses reporting"| node_analytics
node_admin_content -->|"updates content"| node_database_access
node_admin -->|"shows controls"| node_admin_keyboards
node_database_access -->|"creates tables"| node_models
node_analytics -->|"writes activity"| node_database_access
node_analytics -->|"records activity"| node_models

click node_bot_runtime "https://github.com/mirier1/tg_bot/blob/main/bot.py"
click node_configuration "https://github.com/mirier1/tg_bot/blob/main/config.py"
click node_start_profile "https://github.com/mirier1/tg_bot/blob/main/handlers/start.py"
click node_settings "https://github.com/mirier1/tg_bot/blob/main/handlers/settings.py"
click node_main_menu "https://github.com/mirier1/tg_bot/blob/main/handlers/main_menu.py"
click node_menu_keyboard "https://github.com/mirier1/tg_bot/blob/main/keyboards/main_menu_kb.py"
click node_sdg_content "https://github.com/mirier1/tg_bot/blob/main/handlers/sdg.py"
click node_sdg_data "https://github.com/mirier1/tg_bot/blob/main/utils/constants.py"
click node_sdg_keyboards "https://github.com/mirier1/tg_bot/blob/main/keyboards/sdg_keyboards.py"
click node_quiz_flow "https://github.com/mirier1/tg_bot/blob/main/handlers/quizzes.py"
click node_quiz_questions "https://github.com/mirier1/tg_bot/blob/main/data/quiz_questions.py"
click node_game_menu "https://github.com/mirier1/tg_bot/blob/main/handlers/games/menu.py"
click node_game_handlers "https://github.com/mirier1/tg_bot/tree/main/handlers/games"
click node_game_data "https://github.com/mirier1/tg_bot/blob/main/data/games_data.py"
click node_story_game "https://github.com/mirier1/tg_bot/blob/main/handlers/games/story.py"
click node_story_engine "https://github.com/mirier1/tg_bot/blob/main/data/story_engine.py"
click node_questions "https://github.com/mirier1/tg_bot/blob/main/handlers/questions.py"
click node_ambassadors "https://github.com/mirier1/tg_bot/blob/main/handlers/ambassador.py"
click node_feedback "https://github.com/mirier1/tg_bot/blob/main/handlers/feedback.py"
click node_contest "https://github.com/mirier1/tg_bot/blob/main/handlers/contest.py"
click node_admin "https://github.com/mirier1/tg_bot/blob/main/handlers/admin.py"
click node_admin_content "https://github.com/mirier1/tg_bot/blob/main/handlers/admin_content.py"
click node_admin_keyboards "https://github.com/mirier1/tg_bot/blob/main/keyboards/admin_kb.py"
click node_analytics "https://github.com/mirier1/tg_bot/blob/main/services/analytics.py"
click node_database_access "https://github.com/mirier1/tg_bot/blob/main/database.py"
click node_models "https://github.com/mirier1/tg_bot/blob/main/models.py"
click node_game_results "https://github.com/mirier1/tg_bot/blob/main/handlers/games/utils.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_bot_runtime,node_configuration,node_start_profile,node_settings,node_main_menu,node_menu_keyboard,node_telegram_user toneBlue
class node_sdg_content,node_sdg_data,node_sdg_keyboards toneAmber
class node_quiz_flow,node_quiz_questions,node_game_menu,node_game_handlers,node_game_data,node_story_game,node_story_engine toneMint
class node_questions,node_ambassadors,node_feedback,node_contest toneRose
class node_admin,node_admin_content,node_admin_keyboards,node_analytics,node_database_access,node_models,node_game_results toneIndigo
```

## Components

### Bot and profiles

- [Bot runtime](https://github.com/mirier1/tg_bot/blob/main/bot.py): `bot.py`
- [Configuration](https://github.com/mirier1/tg_bot/blob/main/config.py): `config.py`
- [Start and profile](https://github.com/mirier1/tg_bot/blob/main/handlers/start.py): `handlers/start.py`
- [Profile settings](https://github.com/mirier1/tg_bot/blob/main/handlers/settings.py): `handlers/settings.py`
- [Main menu](https://github.com/mirier1/tg_bot/blob/main/handlers/main_menu.py): `handlers/main_menu.py`
- [Menu keyboard](https://github.com/mirier1/tg_bot/blob/main/keyboards/main_menu_kb.py): `keyboards/main_menu_kb.py`

### SDG learning

- [SDG content](https://github.com/mirier1/tg_bot/blob/main/handlers/sdg.py): `handlers/sdg.py`
- [SDG constants](https://github.com/mirier1/tg_bot/blob/main/utils/constants.py): `utils/constants.py`
- [SDG keyboards](https://github.com/mirier1/tg_bot/blob/main/keyboards/sdg_keyboards.py): `keyboards/sdg_keyboards.py`

### Quizzes and games

- [Quiz flow](https://github.com/mirier1/tg_bot/blob/main/handlers/quizzes.py): `handlers/quizzes.py`
- [Quiz questions](https://github.com/mirier1/tg_bot/blob/main/data/quiz_questions.py): `data/quiz_questions.py`
- [Game menu](https://github.com/mirier1/tg_bot/blob/main/handlers/games/menu.py): `handlers/games/menu.py`
- [Mini-games](https://github.com/mirier1/tg_bot/tree/main/handlers/games): `handlers/games`
- [Game content](https://github.com/mirier1/tg_bot/blob/main/data/games_data.py): `data/games_data.py`
- [Story game](https://github.com/mirier1/tg_bot/blob/main/handlers/games/story.py): `handlers/games/story.py`
- [Story rules](https://github.com/mirier1/tg_bot/blob/main/data/story_engine.py): `data/story_engine.py`

### Community features

- [Expert questions](https://github.com/mirier1/tg_bot/blob/main/handlers/questions.py): `handlers/questions.py`
- [Ambassador applications](https://github.com/mirier1/tg_bot/blob/main/handlers/ambassador.py): `handlers/ambassador.py`
- [Feedback](https://github.com/mirier1/tg_bot/blob/main/handlers/feedback.py): `handlers/feedback.py`
- [Video contest](https://github.com/mirier1/tg_bot/blob/main/handlers/contest.py): `handlers/contest.py`

### Data and administration

- [Admin operations](https://github.com/mirier1/tg_bot/blob/main/handlers/admin.py): `handlers/admin.py`
- [Content management](https://github.com/mirier1/tg_bot/blob/main/handlers/admin_content.py): `handlers/admin_content.py`
- [Admin keyboards](https://github.com/mirier1/tg_bot/blob/main/keyboards/admin_kb.py): `keyboards/admin_kb.py`
- [Activity analytics](https://github.com/mirier1/tg_bot/blob/main/services/analytics.py): `services/analytics.py`
- [Database access](https://github.com/mirier1/tg_bot/blob/main/database.py): `database.py`
- [Domain models](https://github.com/mirier1/tg_bot/blob/main/models.py): `models.py`
- [Game result helper](https://github.com/mirier1/tg_bot/blob/main/handlers/games/utils.py): `handlers/games/utils.py`

### Other components

- **Telegram user**

## Connections

- Telegram user → Bot runtime: sends updates
- Bot runtime → Configuration: loads settings (evidence: `bot.py`)
- Bot runtime → Main menu: registers handler (evidence: `bot.py`)
- Bot runtime → SDG content: registers handler (evidence: `bot.py`)
- Bot runtime → Start and profile: registers handler (evidence: `bot.py`)
- Bot runtime → Profile settings: registers handler (evidence: `bot.py`)
- Bot runtime → Quiz flow: registers handler (evidence: `bot.py`)
- Bot runtime → Admin operations: registers handler (evidence: `bot.py`)
- Bot runtime → Mini-games: registers handlers (evidence: `bot.py`)
- Bot runtime → Ambassador applications: registers handler (evidence: `bot.py`)
- Bot runtime → Feedback: registers handler (evidence: `bot.py`)
- Bot runtime → Video contest: registers handler (evidence: `bot.py`)
- Main menu → Menu keyboard: builds menu (evidence: `handlers/main_menu.py`)
- Main menu → SDG content: routes to (evidence: `handlers/main_menu.py`)
- Main menu → Expert questions: routes to (evidence: `handlers/main_menu.py`)
- Main menu → Ambassador applications: routes to (evidence: `handlers/main_menu.py`)
- Main menu → Game menu: routes to (evidence: `handlers/main_menu.py`)
- SDG content → SDG constants: uses titles (evidence: `handlers/sdg.py`)
- SDG content → SDG keyboards: builds choices (evidence: `handlers/sdg.py`)
- SDG content → Activity analytics: logs activity (evidence: `handlers/sdg.py`)
- Quiz flow → Quiz questions: selects questions (evidence: `handlers/quizzes.py`)
- Quiz flow → Database access: reads and saves (evidence: `handlers/quizzes.py`)
- Quiz flow → Activity analytics: logs activity (evidence: `handlers/quizzes.py`)
- Mini-games → Game content: uses game content (evidence: `handlers/games/good_habits.py`)
- Story game → Story rules: uses story rules (evidence: `handlers/games/story.py`)
- Story game → Database access: saves progress (evidence: `handlers/games/story.py`)
- Story game → Game result helper: saves results (evidence: `handlers/games/story.py`)
- Game result helper → Database access: writes scores (evidence: `handlers/games/utils.py`)
- Expert questions → Database access: stores questions (evidence: `handlers/questions.py`)
- Ambassador applications → Database access: stores applications (evidence: `handlers/ambassador.py`)
- Feedback → Database access: stores feedback (evidence: `handlers/feedback.py`)
- Video contest → Database access: stores entries (evidence: `handlers/contest.py`)
- Admin operations → Database access: queries records (evidence: `handlers/admin.py`)
- Admin operations → Activity analytics: uses reporting (evidence: `handlers/admin.py`)
- Content management → Database access: updates content (evidence: `handlers/admin_content.py`)
- Admin operations → Admin keyboards: shows controls (evidence: `handlers/admin.py`)
- Database access → Domain models: creates tables (evidence: `database.py`)
- Activity analytics → Database access: writes activity (evidence: `services/analytics.py`)
- Activity analytics → Domain models: records activity (evidence: `services/analytics.py`)
