# haivision/srt architecture

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

- Interactive diagram: https://gitdiagram.com/haivision/srt
- Repository: https://github.com/haivision/srt

## Overview

##### Project type and purpose
- This is an open-source protocol library (Secure Reliable Transport – SRT) implemented in C/C++.
- It provides:
- Core protocol engine (packetizing, ARQ, FEC, bonding, handshakes)
- Crypto abstraction layer (haicrypt) for AES encryption via OpenSSL, Botan, mbedTLS, or GnuTLS
- Sample CLI applications (srt-live-transmit, srt-file-transmit, etc.)
- Examples, tests, and build/deployment scripts for multiple platforms.

##### File structure
- Top-level:
- srtcore/ – core engine, API exposure, platform abstraction
- haicrypt/ – pluggable crypto backends
- apps/ – command-line tools demonstrating library usage
- examples/ – minimal code snippets showing client/server usage
- test/ & testing/ – unit tests and functional tests
- scripts/ – CMake helpers, platform build wrappers, installer scripts, CI workflows
- docs/, docs/API, docs/features, docs/build – architecture docs, API reference, feature descriptions, build guides
- Build: configure, CMakeLists.txt, per-platform CI YAMLs (.github/workflows, .travis.yml, appveyor).
- External dependencies are injected via CMake scripts (FindBotan, FindMbedTLS, OpenSSL, pthreads).

##### README for additional insights
- Confirms the protocol features (low-latency transport, ARQ/FEC, bonding, encryption).
- References to API documentation and sample applications.
- Build targets: Linux/macOS/iOS/Android/Windows, package managers.

##### Elements
- Labels for: Developer, Build System, srtcore (with submodules), haicrypt (interface + backends), Apps, Examples, Tests, External Dependencies, CI/CD
- Developer → Build System → Library+Apps
- Apps/Tests → srtcore → haicrypt → crypto backends
- srtcore → OS Socket API
- CI/CD → triggers Build System and runs Tests
- Orange for build artifacts/scripts

## Diagram (Mermaid)

