# mavlink/mavlink-camera-manager architecture

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

- Interactive diagram: https://gitdiagram.com/mavlink/mavlink-camera-manager
- Repository: https://github.com/mavlink/mavlink-camera-manager

## Overview

##### Project type and purpose
- This is a cross-platform, full-stack camera server written in Rust.
- It exposes a REST API and a web UI for managing camera streams, integrates with GStreamer for media pipelines, and uses MAVLink to advertise streams to ground stations.
- It also offers WebRTC streaming via an embedded signalling server and optional TURN.

##### File structure
- Top-level:
- Cargo.toml / build.rs: Rust project config and build script
- docker/: Dockerfile and launch scripts
- src/main.rs: entrypoint (CLI)
- src/lib/: all business logic, grouped by domain
- src/lib modules:
- cli: parses args, bootstraps managers
- server: REST API (pages.rs serves HTML, manager.rs wires routes)
- stream: GStreamer pipelines, multiple sink types (RTSP, WebRTC, UDP)
- video & video_source: abstracts camera sources (V4L2, ONVIF, redirect, local)
- controls: camera control interfaces (V4L2, ONVIF)
- mavlink: rust-mavlink integration, advertises streams via MAVLink messages
- settings: persistent configuration
- logger: log management (rotation, verbosity)
- network/helper: utility functions, threads, macros
- Frontend nested under stream/webrtc/frontend: a Vue + Vite app serving the WebRTC client.

##### README for additional insights
- Describes key features: REST API + Swagger, WebRTC readiness, SDP files for RTSP, MAVLink integration, and CLI usage.
- Mentions ports (REST: 6020, MAVLink: configurable), GStreamer version, and persistent settings.

##### Elements
- CLI → Managers (initialization)
- Browser → REST API → Stream Manager → Pipelines → Sinks → Clients
- Stream Manager → MAVLink Manager → GCS
- Pipelines ⇄ GStreamer libraries
- Orange: frontend/UI

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend UI"
        UI["Vue + Vite App"]:::frontend
    end

    subgraph "Backend Services"
        CLI["CLI"]:::core
        Server["REST API & Static UI"]:::core
        SigServ["Signalling & TURN Server"]:::core
        StreamMgr["Stream Manager"]:::core
        Pipeline["Pipeline Modules"]:::core
        Gst["GStreamer Integration"]:::external
        Sources["Video Sources"]:::core
        Sink["Sink Implementations"]:::core
        Controls["Controls Manager"]:::core
        MAV["MAVLink Manager"]:::core
        Settings["Settings & Persistence"]:::core
        Logger["Logger"]:::core
        Net["Network Helpers"]:::core
    end

    subgraph "External / Hardware"
        Browser["Browser"]:::external
        RTSPClient["RTSP Client"]:::external
        WebClient["WebRTC Client"]:::external
        GCS["Ground Station"]:::external
        Cameras["IP / Local Cameras"]:::external
    end

    %% Initialization
    CLI -->|"initializes"| Server
    CLI -->|"initializes"| StreamMgr
    CLI -->|"initializes"| SigServ
    CLI -->|"initializes"| MAV
    CLI -->|"initializes"| Settings
    CLI -->|"initializes"| Logger

    %% Control flows
    Browser -->|"HTTP JSON"| Server
    Server -->|"serves UI"| UI
    UI -->|"WebSocket Signalling"| SigServ
    Server -->|"uses"| Settings
    Server -->|"logs to"| Logger

    %% Streaming orchestration
    Server -->|"REST Control"| StreamMgr
    StreamMgr -->|"builds pipelines"| Pipeline
    StreamMgr -->|"selects sources"| Sources
    StreamMgr -->|"controls cameras"| Controls
    Pipeline -->|"uses GStreamer"| Gst
    Pipeline -->|"produces streams"| Sink

    %% Data flows to clients
    Sink -->|"H264 RTP"| RTSPClient
    Sink -->|"WebRTC"| WebClient
    StreamMgr -->|"events"| MAV
    MAV -->|"MAVLink messages"| GCS

    %% Hardware integration
    Sources -->|"video capture"| Cameras
    Controls -->|"camera commands"| Cameras

    %% Utilities
    CLI -->|"logs to"| Logger
    StreamMgr -->|"logs to"| Logger
    SigServ -->|"logs to"| Logger
    Net -->|"helpers for"| StreamMgr

    %% Click Events
    click CLI "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/main.rs"
    click CLI "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/cli/mod.rs"
    click CLI "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/cli/manager.rs"

    click Server "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/server/mod.rs"
    click Server "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/server/manager.rs"
    click Server "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/server/pages.rs"
    click Server "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/server/error.rs"
    click UI "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/html/index.html"

    click StreamMgr "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/stream/mod.rs"
    click StreamMgr "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/stream/manager.rs"

    click Gst "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/stream/gst/mod.rs"
    click Gst "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/stream/gst/info.rs"
    click Gst "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/stream/gst/utils.rs"

    click Pipeline "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/stream/pipeline/mod.rs"
    click Pipeline "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/stream/pipeline/runner.rs"

    click Sources "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/video/mod.rs"
    click Controls "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/controls/mod.rs"
    click MAV "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/mavlink/mod.rs"
    click Settings "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/settings/mod.rs"
    click Logger "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/logger/mod.rs"
    click Net "https://github.com/mavlink/mavlink-camera-manager/blob/master/src/lib/network/mod.rs"

    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5
    classDef frontend fill:#FFA500,stroke:#000,stroke-width:1px
```
