# alexbers/mtprotoproxy architecture

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

- Interactive diagram: https://gitdiagram.com/alexbers/mtprotoproxy
- Repository: https://github.com/alexbers/mtprotoproxy

## Overview

Async MTProto Proxy accepts Telegram client connections, applies configured MTProto modes and secrets, establishes upstream proxy connections, and relays traffic. The runtime is concentrated in one large module; the local pure-Python AES package supplies an encryption fallback. The README also documents channel-ad tags, statistics, multiple instances, and optional Prometheus export. Source excerpts show configuration handling, encryption adapters, relay accounting, and startup, but omit much of the connection-handler implementation; uncertain internal calls are therefore not asserted.

Main entry points: [`mtprotoproxy.py`](https://github.com/alexbers/mtprotoproxy/blob/master/mtprotoproxy.py) (Async MTProto proxy), [`pyaes/__init__.py`](https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/__init__.py) (AES API), [`pyaes/blockfeeder.py`](https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/blockfeeder.py) (Block feeder), [`pyaes/aes.py`](https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/aes.py) (AES modes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Proxy runtime"]
  node_proxy["Async MTProto proxy<br/>[mtprotoproxy.py]"]
  node_config["Proxy configuration<br/>[config.py]"]
end

subgraph group_crypto["Encryption"]
  node_aes_api["AES API<br/>[__init__.py]"]
  node_aes_modes["AES modes<br/>[aes.py]"]
  node_block_feeder["Block feeder<br/>[blockfeeder.py]"]
  node_aes_util["AES utilities<br/>[util.py]"]
end

subgraph group_operations["Operations"]
  node_proxy_stats["Runtime statistics<br/>[mtprotoproxy.py]"]
end

node_clients(("Telegram clients"))
node_telegram(("Telegram network"))
node_prometheus(("Prometheus"))

node_clients -->|"connects to"| node_proxy
node_config -->|"configures"| node_proxy
node_proxy -.->|"relays traffic"| node_telegram
node_proxy -->|"uses encryption"| node_aes_api
node_aes_api -->|"exports modes"| node_aes_modes
node_aes_api -->|"exports feeders"| node_block_feeder
node_block_feeder -->|"feeds cipher modes"| node_aes_modes
node_block_feeder -->|"uses padding"| node_aes_util
node_proxy -->|"updates counters"| node_proxy_stats
node_proxy_stats -.->|"exports metrics"| node_prometheus

click node_proxy "https://github.com/alexbers/mtprotoproxy/blob/master/mtprotoproxy.py"
click node_config "https://github.com/alexbers/mtprotoproxy/blob/master/config.py"
click node_aes_api "https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/__init__.py"
click node_aes_modes "https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/aes.py"
click node_block_feeder "https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/blockfeeder.py"
click node_aes_util "https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/util.py"
click node_proxy_stats "https://github.com/alexbers/mtprotoproxy/blob/master/mtprotoproxy.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_proxy,node_config,node_clients toneBlue
class node_aes_api,node_aes_modes,node_block_feeder,node_aes_util toneAmber
class node_proxy_stats toneMint
class node_telegram,node_prometheus toneIndigo
```

## Components

### Proxy runtime

- [Async MTProto proxy](https://github.com/alexbers/mtprotoproxy/blob/master/mtprotoproxy.py): `mtprotoproxy.py`
- [Proxy configuration](https://github.com/alexbers/mtprotoproxy/blob/master/config.py): `config.py`

### Encryption

- [AES API](https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/__init__.py): `pyaes/__init__.py`
- [AES modes](https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/aes.py): `pyaes/aes.py`
- [Block feeder](https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/blockfeeder.py): `pyaes/blockfeeder.py`
- [AES utilities](https://github.com/alexbers/mtprotoproxy/blob/master/pyaes/util.py): `pyaes/util.py`

### Operations

- [Runtime statistics](https://github.com/alexbers/mtprotoproxy/blob/master/mtprotoproxy.py): `mtprotoproxy.py`

### Other components

- **Telegram clients**
- **Telegram network**
- **Prometheus**

## Connections

- Telegram clients → Async MTProto proxy: connects to (evidence: `README.md`)
- Proxy configuration → Async MTProto proxy: configures (evidence: `README.md`)
- Async MTProto proxy → Telegram network: relays traffic
- Async MTProto proxy → AES API: uses encryption (evidence: `mtprotoproxy.py`)
- AES API → AES modes: exports modes (evidence: `pyaes/__init__.py`)
- AES API → Block feeder: exports feeders (evidence: `pyaes/__init__.py`)
- Block feeder → AES modes: feeds cipher modes (evidence: `pyaes/blockfeeder.py`)
- Block feeder → AES utilities: uses padding (evidence: `pyaes/blockfeeder.py`)
- Async MTProto proxy → Runtime statistics: updates counters (evidence: `mtprotoproxy.py`)
- Runtime statistics → Prometheus: exports metrics (evidence: `README.md`)
