# casparcg/server architecture

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

- Interactive diagram: https://gitdiagram.com/casparcg/server
- Repository: https://github.com/casparcg/server
- Video tour (about a minute): https://gitdiagram.com/casparcg/server/video

## Overview

##### Main Components
- Server Engine (Core) – This is found in the “src/core” folder. It includes frame handling, mixing, diagnostics, producers, and consumers. It is the central part that coordinates data streams.
- Accelerator – Located in “src/accelerator,” these components leverage GPU/OpenGL functionality for processing graphics and image manipulation.
- Modules – In “src/modules,” many plug-in modules add media-specific functionality. Examples include:
- FFmpeg module for handling audio/video encoding/decoding.
- Decklink module for hardware interfacing.
- ArtNet, Bluefish, Flash, HTML, Image, NewTek, OAL (audio), and Screen modules.
These modules allow for networked control, video capture, consumer/producer pipelines, and hardware interop.
- Protocol Layer – Found in “src/protocol,” this layer implements different communication protocols (AMCP and OSC, for instance) and related utilities. It deals with command parsing, client messaging, and HTTP request handling.
- Shell and Tools – The “src/shell” folder contains the main application entry point, configuration (casparcg.config), startup scripts, and platform-specific code. Additionally, “tools” provide build and packaging utilities.
- Common Libraries and Utilities – The “src/common” directory provides a shared set of helper functions and abstractions (logging, filesystem access, threading, timer utilities) that are used by the rest of the system.
- External/3rd-Party Dependencies – While not part of the core directory structure, note that the project relies on libraries like FFmpeg, TBB (Threading Building Blocks), SFML, GLEW, and Boost. These should be depicted externally to indicate integration points.

##### Relationships and Data Flow
- The Shell launches the Core engine. From here, control flows into:
- The Accelerator subsystem for GPU-accelerated image processing.
- The Protocol layer, which listens for client commands (via AMCP and OSC) and dispatches them to the core.
- Plug-in Modules that extend functionality, tied into either media capture (Producers) or media output (Consumers). Many of these modules are interconnected—producing frames to be later mixed and consumed.
- Utility layers (Common libraries) that serve as infrastructure across these main components.

##### Architectural Patterns and Design Principles
- Layered and Component-Based Design: Separate layers include the Presentation/Interface (Shell), Business Logic (Core and Accelerator), Protocol/Communication (AMCP, OSC), and External Integrations (third-party libraries).

##### Technologies and Frameworks
- C++ (as the language).
- CMake (build system).
- OpenGL (via Accelerator, as evidenced by shader files and OGL directories).
- The external libraries: FFmpeg, TBB, SFML, GLEW, and Boost.
- OS-specific modules such as “src/common/os/linux” and “src/common/os/windows” to show platform-dependent implementations in areas like filesystem and threading.

- Flow of data (e.g., frame data from producers → core mixing → consumers).
- Control flow (e.g., configuration commands from Shell → Core initialization).
- Interactions between the protocol layer (receiving commands) and the Core.
- Core system components (e.g., use rectangles).
- Component has a clear label and, where necessary, add annotations (e.g., “GPU acceleration via OpenGL”, “Media encoding/decoding via FFmpeg”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Shell & Tools Layer
    subgraph "Shell & Tools Layer"
        sh["Shell & Config"]:::shell
        tools["Build & Packaging Tools"]:::tools
    end

    %% Core Processing Layer
    subgraph "Core Processing Layer"
        core["Server Engine Core"]:::core
        accel["Accelerator (GPU/OpenGL)"]:::accelerator
        prot["Protocol Layer (AMCP/OSC)"]:::protocol
        common["Common Libraries & Utilities"]:::common
    end

    %% Modules (Plugins)
    subgraph "Modules (Plugins)"
        modff["FFmpeg Module"]:::module
        moddeck["Decklink Module"]:::module
        modart["ArtNet Module"]:::module
        modblue["Bluefish Module"]:::module
        modflash["Flash Module"]:::module
        modhtml["HTML Module"]:::module
        modimg["Image Module"]:::module
        modnewtek["NewTek Module"]:::module
        modoal["OAL Module"]:::module
        modscreen["Screen Module"]:::module
    end

    %% External Dependencies
    subgraph "External Dependencies"
        ffmpeg_ext["FFmpeg Library"]:::external
        tbb_ext["TBB"]:::external
        sfml_ext["SFML"]:::external
        glew_ext["GLEW"]:::external
        boost_ext["Boost"]:::external
    end

    %% Connections
    %% Initialization Flow
    sh -->|"init/config"| core
    sh --> tools

    %% Core Interactions
    prot -->|"dispatches_commands"| core
    core -->|"processes_frames"| accel
    core <-->|"media_flow"| modff
    core <-->|"media_flow"| moddeck
    core <-->|"media_flow"| modart
    core <-->|"media_flow"| modblue
    core <-->|"media_flow"| modflash
    core <-->|"media_flow"| modhtml
    core <-->|"media_flow"| modimg
    core <-->|"media_flow"| modnewtek
    core <-->|"media_flow"| modoal
    core <-->|"media_flow"| modscreen

    %% Modules using external dependencies
    modff -->|"encodes/decodes"| ffmpeg_ext

    %% Shared Utilities
    core --- common
    accel --- common
    prot --- common
    modff --- common
    moddeck --- common
    modart --- common
    modblue --- common
    modflash --- common
    modhtml --- common
    modimg --- common
    modnewtek --- common
    modoal --- common
    modscreen --- common

    %% External Dependencies can be used by various modules/components
    accel --- glew_ext
    prot --- boost_ext

    %% Click Events
    click core "https://github.com/casparcg/server/tree/master/src/core"
    click accel "https://github.com/casparcg/server/tree/master/src/accelerator"
    click modff "https://github.com/casparcg/server/tree/master/src/modules/ffmpeg"
    click moddeck "https://github.com/casparcg/server/tree/master/src/modules/decklink"
    click modart "https://github.com/casparcg/server/tree/master/src/modules/artnet"
    click modblue "https://github.com/casparcg/server/tree/master/src/modules/bluefish"
    click modflash "https://github.com/casparcg/server/tree/master/src/modules/flash"
    click modhtml "https://github.com/casparcg/server/tree/master/src/modules/html"
    click modimg "https://github.com/casparcg/server/tree/master/src/modules/image"
    click modnewtek "https://github.com/casparcg/server/tree/master/src/modules/newtek"
    click modoal "https://github.com/casparcg/server/tree/master/src/modules/oal"
    click modscreen "https://github.com/casparcg/server/tree/master/src/modules/screen"
    click prot "https://github.com/casparcg/server/tree/master/src/protocol"
    click sh "https://github.com/casparcg/server/tree/master/src/shell"
    click tools "https://github.com/casparcg/server/tree/master/src/tools"
    click common "https://github.com/casparcg/server/tree/master/src/common"

    %% Styles
    classDef shell fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
    classDef tools fill:#aed6f1,stroke:#5dade2,stroke-width:2px;
    classDef core fill:#d2b4de,stroke:#7d3c98,stroke-width:2px;
    classDef accelerator fill:#a9dfbf,stroke:#28b463,stroke-width:2px;
    classDef protocol fill:#f5cba7,stroke:#d35400,stroke-width:2px;
    classDef module fill:#f7dc6f,stroke:#d4ac0d,stroke-width:2px;
    classDef common fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef external fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
```