```mermaid
flowchart TD
    Developer["Developer"]:::actor
    BuildSystem["Build System"]:::build
    CICD["CI/CD Pipelines"]:::build
    srtcore["srtcore Library"]:::component
    subgraph "srtcore Modules"
        API["API Layer"]:::component
        Handshake["Handshake Module"]:::component
        Packet["Packet Pipeline"]:::component
        Buffer["Buffer Management"]:::component
        CongCtl["Congestion Control"]:::component
        FEC["FEC Support"]:::component
        Bonding["Bonding/Group Management"]:::component
        Stats["Statistics"]:::component
        CoreGlue["Core Engine Glue"]:::component
    end
    subgraph "Platform Abstraction"
        Epoll["Event Polling"]:::component
        Sync["Threading & Sync"]:::component
        Clock["Atomic Clocks"]:::component
        OSCompat["OS Compatibility"]:::component
    end
    haicrypt["haicrypt Layer"]:::component
    subgraph "Crypto Backends"
        OpenSSL["OpenSSL Backend"]:::external
        Botan["Botan Backend"]:::external
        MbedTLS["mbedTLS Backend"]:::external
        GnuTLS["GnuTLS Backend"]:::external
    end
    Apps["CLI Applications"]:::component
    Examples["Examples"]:::component
    UnitTests["Unit Tests"]:::test
    FuncTests["Functional Tests"]:::test
    ExternalDeps["External Dependencies"]:::external
    Docs["Documentation"]:::component

    Developer -->|"configures & invokes"| BuildSystem
    CICD -->|"triggers builds/tests"| BuildSystem
    BuildSystem -->|"builds & links"| srtcore
    BuildSystem -->|"builds & links"| haicrypt
    BuildSystem -->|"builds"| Apps
    BuildSystem -->|"builds"| UnitTests
    BuildSystem -->|"builds"| FuncTests

    Apps -->|"call API"| API
    Examples -->|"call API"| API
    UnitTests -->|"test API modules"| API
    FuncTests -->|"test features"| API

    API -->|"protocol logic"| Handshake
    API -->|"protocol logic"| Packet
    API -->|"protocol logic"| Buffer
    API -->|"protocol logic"| CongCtl
    API -->|"protocol logic"| FEC
    API -->|"protocol logic"| Bonding
    API -->|"gather stats"| Stats
    API -->|"core orchestration"| CoreGlue

    CoreGlue -->|"uses"| Epoll
    CoreGlue -->|"uses"| Sync
    CoreGlue -->|"uses"| Clock
    CoreGlue -->|"uses"| OSCompat

    CoreGlue -->|"encrypt/decrypt"| haicrypt
    haicrypt -->|"implements"| OpenSSL
    haicrypt -->|"implements"| Botan
    haicrypt -->|"implements"| MbedTLS
    haicrypt -->|"implements"| GnuTLS

    CoreGlue -->|"send/recv"| ExternalDeps
    ExternalDeps -->|"includes"| OpenSSL
    ExternalDeps -->|"includes"| Botan
    ExternalDeps -->|"includes"| MbedTLS
    ExternalDeps -->|"includes"| GnuTLS

    Developer -->|"reads & writes"| Docs

    %% Click Events
    click srtcore "https://github.com/haivision/srt/tree/master/srtcore/"
    click API "https://github.com/haivision/srt/blob/master/srtcore/api.cpp"
    click Handshake "https://github.com/haivision/srt/blob/master/srtcore/handshake.cpp"
    click Packet "https://github.com/haivision/srt/blob/master/srtcore/packet.cpp"
    click Buffer "https://github.com/haivision/srt/blob/master/srtcore/buffer_rcv.cpp"
    click CongCtl "https://github.com/haivision/srt/blob/master/srtcore/congctl.cpp"
    click FEC "https://github.com/haivision/srt/blob/master/srtcore/fec.cpp"
    click Bonding "https://github.com/haivision/srt/blob/master/srtcore/group.cpp"
    click CoreGlue "https://github.com/haivision/srt/blob/master/srtcore/core.cpp"
    click Epoll "https://github.com/haivision/srt/blob/master/srtcore/epoll.cpp"
    click Sync "https://github.com/haivision/srt/blob/master/srtcore/sync.cpp"
    click Clock "https://github.com/haivision/srt/blob/master/srtcore/atomic_clock.h"
    click OSCompat "https://github.com/haivision/srt/blob/master/srtcore/platform_sys.h"
    click haicrypt "https://github.com/haivision/srt/blob/master/haicrypt/haicrypt.h"
    click OpenSSL "https://github.com/haivision/srt/blob/master/haicrypt/cryspr-openssl.c"
    click Botan "https://github.com/haivision/srt/blob/master/haicrypt/cryspr-botan.c"
    click MbedTLS "https://github.com/haivision/srt/blob/master/haicrypt/cryspr-mbedtls.c"
    click GnuTLS "https://github.com/haivision/srt/blob/master/haicrypt/cryspr-gnutls.c"
    click Apps "https://github.com/haivision/srt/tree/master/apps/"
    click Examples "https://github.com/haivision/srt/tree/master/examples/"
    click UnitTests "https://github.com/haivision/srt/tree/master/test/"
    click FuncTests "https://github.com/haivision/srt/tree/master/testing/"
    click BuildSystem "https://github.com/haivision/srt/blob/master/CMakeLists.txt"
    click CICD "https://github.com/haivision/srt/tree/master/.github/workflows/"
    click Docs "https://github.com/haivision/srt/tree/master/docs/"

    %% Styles
    classDef component fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef external fill:#90EE90,stroke:#333,stroke-width:1px
    classDef build fill:#FFA500,stroke:#333,stroke-width:1px
    classDef test fill:#FFD700,stroke:#333,stroke-width:1px
    classDef actor fill:#FFB6C1,stroke:#333,stroke-width:1px
```
