# classicoldsong/apollo architecture

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

- Interactive diagram: https://gitdiagram.com/classicoldsong/apollo
- Repository: https://github.com/classicoldsong/apollo

## Overview

##### Project type and purpose
- Apollo is a native C++17-based streaming server (desktop stream host) with an integrated web UI.
- Purpose: host low-latency game streams for Artemis/Moonlight clients, manage virtual displays, input, encoding (HW/SW), and client permissions.

##### File structure
- src/ : core server modules (network, HTTP, RTSP, UPnP, config, crypto, audio/video, input, logging, task/thread pools, virtual display management).
- src/platform/ : OS-specific abstractions (Windows via SudoVDA & DirectX, Linux via VAAPI/Wayland/X11, macOS via AVFoundation).
- src_assets/ : static web-UI assets (Vue components, HTML/CSS/JS) served by the builtin HTTP server.
- third-party/ : embedded external libraries.
- CMakeLists.txt & cmake/ : build configuration, cross-platform packaging, dependency detection.
- packaging/, docker/, scripts/ : deployment artifacts (AppImage, Flatpak, Dockerfiles), helper scripts.

##### README for additional insights
- Backend features: virtual display creation/removal, permission system, HDR handling, multi-GPU support, input sync, auto-resolution matching.
- Web UI for pairing and configuration over HTTP(S).
- Integration points with SudoVDA, Artemis (Moonlight Noir), and hardware encoders (AMD VCE, Intel VAAPI, Nvidia NVENC).

##### Exploding Third-Party Modules
- Simple-Web-Server (HTTP layer)
- nlohmann_json (config, API payloads)
- Boost (where used)
- TPCircularBuffer (stream buffering)
- ViGEmClient/SudoVDA (virtual display driver)
- inputtino (input abstraction)
- libevdev (Linux input)
- glad (OpenGL function loading)
- nv-codec-headers & NVENC SDK (Nvidia encoding)
- moonlight-common-c (Moonlight protocol support)
- googletest (unit tests, can be shaded off as “Test Harness”)

