# devgaganin/save-restricted-content-bot-v3 architecture

> Architecture diagram of the GitHub repository devgaganin/save-restricted-content-bot-v3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devgaganin/save-restricted-content-bot-v3
- Repository: https://github.com/devgaganin/save-restricted-content-bot-v3

## Overview

##### Project type and purpose
- This is a Python-based Telegram Bot (Save Restricted Content Bot v3) that retrieves and forwards restricted content from channels/groups, downloads media from 100+ sites, handles large files (up to 4 GB), and provides a plugin-based command interface with optional premium features.

##### File structure
- Top-level:
- main.py / app.py: entrypoints that initialize the bot and load plugins
- config.py: environment/configuration loader
- shared_client.py: central Pyrogram client wrapper
- Dockerfile, Procfile, heroku.yml, app.json: deployment artifacts
- requirements.txt: Python dependencies
- Directories:
- plugins/ : individual command handlers (start, login, ytdl, stats, etc.)
- utils/ : shared helper functions (encryption, filters, general functions)
- templates/ : static assets (welcome.html for custom messages)
- External integrations:
- MongoDB (sessions & premium data)
- Pyrogram v2 (Telegram API)
- yt-dlp or similar (video/audio downloading)
- Optional short-link monetizer (UPShrink etc.)

##### README for additional insights
- Features: forced login, custom thumbnails/captions, file-splitting, rate limits per user tier
- Deployment options: VPS, Heroku, Render, Koyeb/Docker
- Runtime environment: environment variables for API_ID, API_HASH, BOT_TOKEN, OWNER_ID, MONGO_DB, etc.

