# cwr-su/manager_cw_bot architecture

> Architecture diagram of the GitHub repository cwr-su/manager_cw_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/cwr-su/manager_cw_bot
- Repository: https://github.com/cwr-su/manager_cw_bot

## Overview

Manager CW Bot API is a Python library for a Telegram bot, with business-management and subscription workflows. The visible entry point is `main.py` importing the business bot; the bot coordinates user/admin interactions, while feature modules handle tickets, email, promotions, payments/refunds, and AI features. Database operations and PDF generation provide internal services. The README identifies the product but does not describe its feature flow; some feature links below are therefore dashed and unverified rather than asserted as calls.

Main entry points: [`manager_cw_bot_api/business.py`](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/business.py) (Business bot), [`manager_cw_bot_api/handler_db_sub_operations.py`](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_db_sub_operations.py) (Database operations), [`manager_cw_bot_api/refund.py`](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/refund.py) (Refunds), [`manager_cw_bot_api/handler_successful_payment.py`](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_successful_payment.py) (Successful payments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bot["Bot orchestration"]
  node_entry["Bot entry<br/>[main.py]"]
  node_business["Business bot<br/>[business.py]"]
  node_buttons["Menu buttons<br/>[buttons.py]"]
end

subgraph group_support["User support"]
  node_business_handler["Business requests"]
  node_tickets["Ticket system<br/>[tickets.py]"]
  node_email_handler["Email settings<br/>[handler_email.py]"]
  node_email_sender["Email sender"]
end

subgraph group_subscriptions["Subscriptions and payments"]
  node_promos["Promo management<br/>[handler_promo.py]"]
  node_payments["Successful payments"]
  node_invoice["Invoice handling<br/>[send_invoice.py]"]
  node_yookassa["YooKassa handling"]
  node_refund["Refunds<br/>[refund.py]"]
end

subgraph group_services["Shared services"]
  node_db_ops["Database operations"]
  node_mysql["MySQL connection"]
  node_database[("MySQL database")]
  node_pdf["PDF generation"]
  node_fsm["Conversation states<br/>[fsm_handler.py]"]
  node_analytics["Analytics<br/>[analytics.py]"]
end

subgraph group_ai["AI features"]
  node_giga_chat["GigaChat features<br/>[gigachatai.py]"]
  node_giga_images["AI image features<br/>[giga_images.py]"]
  node_giga_request["GigaChat requests<br/>[giga_request.py]"]
end

node_user(("Telegram user"))
node_telegram(("Telegram"))
node_admin(("Bot administrator"))
node_smtp(("SMTP service"))

node_user -.->|"sends updates"| node_telegram
node_telegram -.->|"delivers updates"| node_entry
node_entry -->|"imports"| node_business
node_business -.->|"sends bot messages"| node_telegram
node_business -->|"routes ticket answers"| node_tickets
node_business -->|"handles payment"| node_payments
node_business -->|"opens promo menu"| node_promos
node_business -.->|"builds menus"| node_buttons
node_business -.->|"dispatches refund"| node_refund
node_business -.->|"dispatches AI"| node_giga_chat
node_business -.->|"dispatches image requests"| node_giga_images
node_business_handler -->|"builds menus"| node_buttons
node_business_handler -->|"sets conversation state"| node_fsm
node_buttons -->|"reads user data"| node_db_ops
node_buttons -->|"reads admin email"| node_email_sender
node_tickets -.->|"ticket data access"| node_db_ops
node_email_handler -->|"email data access"| node_db_ops
node_email_handler -->|"reads admin email"| node_email_sender
node_promos -->|"checks and stores promos"| node_db_ops
node_payments -->|"records subscription"| node_db_ops
node_payments -->|"generates receipt"| node_pdf
node_payments -->|"emails receipt"| node_email_sender
node_invoice -.->|"uses payment handling"| node_yookassa
node_invoice -.->|"dispatches payment result"| node_payments
node_yookassa -.->|"accesses payment data"| node_db_ops
node_refund -.->|"reads subscription data"| node_db_ops
node_refund -.->|"generates refund receipt"| node_pdf
node_refund -->|"emails refund receipt"| node_email_sender
node_refund -.->|"requests refunds"| node_telegram
node_db_ops -.->|"opens connections"| node_mysql
node_mysql -.->|"connects"| node_database
node_email_sender -.->|"sends mail"| node_smtp
node_analytics -.->|"records analytics"| node_db_ops
node_giga_chat -.->|"sends requests"| node_giga_request
node_giga_images -.->|"sends requests"| node_giga_request
node_giga_chat -.->|"uses conversation state"| node_fsm
node_giga_images -.->|"uses conversation state"| node_fsm
node_admin -.->|"administers bot"| node_telegram

click node_entry "https://github.com/cwr-su/manager_cw_bot/blob/master/main.py"
click node_business "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/business.py"
click node_buttons "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/buttons.py"
click node_business_handler "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/business_handler.py"
click node_tickets "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/tickets.py"
click node_email_handler "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_email.py"
click node_email_sender "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_email_sender.py"
click node_promos "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_promo.py"
click node_payments "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_successful_payment.py"
click node_invoice "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/send_invoice.py"
click node_yookassa "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_yookassa.py"
click node_refund "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/refund.py"
click node_db_ops "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_db_sub_operations.py"
click node_mysql "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/mysql_connection.py"
click node_pdf "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/pdf_generate_data.py"
click node_fsm "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/fsm_handler.py"
click node_analytics "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/analytics.py"
click node_giga_chat "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/gigachatai.py"
click node_giga_images "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/giga_images.py"
click node_giga_request "https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/giga_request.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_entry,node_business,node_buttons,node_user toneBlue
class node_business_handler,node_tickets,node_email_handler,node_email_sender toneAmber
class node_promos,node_payments,node_invoice,node_yookassa,node_refund toneMint
class node_db_ops,node_mysql,node_database,node_pdf,node_fsm,node_analytics toneRose
class node_giga_chat,node_giga_images,node_giga_request,node_telegram,node_admin,node_smtp toneIndigo
```

## Components

### Bot orchestration

- [Bot entry](https://github.com/cwr-su/manager_cw_bot/blob/master/main.py): `main.py`
- [Business bot](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/business.py): `manager_cw_bot_api/business.py`
- [Menu buttons](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/buttons.py): `manager_cw_bot_api/buttons.py`

### User support

- [Business requests](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/business_handler.py): `manager_cw_bot_api/business_handler.py`
- [Ticket system](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/tickets.py): `manager_cw_bot_api/tickets.py`
- [Email settings](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_email.py): `manager_cw_bot_api/handler_email.py`
- [Email sender](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_email_sender.py): `manager_cw_bot_api/handler_email_sender.py`

### Subscriptions and payments

- [Promo management](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_promo.py): `manager_cw_bot_api/handler_promo.py`
- [Successful payments](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_successful_payment.py): `manager_cw_bot_api/handler_successful_payment.py`
- [Invoice handling](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/send_invoice.py): `manager_cw_bot_api/send_invoice.py`
- [YooKassa handling](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_yookassa.py): `manager_cw_bot_api/handler_yookassa.py`
- [Refunds](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/refund.py): `manager_cw_bot_api/refund.py`

### Shared services

- [Database operations](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/handler_db_sub_operations.py): `manager_cw_bot_api/handler_db_sub_operations.py`
- [MySQL connection](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/mysql_connection.py): `manager_cw_bot_api/mysql_connection.py`
- **MySQL database**
- [PDF generation](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/pdf_generate_data.py): `manager_cw_bot_api/pdf_generate_data.py`
- [Conversation states](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/fsm_handler.py): `manager_cw_bot_api/fsm_handler.py`
- [Analytics](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/analytics.py): `manager_cw_bot_api/analytics.py`

### AI features

- [GigaChat features](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/gigachatai.py): `manager_cw_bot_api/gigachatai.py`
- [AI image features](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/giga_images.py): `manager_cw_bot_api/giga_images.py`
- [GigaChat requests](https://github.com/cwr-su/manager_cw_bot/blob/master/manager_cw_bot_api/giga_request.py): `manager_cw_bot_api/giga_request.py`

### Other components

- **Telegram user**
- **Telegram**
- **Bot administrator**
- **SMTP service**

## Connections

- Telegram user → Telegram: sends updates
- Telegram → Bot entry: delivers updates
- Bot entry → Business bot: imports (evidence: `main.py`)
- Business bot → Telegram: sends bot messages
- Business bot → Ticket system: routes ticket answers (evidence: `manager_cw_bot_api/business.py`)
- Business bot → Successful payments: handles payment (evidence: `manager_cw_bot_api/business.py`)
- Business bot → Promo management: opens promo menu (evidence: `manager_cw_bot_api/business.py`)
- Business bot → Menu buttons: builds menus (evidence: `manager_cw_bot_api/business.py`)
- Business bot → Refunds: dispatches refund (evidence: `manager_cw_bot_api/business.py`)
- Business bot → GigaChat features: dispatches AI (evidence: `manager_cw_bot_api/business.py`)
- Business bot → AI image features: dispatches image requests (evidence: `manager_cw_bot_api/business.py`)
- Business requests → Menu buttons: builds menus (evidence: `manager_cw_bot_api/business_handler.py`)
- Business requests → Conversation states: sets conversation state (evidence: `manager_cw_bot_api/business_handler.py`)
- Menu buttons → Database operations: reads user data (evidence: `manager_cw_bot_api/buttons.py`)
- Menu buttons → Email sender: reads admin email (evidence: `manager_cw_bot_api/buttons.py`)
- Ticket system → Database operations: ticket data access (evidence: `manager_cw_bot_api/tickets.py`)
- Email settings → Database operations: email data access (evidence: `manager_cw_bot_api/handler_email.py`)
- Email settings → Email sender: reads admin email (evidence: `manager_cw_bot_api/handler_email.py`)
- Promo management → Database operations: checks and stores promos (evidence: `manager_cw_bot_api/handler_promo.py`)
- Successful payments → Database operations: records subscription (evidence: `manager_cw_bot_api/handler_successful_payment.py`)
- Successful payments → PDF generation: generates receipt (evidence: `manager_cw_bot_api/handler_successful_payment.py`)
- Successful payments → Email sender: emails receipt (evidence: `manager_cw_bot_api/handler_successful_payment.py`)
- Invoice handling → YooKassa handling: uses payment handling (evidence: `manager_cw_bot_api/send_invoice.py`)
- Invoice handling → Successful payments: dispatches payment result (evidence: `manager_cw_bot_api/send_invoice.py`)
- YooKassa handling → Database operations: accesses payment data (evidence: `manager_cw_bot_api/handler_yookassa.py`)
- Refunds → Database operations: reads subscription data (evidence: `manager_cw_bot_api/refund.py`)
- Refunds → PDF generation: generates refund receipt (evidence: `manager_cw_bot_api/refund.py`)
- Refunds → Email sender: emails refund receipt (evidence: `manager_cw_bot_api/refund.py`)
- Refunds → Telegram: requests refunds
- Database operations → MySQL connection: opens connections (evidence: `manager_cw_bot_api/handler_db_sub_operations.py`)
- MySQL connection → MySQL database: connects
- Email sender → SMTP service: sends mail
- Analytics → Database operations: records analytics (evidence: `manager_cw_bot_api/analytics.py`)
- GigaChat features → GigaChat requests: sends requests (evidence: `manager_cw_bot_api/gigachatai.py`)
- AI image features → GigaChat requests: sends requests (evidence: `manager_cw_bot_api/giga_images.py`)
- GigaChat features → Conversation states: uses conversation state (evidence: `manager_cw_bot_api/gigachatai.py`)
- AI image features → Conversation states: uses conversation state (evidence: `manager_cw_bot_api/giga_images.py`)
- Bot administrator → Telegram: administers bot
