# wwwyssa/chat_ai_bot architecture

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

- Interactive diagram: https://gitdiagram.com/wwwyssa/chat_ai_bot
- Repository: https://github.com/wwwyssa/chat_ai_bot

## Overview

This is a Telegram conversational bot for chatting with an AI persona. Users register, choose text or voice replies, and send messages; the bot checks their account state, requests an OpenAI response, and optionally synthesizes it with Yandex SpeechKit. Conversation history is stored on user records and periodically summarized for future responses. The graph distinguishes bot orchestration, AI and speech integrations, and persistence. Source excerpts show these calls; prompt-file wiring and some Telegram internals are not independently verified.

Main entry points: [`bot.py`](https://github.com/wwwyssa/chat_ai_bot/blob/master/bot.py) (Bot handlers), [`chat_gpt.py`](https://github.com/wwwyssa/chat_ai_bot/blob/master/chat_gpt.py) (Response and memory), [`data/db_session.py`](https://github.com/wwwyssa/chat_ai_bot/blob/master/data/db_session.py) (Session setup), [`yandex_speechkit.py`](https://github.com/wwwyssa/chat_ai_bot/blob/master/yandex_speechkit.py) (Voice synthesis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bot["Telegram bot"]
  node_bot_app["Bot handlers<br/>[bot.py]"]
end

subgraph group_ai["AI services"]
  node_gpt["Response and memory<br/>[chat_gpt.py]"]
  node_openai["OpenAI API"]
  node_speech["Voice synthesis"]
  node_yandex["Yandex SpeechKit"]
end

subgraph group_storage["User persistence"]
  node_sessions["Session setup<br/>[db_session.py]"]
  node_user_model["User records<br/>[users.py]"]
  node_sqlite[("SQLite database<br/>[users.db]")]
end

node_user(("Telegram user"))

node_user -->|"sends messages"| node_bot_app
node_bot_app -->|"sends replies"| node_user
node_bot_app -->|"creates sessions"| node_sessions
node_bot_app -->|"queries and updates"| node_user_model
node_bot_app -->|"requests responses"| node_gpt
node_bot_app -->|"requests summaries"| node_gpt
node_bot_app -->|"requests synthesis"| node_speech
node_gpt -->|"creates sessions"| node_sessions
node_gpt -->|"reads and updates"| node_user_model
node_gpt -->|"requests completions"| node_openai
node_speech -->|"synthesizes audio"| node_yandex
node_sessions -->|"connects to"| node_sqlite

click node_bot_app "https://github.com/wwwyssa/chat_ai_bot/blob/master/bot.py"
click node_gpt "https://github.com/wwwyssa/chat_ai_bot/blob/master/chat_gpt.py"
click node_speech "https://github.com/wwwyssa/chat_ai_bot/blob/master/yandex_speechkit.py"
click node_sessions "https://github.com/wwwyssa/chat_ai_bot/blob/master/data/db_session.py"
click node_user_model "https://github.com/wwwyssa/chat_ai_bot/blob/master/data/users.py"
click node_sqlite "https://github.com/wwwyssa/chat_ai_bot/blob/master/db/users.db"

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_app,node_user toneBlue
class node_gpt,node_openai,node_speech,node_yandex toneAmber
class node_sessions,node_user_model,node_sqlite toneMint
```

## Components

### Telegram bot

- [Bot handlers](https://github.com/wwwyssa/chat_ai_bot/blob/master/bot.py): `bot.py`

### AI services

- [Response and memory](https://github.com/wwwyssa/chat_ai_bot/blob/master/chat_gpt.py): `chat_gpt.py`
- **OpenAI API**
- [Voice synthesis](https://github.com/wwwyssa/chat_ai_bot/blob/master/yandex_speechkit.py): `yandex_speechkit.py`
- **Yandex SpeechKit**

### User persistence

- [Session setup](https://github.com/wwwyssa/chat_ai_bot/blob/master/data/db_session.py): `data/db_session.py`
- [User records](https://github.com/wwwyssa/chat_ai_bot/blob/master/data/users.py): `data/users.py`
- [SQLite database](https://github.com/wwwyssa/chat_ai_bot/blob/master/db/users.db): `db/users.db`

### Other components

- **Telegram user**

## Connections

- Telegram user → Bot handlers: sends messages (evidence: `bot.py`)
- Bot handlers → Telegram user: sends replies (evidence: `bot.py`)
- Bot handlers → Session setup: creates sessions (evidence: `bot.py`)
- Bot handlers → User records: queries and updates (evidence: `bot.py`)
- Bot handlers → Response and memory: requests responses (evidence: `bot.py`)
- Bot handlers → Response and memory: requests summaries (evidence: `bot.py`)
- Bot handlers → Voice synthesis: requests synthesis (evidence: `bot.py`)
- Response and memory → Session setup: creates sessions (evidence: `chat_gpt.py`)
- Response and memory → User records: reads and updates (evidence: `chat_gpt.py`)
- Response and memory → OpenAI API: requests completions (evidence: `chat_gpt.py`)
- Voice synthesis → Yandex SpeechKit: synthesizes audio (evidence: `yandex_speechkit.py`)
- Session setup → SQLite database: connects to (evidence: `data/db_session.py`)
