# ayugram/ayugramdesktop architecture

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

- Interactive diagram: https://gitdiagram.com/ayugram/ayugramdesktop
- Repository: https://github.com/ayugram/ayugramdesktop

## Overview

This project is a full-featured, cross‐platform desktop Telegram client that builds on and customizes the Telegram Desktop codebase. The goals (as described in the README) include features such as enhanced ghost mode, message history, anti-recall functionality, font and appearance customization, streamer mode, local “Telegram Premium” functionality, and improved media previews among others. The project is written in C++ and uses CMake for its build system, along with several third‐party libraries (such as “JSON for Modern C++”, SQLite, ffmpeg, and others) and custom platform integration code for Windows, macOS, and Linux.

##### Main Architectural Components
a. User Interface (UI) Layer:
- This includes everything related to dialogs, chats, settings, menus, media views, and widgets. It is organized into multiple modules under “Telegram/SourceFiles/ui” as well as subdirectories like “dialogs”, “chat”, “widgets”, and “window”.

b. Core Application Logic:
- The core logic resides in directories like “Telegram/SourceFiles/core”, “main”, “logs”, “data”, “storage” and “support”. This layer encapsulates the business logic for handling chats, user sessions, message processing, history, state management, and utility services.
- A block for “Core Engine” that orchestrates the application’s behavior.

c. Network & Communication (MTProto Layer):
- The “Telegram/SourceFiles/mtproto” directory contains the network communication layer, including MTProto connection handling, encryption (e.g., mtproto_auth_key), session management, and low-level messaging.
- A distinct “Network/MTProto Module” which interfaces with both the core engine and the remote Telegram API servers.

d. Media & Data Processing:
- Media processing is spread across “Telegram/SourceFiles/media”, “ffmpeg”, and related folders. This includes audio, video, image media processing, streaming, and document handling.
- A “Media Management” or “Multimedia Processing” component should be drawn that interacts with both the UI (for media playback/display) and core layers (for media preloading and caching).

e. Storage, Database & Local Data:
- Data persistence and caching (e.g., messages history, user profiles, settings) are handled by components in “data”, “storage” and possibly through SQLite bindings present in the project.
- A “Local Database / Persistence” module that feeds data to the core layer.

f. Platform Abstraction/Integration:
- Platform-specific folders like “Telegram/SourceFiles/platform” (with subfolders for linux, mac, win) provide operating system–focused integrations like file utilities, notifications, window management, and custom UI behavior.

g. Build, Configuration & Third‐Party Libraries:
- Critical build scripts are in “CMakeLists.txt”, the “cmake” folder, and the “build” directory.
- Third‑party components like JSON, SQLite, ffmpeg, and additional libraries (eg. lib_lottie, lib_qr) which are linked into various modules.

##### Relationships and Interactions
- The UI sends user input to the Core Engine.
- The Core Engine processes the logic and retrieves/stores data in the persistence layer.
- The Network/MTProto module communicates with remote Telegram servers and passes incoming/outgoing messages to the Core Engine.
- The Media module handles media rendering and passes media data between storage and the UI.
- The Platform Abstraction Layer provides OS-specific services (notifications, file operations, session management) that are used by the core and UI layers.
- The Build & Dependency block influences nearly every module by providing necessary libraries via the build system.

##### Architectural Patterns and Technologies
– Note the modular separation where the application is divided into multiple components (UI, Core, MTProto, Media, Storage, Platform Integration).
– Emphasize abstraction layers (e.g., platform abstraction), decoupling of UI and business logic, and separation between network communication and application logic.
– Identify the “plugin” or “extensibility” points in settings, customization of fonts/themes, and potentially localized resources (language files under “Telegram/Resources/langs”).
– Mention that build and integration are centrally managed via CMake, with directory structures clearly reflecting the separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer (UI)"
        UI["UI Components"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        CoreEngine["Core Engine"]:::core
    end

    %% Communication & Media Processing
    subgraph "Communication & Media"
        MTProto["Network & MTProto"]:::network
        Media["Media Handler"]:::media
    end

    %% Data Storage & Persistence
    subgraph "Data Storage & Persistence"
        Storage["Local Persistence"]:::storage
    end

    %% Platform Integration
    subgraph "Platform Integration"
        Platform["Platform Abstraction"]:::platform
    end

    %% Build & Dependency Management
    subgraph "Build & Dependency Management"
        BuildMgmt["Build Management"]:::build
        B1["CMakeLists.txt"]:::build
        B2["Telegram/CMakeLists.txt"]:::build
        B3["Telegram/cmake"]:::build
        B4["Telegram/build"]:::build
    end

    %% Relationships
    UI -->|"UserCommands"| CoreEngine
    CoreEngine -->|"ProcessMsg"| MTProto
    CoreEngine -->|"AccessData"| Storage
    MTProto -->|"MsgFlow"| CoreEngine
    CoreEngine -->|"MediaRequest"| Media
    Media -->|"MediaContent"| UI
    Platform -->|"OS_Services"| CoreEngine
    Platform -->|"OS_Features"| UI
    BuildMgmt -->|"Deps"| UI
    BuildMgmt -->|"Deps"| CoreEngine
    BuildMgmt -->|"Deps"| MTProto
    BuildMgmt -->|"Deps"| Media
    BuildMgmt -->|"Deps"| Storage
    BuildMgmt -->|"Deps"| Platform

    %% Styles
    classDef ui fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef core fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef network fill:#ffe5b4,stroke:#fd7e14,stroke-width:2px;
    classDef media fill:#e2e3f3,stroke:#6f42c1,stroke-width:2px;
    classDef storage fill:#d1ecf1,stroke:#17a2b8,stroke-width:2px;
    classDef platform fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef build fill:#f8d7da,stroke:#dc3545,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/ayugram/ayugramdesktop/tree/dev/Telegram/SourceFiles/ui"
    click CoreEngine "https://github.com/ayugram/ayugramdesktop/tree/dev/Telegram/SourceFiles/core"
    click MTProto "https://github.com/ayugram/ayugramdesktop/tree/dev/Telegram/SourceFiles/mtproto"
    click Media "https://github.com/ayugram/ayugramdesktop/tree/dev/Telegram/SourceFiles/media"
    click Storage "https://github.com/ayugram/ayugramdesktop/tree/dev/Telegram/SourceFiles/storage"
    click Platform "https://github.com/ayugram/ayugramdesktop/tree/dev/Telegram/SourceFiles/platform"
    click BuildMgmt "https://github.com/ayugram/ayugramdesktop/blob/dev/CMakeLists.txt"
    click B1 "https://github.com/ayugram/ayugramdesktop/blob/dev/CMakeLists.txt"
    click B2 "https://github.com/ayugram/ayugramdesktop/blob/dev/Telegram/CMakeLists.txt"
    click B3 "https://github.com/ayugram/ayugramdesktop/tree/dev/Telegram/cmake"
    click B4 "https://github.com/ayugram/ayugramdesktop/tree/dev/Telegram/build"
```
