# lotovich/amnezia-vpn-manager architecture

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

- Interactive diagram: https://gitdiagram.com/lotovich/amnezia-vpn-manager
- Repository: https://github.com/lotovich/amnezia-vpn-manager

## Overview

AmneziaWG VPN Manager is an admin-operated Telegram bot for provisioning and managing VPN clients, tracking traffic, and monitoring server health. Administrators issue commands; handlers coordinate client records and AmneziaWG configuration, then deliver client connection material. Background tasks collect peer traffic and server metrics for statistics and alerts. The graph reflects README-described QR/config delivery and bot capabilities, but their full implementations were not sampled; relationships are included only where excerpts, the source index, or README support them.

Main entry points: [`src/bot_handlers.py`](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/bot_handlers.py) (Command handlers), [`src/database.py`](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/database.py) (Data access), [`src/main.py`](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/main.py) (Application runtime), [`src/vpn_manager.py`](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/vpn_manager.py) (VPN manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Bot control"]
  node_main["Application runtime<br/>[main.py]"]
  node_handlers["Command handlers<br/>[bot_handlers.py]"]
end

subgraph group_vpn["VPN operations"]
  node_client_delivery["Client config and QR<br/>[bot_handlers.py]"]
  node_vpn_manager["VPN manager<br/>[vpn_manager.py]"]
  node_awg["AmneziaWG interface"]
end

subgraph group_data["Persistence and statistics"]
  node_traffic_collector["Traffic collector<br/>[main.py]"]
  node_database["Data access<br/>[database.py]"]
  node_sqlite[("SQLite database")]
  node_stats_viz["Statistics charts<br/>[stats_viz.py]"]
end

subgraph group_monitoring["Server monitoring"]
  node_server_collector["Server stats collector<br/>[main.py]"]
  node_server_monitor["Server monitor<br/>[server_monitor.py]"]
end

node_admin(("Administrator"))
node_telegram(("Telegram"))
node_host_metrics["Host metrics"]

node_admin -->|"issues commands"| node_telegram
node_telegram -->|"routes commands"| node_handlers
node_main -->|"registers router"| node_handlers
node_handlers -->|"manages clients"| node_database
node_handlers -->|"provisions peers"| node_vpn_manager
node_handlers -->|"creates materials"| node_client_delivery
node_client_delivery -->|"delivers config and QR"| node_telegram
node_vpn_manager -->|"configures interface"| node_awg
node_main -->|"initializes and syncs"| node_vpn_manager
node_main -->|"starts task"| node_traffic_collector
node_traffic_collector -->|"reads peer counters"| node_vpn_manager
node_traffic_collector -->|"records traffic and sessions"| node_database
node_handlers -->|"renders statistics"| node_stats_viz
node_handlers -->|"reads statistics"| node_database
node_database -->|"reads and writes"| node_sqlite
node_main -->|"starts task"| node_server_collector
node_server_collector -->|"collects and checks metrics"| node_server_monitor
node_server_monitor -->|"samples system"| node_host_metrics
node_server_collector -->|"records metrics and events"| node_database
node_server_collector -->|"sends alerts"| node_telegram

click node_main "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/main.py"
click node_handlers "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/bot_handlers.py"
click node_client_delivery "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/bot_handlers.py"
click node_vpn_manager "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/vpn_manager.py"
click node_traffic_collector "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/main.py"
click node_database "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/database.py"
click node_stats_viz "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/stats_viz.py"
click node_server_collector "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/main.py"
click node_server_monitor "https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/server_monitor.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_handlers toneBlue
class node_client_delivery,node_vpn_manager,node_awg toneAmber
class node_traffic_collector,node_database,node_sqlite,node_stats_viz toneMint
class node_server_collector,node_server_monitor toneRose
class node_admin,node_telegram,node_host_metrics toneIndigo
```

## Components

### Bot control

- [Application runtime](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/main.py): `src/main.py`
- [Command handlers](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/bot_handlers.py): `src/bot_handlers.py`

### VPN operations

- [Client config and QR](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/bot_handlers.py): `src/bot_handlers.py`
- [VPN manager](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/vpn_manager.py): `src/vpn_manager.py`
- **AmneziaWG interface**

### Persistence and statistics

- [Traffic collector](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/main.py): `src/main.py`
- [Data access](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/database.py): `src/database.py`
- **SQLite database**
- [Statistics charts](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/stats_viz.py): `src/stats_viz.py`

### Server monitoring

- [Server stats collector](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/main.py): `src/main.py`
- [Server monitor](https://github.com/lotovich/amnezia-vpn-manager/blob/main/src/server_monitor.py): `src/server_monitor.py`

### Other components

- **Administrator**
- **Telegram**
- **Host metrics**

## Connections

- Administrator → Telegram: issues commands (evidence: `README.md`)
- Telegram → Command handlers: routes commands (evidence: `README.md`)
- Application runtime → Command handlers: registers router (evidence: `src/main.py`)
- Command handlers → Data access: manages clients (evidence: `src/bot_handlers.py`)
- Command handlers → VPN manager: provisions peers (evidence: `src/bot_handlers.py`)
- Command handlers → Client config and QR: creates materials (evidence: `README.md`)
- Client config and QR → Telegram: delivers config and QR (evidence: `README.md`)
- VPN manager → AmneziaWG interface: configures interface (evidence: `src/vpn_manager.py`)
- Application runtime → VPN manager: initializes and syncs (evidence: `src/main.py`)
- Application runtime → Traffic collector: starts task (evidence: `src/main.py`)
- Traffic collector → VPN manager: reads peer counters (evidence: `src/main.py`)
- Traffic collector → Data access: records traffic and sessions (evidence: `src/main.py`)
- Command handlers → Statistics charts: renders statistics (evidence: `src/bot_handlers.py`)
- Command handlers → Data access: reads statistics (evidence: `src/bot_handlers.py`)
- Data access → SQLite database: reads and writes (evidence: `src/database.py`)
- Application runtime → Server stats collector: starts task (evidence: `src/main.py`)
- Server stats collector → Server monitor: collects and checks metrics (evidence: `src/main.py`)
- Server monitor → Host metrics: samples system (evidence: `src/server_monitor.py`)
- Server stats collector → Data access: records metrics and events (evidence: `src/main.py`)
- Server stats collector → Telegram: sends alerts (evidence: `src/main.py`)