##### Thoroughness
- Every plugin module as part of “Commands” group
- Rate-limiting logic (fremium vs. premium timers)
- Environment variables block feeding into Config
- Deployment options as separate clusters (Heroku dyno, Docker container, VPS)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and External APIs
    User["Telegram User"]:::external
    TelegramAPI["Telegram API\n(MTProto/HTTPS)"]:::external
    MediaDownloader["Media Downloader\n(yt-dlp, Instaloader)"]:::external
    LinkShortener["Link Shortener API"]:::external
    LogGroup["Log Group/Channel"]:::external

    %% Bot Process Components
    subgraph "Bot Process" 
        direction TB
        BotEntrypoint["Core Module\n(main.py/app.py)"]:::internal
        ConfigLoader["Config Loader\n(config.py)"]:::internal
        SharedClient["Shared Pyrogram Client\n(shared_client.py)"]:::internal
        PluginManager["Plugin Manager\n(plugins/)"]:::internal

        subgraph "Plugins" 
            direction TB
            Start["/start Command\n(start.py)"]:::internal
            Login["Login/Session\n(login.py)"]:::internal
            Batch["Batch Processing\n(batch.py)"]:::internal
            YTDL["Media Download\n(yt-dl.py)"]:::internal
            Pay["Payment Interface\n(pay.py)"]:::internal
            Premium["Premium Features\n(premium.py)"]:::internal
            Settings["Bot Settings\n(settings.py)"]:::internal
            Stats["Statistics\n(stats.py)"]:::internal
        end

        subgraph "Utils Library"
            direction TB
            Filters["Custom Filters\n(utils/custom_filters.py)"]:::internal
            Encrypt["Encryption Utils\n(utils/encrypt.py)"]:::internal
            Funcs["Helper Functions\n(utils/func.py)"]:::internal
        end

        TemplatesEngine["Templates Engine\n(welcome.html)"]:::internal
        MongoDB["MongoDB\n(session & premium)"]:::datastore
    end

    %% Deployment Artifacts
    subgraph "Deployment Infrastructure"
        direction TB
        Dockerfile["Dockerfile"]:::infra
        Procfile["Procfile"]:::infra
        HerokuYml["heroku.yml"]:::infra
        AppJson["app.json"]:::infra
        Requirements["requirements.txt"]:::infra
        Docs["README.md / LICENSE"]:::infra
    end

    %% Data Flows
    User -->|"Update"| TelegramAPI
    TelegramAPI -->|"Webhook/Long Poll"| BotEntrypoint
    BotEntrypoint -->|"/load config"| ConfigLoader
    BotEntrypoint -->|"init client"| SharedClient
    BotEntrypoint -->|"load plugins"| PluginManager

    PluginManager --> Start
    PluginManager --> Login
    PluginManager --> Batch
    PluginManager --> YTDL
    PluginManager --> Pay
    PluginManager --> Premium
    PluginManager --> Settings
    PluginManager --> Stats

    Start -->|"render welcome"| TemplatesEngine
    Start -->|"db read/write"| MongoDB

    Login -->|"session ops"| SharedClient
    Login -->|"db read/write"| MongoDB

    Batch -->|"calls media下载"| MediaDownloader
    Batch -->|"db read/write"| MongoDB

    YTDL -->|"HTTP/CLI"| MediaDownloader
    YTDL -->|"db read/write"| MongoDB

    Pay -->|"HTTP API"| LinkShortener
    Pay -->|"db read/write"| MongoDB

    Premium -->|"check tier"| MongoDB

    Settings -->|"db read/write"| MongoDB

    Stats -->|"aggregate data"| MongoDB

    Filters --> Start
    Encrypt --> Login
    Funcs --> Batch

    %% Response Flows
    Start -->|"send message"| TelegramAPI
    Login -->|"send message"| TelegramAPI
    Batch -->|"send files"| TelegramAPI
    YTDL -->|"send media"| TelegramAPI
    Pay -->|"send invoice"| TelegramAPI
    Premium -->|"send features"| TelegramAPI
    Settings -->|"confirm"| TelegramAPI
    Stats -->|"report"| TelegramAPI

    TelegramAPI -->|"deliver"| User

    %% Logging
    BotEntrypoint -->|"log events"| LogGroup
    PluginManager -->|"log plugin load"| LogGroup
    MongoDB -->|"log db ops"| LogGroup

    %% Deployment to Infrastructure
    BotEntrypoint -.-> Dockerfile
    BotEntrypoint -.-> Procfile
    BotEntrypoint -.-> HerokuYml
    BotEntrypoint -.-> AppJson
    BotEntrypoint -.-> Requirements
    BotEntrypoint -.-> Docs

    %% Click Events
    click BotEntrypoint "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/main.py"
    click ConfigLoader "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/config.py"
    click SharedClient "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/shared_client.py"
    click PluginManager "https://github.com/devgaganin/save-restricted-content-bot-v3/tree/main/plugins/"
    click Start "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/plugins/start.py"
    click Login "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/plugins/login.py"
    click Batch "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/plugins/batch.py"
    click YTDL "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/plugins/ytdl.py"
    click Pay "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/plugins/pay.py"
    click Premium "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/plugins/premium.py"
    click Settings "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/plugins/settings.py"
    click Stats "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/plugins/stats.py"
    click Filters "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/utils/custom_filters.py"
    click Encrypt "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/utils/encrypt.py"
    click Funcs "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/utils/func.py"
    click TemplatesEngine "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/templates/welcome.html"
    click Dockerfile "https://github.com/devgaganin/save-restricted-content-bot-v3/tree/main/Dockerfile"
    click Procfile "https://github.com/devgaganin/save-restricted-content-bot-v3/tree/main/Procfile"
    click HerokuYml "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/heroku.yml"
    click AppJson "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/app.json"
    click Requirements "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/requirements.txt"
    click Docs "https://github.com/devgaganin/save-restricted-content-bot-v3/blob/main/README.md"

    %% Styles
    classDef internal fill:#D0E8FF,stroke:#0366D6,stroke-width:1px;
    classDef external fill:#E2F0D9,stroke:#2E7D32,stroke-width:1px;
    classDef datastore fill:#FFE8A1,stroke:#FFA000,stroke-width:1px;
    classDef infra fill:#ECECEC,stroke:#888888,stroke-width:1px;
```
