# xdefox/mts_hacaton_ai_agent architecture

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

- Interactive diagram: https://gitdiagram.com/xdefox/mts_hacaton_ai_agent
- Repository: https://github.com/xdefox/mts_hacaton_ai_agent

## Overview

MTS Hackathon Track 1 is an AI secretary for incoming calls. Its main workflow accepts text or audio, transcribes voice when needed, produces a classified response, optionally synthesizes speech, and records the call for review. Supporting capabilities include routing rules and scenarios, per-line service settings, call history and analytics, Telegram notifications, and readiness checks. The README describes these features; some service connections below are based on the SOURCE INDEX because their implementations were not excerpted.

Main entry points: [`backend/api/routes_call.py`](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/api/routes_call.py) (Call API), [`backend/main.py`](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/main.py) (FastAPI startup), [`backend/services/call_agent.py`](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/call_agent.py) (Call agent), [`backend/services/speech_providers.py`](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/speech_providers.py) (Speech provider selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and startup"]
  node_app["FastAPI startup<br/>[main.py]"]
  node_routes["Call API<br/>[routes_call.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
end

subgraph group_conversation["Call processing"]
  node_agent["Call agent<br/>[call_agent.py]"]
  node_rules["Routing rules<br/>[routing_rules.py]"]
  node_scenarios["Scenarios<br/>[scenarios.py]"]
  node_training["Training examples"]
  node_prompt["System prompt<br/>[system_ivan.py]"]
  node_yandex["YandexGPT<br/>[yandex_llm.py]"]
  node_local_llm["Local LLM<br/>[local_llm.py]"]
end

subgraph group_speech["Speech services"]
  node_speech_providers["Speech provider selection"]
  node_local_stt["Local STT<br/>[local_stt.py]"]
  node_speechkit["SpeechKit<br/>[speechkit_stt.py]"]
  node_local_tts["Local TTS<br/>[local_tts.py]"]
  node_tts_storage["Audio storage<br/>[tts_storage.py]"]
end

subgraph group_operations["History and controls"]
  node_db_config["Runtime configuration<br/>[config.py]"]
  node_database["Database session<br/>[database.py]"]
  node_call_logs[("Call history store<br/>[models.py]")]
  node_history["History service<br/>[call_history.py]"]
  node_analytics["Call analytics<br/>[analytics.py]"]
  node_service_settings["Line settings"]
  node_notifications["Telegram notifications<br/>[telegram_notify.py]"]
  node_readiness["Readiness checks<br/>[readiness.py]"]
  node_warmup["Demo warmup<br/>[warmup.py]"]
end

subgraph group_clients["Owner interfaces"]
  node_tg_bot["Telegram bot<br/>[tg_bot.py]"]
  node_tg_dashboard["Call dashboard<br/>[tg_dashboard.py]"]
  node_web_app["Web interface<br/>[app.py]"]
end

node_caller(("Caller"))
node_telegram(("Telegram"))

node_caller -->|"submits call"| node_routes
node_app -->|"mounts routes"| node_routes
node_app -->|"initializes"| node_database
node_app -->|"starts warmup"| node_warmup
node_app -->|"checks readiness"| node_readiness
node_routes -->|"validates requests"| node_schemas
node_routes -->|"processes calls"| node_agent
node_agent -->|"checks routing"| node_rules
node_agent -->|"requests response"| node_yandex
node_agent -.->|"uses local model"| node_local_llm
node_yandex -->|"builds prompt"| node_prompt
node_local_llm -->|"builds prompt"| node_prompt
node_prompt -->|"loads scenarios"| node_scenarios
node_prompt -->|"loads examples"| node_training
node_routes -->|"selects speech service"| node_speech_providers
node_speech_providers -->|"selects local STT"| node_local_stt
node_speech_providers -->|"selects SpeechKit"| node_speechkit
node_speech_providers -->|"selects local TTS"| node_local_tts
node_routes -->|"stores generated audio"| node_tts_storage
node_routes -->|"reads and records calls"| node_history
node_routes -->|"requests statistics"| node_analytics
node_routes -->|"manages line settings"| node_service_settings
node_routes -->|"manages notifications"| node_notifications
node_database -->|"loads database config"| node_db_config
node_database -->|"creates tables"| node_call_logs
node_history -->|"queries records"| node_call_logs
node_analytics -->|"reads records"| node_call_logs
node_service_settings -->|"uses root path"| node_db_config
node_notifications -->|"sends messages"| node_telegram
node_warmup -->|"warms speech model"| node_local_stt
node_warmup -->|"uses settings"| node_db_config
node_readiness -->|"checks database"| node_database
node_tg_bot -->|"renders dashboard"| node_tg_dashboard
node_web_app -->|"uses dashboard views"| node_tg_dashboard
node_web_app -->|"uses notification service"| node_notifications
node_tg_bot -->|"manages preferences"| node_service_settings

click node_app "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/main.py"
click node_routes "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/api/routes_call.py"
click node_schemas "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/schemas.py"
click node_agent "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/call_agent.py"
click node_rules "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/routing_rules.py"
click node_scenarios "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/scenarios.py"
click node_training "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/training_examples.py"
click node_prompt "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/prompts/system_ivan.py"
click node_yandex "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/yandex_llm.py"
click node_local_llm "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/local_llm.py"
click node_speech_providers "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/speech_providers.py"
click node_local_stt "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/local_stt.py"
click node_speechkit "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/speechkit_stt.py"
click node_local_tts "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/local_tts.py"
click node_tts_storage "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/tts_storage.py"
click node_db_config "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/config.py"
click node_database "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/database.py"
click node_call_logs "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/models.py"
click node_history "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/call_history.py"
click node_analytics "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/analytics.py"
click node_service_settings "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/service_settings.py"
click node_notifications "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/telegram_notify.py"
click node_readiness "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/readiness.py"
click node_warmup "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/warmup.py"
click node_tg_bot "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/frontend/tg_bot.py"
click node_tg_dashboard "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/frontend/tg_dashboard.py"
click node_web_app "https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/frontend/app.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_app,node_routes,node_schemas toneBlue
class node_agent,node_rules,node_scenarios,node_training,node_prompt,node_yandex,node_local_llm toneAmber
class node_speech_providers,node_local_stt,node_speechkit,node_local_tts,node_tts_storage toneMint
class node_db_config,node_database,node_call_logs,node_history,node_analytics,node_service_settings,node_notifications,node_readiness,node_warmup toneRose
class node_tg_bot,node_tg_dashboard,node_web_app,node_caller,node_telegram toneIndigo
```

## Components

### API and startup

- [FastAPI startup](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/main.py): `backend/main.py`
- [Call API](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/api/routes_call.py): `backend/api/routes_call.py`
- [API schemas](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/schemas.py): `backend/schemas.py`

### Call processing

- [Call agent](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/call_agent.py): `backend/services/call_agent.py`
- [Routing rules](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/routing_rules.py): `backend/services/routing_rules.py`
- [Scenarios](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/scenarios.py): `backend/services/scenarios.py`
- [Training examples](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/training_examples.py): `backend/services/training_examples.py`
- [System prompt](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/prompts/system_ivan.py): `backend/prompts/system_ivan.py`
- [YandexGPT](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/yandex_llm.py): `backend/services/yandex_llm.py`
- [Local LLM](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/local_llm.py): `backend/services/local_llm.py`

### Speech services

- [Speech provider selection](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/speech_providers.py): `backend/services/speech_providers.py`
- [Local STT](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/local_stt.py): `backend/services/local_stt.py`
- [SpeechKit](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/speechkit_stt.py): `backend/services/speechkit_stt.py`
- [Local TTS](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/local_tts.py): `backend/services/local_tts.py`
- [Audio storage](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/tts_storage.py): `backend/services/tts_storage.py`

### History and controls

- [Runtime configuration](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/config.py): `backend/config.py`
- [Database session](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/database.py): `backend/database.py`
- [Call history store](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/models.py): `backend/models.py`
- [History service](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/call_history.py): `backend/services/call_history.py`
- [Call analytics](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/analytics.py): `backend/services/analytics.py`
- [Line settings](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/service_settings.py): `backend/services/service_settings.py`
- [Telegram notifications](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/telegram_notify.py): `backend/services/telegram_notify.py`
- [Readiness checks](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/readiness.py): `backend/services/readiness.py`
- [Demo warmup](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/backend/services/warmup.py): `backend/services/warmup.py`

### Owner interfaces

- [Telegram bot](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/frontend/tg_bot.py): `frontend/tg_bot.py`
- [Call dashboard](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/frontend/tg_dashboard.py): `frontend/tg_dashboard.py`
- [Web interface](https://github.com/xdefox/mts_hacaton_ai_agent/blob/main/frontend/app.py): `frontend/app.py`

### Other components

- **Caller**
- **Telegram**

## Connections

- Caller → Call API: submits call (evidence: `README.md`)
- FastAPI startup → Call API: mounts routes (evidence: `backend/main.py`)
- FastAPI startup → Database session: initializes (evidence: `backend/main.py`)
- FastAPI startup → Demo warmup: starts warmup (evidence: `backend/main.py`)
- FastAPI startup → Readiness checks: checks readiness (evidence: `backend/main.py`)
- Call API → API schemas: validates requests (evidence: `backend/api/routes_call.py`)
- Call API → Call agent: processes calls (evidence: `backend/api/routes_call.py`)
- Call agent → Routing rules: checks routing (evidence: `backend/services/call_agent.py`)
- Call agent → YandexGPT: requests response (evidence: `backend/services/call_agent.py`)
- Call agent → Local LLM: uses local model
- YandexGPT → System prompt: builds prompt (evidence: `backend/services/yandex_llm.py`)
- Local LLM → System prompt: builds prompt (evidence: `backend/services/local_llm.py`)
- System prompt → Scenarios: loads scenarios (evidence: `backend/prompts/system_ivan.py`)
- System prompt → Training examples: loads examples (evidence: `backend/prompts/system_ivan.py`)
- Call API → Speech provider selection: selects speech service (evidence: `backend/api/routes_call.py`)
- Speech provider selection → Local STT: selects local STT (evidence: `backend/services/speech_providers.py`)
- Speech provider selection → SpeechKit: selects SpeechKit (evidence: `backend/services/speech_providers.py`)
- Speech provider selection → Local TTS: selects local TTS (evidence: `backend/services/speech_providers.py`)
- Call API → Audio storage: stores generated audio (evidence: `backend/api/routes_call.py`)
- Call API → History service: reads and records calls (evidence: `backend/api/routes_call.py`)
- Call API → Call analytics: requests statistics (evidence: `backend/api/routes_call.py`)
- Call API → Line settings: manages line settings (evidence: `backend/api/routes_call.py`)
- Call API → Telegram notifications: manages notifications (evidence: `backend/api/routes_call.py`)
- Database session → Runtime configuration: loads database config (evidence: `backend/database.py`)
- Database session → Call history store: creates tables (evidence: `backend/database.py`)
- History service → Call history store: queries records (evidence: `backend/services/call_history.py`)
- Call analytics → Call history store: reads records (evidence: `backend/services/analytics.py`)
- Line settings → Runtime configuration: uses root path (evidence: `backend/services/service_settings.py`)
- Telegram notifications → Telegram: sends messages (evidence: `backend/services/telegram_notify.py`)
- Demo warmup → Local STT: warms speech model (evidence: `backend/services/warmup.py`)
- Demo warmup → Runtime configuration: uses settings (evidence: `backend/services/warmup.py`)
- Readiness checks → Database session: checks database (evidence: `backend/services/readiness.py`)
- Telegram bot → Call dashboard: renders dashboard (evidence: `frontend/tg_bot.py`)
- Web interface → Call dashboard: uses dashboard views (evidence: `frontend/app.py`)
- Web interface → Telegram notifications: uses notification service (evidence: `frontend/app.py`)
- Telegram bot → Line settings: manages preferences (evidence: `frontend/tg_bot.py`)
