# jarvis2f/telegram-files architecture

> Architecture diagram of the GitHub repository jarvis2f/telegram-files, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jarvis2f/telegram-files
- Repository: https://github.com/jarvis2f/telegram-files

## Overview

##### Main Components Identification

The system consists of three main parts:
- Frontend (Web Application)
- Backend API (Java-based)
- Telegram Integration (TDLib)

##### Key Architectural Elements

a) Backend Architecture:
- Uses Vert.x (evident from Verticle patterns in the code)
- Repository pattern for data management
- Multiple specialized verticles:
- HttpVerticle (API endpoints)
- TelegramVerticle (Telegram communication)
- AutoDownloadVerticle (Automated downloads)
- DataVerticle (Data management)

b) Frontend Architecture:
- Next.js application
- React components
- WebSocket integration for real-time updates

**[Client Layer]**
**Web UI (Next.js) <---> WebSocket Connection**

- v
**[API Layer]**
**HTTP Verticle <---> Data Verticle**

- v               v
**[Integration Layer]**
**Telegram Verticle   File Repository**

- v               v
**[External Services]**
**TDLib <-----------> Telegram Servers**

##### Component Relationships

- Bidirectional communication between Web UI and Backend via WebSocket and HTTP
- Data flow from Telegram through TDLib to the application
- File download paths
- Repository interactions

##### Important Details

a) Frontend Components:
- Account management
- File listing and controls
- Settings management
- Real-time updates via WebSocket

b) Backend Services:
- File download management
- Multiple account handling
- Auto-download functionality
- Proxy support

c) Data Stores:
- File records
- Settings storage
- Telegram account information
- Download state management

##### Implementation Notes

- The event-driven nature of the system (Vert.x)
- Real-time communication paths
- File processing pipeline
- Security boundaries

This system design should help developers understand how the components interact and how data flows through the application, from Telegram sources to the end user's downloads.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef data fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef ws fill:#9b59b6,stroke:#8e44ad,color:white

    %% Frontend Layer
    subgraph Frontend
        WebUI["Web Application (Next.js)"]:::frontend
        AccountUI["Account Management"]:::frontend
        FileUI["File Management"]:::frontend
        SettingsUI["Settings Management"]:::frontend
        ProxyUI["Proxy Configuration"]:::frontend
        WSClient["WebSocket Client"]:::ws
        APIClient["API Client"]:::frontend
    end

    %% Backend Layer
    subgraph Backend
        HttpV["HTTP Verticle"]:::backend
        DataV["Data Verticle"]:::backend
        TelegramV["Telegram Verticle"]:::backend
        AutoDownloadV["Auto Download Verticle"]:::backend
    end

    %% Repository Layer
    subgraph Repositories
        FileRepo["File Repository"]:::data
        SettingsRepo["Settings Repository"]:::data
        TelegramRepo["Telegram Repository"]:::data
    end

    %% External Services
    subgraph External
        TDLib["TDLib Integration"]:::external
        TGServers["Telegram Servers"]:::external
    end

    %% Connections
    WebUI --> AccountUI & FileUI & SettingsUI & ProxyUI
    AccountUI & FileUI & SettingsUI & ProxyUI --> APIClient
    WebUI --> WSClient
    WSClient <--> HttpV
    APIClient <--> HttpV
    HttpV <--> DataV
    DataV <--> FileRepo & SettingsRepo & TelegramRepo
    TelegramV <--> TDLib
    AutoDownloadV <--> DataV
    TDLib <--> TGServers

    %% Click Events
    click WebUI "https://github.com/jarvis2f/telegram-files/tree/main/web/src/app"
    click AccountUI "https://github.com/jarvis2f/telegram-files/blob/main/web/src/components/account-list.tsx"
    click FileUI "https://github.com/jarvis2f/telegram-files/blob/main/web/src/components/file-list.tsx"
    click SettingsUI "https://github.com/jarvis2f/telegram-files/blob/main/web/src/components/settings-form.tsx"
    click ProxyUI "https://github.com/jarvis2f/telegram-files/blob/main/web/src/components/proxys.tsx"
    click WSClient "https://github.com/jarvis2f/telegram-files/blob/main/web/src/hooks/use-websocket.tsx"
    click APIClient "https://github.com/jarvis2f/telegram-files/blob/main/web/src/lib/api.ts"
    click HttpV "https://github.com/jarvis2f/telegram-files/blob/main/api/src/main/java/telegram/files/HttpVerticle.java"
    click DataV "https://github.com/jarvis2f/telegram-files/blob/main/api/src/main/java/telegram/files/DataVerticle.java"
    click TelegramV "https://github.com/jarvis2f/telegram-files/blob/main/api/src/main/java/telegram/files/TelegramVerticle.java"
    click AutoDownloadV "https://github.com/jarvis2f/telegram-files/blob/main/api/src/main/java/telegram/files/AutoDownloadVerticle.java"
    click FileRepo "https://github.com/jarvis2f/telegram-files/blob/main/api/src/main/java/telegram/files/repository/impl/FileRepositoryImpl.java"
    click SettingsRepo "https://github.com/jarvis2f/telegram-files/blob/main/api/src/main/java/telegram/files/repository/impl/SettingRepositoryImpl.java"
    click TelegramRepo "https://github.com/jarvis2f/telegram-files/blob/main/api/src/main/java/telegram/files/repository/impl/TelegramRepositoryImpl.java"
    click TDLib "https://github.com/jarvis2f/telegram-files/tree/main/api/src/main/java/org/drinkless/tdlib"
```
