# sanyok12345/teleproto architecture

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

- Interactive diagram: https://gitdiagram.com/sanyok12345/teleproto
- Repository: https://github.com/sanyok12345/teleproto

## Overview

teleproto is a TypeScript Telegram MTProto client. The main workflow is that an application configures a client with a session, authenticates or resumes it, then invokes Telegram operations and handles incoming updates. The map highlights domain APIs, the update/event path, protocol transport, and session/TL state. README capabilities are included even where source excerpts were incomplete; edges for unsampled subsystem wiring are omitted where ownership could not be established.

Main entry points: [`teleproto/client/TelegramClient.ts`](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/TelegramClient.ts) (Telegram client), [`teleproto/client/telegramBaseClient.ts`](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/telegramBaseClient.ts) (Client runtime), [`teleproto/network/MTProtoSender.ts`](https://github.com/sanyok12345/teleproto/blob/main/teleproto/network/MTProtoSender.ts) (MTProto sender), [`teleproto/client/updates/manager.ts`](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/updates/manager.ts) (Update manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client workflows"]
  node_client["Telegram client<br/>[TelegramClient.ts]"]
  node_base["Client runtime"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_messages["Messaging<br/>[messages.ts]"]
  node_chats["Chats and dialogs<br/>[chats.ts]"]
  node_files["File transfer<br/>[downloads.ts]"]
  node_uploads["Uploads<br/>[uploads.ts]"]
  node_account["Account features<br/>[account.ts]"]
end

subgraph group_updates["Updates and events"]
  node_updates["Update manager<br/>[manager.ts]"]
  node_dispatch["Update dispatch<br/>[dispatch.ts]"]
  node_composer["Update subscriptions<br/>[composer.ts]"]
  node_events["Event builders<br/>[index.ts]"]
end

subgraph group_protocol["MTProto transport"]
  node_network["Network manager<br/>[Network.ts]"]
  node_sender["MTProto sender<br/>[MTProtoSender.ts]"]
  node_connection["Connections<br/>[index.ts]"]
  node_crypto["Protocol crypto<br/>[crypto.ts]"]
end

subgraph group_state["Session and entities"]
  node_sessions["Session storage<br/>[index.ts]"]
  node_entitycache["Entity cache<br/>[entityCache.ts]"]
end

subgraph group_schema["TL schema and types"]
  node_api["Raw API proxy<br/>[apiProxy.ts]"]
  node_tl["TL schema types<br/>[api.ts]"]
  node_custom["Custom TL objects<br/>[index.ts]"]
end

node_app(("Application"))
node_telegram(("Telegram"))

node_app -->|"configures and calls"| node_client
node_client -->|"inherits runtime"| node_base
node_client -->|"starts sign-in"| node_auth
node_client -->|"delegates messaging"| node_messages
node_client -->|"delegates chat actions"| node_chats
node_client -->|"manages updates"| node_updates
node_client -->|"exposes raw API"| node_api
node_client -->|"downloads media"| node_files
node_client -->|"uploads media"| node_uploads
node_client -->|"offers account actions"| node_account
node_base -->|"loads and saves"| node_sessions
node_base -->|"manages transport"| node_network
node_base -->|"creates cache"| node_entitycache
node_auth -->|"authenticates with"| node_telegram
node_network -->|"provides sessions"| node_sender
node_sender -->|"sends packets"| node_connection
node_sender -->|"protects messages"| node_crypto
node_sender -->|"exchanges MTProto"| node_telegram
node_telegram -->|"sends updates"| node_updates
node_updates -->|"dispatches updates"| node_dispatch
node_updates -->|"caches entities"| node_entitycache
node_composer -->|"builds event handlers"| node_events
node_api -->|"constructs TL requests"| node_tl
node_client -->|"uses custom objects"| node_custom

click node_client "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/TelegramClient.ts"
click node_base "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/telegramBaseClient.ts"
click node_auth "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/auth.ts"
click node_messages "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/messages.ts"
click node_chats "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/chats.ts"
click node_files "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/downloads.ts"
click node_uploads "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/uploads.ts"
click node_account "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/account.ts"
click node_updates "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/updates/manager.ts"
click node_dispatch "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/updates/dispatch.ts"
click node_composer "https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/updates/composer.ts"
click node_events "https://github.com/sanyok12345/teleproto/blob/main/teleproto/events/index.ts"
click node_network "https://github.com/sanyok12345/teleproto/blob/main/teleproto/network/Network.ts"
click node_sender "https://github.com/sanyok12345/teleproto/blob/main/teleproto/network/MTProtoSender.ts"
click node_connection "https://github.com/sanyok12345/teleproto/blob/main/teleproto/network/connection/index.ts"
click node_crypto "https://github.com/sanyok12345/teleproto/blob/main/teleproto/crypto/crypto.ts"
click node_sessions "https://github.com/sanyok12345/teleproto/blob/main/teleproto/sessions/index.ts"
click node_entitycache "https://github.com/sanyok12345/teleproto/blob/main/teleproto/entityCache.ts"
click node_api "https://github.com/sanyok12345/teleproto/blob/main/teleproto/tl/runtime/apiProxy.ts"
click node_tl "https://github.com/sanyok12345/teleproto/blob/main/teleproto/tl/api.ts"
click node_custom "https://github.com/sanyok12345/teleproto/blob/main/teleproto/tl/custom/index.ts"

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_base,node_auth,node_messages,node_chats,node_files,node_uploads,node_account toneBlue
class node_updates,node_dispatch,node_composer,node_events toneAmber
class node_network,node_sender,node_connection,node_crypto toneMint
class node_sessions,node_entitycache toneRose
class node_api,node_tl,node_custom,node_app,node_telegram toneIndigo
```

## Components

### Client workflows

- [Telegram client](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/TelegramClient.ts): `teleproto/client/TelegramClient.ts`
- [Client runtime](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/telegramBaseClient.ts): `teleproto/client/telegramBaseClient.ts`
- [Authentication](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/auth.ts): `teleproto/client/auth.ts`
- [Messaging](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/messages.ts): `teleproto/client/messages.ts`
- [Chats and dialogs](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/chats.ts): `teleproto/client/chats.ts`
- [File transfer](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/downloads.ts): `teleproto/client/downloads.ts`
- [Uploads](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/uploads.ts): `teleproto/client/uploads.ts`
- [Account features](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/account.ts): `teleproto/client/account.ts`

### Updates and events

- [Update manager](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/updates/manager.ts): `teleproto/client/updates/manager.ts`
- [Update dispatch](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/updates/dispatch.ts): `teleproto/client/updates/dispatch.ts`
- [Update subscriptions](https://github.com/sanyok12345/teleproto/blob/main/teleproto/client/updates/composer.ts): `teleproto/client/updates/composer.ts`
- [Event builders](https://github.com/sanyok12345/teleproto/blob/main/teleproto/events/index.ts): `teleproto/events/index.ts`

### MTProto transport

- [Network manager](https://github.com/sanyok12345/teleproto/blob/main/teleproto/network/Network.ts): `teleproto/network/Network.ts`
- [MTProto sender](https://github.com/sanyok12345/teleproto/blob/main/teleproto/network/MTProtoSender.ts): `teleproto/network/MTProtoSender.ts`
- [Connections](https://github.com/sanyok12345/teleproto/blob/main/teleproto/network/connection/index.ts): `teleproto/network/connection/index.ts`
- [Protocol crypto](https://github.com/sanyok12345/teleproto/blob/main/teleproto/crypto/crypto.ts): `teleproto/crypto/crypto.ts`

### Session and entities

- [Session storage](https://github.com/sanyok12345/teleproto/blob/main/teleproto/sessions/index.ts): `teleproto/sessions/index.ts`
- [Entity cache](https://github.com/sanyok12345/teleproto/blob/main/teleproto/entityCache.ts): `teleproto/entityCache.ts`

### TL schema and types

- [Raw API proxy](https://github.com/sanyok12345/teleproto/blob/main/teleproto/tl/runtime/apiProxy.ts): `teleproto/tl/runtime/apiProxy.ts`
- [TL schema types](https://github.com/sanyok12345/teleproto/blob/main/teleproto/tl/api.ts): `teleproto/tl/api.ts`
- [Custom TL objects](https://github.com/sanyok12345/teleproto/blob/main/teleproto/tl/custom/index.ts): `teleproto/tl/custom/index.ts`

### Other components

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

## Connections

- Application → Telegram client: configures and calls
- Telegram client → Client runtime: inherits runtime
- Telegram client → Authentication: starts sign-in
- Telegram client → Messaging: delegates messaging
- Telegram client → Chats and dialogs: delegates chat actions
- Telegram client → Update manager: manages updates
- Telegram client → Raw API proxy: exposes raw API
- Telegram client → File transfer: downloads media
- Telegram client → Uploads: uploads media
- Telegram client → Account features: offers account actions
- Client runtime → Session storage: loads and saves
- Client runtime → Network manager: manages transport
- Client runtime → Entity cache: creates cache
- Authentication → Telegram: authenticates with
- Network manager → MTProto sender: provides sessions
- MTProto sender → Connections: sends packets
- MTProto sender → Protocol crypto: protects messages
- MTProto sender → Telegram: exchanges MTProto
- Telegram → Update manager: sends updates
- Update manager → Update dispatch: dispatches updates
- Update manager → Entity cache: caches entities
- Update subscriptions → Event builders: builds event handlers
- Raw API proxy → TL schema types: constructs TL requests
- Telegram client → Custom TL objects: uses custom objects
