# xcyclonev3/pyrofork architecture

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

- Interactive diagram: https://gitdiagram.com/xcyclonev3/pyrofork
- Repository: https://github.com/xcyclonev3/pyrofork

## Overview

Pyrogram is an asynchronous Python client framework for Telegram’s MTProto API, usable with user accounts and bots. A user or bot configures a Client, authenticates, then calls high-level methods or registers handlers; updates are dispatched to filtered callbacks, while API requests travel through session, transport, and cryptographic layers to Telegram. The graph also preserves the broad messaging, bot/business, chat, and payment method domains documented by the repository. Source excerpts are partial, so unverified internal links are omitted or shown as dashed.

Main entry points: [`pyrogram/client.py`](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/client.py) (Client lifecycle), [`pyrogram/raw`](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/raw) (Raw API schema), [`pyrogram/session/session.py`](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/session/session.py) (MTProto session), [`pyrogram/handlers/handler.py`](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/handlers/handler.py) (Typed handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client_api["Client and API"]
  node_client["Client lifecycle<br/>[client.py]"]
  node_auth["Authentication"]
  node_messages["Messages and media"]
  node_chats["Chats and communities"]
  node_bot_business["Bot and business APIs"]
  node_payments["Payments and wallets"]
end

subgraph group_updates["Update handling"]
  node_dispatcher["Update dispatcher<br/>[dispatcher.py]"]
  node_handlers["Typed handlers<br/>[handler.py]"]
  node_filters["Filters<br/>[filters.py]"]
end

subgraph group_protocol["MTProto transport"]
  node_session["MTProto session<br/>[session.py]"]
  node_connection["Connection transport<br/>[connection.py]"]
  node_crypto["MTProto cryptography<br/>[mtproto.py]"]
  node_aes["AES primitives<br/>[aes.py]"]
end

subgraph group_domain["Types and domains"]
  node_types["Telegram types"]
  node_raw_api["Raw API schema"]
  node_storage[("Session storage")]
  node_file_ids["File identifiers<br/>[file_id.py]"]
  node_emoji["Emoji utilities<br/>[emoji.py]"]
  node_enums["Enums<br/>[auto_name.py]"]
end

node_developer(("Application developer"))
node_telegram(("Telegram"))

node_developer -->|"configures"| node_client
node_client -.->|"authenticates via"| node_auth
node_developer -->|"calls methods"| node_messages
node_developer -->|"calls methods"| node_chats
node_developer -->|"calls methods"| node_bot_business
node_developer -.->|"calls methods"| node_payments
node_client -->|"queues updates"| node_dispatcher
node_dispatcher -.->|"dispatches updates"| node_handlers
node_handlers -->|"checks filters"| node_filters
node_handlers -->|"runs callbacks"| node_developer
node_client -.->|"persists session"| node_storage
node_client -->|"starts session"| node_session
node_session -->|"uses transport"| node_connection
node_session -->|"encrypts messages"| node_crypto
node_crypto -->|"uses AES"| node_aes
node_session -->|"encodes requests"| node_raw_api
node_messages -.->|"issues API calls"| node_raw_api
node_chats -.->|"issues API calls"| node_raw_api
node_bot_business -.->|"issues API calls"| node_raw_api
node_payments -.->|"issues API calls"| node_raw_api
node_raw_api -->|"exchanges protocol data"| node_telegram
node_telegram -.->|"returns updates"| node_client
node_types -->|"exposes objects"| node_developer
node_client -.->|"uses identifiers"| node_file_ids
node_client -->|"exposes utilities"| node_emoji
node_client -->|"exposes enums"| node_enums

click node_client "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/client.py"
click node_auth "https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/auth"
click node_messages "https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/messages"
click node_chats "https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/chats"
click node_bot_business "https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/bots"
click node_payments "https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/payments"
click node_dispatcher "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/dispatcher.py"
click node_handlers "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/handlers/handler.py"
click node_filters "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/filters.py"
click node_types "https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/types"
click node_raw_api "https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/raw"
click node_storage "https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/storage"
click node_session "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/session/session.py"
click node_connection "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/connection/connection.py"
click node_crypto "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/crypto/mtproto.py"
click node_aes "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/crypto/aes.py"
click node_file_ids "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/file_id.py"
click node_emoji "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/emoji.py"
click node_enums "https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/enums/auto_name.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_client,node_auth,node_messages,node_chats,node_bot_business,node_payments toneBlue
class node_dispatcher,node_handlers,node_filters toneAmber
class node_session,node_connection,node_crypto,node_aes toneMint
class node_types,node_raw_api,node_storage,node_file_ids,node_emoji,node_enums toneRose
class node_developer,node_telegram toneIndigo
```

## Components

### Client and API

- [Client lifecycle](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/client.py): `pyrogram/client.py`
- [Authentication](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/auth): `pyrogram/methods/auth`
- [Messages and media](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/messages): `pyrogram/methods/messages`
- [Chats and communities](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/chats): `pyrogram/methods/chats`
- [Bot and business APIs](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/bots): `pyrogram/methods/bots`
- [Payments and wallets](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/methods/payments): `pyrogram/methods/payments`

### Update handling

- [Update dispatcher](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/dispatcher.py): `pyrogram/dispatcher.py`
- [Typed handlers](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/handlers/handler.py): `pyrogram/handlers/handler.py`
- [Filters](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/filters.py): `pyrogram/filters.py`

### MTProto transport

- [MTProto session](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/session/session.py): `pyrogram/session/session.py`
- [Connection transport](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/connection/connection.py): `pyrogram/connection/connection.py`
- [MTProto cryptography](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/crypto/mtproto.py): `pyrogram/crypto/mtproto.py`
- [AES primitives](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/crypto/aes.py): `pyrogram/crypto/aes.py`

### Types and domains

- [Telegram types](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/types): `pyrogram/types`
- [Raw API schema](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/raw): `pyrogram/raw`
- [Session storage](https://github.com/xcyclonev3/pyrofork/tree/main/pyrogram/storage): `pyrogram/storage`
- [File identifiers](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/file_id.py): `pyrogram/file_id.py`
- [Emoji utilities](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/emoji.py): `pyrogram/emoji.py`
- [Enums](https://github.com/xcyclonev3/pyrofork/blob/main/pyrogram/enums/auto_name.py): `pyrogram/enums/auto_name.py`

### Other components

- **Application developer**
- **Telegram**

## Connections

- Application developer → Client lifecycle: configures
- Client lifecycle → Authentication: authenticates via
- Application developer → Messages and media: calls methods
- Application developer → Chats and communities: calls methods
- Application developer → Bot and business APIs: calls methods
- Application developer → Payments and wallets: calls methods
- Client lifecycle → Update dispatcher: queues updates (evidence: `pyrogram/client.py`)
- Update dispatcher → Typed handlers: dispatches updates
- Typed handlers → Filters: checks filters (evidence: `pyrogram/handlers/handler.py`)
- Typed handlers → Application developer: runs callbacks (evidence: `pyrogram/handlers/handler.py`)
- Client lifecycle → Session storage: persists session (evidence: `pyrogram/client.py`)
- Client lifecycle → MTProto session: starts session (evidence: `pyrogram/client.py`)
- MTProto session → Connection transport: uses transport (evidence: `pyrogram/session/session.py`)
- MTProto session → MTProto cryptography: encrypts messages (evidence: `pyrogram/session/session.py`)
- MTProto cryptography → AES primitives: uses AES (evidence: `pyrogram/crypto/mtproto.py`)
- MTProto session → Raw API schema: encodes requests (evidence: `pyrogram/session/session.py`)
- Messages and media → Raw API schema: issues API calls
- Chats and communities → Raw API schema: issues API calls
- Bot and business APIs → Raw API schema: issues API calls (evidence: `pyrogram/methods/bots/answer_inline_query.py`)
- Payments and wallets → Raw API schema: issues API calls
- Raw API schema → Telegram: exchanges protocol data
- Telegram → Client lifecycle: returns updates
- Telegram types → Application developer: exposes objects
- Client lifecycle → File identifiers: uses identifiers (evidence: `pyrogram/client.py`)
- Client lifecycle → Emoji utilities: exposes utilities (evidence: `pyrogram/__init__.py`)
- Client lifecycle → Enums: exposes enums
