# dizixxx/cryptomirror architecture

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

- Interactive diagram: https://gitdiagram.com/dizixxx/cryptomirror
- Repository: https://github.com/dizixxx/cryptomirror

## Overview

CryptoMirror is a Telegram bot for simulated crypto trading, live Binance prices, balances, and trade history. Users issue bot commands; the registered handlers guide buy/sell confirmation flows, fetch market prices when needed, and update simulated holdings and trade records. Other handlers provide price monitoring, portfolio, balance/history, start, and help functions. SQLite-backed SQLAlchemy models and CRUD operations support the trading state. The graph follows shown imports and calls plus README-described capabilities; unsampled handler internals are not inferred.

Main entry points: [`app/handlers/__init__.py`](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/__init__.py) (Router registry), [`app/handlers/buy.py`](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/buy.py) (Buy flow), [`app/handlers/sell.py`](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/sell.py) (Sell flow), [`app/database/init_engine.py`](https://github.com/dizixxx/cryptomirror/blob/main/app/database/init_engine.py) (DB engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_main["Bot startup<br/>[main.py]"]
  node_router_registry["Router registry<br/>[__init__.py]"]
end

subgraph group_workflows["User workflows"]
  node_start["Start handler<br/>[start.py]"]
  node_help["Help handler<br/>[help.py]"]
  node_buy["Buy flow<br/>[buy.py]"]
  node_sell["Sell flow<br/>[sell.py]"]
  node_balance["Balance history<br/>[balance.py]"]
  node_portfolio["Portfolio view<br/>[portfolio.py]"]
end

subgraph group_market["Market data"]
  node_prices["Price monitor<br/>[prices.py]"]
  node_updater["Monitor state<br/>[prices_updater.py]"]
  node_binance["Price client<br/>[binance.py]"]
end

subgraph group_persistence["Trading persistence"]
  node_sessions["DB engine<br/>[init_engine.py]"]
  node_crud["Trading CRUD<br/>[crud.py]"]
  node_models[("Trading records<br/>[models.py]")]
end

node_telegram_user(("Telegram user"))
node_binance_api{{"Binance API"}}

node_main -->|"initializes DB"| node_sessions
node_main -->|"loads routers"| node_router_registry
node_main -->|"configures bot"| node_updater
node_router_registry -->|"registers"| node_start
node_router_registry -->|"registers"| node_help
node_router_registry -->|"registers"| node_buy
node_router_registry -->|"registers"| node_sell
node_router_registry -->|"registers"| node_balance
node_router_registry -->|"registers"| node_portfolio
node_router_registry -->|"registers"| node_prices
node_telegram_user -->|"requests trade"| node_buy
node_telegram_user -->|"requests trade"| node_sell
node_telegram_user -->|"requests prices"| node_prices
node_telegram_user -->|"requests history"| node_balance
node_telegram_user -->|"starts bot use"| node_start
node_telegram_user -->|"requests help"| node_help
node_telegram_user -->|"requests portfolio"| node_portfolio
node_buy -->|"gets quote"| node_binance
node_sell -->|"gets quote"| node_binance
node_prices -->|"gets prices"| node_binance
node_binance -->|"requests prices"| node_binance_api
node_prices -->|"tracks updates"| node_updater
node_buy -->|"opens session"| node_sessions
node_sell -->|"opens session"| node_sessions
node_balance -->|"queries history"| node_sessions
node_buy -->|"reads and updates"| node_crud
node_sell -->|"reads and updates"| node_crud
node_portfolio -->|"reads holdings"| node_crud
node_start -->|"creates user"| node_crud
node_crud -->|"queries records"| node_models
node_sessions -->|"creates schema"| node_models
node_balance -->|"reads trades"| node_models

click node_main "https://github.com/dizixxx/cryptomirror/blob/main/app/main.py"
click node_router_registry "https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/__init__.py"
click node_start "https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/start.py"
click node_help "https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/help.py"
click node_buy "https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/buy.py"
click node_sell "https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/sell.py"
click node_balance "https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/balance.py"
click node_portfolio "https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/portfolio.py"
click node_prices "https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/prices.py"
click node_updater "https://github.com/dizixxx/cryptomirror/blob/main/app/services/prices_updater.py"
click node_binance "https://github.com/dizixxx/cryptomirror/blob/main/app/services/binance.py"
click node_sessions "https://github.com/dizixxx/cryptomirror/blob/main/app/database/init_engine.py"
click node_crud "https://github.com/dizixxx/cryptomirror/blob/main/app/database/crud.py"
click node_models "https://github.com/dizixxx/cryptomirror/blob/main/app/database/models.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_main,node_router_registry,node_telegram_user toneBlue
class node_start,node_help,node_buy,node_sell,node_balance,node_portfolio toneAmber
class node_prices,node_updater,node_binance,node_binance_api toneMint
class node_sessions,node_crud,node_models toneRose
```

## Components

### Bot runtime

- [Bot startup](https://github.com/dizixxx/cryptomirror/blob/main/app/main.py): `app/main.py`
- [Router registry](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/__init__.py): `app/handlers/__init__.py`

### User workflows

- [Start handler](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/start.py): `app/handlers/start.py`
- [Help handler](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/help.py): `app/handlers/help.py`
- [Buy flow](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/buy.py): `app/handlers/buy.py`
- [Sell flow](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/sell.py): `app/handlers/sell.py`
- [Balance history](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/balance.py): `app/handlers/balance.py`
- [Portfolio view](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/portfolio.py): `app/handlers/portfolio.py`

### Market data

- [Price monitor](https://github.com/dizixxx/cryptomirror/blob/main/app/handlers/prices.py): `app/handlers/prices.py`
- [Monitor state](https://github.com/dizixxx/cryptomirror/blob/main/app/services/prices_updater.py): `app/services/prices_updater.py`
- [Price client](https://github.com/dizixxx/cryptomirror/blob/main/app/services/binance.py): `app/services/binance.py`

### Trading persistence

- [DB engine](https://github.com/dizixxx/cryptomirror/blob/main/app/database/init_engine.py): `app/database/init_engine.py`
- [Trading CRUD](https://github.com/dizixxx/cryptomirror/blob/main/app/database/crud.py): `app/database/crud.py`
- [Trading records](https://github.com/dizixxx/cryptomirror/blob/main/app/database/models.py): `app/database/models.py`

### Other components

- **Telegram user**
- **Binance API**

## Connections

- Bot startup → DB engine: initializes DB (evidence: `app/main.py`)
- Bot startup → Router registry: loads routers (evidence: `app/main.py`)
- Bot startup → Monitor state: configures bot (evidence: `app/main.py`)
- Router registry → Start handler: registers (evidence: `app/handlers/__init__.py`)
- Router registry → Help handler: registers (evidence: `app/handlers/__init__.py`)
- Router registry → Buy flow: registers (evidence: `app/handlers/__init__.py`)
- Router registry → Sell flow: registers (evidence: `app/handlers/__init__.py`)
- Router registry → Balance history: registers (evidence: `app/handlers/__init__.py`)
- Router registry → Portfolio view: registers (evidence: `app/handlers/__init__.py`)
- Router registry → Price monitor: registers (evidence: `app/handlers/__init__.py`)
- Telegram user → Buy flow: requests trade (evidence: `app/handlers/buy.py`)
- Telegram user → Sell flow: requests trade (evidence: `app/handlers/sell.py`)
- Telegram user → Price monitor: requests prices (evidence: `app/handlers/prices.py`)
- Telegram user → Balance history: requests history (evidence: `app/handlers/balance.py`)
- Telegram user → Start handler: starts bot use (evidence: `README.md`)
- Telegram user → Help handler: requests help (evidence: `README.md`)
- Telegram user → Portfolio view: requests portfolio (evidence: `README.md`)
- Buy flow → Price client: gets quote (evidence: `app/handlers/buy.py`)
- Sell flow → Price client: gets quote (evidence: `app/handlers/sell.py`)
- Price monitor → Price client: gets prices (evidence: `app/handlers/prices.py`)
- Price client → Binance API: requests prices (evidence: `app/services/binance.py`)
- Price monitor → Monitor state: tracks updates (evidence: `app/handlers/prices.py`)
- Buy flow → DB engine: opens session (evidence: `app/handlers/buy.py`)
- Sell flow → DB engine: opens session (evidence: `app/handlers/sell.py`)
- Balance history → DB engine: queries history (evidence: `app/handlers/balance.py`)
- Buy flow → Trading CRUD: reads and updates (evidence: `app/handlers/buy.py`)
- Sell flow → Trading CRUD: reads and updates (evidence: `app/handlers/sell.py`)
- Portfolio view → Trading CRUD: reads holdings (evidence: `app/handlers/portfolio.py`)
- Start handler → Trading CRUD: creates user (evidence: `app/handlers/start.py`)
- Trading CRUD → Trading records: queries records (evidence: `app/database/crud.py`)
- DB engine → Trading records: creates schema (evidence: `app/database/init_engine.py`)
- Balance history → Trading records: reads trades (evidence: `app/handlers/balance.py`)
