# codexbotz/file-sharing-bot architecture

> Architecture diagram of the GitHub repository codexbotz/file-sharing-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codexbotz/file-sharing-bot
- Repository: https://github.com/codexbotz/file-sharing-bot

## Overview

##### Project type and purpose
- This is a Python-based Telegram Bot (“File-sharing-Bot”) that lets users upload posts/documents, stores them in a private Telegram channel, and returns special shareable links.
- It is essentially a backend service (no separate “frontend” UI) that interfaces with Telegram’s Bot API, a MongoDB database, and a Telegram channel used as file storage.

##### File structure
- Top-level files:
- Dockerfile, Procfile, app.json – deployment descriptors (Heroku, Docker, etc.)
- bot.py, main.py – bootstrap and run logic for the Pyrogram client
- config.py – environment-variable based configuration loader
- helper_func.py – shared utilities
- database/database.py – MongoDB connection and data-access layer
- plugins/ – individual command handlers and business-logic modules (cbb.py, channel_post.py, link_generator.py, route.py, start.py, useless.py)
- requirements.txt – pinned Python dependencies (Pyrogram, motor or pymongo, etc.)

##### README for additional insights
- Uses Pyrogram to handle updates and file operations
- Stores metadata (file IDs, captions, link tokens) in MongoDB via `DATABASE_URL`
- Posts/reads files from a “Database Channel” on Telegram
- Supports configurable features (force-sub, auto-delete, protect content) via environment variables
- Deployable on Heroku, Railway, Koyeb, or any VPS

- Blue rectangles for internal components (Application Core, Plugins)

##### Detailed capture of architectural elements
- How environment variables feed into config.py and influence feature toggles (force-sub, auto-delete)
- “Database Channel” as a special storage unit outside MongoDB but managed via the same Bot API
- If desired, annotate high-level sequence: e.g., on `/genlink` flow, highlight steps from HTTP update to final file share link

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    User["Telegram User"]:::external
    TelegramAPI["Telegram Bot API"]:::external

    %% Deployment Environment
    subgraph "Deployment Environment" 
        direction TB
        Dockerfile["Dockerfile"]:::external
        Procfile["Procfile"]:::external
        AppJSON["app.json"]:::external
    end

    %% Main Service
    subgraph "File-sharing-Bot Service"
        direction TB
        BotInit["bot.py / main.py"]:::internal
        Config["config.py"]:::config
        Utils["helper_func.py"]:::internal
        Requirements["requirements.txt"]:::internal

        subgraph "Plugin Manager & Core"
            direction TB
            Router["plugins/route.py"]:::internal

            subgraph "Plugins"
                direction TB
                CBB["plugins/cbb.py"]:::internal
                ChannelPost["plugins/channel_post.py"]:::internal
                LinkGen["plugins/link_generator.py"]:::internal
                Start["plugins/start.py"]:::internal
                Useless["plugins/useless.py"]:::internal
            end
        end

        DBLayer["database/database.py"]:::internal
    end

    %% Data Stores
    Mongo["MongoDB"]:::datastore
    Channel["Telegram Database Channel"]:::datastore

    %% Documentation
    README["README.md"]:::external

    %% Interactions
    User -->|sends update| TelegramAPI
    TelegramAPI -->|forwards update| BotInit
    BotInit -->|initializes| Config
    Config -->|loads env vars| BotInit
    BotInit -->|bootstraps| Router

    Router --> CBB
    Router --> ChannelPost
    Router --> LinkGen
    Router --> Start
    Router --> Useless

    CBB --> Utils
    ChannelPost --> Utils
    LinkGen --> Utils
    Start --> Utils
    Useless --> Utils

    CBB --> DBLayer
    ChannelPost --> DBLayer
    LinkGen --> DBLayer
    Start --> DBLayer
    Useless --> DBLayer

    DBLayer --> Mongo
    LinkGen -->|upload file| TelegramAPI
    TelegramAPI -->|posts to channel| Channel
    Channel -->|returns file_id| LinkGen
    DBLayer -->|stores metadata| Mongo

    %% Deployment link
    Dockerfile --> BotInit
    Procfile --> BotInit
    AppJSON --> BotInit

    %% Documentation link
    README --> BotInit

    %% Click Events
    click BotInit "https://github.com/codexbotz/file-sharing-bot/blob/main/bot.py"
    click Config "https://github.com/codexbotz/file-sharing-bot/blob/main/config.py"
    click Utils "https://github.com/codexbotz/file-sharing-bot/blob/main/helper_func.py"
    click Requirements "https://github.com/codexbotz/file-sharing-bot/blob/main/requirements.txt"
    click Router "https://github.com/codexbotz/file-sharing-bot/blob/main/plugins/route.py"
    click CBB "https://github.com/codexbotz/file-sharing-bot/blob/main/plugins/cbb.py"
    click ChannelPost "https://github.com/codexbotz/file-sharing-bot/blob/main/plugins/channel_post.py"
    click LinkGen "https://github.com/codexbotz/file-sharing-bot/blob/main/plugins/link_generator.py"
    click Start "https://github.com/codexbotz/file-sharing-bot/blob/main/plugins/start.py"
    click Useless "https://github.com/codexbotz/file-sharing-bot/blob/main/plugins/useless.py"
    click DBLayer "https://github.com/codexbotz/file-sharing-bot/blob/main/database/database.py"
    click Dockerfile "https://github.com/codexbotz/file-sharing-bot/tree/main/Dockerfile"
    click Procfile "https://github.com/codexbotz/file-sharing-bot/tree/main/Procfile"
    click AppJSON "https://github.com/codexbotz/file-sharing-bot/blob/main/app.json"
    click README "https://github.com/codexbotz/file-sharing-bot/blob/main/README.md"

    %% Styles
    classDef internal fill:#add8e6,stroke:#000,stroke-width:1px
    classDef datastore fill:#90ee90,stroke:#000,stroke-width:1px
    classDef external fill:#ffa500,stroke:#000,stroke-width:1px
    classDef config fill:#d3d3d3,stroke:#000,stroke-width:1px
```
