# nicegram/tdjson architecture

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

- Interactive diagram: https://gitdiagram.com/nicegram/tdjson
- Repository: https://github.com/nicegram/tdjson

## Overview

##### Main Components

a. Core Components:
- TDJSON Framework (Swift Wrapper)
- TDLib (Core Telegram Database Library)
- OpenSSL Dependencies
- JSON Interface Layer
- Client Applications

**┌─────────────────────────────────────┐**
- Client iOS Application       │
- ┘
- ↓
**┌─────────────────────────────────────┐**
- TDJSON.framework            │
- ┌─────────────────────────────┐    │
- Swift Interface Layer    │    │
- td_json_client.swift     │    │
- td_log.swift            │    │
- ┘    │
- ┘
- ↓
**┌─────────────────────────────────────┐**
- TDLib Core               │
- ┌─────────────────────────────┐    │
- Native Libraries        │    │
- libtdjson_static.a      │    │
- libtdclient.a           │    │
- libtdcore.a             │    │
- ┘    │
- ┘
- ↓
**┌─────────────────────────────────────┐**
- OpenSSL Dependencies        │
- (iOS and macOS implementations)    │
- ┘

##### Important Details to Highlight

a. Integration Points:
- JSON-based communication interface
- Swift wrapper methods
- Native library bindings

b. Platform Support:
- iOS framework compatibility
- macOS support
- Cross-platform capabilities

##### Component Relationships

- How the Swift wrapper interfaces with TDLib through JSON
- Dependency on OpenSSL for cryptographic operations
- Demonstrate the modular nature of the library components

##### Additional Elements

- A note about version compatibility with TDLib releases
- Build process flow (optional)
- Carthage integration path

##### Technical Details

- The JSON-based communication protocol
- The static library architecture
- The security layer implementation
- Platform-specific implementations (iOS/macOS)

##### Implementation Notes

- Use standardized UML notation where appropriate
- Maintain clean separation between layers
- Both compilation and runtime relationships

- Layer-based architecture representation
- Clear typography for labels
- Export in high-resolution formats
- Easy maintenance and updates

Remember to keep the focus on the wrapper nature of the project while showing its relationship to the underlying TDLib implementation and security infrastructure.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        App[iOS Application]:::client
    end

    subgraph TDJSON["TDJSON Framework"]
        SwiftInterface[Swift Interface Layer]:::swift
        TDJSONClient["td_json_client.swift"]:::swift
        TDLog["td_log.swift"]:::swift
        TDJSONH["TDJSON.h"]:::header
    end

    subgraph TDLib["TDLib Core"]
        JSONInterface["JSON Interface Layer"]:::core
        TDLibCore["Core Libraries"]:::core
        subgraph CoreLibs["Static Libraries"]
            LibTDJSON["libtdjson_static.a"]:::lib
            LibTDClient["libtdclient.a"]:::lib
            LibTDCore["libtdcore.a"]:::lib
            LibTDActor["libtdactor.a"]:::lib
            LibTDDB["libtddb.a"]:::lib
            LibTDNet["libtdnet.a"]:::lib
            LibTDSQLite["libtdsqlite.a"]:::lib
            LibTDUtils["libtdutils.a"]:::lib
        end
        TDAPI["td_api.h"]:::header
        TDClient["Client.h"]:::header
    end

    subgraph Security["Security Layer"]
        OpenSSL["OpenSSL Dependencies"]:::security
        subgraph SSLLibs["SSL Libraries"]
            LibSSL["libssl.a"]:::lib
            LibCrypto["libcrypto.a"]:::lib
        end
        subgraph Platforms["Platform Implementations"]
            iOSSSL["iOS OpenSSL"]:::security
            macOSSSL["macOS OpenSSL"]:::security
        end
    end

    %% Relationships
    App --> SwiftInterface
    SwiftInterface --> TDJSONClient
    SwiftInterface --> TDLog
    SwiftInterface --> TDJSONH
    TDJSONClient --> JSONInterface
    TDLog --> JSONInterface
    JSONInterface --> TDLibCore
    TDLibCore --> CoreLibs
    TDLibCore --> OpenSSL
    OpenSSL --> SSLLibs
    OpenSSL --> Platforms

    %% Click Events
    click TDJSONClient "https://github.com/nicegram/TDJSON/blob/master/TDJSON/td_json_client.swift"
    click TDLog "https://github.com/nicegram/TDJSON/blob/master/TDJSON/td_log.swift"
    click TDJSONH "https://github.com/nicegram/TDJSON/blob/master/TDJSON/TDJSON.h"
    click LibTDJSON "https://github.com/nicegram/TDJSON/blob/master/lib/libtdjson_static.a"
    click LibTDClient "https://github.com/nicegram/TDJSON/blob/master/lib/libtdclient.a"
    click LibTDCore "https://github.com/nicegram/TDJSON/blob/master/lib/libtdcore.a"
    click TDAPI "https://github.com/nicegram/TDJSON/blob/master/include/td/telegram/td_api.h"
    click TDClient "https://github.com/nicegram/TDJSON/blob/master/include/td/telegram/Client.h"
    click LibTDActor "https://github.com/nicegram/TDJSON/blob/master/lib/libtdactor.a"
    click LibTDDB "https://github.com/nicegram/TDJSON/blob/master/lib/libtddb.a"
    click LibTDNet "https://github.com/nicegram/TDJSON/blob/master/lib/libtdnet.a"
    click LibTDSQLite "https://github.com/nicegram/TDJSON/blob/master/lib/libtdsqlite.a"
    click LibTDUtils "https://github.com/nicegram/TDJSON/blob/master/lib/libtdutils.a"
    click LibSSL "https://github.com/nicegram/TDJSON/blob/master/lib/libssl.a"
    click LibCrypto "https://github.com/nicegram/TDJSON/blob/master/lib/libcrypto.a"
    click iOSSSL "https://github.com/nicegram/TDJSON/tree/master/third_party/openssl/iOS"
    click macOSSSL "https://github.com/nicegram/TDJSON/tree/master/third_party/openssl/macOS"

    %% Styles
    classDef client fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef swift fill:#5596e6,stroke:#333,color:white
    classDef core fill:#41d6c3,stroke:#333
    classDef security fill:#ffd591,stroke:#333
    classDef header fill:#e8e8e8,stroke:#333
    classDef lib fill:#d4bbf9,stroke:#333
```