##### Final checklist
- All major components identified and labeled.
- Platform-specific adapters grouped but detailed.
- Third-party modules exploded and linked.
- Clear data flows: control (HTTP/API), media (video/audio streams), input.
- Technology names annotated.
- Permission and config manager centrally located.
- Host hardware and external clients represented.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Clients
    subgraph "External Clients" 
        direction TB
        WebBrowser["Web Browser"]:::external
        ArtemisClient["Artemis/Moonlight Client"]:::external
    end

    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        WebUI["Frontend Web UI"]:::ui
    end

    %% API & Control Layer
    subgraph "API & Control" 
        direction TB
        HTTPServer["HTTP/REST API Layer"]:::api
        ConfigManager["Configuration & Permission Manager"]:::control
        LoggingMetrics["Logging & Metrics"]:::control
    end

    %% Streaming & Encoding Layer
    subgraph "Streaming & Encoding" 
        direction TB
        subgraph "Streaming Pipeline"
            direction TB
            Capture["Capture & Buffer"]:::stream
            VideoProcessing["Video Processing"]:::stream
            AudioProcessing["Audio Processing"]:::stream
            NetworkTransport["Network Transport"]:::stream
        end
        EncoderModule["Encoder/Decoder Module"]:::encode
        InputHandler["Input Handler"]:::stream
    end

    %% Virtual Display & Platform
    subgraph "Platform & Drivers" 
        direction TB
        VirtualDisplay["Virtual Display Manager"]:::platform
        PlatformAbstraction["Platform Abstraction Layer"]:::platform
    end

    %% Third-Party Modules
    subgraph "Third-Party Modules" 
        direction TB
        SimpleWeb["Simple-Web-Server"]:::third
        JSON["nlohmann_json"]:::third
        CircularBuffer["TPCircularBuffer"]:::third
        ViGEm["ViGEmClient"]:::third
        SudoVDA["SudoVDA"]:::third
        InputtinoTP["inputtino"]:::third
        GLAD["glad"]:::third
        NVCodec["nv-codec-headers"]:::third
        Moonlight["moonlight-common-c"]:::third
        GTest["googletest"]:::third
        Boost["Boost"]:::third
    end

    %% Host Hardware
    subgraph "Host Hardware"
        direction TB
        GPU["GPU"]:::hardware
        AudioHW["Audio"]:::hardware
        NetworkHW["Network"]:::hardware
    end

    %% Connections - External to UI/API
    WebBrowser -->|"HTTP/HTTPS"| HTTPServer
    ArtemisClient -->|"RTSP/Pairing"| HTTPServer

    %% UI
    WebUI -->|"serves static assets"| HTTPServer

    %% API Control flows
    HTTPServer -->|queries| ConfigManager
    HTTPServer -->|logs events| LoggingMetrics

    %% Streaming flows
    HTTPServer -->|"start/stop stream"| Capture
    Capture -->|"frames"| VideoProcessing
    VideoProcessing -->|"encoded frames"| NetworkTransport
    AudioProcessing -->|"audio frames"| NetworkTransport
    NetworkTransport -->|stream| ArtemisClient

    %% Encoder & Input
    VideoProcessing -->|encode| EncoderModule
    EncoderModule -->|encoded video| NetworkTransport
    InputHandler -->|input events| HTTPServer
    InputHandler -->|injection| VirtualDisplay

    %% Virtual Display flows
    HTTPServer -->|create/remove display| VirtualDisplay
    VirtualDisplay -->|display buffers| EncoderModule
    VirtualDisplay -->|display buffers| Capture

    %% Platform flows
    VirtualDisplay -->|OS-specific calls| PlatformAbstraction
    EncoderModule -->|HW calls| PlatformAbstraction
    InputHandler -->|OS input| PlatformAbstraction

    %% Hardware
    PlatformAbstraction -->|GPU commands| GPU
    PlatformAbstraction -->|audio interface| AudioHW
    NetworkTransport -->|network I/O| NetworkHW

    %% Config & Logging usage
    Capture -->|configs| ConfigManager
    VideoProcessing -->|configs| ConfigManager
    AudioProcessing -->|configs| ConfigManager
    VirtualDisplay -->|permissions| ConfigManager
    EncoderModule -->|settings| ConfigManager
    InputHandler -->|permissions| ConfigManager

    Capture -->|metrics| LoggingMetrics
    VideoProcessing -->|metrics| LoggingMetrics
    AudioProcessing -->|metrics| LoggingMetrics
    EncoderModule -->|metrics| LoggingMetrics
    InputHandler -->|metrics| LoggingMetrics

    %% Third-Party integrations
    SimpleWeb -->|used by| HTTPServer
    JSON -->|used by| HTTPServer
    CircularBuffer -->|used by| Capture
    ViGEm -->|used by| VirtualDisplay
    SudoVDA -->|used by| VirtualDisplay
    InputtinoTP -->|used by| InputHandler
    GLAD -->|used by| VideoProcessing
    NVCodec -->|used by| EncoderModule
    Moonlight -->|protocols| HTTPServer
    GTest -->|tests| Capture
    Boost -->|utilities| VideoProcessing

    %% Click Events
    click WebUI "https://github.com/classicoldsong/apollo/tree/master/src_assets/common/assets/web"
    click HTTPServer "https://github.com/classicoldsong/apollo/blob/master/src/confighttp.cpp"
    click HTTPServer "https://github.com/classicoldsong/apollo/blob/master/src/httpcommon.cpp"
    click Capture "https://github.com/classicoldsong/apollo/blob/master/src/stream.cpp"
    click Capture "https://github.com/classicoldsong/apollo/blob/master/src/process.cpp"
    click Capture "https://github.com/classicoldsong/apollo/blob/master/src/rswrapper.c"
    click VideoProcessing "https://github.com/classicoldsong/apollo/blob/master/src/video.cpp"
    click VideoProcessing "https://github.com/classicoldsong/apollo/blob/master/src/video_colorspace.cpp"
    click AudioProcessing "https://github.com/classicoldsong/apollo/blob/master/src/audio.cpp"
    click NetworkTransport "https://github.com/classicoldsong/apollo/blob/master/src/rtsp.cpp"
    click NetworkTransport "https://github.com/classicoldsong/apollo/blob/master/src/network.cpp"
    click VirtualDisplay "https://github.com/classicoldsong/apollo/blob/master/src/display_device.cpp"
    click WinVD "https://github.com/classicoldsong/apollo/blob/master/src/platform/windows/virtual_display.cpp"
    click LinuxKMS "https://github.com/classicoldsong/apollo/blob/master/src/platform/linux/kmsgrab.cpp"
    click LinuxX11 "https://github.com/classicoldsong/apollo/blob/master/src/platform/linux/x11grab.cpp"
    click LinuxWayland "https://github.com/classicoldsong/apollo/blob/master/src/platform/linux/wlgrab.cpp"
    click MacVD "https://github.com/classicoldsong/apollo/blob/master/src/platform/macos/display.mm"
    click EncoderModule "https://github.com/classicoldsong/apollo/tree/master/src/nvenc"
    click VAAPI "https://github.com/classicoldsong/apollo/blob/master/src/platform/linux/vaapi.cpp"
    click InputHandler "https://github.com/classicoldsong/apollo/blob/master/src/input.cpp"
    click WinInput "https://github.com/classicoldsong/apollo/blob/master/src/platform/windows/input.cpp"
    click LinuxInput "https://github.com/classicoldsong/apollo/tree/master/src/platform/linux/input"
    click MacInput "https://github.com/classicoldsong/apollo/blob/master/src/platform/macos/input.cpp"
    click ConfigManager "https://github.com/classicoldsong/apollo/blob/master/src/config.cpp"
    click LoggingMetrics "https://github.com/classicoldsong/apollo/blob/master/src/logging.cpp"
    click LoggingMetrics "https://github.com/classicoldsong/apollo/blob/master/src/stat_trackers.cpp"
    click PlatformAbstraction "https://github.com/classicoldsong/apollo/blob/master/src/platform/common.h"
    click PlatformAbstraction "https://github.com/classicoldsong/apollo/tree/master/src/platform"
    click SimpleWeb "https://github.com/classicoldsong/apollo/tree/master/third-party/Simple-Web-Server"
    click JSON "https://github.com/classicoldsong/apollo/blob/master/cmake/dependencies/nlohmann_json.cmake"
    click CircularBuffer "https://github.com/classicoldsong/apollo/tree/master/third-party/TPCircularBuffer"
    click ViGEm "https://github.com/classicoldsong/apollo/tree/master/third-party/ViGEmClient"
    click SudoVDA "https://github.com/classicoldsong/apollo/tree/master/third-party/sudovda"
    click InputtinoTP "https://github.com/classicoldsong/apollo/tree/master/third-party/inputtino"
    click GLAD "https://github.com/classicoldsong/apollo/tree/master/third-party/glad"
    click NVCodec "https://github.com/classicoldsong/apollo/tree/master/third-party/nv-codec-headers"
    click Moonlight "https://github.com/classicoldsong/apollo/tree/master/third-party/moonlight-common-c"
    click GTest "https://github.com/classicoldsong/apollo/tree/master/third-party/googletest"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085;
    classDef api fill:#d4edda,stroke:#155724,color:#155724;
    classDef control fill:#d4edda,stroke:#155724,color:#155724;
    classDef stream fill:#fff3cd,stroke:#856404,color:#856404;
    classDef encode fill:#ffe5b4,stroke:#cc7a00,color:#cc7a00;
    classDef platform fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef third fill:#f8f9fa,stroke:#6c757d,color:#6c757d;
    classDef external fill:#d1ecf1,stroke:#0c5460,color:#0c5460;
    classDef hardware fill:#f5c6cb,stroke:#721c24,color:#721c24;
```
