# ersizyka/telegram-video-downloader-userbot architecture

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

- Interactive diagram: https://gitdiagram.com/ersizyka/telegram-video-downloader-userbot
- Repository: https://github.com/ersizyka/telegram-video-downloader-userbot

## Overview

This is a self-hosted Telegram video-downloader userbot. A whitelisted user submits a link, chooses quality (and playlist items when applicable), then a persistent FIFO worker downloads and uploads the video to a configured Telegram channel. The graph also includes history/dedup, admin controls, and the local control API. Edges use README statements or SOURCE INDEX references; unsampled API-to-panel wiring is shown as unverified.

Main entry points: [`bot/handlers.py`](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/handlers.py) (Message handlers), [`run.py`](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/run.py) (Bot startup), [`bot/extractors/__init__.py`](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/extractors/__init__.py) (Extractor registry), [`bot/api.py`](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/api.py) (Local control API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["User interaction"]
  node_client["Telegram client<br/>[client.py]"]
  node_handlers["Message handlers<br/>[handlers.py]"]
end

subgraph group_extraction["Video extraction"]
  node_extractor_registry["Extractor registry<br/>[__init__.py]"]
  node_site_extractors["Site extractors"]
  node_browser_extractor["Browser fallback<br/>[universal.py]"]
  node_extractor_base["Browser extraction core<br/>[base.py]"]
end

subgraph group_processing["Download and delivery"]
  node_downloader["Download and media prep<br/>[downloader.py]"]
  node_queue_worker["FIFO queue worker<br/>[handlers.py]"]
  node_uploader["Parallel Telegram upload<br/>[fasttelethon.py]"]
end

subgraph group_operations["State and control"]
  node_runtime["Bot startup<br/>[run.py]"]
  node_whitelist["User whitelist<br/>[whitelist.py]"]
  node_queue_state["Persistent queue<br/>[queue.py]"]
  node_history["Download history<br/>[history.py]"]
  node_progress["Progress reporting<br/>[progress.py]"]
  node_local_api["Local control API<br/>[api.py]"]
  node_panel["Local panel<br/>[panel.py]"]
  node_logging["Logging<br/>[logging_config.py]"]
end

node_requester(("Whitelisted user"))
node_telegram(("Telegram"))

node_requester -->|"submits links"| node_handlers
node_handlers -->|"checks access"| node_whitelist
node_handlers -->|"resolves link"| node_extractor_registry
node_extractor_registry -->|"selects extractor"| node_site_extractors
node_extractor_registry -->|"offers fallback"| node_browser_extractor
node_browser_extractor -->|"uses browser core"| node_extractor_base
node_handlers -->|"starts worker"| node_queue_worker
node_queue_worker -->|"reads and updates"| node_queue_state
node_queue_worker -->|"downloads video"| node_downloader
node_queue_worker -->|"uploads media"| node_uploader
node_queue_worker -->|"records outcomes"| node_history
node_handlers -->|"checks prior result"| node_history
node_handlers -->|"updates status"| node_progress
node_runtime -->|"creates client"| node_client
node_runtime -->|"registers handlers"| node_handlers
node_runtime -->|"starts API"| node_local_api
node_local_api -->|"uses live bot state"| node_handlers
node_panel -.->|"controls bot"| node_local_api
node_client -->|"connects to"| node_telegram
node_uploader -->|"sends videos"| node_telegram
node_runtime -->|"configures logging"| node_logging

click node_runtime "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/run.py"
click node_client "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/client.py"
click node_handlers "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/handlers.py"
click node_whitelist "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/whitelist.py"
click node_extractor_registry "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/extractors/__init__.py"
click node_site_extractors "https://github.com/ersizyka/telegram-video-downloader-userbot/tree/main/bot/extractors"
click node_browser_extractor "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/extractors/universal.py"
click node_extractor_base "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/extractors/base.py"
click node_downloader "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/downloader.py"
click node_queue_worker "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/handlers.py"
click node_queue_state "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/queue.py"
click node_uploader "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/fasttelethon.py"
click node_history "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/history.py"
click node_progress "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/progress.py"
click node_local_api "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/api.py"
click node_panel "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/panel.py"
click node_logging "https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/logging_config.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_handlers,node_requester toneBlue
class node_extractor_registry,node_site_extractors,node_browser_extractor,node_extractor_base toneAmber
class node_downloader,node_queue_worker,node_uploader toneMint
class node_runtime,node_whitelist,node_queue_state,node_history,node_progress,node_local_api,node_panel,node_logging toneRose
class node_telegram toneIndigo
```

## Components

### User interaction

- [Telegram client](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/client.py): `bot/client.py`
- [Message handlers](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/handlers.py): `bot/handlers.py`

### Video extraction

- [Extractor registry](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/extractors/__init__.py): `bot/extractors/__init__.py`
- [Site extractors](https://github.com/ersizyka/telegram-video-downloader-userbot/tree/main/bot/extractors): `bot/extractors`
- [Browser fallback](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/extractors/universal.py): `bot/extractors/universal.py`
- [Browser extraction core](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/extractors/base.py): `bot/extractors/base.py`

### Download and delivery

- [Download and media prep](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/downloader.py): `bot/downloader.py`
- [FIFO queue worker](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/handlers.py): `bot/handlers.py`
- [Parallel Telegram upload](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/fasttelethon.py): `bot/fasttelethon.py`

### State and control

- [Bot startup](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/run.py): `run.py`
- [User whitelist](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/whitelist.py): `bot/whitelist.py`
- [Persistent queue](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/queue.py): `bot/queue.py`
- [Download history](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/history.py): `bot/history.py`
- [Progress reporting](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/progress.py): `bot/progress.py`
- [Local control API](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/api.py): `bot/api.py`
- [Local panel](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/panel.py): `panel.py`
- [Logging](https://github.com/ersizyka/telegram-video-downloader-userbot/blob/main/bot/logging_config.py): `bot/logging_config.py`

### Other components

- **Whitelisted user**
- **Telegram**

## Connections

- Whitelisted user → Message handlers: submits links (evidence: `README.md`)
- Message handlers → User whitelist: checks access (evidence: `bot/handlers.py`)
- Message handlers → Extractor registry: resolves link (evidence: `bot/handlers.py`)
- Extractor registry → Site extractors: selects extractor (evidence: `bot/extractors/__init__.py`)
- Extractor registry → Browser fallback: offers fallback (evidence: `bot/extractors/__init__.py`)
- Browser fallback → Browser extraction core: uses browser core (evidence: `bot/extractors/universal.py`)
- Message handlers → FIFO queue worker: starts worker (evidence: `bot/handlers.py`)
- FIFO queue worker → Persistent queue: reads and updates (evidence: `README.md`)
- FIFO queue worker → Download and media prep: downloads video (evidence: `bot/handlers.py`)
- FIFO queue worker → Parallel Telegram upload: uploads media (evidence: `bot/handlers.py`)
- FIFO queue worker → Download history: records outcomes (evidence: `bot/handlers.py`)
- Message handlers → Download history: checks prior result (evidence: `bot/handlers.py`)
- Message handlers → Progress reporting: updates status (evidence: `bot/handlers.py`)
- Bot startup → Telegram client: creates client (evidence: `run.py`)
- Bot startup → Message handlers: registers handlers (evidence: `run.py`)
- Bot startup → Local control API: starts API (evidence: `run.py`)
- Local control API → Message handlers: uses live bot state (evidence: `bot/api.py`)
- Local panel → Local control API: controls bot
- Telegram client → Telegram: connects to (evidence: `bot/client.py`)
- Parallel Telegram upload → Telegram: sends videos (evidence: `README.md`)
- Bot startup → Logging: configures logging (evidence: `run.py`)
