# tueen/telegram architecture

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

- Interactive diagram: https://gitdiagram.com/tueen/telegram
- Repository: https://github.com/tueen/telegram

## Overview

Tueen Telegram is a modern PHP SDK for building Telegram bots. A bot is configured, run through polling or webhook intake, and incoming updates are decoded and dispatched to registered routes or conversational flows; handlers use typed API methods to send requests through the HTTP client. The SDK also provides typed models, formatting and keyboard builders, resilient middleware, app/dashboard tooling, and test fakes. Some subsystem links are documented capabilities rather than inspected call sites, so those edges cite the README.

Main entry points: [`src/Telegram.php`](https://github.com/tueen/telegram/blob/main/src/Telegram.php) (Bot facade), [`src/Client/TelegramClient.php`](https://github.com/tueen/telegram/blob/main/src/Client/TelegramClient.php) (API client), [`src/Methods/Method.php`](https://github.com/tueen/telegram/blob/main/src/Methods/Method.php) (Typed API methods), [`src/Client/HttpClientInterface.php`](https://github.com/tueen/telegram/blob/main/src/Client/HttpClientInterface.php) (HTTP transports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_bot["Bot facade<br/>[Telegram.php]"]
  node_config["Configuration<br/>[Config.php]"]
  node_running["Polling and webhook"]
  node_updates["Typed updates<br/>[Update.php]"]
  node_router["Update routing<br/>[Router.php]"]
  node_context["Handler context"]
  node_dispatcher["Update dispatcher"]
end

subgraph group_api["Telegram API"]
  node_methods["Typed API methods<br/>[Method.php]"]
  node_models["Typed data models<br/>[Type.php]"]
  node_api_client["API client<br/>[TelegramClient.php]"]
  node_http["HTTP transports"]
end

subgraph group_interaction["Bot interaction"]
  node_flows["Conversational flows<br/>[FlowManager.php]"]
  node_flow_state[("Flow state stores")]
  node_formatting["Formatting and keyboards<br/>[Text.php]"]
end

subgraph group_app["App tooling"]
  node_app["Zero-config app<br/>[App.php]"]
  node_dashboard["Web dashboard<br/>[WebDashboard.php]"]
end

subgraph group_resilience["Resilience and testing"]
  node_pipeline["HTTP middleware<br/>[Pipeline.php]"]
  node_errors["Typed error handling"]
  node_fakes["Testing fakes<br/>[TelegramFake.php]"]
end

node_developer(("Bot developer"))
node_telegram(("Telegram users"))
node_telegram_service(("Telegram Bot API"))

node_developer -->|"configures and runs"| node_bot
node_telegram -->|"sends updates"| node_running
node_running -->|"delivers updates"| node_bot
node_bot -->|"decodes payload"| node_updates
node_bot -->|"dispatches updates"| node_dispatcher
node_dispatcher -.->|"routes updates"| node_router
node_router -.->|"resolves handler arguments"| node_context
node_bot -->|"starts and manages"| node_flows
node_flows -->|"reads and writes state"| node_flow_state
node_developer -->|"calls bot methods"| node_methods
node_methods -.->|"executes method"| node_api_client
node_api_client -->|"sends requests"| node_http
node_http -->|"calls API"| node_telegram_service
node_telegram_service -.->|"returns response"| node_http
node_api_client -->|"maps API errors"| node_errors
node_methods -->|"uses typed values"| node_models
node_developer -->|"builds messages"| node_formatting
node_developer -->|"launches bot"| node_app
node_app -->|"serves dashboard"| node_dashboard
node_bot -->|"uses settings"| node_config
node_api_client -->|"applies middleware"| node_pipeline
node_developer -->|"tests bot behavior"| node_fakes

click node_bot "https://github.com/tueen/telegram/blob/main/src/Telegram.php"
click node_config "https://github.com/tueen/telegram/blob/main/src/Config.php"
click node_running "https://github.com/tueen/telegram/tree/main/src/Running"
click node_updates "https://github.com/tueen/telegram/blob/main/src/Types/Update.php"
click node_router "https://github.com/tueen/telegram/blob/main/src/Routing/Router.php"
click node_context "https://github.com/tueen/telegram/blob/main/src/Context/ContextResolver.php"
click node_dispatcher "https://github.com/tueen/telegram/blob/main/src/Dispatcher/UpdateDispatcher.php"
click node_flows "https://github.com/tueen/telegram/blob/main/src/Flow/FlowManager.php"
click node_flow_state "https://github.com/tueen/telegram/tree/main/src/Flow/Storage"
click node_methods "https://github.com/tueen/telegram/blob/main/src/Methods/Method.php"
click node_models "https://github.com/tueen/telegram/blob/main/src/Types/Type.php"
click node_api_client "https://github.com/tueen/telegram/blob/main/src/Client/TelegramClient.php"
click node_http "https://github.com/tueen/telegram/blob/main/src/Client/HttpClientInterface.php"
click node_formatting "https://github.com/tueen/telegram/blob/main/src/Formatting/Text.php"
click node_app "https://github.com/tueen/telegram/blob/main/src/App.php"
click node_dashboard "https://github.com/tueen/telegram/blob/main/src/App/WebDashboard.php"
click node_pipeline "https://github.com/tueen/telegram/blob/main/src/Pipeline/Pipeline.php"
click node_errors "https://github.com/tueen/telegram/blob/main/src/Enums/TelegramErrorCode.php"
click node_fakes "https://github.com/tueen/telegram/blob/main/src/Testing/TelegramFake.php"

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_bot,node_config,node_running,node_updates,node_router,node_context,node_dispatcher,node_telegram toneBlue
class node_methods,node_models,node_api_client,node_http toneAmber
class node_flows,node_flow_state,node_formatting,node_telegram_service toneMint
class node_app,node_dashboard toneRose
class node_pipeline,node_errors,node_fakes,node_developer toneIndigo
```

## Components

### Bot runtime

- [Bot facade](https://github.com/tueen/telegram/blob/main/src/Telegram.php): `src/Telegram.php`
- [Configuration](https://github.com/tueen/telegram/blob/main/src/Config.php): `src/Config.php`
- [Polling and webhook](https://github.com/tueen/telegram/tree/main/src/Running): `src/Running`
- [Typed updates](https://github.com/tueen/telegram/blob/main/src/Types/Update.php): `src/Types/Update.php`
- [Update routing](https://github.com/tueen/telegram/blob/main/src/Routing/Router.php): `src/Routing/Router.php`
- [Handler context](https://github.com/tueen/telegram/blob/main/src/Context/ContextResolver.php): `src/Context/ContextResolver.php`
- [Update dispatcher](https://github.com/tueen/telegram/blob/main/src/Dispatcher/UpdateDispatcher.php): `src/Dispatcher/UpdateDispatcher.php`

### Telegram API

- [Typed API methods](https://github.com/tueen/telegram/blob/main/src/Methods/Method.php): `src/Methods/Method.php`
- [Typed data models](https://github.com/tueen/telegram/blob/main/src/Types/Type.php): `src/Types/Type.php`
- [API client](https://github.com/tueen/telegram/blob/main/src/Client/TelegramClient.php): `src/Client/TelegramClient.php`
- [HTTP transports](https://github.com/tueen/telegram/blob/main/src/Client/HttpClientInterface.php): `src/Client/HttpClientInterface.php`

### Bot interaction

- [Conversational flows](https://github.com/tueen/telegram/blob/main/src/Flow/FlowManager.php): `src/Flow/FlowManager.php`
- [Flow state stores](https://github.com/tueen/telegram/tree/main/src/Flow/Storage): `src/Flow/Storage`
- [Formatting and keyboards](https://github.com/tueen/telegram/blob/main/src/Formatting/Text.php): `src/Formatting/Text.php`

### App tooling

- [Zero-config app](https://github.com/tueen/telegram/blob/main/src/App.php): `src/App.php`
- [Web dashboard](https://github.com/tueen/telegram/blob/main/src/App/WebDashboard.php): `src/App/WebDashboard.php`

### Resilience and testing

- [HTTP middleware](https://github.com/tueen/telegram/blob/main/src/Pipeline/Pipeline.php): `src/Pipeline/Pipeline.php`
- [Typed error handling](https://github.com/tueen/telegram/blob/main/src/Enums/TelegramErrorCode.php): `src/Enums/TelegramErrorCode.php`
- [Testing fakes](https://github.com/tueen/telegram/blob/main/src/Testing/TelegramFake.php): `src/Testing/TelegramFake.php`

### Other components

- **Bot developer**
- **Telegram users**
- **Telegram Bot API**

## Connections

- Bot developer → Bot facade: configures and runs (evidence: `README.md`)
- Telegram users → Polling and webhook: sends updates (evidence: `README.md`)
- Polling and webhook → Bot facade: delivers updates (evidence: `src/Running/WebhookMode.php`)
- Bot facade → Typed updates: decodes payload (evidence: `src/Telegram.php`)
- Bot facade → Update dispatcher: dispatches updates (evidence: `src/Telegram.php`)
- Update dispatcher → Update routing: routes updates
- Update routing → Handler context: resolves handler arguments
- Bot facade → Conversational flows: starts and manages (evidence: `src/Telegram.php`)
- Conversational flows → Flow state stores: reads and writes state (evidence: `src/Flow/FlowManager.php`)
- Bot developer → Typed API methods: calls bot methods (evidence: `README.md`)
- Typed API methods → API client: executes method (evidence: `src/Client/TelegramClient.php`)
- API client → HTTP transports: sends requests (evidence: `src/Client/TelegramClient.php`)
- HTTP transports → Telegram Bot API: calls API (evidence: `src/Client/HttpClientInterface.php`)
- Telegram Bot API → HTTP transports: returns response
- API client → Typed error handling: maps API errors (evidence: `src/Client/TelegramClient.php`)
- Typed API methods → Typed data models: uses typed values (evidence: `src/Methods/Method.php`)
- Bot developer → Formatting and keyboards: builds messages (evidence: `README.md`)
- Bot developer → Zero-config app: launches bot (evidence: `README.md`)
- Zero-config app → Web dashboard: serves dashboard (evidence: `src/App.php`)
- Bot facade → Configuration: uses settings (evidence: `src/Telegram.php`)
- API client → HTTP middleware: applies middleware (evidence: `src/Client/TelegramClient.php`)
- Bot developer → Testing fakes: tests bot behavior (evidence: `README.md`)
