# overtake/telegram architecture

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

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

## Overview

##### Project type and purpose
- This is a monolithic macOS client application (Objective-C) for Telegram, with a Share extension (TGShare) and an Updater component.
- Its purpose: provide a full Telegram desktop experience, handling UI, persistence, networking (MTProto), encryption, media codecs, crash reporting, and auto-updates.

##### File structure
- Top-level frameworks: HockeySDK.framework (crash/feedback), Sparkle.framework (auto-update).
- Submodules: MtProtoKit + Signals (Telegram’s MTProto networking & crypto).
- Static libs: libcrypto.a, libssl.a, opus/ogg/opusfile (audio codec), libwebp (image codec), sqlcipher (encrypted SQLite).
- Application code:
- TelegramTest/ – the main app’s source (view controllers, managers, models, categories).
- TGShare/ – a macOS Share extension to forward content into Telegram.
- YapDatabase/ – embedded core persistence engine.
- Xcode project with multiple targets/schemes: Telegram (main), Updater, TGShare, TGKeeper, etc.

##### README
- Confirms it is the deprecated Objective-C macOS client.
- New repo uses Swift; this one still integrates all core modules manually.

##### Main components & interactions
a. UI Layer
- TelegramTest/– NSViewControllers, windows, table views, custom controls (e.g., MessagesViewController, ChatHistoryController, SettingsViewController).
- TGShare/– ShareViewController for the extension.
b. Business Logic & Controllers
- Logic controllers in TelegramTest (e.g., TGSAppManager, TelegramTest/*Manager classes).
- View models and “SenderItem” objects for composing and sending messages.
c. Networking & Crypto
- MtProtoKit + Signals handle MTProto handshake, message encryption.
- TGS-prefixed network classes (TGS_RPCRequest, TGS_MTNetwork).
- Static crypto libs (libcrypto, libssl).
d. Persistence
- YapDatabase stores chats, messages, media metadata.
- sqlcipher for encrypted disk storage.
- FMDatabase wrappers for SQLite support.
e. Media & Codecs
- opus/ogg/opusfile for audio encoding/decoding.
- libwebp for image decoding/encoding.
f. Crash Reporting & Feedback
- HockeySDK.framework to capture and send crash reports & user feedback.
g. Auto-Update
- Sparkle.framework embedded in Updater target to check and install new versions.
h. External Services
- Telegram backend servers (MTProto API endpoints).
- Possibly third-party social service integrations (InstagramServiceDescription, YoutubeServiceDescription).

##### Architectural patterns & design principles
- MVC: View controllers orchestrate UI, models stored in YapDatabase.
- Modular subsystems: networking, persistence, UI, media codecs.
- Dependency injection via managers (ChatsManager, MessagesManager).
- Separation of concerns: Share extension isolated from main app.

##### Detailed checklist
- Components: TelegramTest App, TGShare Extension, Updater Target
- Frameworks: HockeySDK, Sparkle, MtProtoKit/Signals, YapDatabase, SQLCipher, media libraries
- Core modules: Managers (ChatsManager, MessagesManager), Network (TGS_MTNetwork), Storage (YapDatabaseConnection)
- External endpoints: Telegram MTProto API, Hockey service
- Data flows:
- User input → UI controllers → Logic → Network → Servers
- Incoming updates → Network → Logic → Persistence → UI
- Crash → HockeySDK → Crash service
- Version check → Sparkle → Download/Install

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        UI["TelegramTest UI Controllers"]:::frontend
        ShareExt["TGShare ShareViewController"]:::frontend
        UpdaterApp["Updater Target"]:::frontend
    end

    %% Core Logic & Services
    subgraph "Domain & Services"
        direction TB
        AppMgr["TGSAppManager"]:::corelogic
        ChatsMgr["ChatsManager"]:::corelogic
        MsgsMgr["MessagesManager"]:::corelogic
        UpdaterMgr["GlobalUpdaterManager"]:::corelogic
        subgraph "Networking & Crypto"
            direction TB
            MTProtoKitMod["MtProtoKit Module"]:::frameworks
            SignalsMod["Signals Crypto Module"]:::frameworks
            MTNet["MTNetwork / MTProto"]:::corelogic
            ShareNet["TGS_MTNetwork & TGS_RPCRequest"]:::corelogic
        end
    end

    %% Persistence & Infrastructure
    subgraph "Data & Infrastructure"
        direction TB
        subgraph "Persistence"
            direction TB
            YapDB["YapDatabase Core"]:::persistence
            SQLCipherLib["SQLCipher Library"]:::persistence
            FMDB["FMDatabase Wrappers"]:::persistence
        end
        subgraph "Media & Codecs"
            direction TB
            Opus["Opus / opusfile"]:::frameworks
            Ogg["Ogg"]:::frameworks
            WebP["libwebp"]:::frameworks
            SSLLibs["libcrypto.a / libssl.a"]:::frameworks
        end
        subgraph "Third-Party Frameworks"
            direction TB
            Hockey["HockeySDK.framework"]:::frameworks
            Sparkle["Sparkle.framework"]:::frameworks
        end
    end

    %% External Services
    TelegramSrv["Telegram MTProto API"]:::external
    HockeySrv["Hockey Crash Service"]:::external

    %% Relationships
    UI -->|"user actions"| AppMgr
    ShareExt -->|"share data"| ShareNet
    AppMgr -->|"orchestrates"| ChatsMgr
    AppMgr -->|"orchestrates"| MsgsMgr
    AppMgr -->|"checks updates"| UpdaterMgr
    ChatsMgr -->|"DB read/write"| YapDB
    MsgsMgr -->|"DB read/write"| YapDB
    UpdaterMgr -->|"version check"| Sparkle
    Sparkle -->|"download/install"| UpdaterApp
    AppMgr -->|"MTProto requests"| MTNet
    ShareNet -->|"MTProto requests"| MTProtoKitMod
    MTNet -->|"crypto ops"| SignalsMod
    MTNet -->|"use libs"| SSLLibs
    MTProtoKitMod -->|"connects"| TelegramSrv
    MTProtoKitMod -->|"encrypts"| SignalsMod
    YapDB -->|"storage"| SQLCipherLib
    FMDB -->|"fallback DB"| SQLCipherLib
    Opus -->|"audio codec"| AppMgr
    Ogg -->|"audio container"| AppMgr
    WebP -->|"image codec"| AppMgr
    UI -->|"capture crash"| Hockey
    Hockey -->|"send report"| HockeySrv

    %% Updater link
    UpdaterApp -->|"uses"| Sparkle

    %% Click Events
    click UI "https://github.com/overtake/telegram/tree/master/TelegramTest/"
    click ShareExt "https://github.com/overtake/telegram/blob/master/TGShare/ShareViewController.m"
    click AppMgr "https://github.com/overtake/telegram/blob/master/TelegramTest/TGSAppManager.m"
    click ChatsMgr "https://github.com/overtake/telegram/blob/master/TelegramTest/ChatsManager.m"
    click MsgsMgr "https://github.com/overtake/telegram/blob/master/TelegramTest/MessagesManager.m"
    click UpdaterMgr "https://github.com/overtake/telegram/blob/master/TelegramTest/GlobalUpdaterManager.m"
    click MTProtoKitMod "https://github.com/overtake/telegram/tree/master/MtProtoKit/"
    click SignalsMod "https://github.com/overtake/telegram/tree/master/Signals/"
    click MTNet "https://github.com/overtake/telegram/blob/master/TelegramTest/MTNetwork.m"
    click ShareNet "https://github.com/overtake/telegram/blob/master/TGShare/TGS_MTNetwork.m"
    click YapDB "https://github.com/overtake/telegram/blob/master/YapDatabase/YapDatabase.m"
    click SQLCipherLib "https://github.com/overtake/telegram/tree/master/sqlcipher/"
    click FMDB "https://github.com/overtake/telegram/blob/master/TelegramTest/FMDatabase.m"
    click Opus "https://github.com/overtake/telegram/tree/master/opus/"
    click Ogg "https://github.com/overtake/telegram/tree/master/ogg/"
    click WebP "https://github.com/overtake/telegram/tree/master/libwebp-0.4.2-mac-10.8/"
    click SSLLibs "https://github.com/overtake/telegram/blob/master/libcrypto.a"
    click Hockey "https://github.com/overtake/telegram/tree/master/HockeySDK.framework/"
    click Sparkle "https://github.com/overtake/telegram/tree/master/Sparkle.framework/"

    %% Styles
    classDef frontend fill:#D0E9FF,stroke:#0366D6,color:#0366D6
    classDef corelogic fill:#DFF5D1,stroke:#228B22,color:#228B22
    classDef persistence fill:#FFE5B4,stroke:#FF8C00,color:#FF8C00
    classDef frameworks fill:#E0E0E0,stroke:#666666,color:#333333
    classDef external fill:#F5D0D0,stroke:#D13F3F,color:#D13F3F
```
