# fyaz05/filetolink architecture

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

- Interactive diagram: https://gitdiagram.com/fyaz05/filetolink
- Repository: https://github.com/fyaz05/filetolink

## Overview

Thunder is a Telegram file-to-link bot: users submit files through Telegram, the bot keeps canonical copies in a storage channel and creates links, and an HTTP server serves downloads and browser streams. The graph includes documented batch, multi-client, access-control, administration, and customization capabilities. Some plugin and route internals were not excerpted; edges supported by the source index or README are cited there, and uncertain wiring is omitted.

Main entry points: [`Thunder/server/stream_routes.py`](https://github.com/fyaz05/filetolink/blob/main/Thunder/server/stream_routes.py) (HTTP stream routes), [`Thunder/bot/plugins/stream.py`](https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/stream.py) (File commands), [`Thunder/utils/database.py`](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/database.py) (Persistence and access records), [`Thunder/__main__.py`](https://github.com/fyaz05/filetolink/blob/main/Thunder/__main__.py) (Application startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telegram["Telegram bot"]
  node_bot_clients["Bot clients<br/>[clients.py]"]
  node_stream_plugin["File commands<br/>[stream.py]"]
  node_common_plugin["User commands<br/>[common.py]"]
  node_admin_plugin["Admin commands<br/>[admin.py]"]
  node_callbacks["Button callbacks<br/>[callbacks.py]"]
  node_broadcast["Broadcast service<br/>[broadcast.py]"]
end

subgraph group_files["File and link lifecycle"]
  node_canonical["Canonical file records<br/>[canonical_files.py]"]
  node_file_metadata["Media metadata<br/>[file_properties.py]"]
  node_link_builder["Link generation<br/>[bot_utils.py]"]
end

subgraph group_delivery["HTTP delivery"]
  node_stream_server["HTTP stream routes<br/>[stream_routes.py]"]
  node_templates["Media page rendering<br/>[render_template.py]"]
  node_download["Telegram file retrieval<br/>[custom_dl.py]"]
end

subgraph group_platform["Platform services"]
  node_entrypoint["Application startup<br/>[__main__.py]"]
  node_database["Persistence and access records<br/>[database.py]"]
  node_decorators["Access checks<br/>[decorators.py]"]
  node_tokens["Token authentication<br/>[tokens.py]"]
  node_force_channel["Channel membership checks<br/>[force_channel.py]"]
  node_limiter["Request rate limiting<br/>[rate_limiter.py]"]
  node_shortener["URL shortening<br/>[shortener.py]"]
end

node_user(("Telegram user"))
node_browser(("Link visitor"))
node_telegram_api["Telegram API"]
node_storage_channel[("Storage channel")]
node_mongo[("MongoDB")]

node_user -->|"submits files"| node_stream_plugin
node_stream_plugin -->|"forwards files"| node_storage_channel
node_stream_plugin -->|"records files"| node_canonical
node_canonical -->|"reads and writes"| node_database
node_database -->|"persists records"| node_mongo
node_stream_plugin -->|"builds links"| node_link_builder
node_link_builder -.->|"shortens URLs"| node_shortener
node_stream_plugin -->|"queues requests"| node_limiter
node_stream_plugin -->|"checks access"| node_decorators
node_decorators -->|"validates tokens"| node_tokens
node_common_plugin -->|"checks membership"| node_force_channel
node_common_plugin -->|"records users"| node_database
node_admin_plugin -->|"manages records"| node_database
node_admin_plugin -->|"starts broadcasts"| node_broadcast
node_callbacks -->|"handles broadcast actions"| node_broadcast
node_browser -->|"requests media"| node_stream_server
node_stream_server -->|"looks up links"| node_canonical
node_stream_server -->|"selects client"| node_bot_clients
node_stream_server -->|"resolves metadata"| node_file_metadata
node_stream_server -->|"retrieves media"| node_download
node_stream_server -->|"renders preview"| node_templates
node_download -.->|"fetches file data"| node_telegram_api
node_entrypoint -->|"initializes clients"| node_bot_clients
node_entrypoint -->|"starts server"| node_stream_server
node_entrypoint -->|"initializes persistence"| node_database

click node_entrypoint "https://github.com/fyaz05/filetolink/blob/main/Thunder/__main__.py"
click node_bot_clients "https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/clients.py"
click node_stream_plugin "https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/stream.py"
click node_common_plugin "https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/common.py"
click node_admin_plugin "https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/admin.py"
click node_callbacks "https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/callbacks.py"
click node_canonical "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/canonical_files.py"
click node_file_metadata "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/file_properties.py"
click node_link_builder "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/bot_utils.py"
click node_database "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/database.py"
click node_decorators "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/decorators.py"
click node_tokens "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/tokens.py"
click node_force_channel "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/force_channel.py"
click node_limiter "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/rate_limiter.py"
click node_shortener "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/shortener.py"
click node_broadcast "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/broadcast.py"
click node_stream_server "https://github.com/fyaz05/filetolink/blob/main/Thunder/server/stream_routes.py"
click node_templates "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/render_template.py"
click node_download "https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/custom_dl.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_bot_clients,node_stream_plugin,node_common_plugin,node_admin_plugin,node_callbacks,node_broadcast,node_user toneBlue
class node_canonical,node_file_metadata,node_link_builder,node_storage_channel,node_mongo toneAmber
class node_stream_server,node_templates,node_download,node_telegram_api toneMint
class node_entrypoint,node_database,node_decorators,node_tokens,node_force_channel,node_limiter,node_shortener toneRose
class node_browser toneIndigo
```

## Components

### Telegram bot

- [Bot clients](https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/clients.py): `Thunder/bot/clients.py`
- [File commands](https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/stream.py): `Thunder/bot/plugins/stream.py`
- [User commands](https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/common.py): `Thunder/bot/plugins/common.py`
- [Admin commands](https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/admin.py): `Thunder/bot/plugins/admin.py`
- [Button callbacks](https://github.com/fyaz05/filetolink/blob/main/Thunder/bot/plugins/callbacks.py): `Thunder/bot/plugins/callbacks.py`
- [Broadcast service](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/broadcast.py): `Thunder/utils/broadcast.py`

### File and link lifecycle

- [Canonical file records](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/canonical_files.py): `Thunder/utils/canonical_files.py`
- [Media metadata](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/file_properties.py): `Thunder/utils/file_properties.py`
- [Link generation](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/bot_utils.py): `Thunder/utils/bot_utils.py`

### HTTP delivery

- [HTTP stream routes](https://github.com/fyaz05/filetolink/blob/main/Thunder/server/stream_routes.py): `Thunder/server/stream_routes.py`
- [Media page rendering](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/render_template.py): `Thunder/utils/render_template.py`
- [Telegram file retrieval](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/custom_dl.py): `Thunder/utils/custom_dl.py`

### Platform services

- [Application startup](https://github.com/fyaz05/filetolink/blob/main/Thunder/__main__.py): `Thunder/__main__.py`
- [Persistence and access records](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/database.py): `Thunder/utils/database.py`
- [Access checks](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/decorators.py): `Thunder/utils/decorators.py`
- [Token authentication](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/tokens.py): `Thunder/utils/tokens.py`
- [Channel membership checks](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/force_channel.py): `Thunder/utils/force_channel.py`
- [Request rate limiting](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/rate_limiter.py): `Thunder/utils/rate_limiter.py`
- [URL shortening](https://github.com/fyaz05/filetolink/blob/main/Thunder/utils/shortener.py): `Thunder/utils/shortener.py`

### Other components

- **Telegram user**
- **Link visitor**
- **Telegram API**
- **Storage channel**
- **MongoDB**

## Connections

- Telegram user → File commands: submits files (evidence: `README.md`)
- File commands → Storage channel: forwards files (evidence: `README.md`)
- File commands → Canonical file records: records files (evidence: `Thunder/bot/plugins/stream.py`)
- Canonical file records → Persistence and access records: reads and writes (evidence: `Thunder/utils/canonical_files.py`)
- Persistence and access records → MongoDB: persists records (evidence: `Thunder/utils/database.py`)
- File commands → Link generation: builds links (evidence: `Thunder/bot/plugins/stream.py`)
- Link generation → URL shortening: shortens URLs (evidence: `Thunder/utils/bot_utils.py`)
- File commands → Request rate limiting: queues requests (evidence: `Thunder/bot/plugins/stream.py`)
- File commands → Access checks: checks access (evidence: `Thunder/bot/plugins/stream.py`)
- Access checks → Token authentication: validates tokens (evidence: `Thunder/utils/decorators.py`)
- User commands → Channel membership checks: checks membership (evidence: `Thunder/bot/plugins/common.py`)
- User commands → Persistence and access records: records users (evidence: `Thunder/bot/plugins/common.py`)
- Admin commands → Persistence and access records: manages records (evidence: `Thunder/bot/plugins/admin.py`)
- Admin commands → Broadcast service: starts broadcasts (evidence: `Thunder/bot/plugins/admin.py`)
- Button callbacks → Broadcast service: handles broadcast actions (evidence: `Thunder/bot/plugins/callbacks.py`)
- Link visitor → HTTP stream routes: requests media (evidence: `README.md`)
- HTTP stream routes → Canonical file records: looks up links (evidence: `Thunder/server/stream_routes.py`)
- HTTP stream routes → Bot clients: selects client (evidence: `Thunder/server/stream_routes.py`)
- HTTP stream routes → Media metadata: resolves metadata (evidence: `Thunder/server/stream_routes.py`)
- HTTP stream routes → Telegram file retrieval: retrieves media (evidence: `Thunder/server/stream_routes.py`)
- HTTP stream routes → Media page rendering: renders preview (evidence: `Thunder/server/stream_routes.py`)
- Telegram file retrieval → Telegram API: fetches file data
- Application startup → Bot clients: initializes clients (evidence: `Thunder/__main__.py`)
- Application startup → HTTP stream routes: starts server (evidence: `Thunder/__main__.py`)
- Application startup → Persistence and access records: initializes persistence (evidence: `Thunder/__main__.py`)
