# aahnik/tgcf architecture

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

- Interactive diagram: https://gitdiagram.com/aahnik/tgcf
- Repository: https://github.com/aahnik/tgcf

## Overview

##### Main Components

a) Core Components:
- Telegram Client Interface (Both Bot and User account support)
- Message Processing Pipeline
- Plugin System
- Web UI Server
- CLI Interface
- Storage Layer

b) Plugin Components:
- Filter Plugin
- Format Plugin
- Replace Plugin
- Caption Plugin
- Watermark Plugin
- OCR Plugin

**Top Layer: User Interfaces**

**Middle Layer: Core Processing**

**Bottom Layer: Telegram API Integration**

##### Specific Elements and Relationships

a) User Interface Layer:
- Web UI (Streamlit-based) with components:
- Telegram Login
- Admin Panel
- Connections Manager
- Plugin Configuration
- Run Controls
- CLI Interface
- Bot Commands Interface

b) Core Processing Layer:
- Configuration Manager
- Message Router
- Plugin Manager
- Mode Controllers (Past/Live)

c) Integration Layer:
- Telegram Client Manager
- Storage Handler
- External Services (OCR, FFmpeg)

##### Flow Representation

- Message flow from source to destination
- Plugin processing pipeline
- Configuration data flow
- Authentication flow

##### Technical Details

- Python 3.10+ requirement
- FFmpeg integration
- Tesseract OCR integration
- Environment variables handling
- Storage mechanisms

##### The message transformation pipeline

Use a hierarchical layout with:
- Clear component boundaries
- Explicit data flow directions
- Plugin chain visualization
- Configuration management flow

Important Notes:
- Keep the core message forwarding logic central
- Plugin system's extensibility
- Both synchronous and asynchronous operations
- Deployment options (Docker, cloud platforms)
- Demonstrate security layers (authentication, authorization)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        WUI["Web UI (Streamlit)"]
        CLI["CLI Interface"]:::cli
        BOT["Bot Commands"]:::bot
        
        subgraph WebPages["Web UI Components"]
            MainUI["Main UI"]:::webui
            Login["Telegram Login"]:::webui
            Admin["Admin Panel"]:::webui
            Conn["Connections Manager"]:::webui
            PlugConfig["Plugin Configuration"]:::webui
            RunCtrl["Run Controls"]:::webui
        end
    end

    subgraph Core["Core Processing Layer"]
        Config["Configuration Manager"]:::config
        Router["Message Router"]
        PluginMgr["Plugin Manager"]:::plugin_models
        
        subgraph Modes["Operation Modes"]
            Live["Live Mode"]:::live
            Past["Past Mode"]:::past
        end
        
        subgraph Plugins["Plugin System"]
            Filter["Filter Plugin"]:::filter
            Format["Format Plugin"]:::format
            Replace["Replace Plugin"]:::replace
            Caption["Caption Plugin"]:::caption
            Mark["Watermark Plugin"]:::mark
            OCR["OCR Plugin"]:::ocr
        end
    end

    subgraph Integration["Integration Layer"]
        TG["Telegram Client Manager"]:::tgclient
        Store["Storage Handler"]:::storage
        ExtSvc["External Services"]
    end

    %% Relationships
    UI --> Core
    Core --> Integration
    Router --> Plugins
    Plugins --> Router
    TG --> Router
    Config --> Store
    
    %% Click Events
    click CLI "https://github.com/aahnik/tgcf/blob/main/tgcf/cli.py"
    click BOT "https://github.com/aahnik/tgcf/tree/main/tgcf/bot/"
    click MainUI "https://github.com/aahnik/tgcf/blob/main/tgcf/web_ui/0_👋_Hello.py"
    click Login "https://github.com/aahnik/tgcf/blob/main/tgcf/web_ui/pages/1_🔑_Telegram_Login.py"
    click Admin "https://github.com/aahnik/tgcf/blob/main/tgcf/web_ui/pages/2_⭐_Admins.py"
    click Conn "https://github.com/aahnik/tgcf/blob/main/tgcf/web_ui/pages/3_🔗_Connections.py"
    click PlugConfig "https://github.com/aahnik/tgcf/blob/main/tgcf/web_ui/pages/4_🔌_Plugins.py"
    click RunCtrl "https://github.com/aahnik/tgcf/blob/main/tgcf/web_ui/pages/5_🏃_Run.py"
    click Config "https://github.com/aahnik/tgcf/blob/main/tgcf/config.py"
    click PluginMgr "https://github.com/aahnik/tgcf/blob/main/tgcf/plugin_models.py"
    click Live "https://github.com/aahnik/tgcf/blob/main/tgcf/live.py"
    click Past "https://github.com/aahnik/tgcf/blob/main/tgcf/past.py"
    click Filter "https://github.com/aahnik/tgcf/blob/main/tgcf/plugins/filter.py"
    click Format "https://github.com/aahnik/tgcf/blob/main/tgcf/plugins/fmt.py"
    click Replace "https://github.com/aahnik/tgcf/blob/main/tgcf/plugins/replace.py"
    click Caption "https://github.com/aahnik/tgcf/blob/main/tgcf/plugins/caption.py"
    click Mark "https://github.com/aahnik/tgcf/blob/main/tgcf/plugins/mark.py"
    click OCR "https://github.com/aahnik/tgcf/blob/main/tgcf/plugins/ocr.py"
    click TG "https://github.com/aahnik/tgcf/tree/main/tgcf/bot/"
    click Store "https://github.com/aahnik/tgcf/blob/main/tgcf/storage.py"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef cli fill:#purple,stroke:#333
    classDef bot fill:#purple,stroke:#333
    classDef webui fill:#purple,stroke:#333
    classDef config fill:#blue,stroke:#333
    classDef plugin_models fill:#blue,stroke:#333
    classDef live fill:#green,stroke:#333
    classDef past fill:#green,stroke:#333
    classDef filter fill:#green,stroke:#333
    classDef format fill:#green,stroke:#333
    classDef replace fill:#green,stroke:#333
    classDef caption fill:#green,stroke:#333
    classDef mark fill:#green,stroke:#333
    classDef ocr fill:#green,stroke:#333
    classDef tgclient fill:#orange,stroke:#333
    classDef storage fill:#gray,stroke:#333
```
