# daverameshbhai4-netizen/drm-video- architecture

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

- Interactive diagram: https://gitdiagram.com/daverameshbhai4-netizen/drm-video-
- Repository: https://github.com/daverameshbhai4-netizen/drm-video-

## Overview

##### Project Type & Purpose
- Project type: A backend-only application (Telegram bot) written in Python.
- Purpose: Accepts commands via Telegram (e.g. /start, /stop), fetches video streams (including DRM-protected content), processes them, and delivers them back to users.
- Deployment targets: Heroku, Render, Koyeb (containerized via Dockerfile, heroku.yml, render.yaml).

##### File Structure
Top-level files:
– app.py, main.py: entry-points that bootstrap the bot
– commands.py, features.py: define user-command handlers and feature toggles
– *.py files ending in `_handler.py`: separate modules for handling DRM content, HTML generation, text, YouTube integration
– authorisation.py: handles bot-level authentication (Telegram API credentials via vars.py)
– broadcast.py, upgrade.py: auxiliary tasks (mass messaging, updating code)
– utils.py, settings.py, globals.py, vars.py: configuration, constants, shared utilities
Configuration & deployment:
– Dockerfile, heroku.yml, render.yaml, Procfile, runtime.txt: define container, dyno, runtime for cloud
– requirements.txt: Python library dependencies

##### README Insights
- Telegram bot commands
- DRM-supported downloads (minimum quality 360p)
- Easy deployment (Heroku/Render/Koyeb)

##### Main Architectural Components
a. Telegram Gateway
– Component: Uses Telethon or Pyrogram library (imported in main/app)
– Role: Listens for incoming messages/commands, forwards them to the bot application
b. Bot Application
– Command Dispatcher (commands.py)
– Business Logic & Features (features.py)
– Handlers:
- youtube_handler.py → invokes YouTube API to fetch streams
- drm_handler.py → decrypts/processes DRM-protected streams
- html_handler.py → generates any HTML previews or embeds
- text_handler.py → handles plain text content
– Utility & Config Layer (utils.py, settings.py, vars.py, globals.py)
c. Data Store / File System
– Temporary storage of downloaded video files, logs, keys (e.g. device_private_key.txt)
d. External Services
– Telegram API (for bot messaging)
– YouTube Data/Streaming API (for fetching media)
e. Deployment Infrastructure
– Docker container
– Heroku/Render/Koyeb as hosting platforms

##### Relationships & Data Flow
1. User sends command in Telegram → Telegram API
2. Telegram API → Bot container’s entry point (main.py / app.py)
3. Dispatcher identifies command → routes to correct handler module
4. Handler (e.g. youtube_handler) calls external API (YouTube) → retrieves media
5. If content is DRM-protected → drm_handler processes video stream
6. Processed media is saved locally → then sent back via Telegram API
7. Logs and metrics emitted by logs.py and broadcast messages can run on schedule

##### Architectural Patterns & Principles
- Modular Handler Pattern: each content type (text, HTML, video, DRM) has its own handler
- Separation of Concerns: config/util modules are separate from business logic
- Cloud-native Deployment: containerized app with 12-factor style config (Procfile, env vars in vars.py)

– Clear component names (matching file names & modules)
– Notes on configuration (env vars in vars.py)

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef internal fill:#D0E8FF,stroke:#004E89,color:#000
    classDef external fill:#DFF2BF,stroke:#4F8A10,color:#000
    classDef storage fill:#FFE4B5,stroke:#CC7722,color:#000
    classDef infra fill:#E8E8E8,stroke:#A9A9A9,color:#000
    classDef async stroke-dasharray: 5 5

    subgraph "Telegram API Gateway"
        TG1["app.py"]:::internal
        TG2["main.py"]:::internal
    end

    subgraph "Bot Application"
        Dispatcher["commands.py"]:::internal
        Features["features.py"]:::internal
        subgraph "Handlers"
            YT["youtube_handler.py"]:::internal
            DRM["drm_handler.py"]:::internal
            HTML["html_handler.py"]:::internal
            Text["text_handler.py"]:::internal
        end
        subgraph "Auth & Config"
            Auth["authorisation.py"]:::internal
            Vars["vars.py"]:::internal
            Settings["settings.py"]:::internal
            Globals["globals.py"]:::internal
        end
        Util["utils.py"]:::internal
        Logs["logs.py"]:::internal
        Broadcast["broadcast.py"]:::internal
        Upgrade["upgrade.py"]:::internal
    end

    subgraph "Temporary Storage"
        DS1["device_private_key.txt"]:::storage
        DS2["device_client_id_blob"]:::storage
    end

    subgraph "External Services"
        TelegramAPI["Telegram API"]:::external
        YouTubeAPI["YouTube API"]:::external
    end

    subgraph "Deployment Infrastructure"
        Dockerfile["Dockerfile"]:::infra
        Runtime["runtime.txt"]:::infra
        HerokuYml["heroku.yml"]:::infra
        Procfile["Procfile"]:::infra
        RenderYml["render.yaml"]:::infra
        Requirements["requirements.txt"]:::infra
    end

    %% Data Flows
    TelegramAPI -->|"Webhook / Updates"| TG1
    TelegramAPI -->|"Webhook / Updates"| TG2
    TG1 -->|"Invoke"| Dispatcher
    TG2 -->|"Invoke"| Dispatcher
    Dispatcher -->|"routes to"| YT
    Dispatcher -->|"routes to"| DRM
    Dispatcher -->|"routes to"| HTML
    Dispatcher -->|"routes to"| Text
    YT -->|"HTTPS REST"| YouTubeAPI
    DRM -->|"decrypt/process"| DS1
    DRM -->|"decrypt/process"| DS2
    DRM -->|"processed media"| TelegramAPI
    Logs -.->|"emit logs"| DS1
    Broadcast -.->|"mass messaging"| TelegramAPI
    Upgrade -.->|"self-update trigger"| Dockerfile

    %% Deployment Links
    Dockerfile -->|"build container"| Runtime
    Dockerfile --> HerokuYml
    Dockerfile --> RenderYml
    HerokuYml --> Procfile
    Dockerfile --> Requirements

    %% Click Events
    click TG1 "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/app.py"
    click TG2 "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/main.py"
    click Dispatcher "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/commands.py"
    click Features "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/features.py"
    click YT "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/youtube_handler.py"
    click DRM "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/drm_handler.py"
    click HTML "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/html_handler.py"
    click Text "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/text_handler.py"
    click Auth "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/authorisation.py"
    click Vars "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/vars.py"
    click Util "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/utils.py"
    click Settings "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/settings.py"
    click Globals "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/globals.py"
    click Logs "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/logs.py"
    click Broadcast "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/broadcast.py"
    click Upgrade "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/upgrade.py"
    click DS1 "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/device_private_key.txt"
    click DS2 "https://github.com/daverameshbhai4-netizen/drm-video-/tree/main/device_client_id_blob"
    click Dockerfile "https://github.com/daverameshbhai4-netizen/drm-video-/tree/main/Dockerfile"
    click Runtime "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/runtime.txt"
    click HerokuYml "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/heroku.yml"
    click Procfile "https://github.com/daverameshbhai4-netizen/drm-video-/tree/main/Procfile"
    click RenderYml "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/render.yaml"
    click Requirements "https://github.com/daverameshbhai4-netizen/drm-video-/blob/main/requirements.txt"
```
