# seeed-studio/sscma-example-sg200x architecture

> Architecture diagram of the GitHub repository seeed-studio/sscma-example-sg200x, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/seeed-studio/sscma-example-sg200x
- Repository: https://github.com/seeed-studio/sscma-example-sg200x

## Overview

##### Project type and purpose
- This is an embedded-oriented, cross-compilation framework for the ReCamera “SG200X” platform. It provides:
- A CMake-based build system and toolchain integration (RISC-V Linux musl).
- A set of hardware abstraction components (audio, video, common IPC).
- An SSCMA-Micro portability layer (MQTT, RTSP, file, WebSocket transports).
- Several “solutions” (sample applications) that consume those components: audio demos, HelloWorld, device control, model execution, node agent, supervisor daemon + web UI, video demo.

##### File structure
- Top-level directories:
- cmake/ – build scripts, toolchain definitions, packaging.
- components/ – divided into:
­ sophgo/ – low-level audio/video drivers and plugin.
­ sscma-micro/ – portable SSCMA runtime API and hardware porting.
- solutions/ – per-application CMake projects for various use cases:
­ helloworld, audio-plugin, audio, device, sscma-model, sscma-node, supervisor (daemon + web front end), video_demo.
- docs/, scripts/, test/, tools/ – supporting material.

##### README for additional insights
- Describes dependency on ReCamera-OS SDK and cross-toolchain.
- Of build → CMake → cmake/ → binaries → cpack into .deb → deploy on device → run.

a. Main components:
- Host Build Environment
– CMake + toolchain (RISC-V GCC)
– ReCamera-OS SDK (headers, libraries)
- Build Artifacts
– .deb packages (per solution)
- Target Device (SG200X)
– Linux/musl runtime
– Hardware Modules: Sophgo SoC with audio/video peripherals
– Device Drivers (components/sophgo/audio, /video)
– SSCMA-Micro Port layer (components/sscma-micro)
– Applications (solutions/*):
· Supervisor daemon (flows engine, HTTP API)
· Supervisor web UI (React/Vite)
· SSCMA-Node (camera agent, gRPC/MQTT/RTSP)
· SSCMA-Model runner (embedded inference)
· Audio plugin (ALSA plugin)
· Video demo (RTSP streaming)
· Device control, HelloWorld, Audio demo
- External Clients / Services
– Browser/UI talking to supervisor HTTP endpoints
– MQTT/RTSP/WebSocket clients for SSCMA-Node

b. Relationships / interactions:
- Build phase: Host → CMake scripts (cmake/) → compile components + solutions → produce .deb
- Deploy: Transfer & install .deb on device → each application installed under /usr or /opt
- Runtime on device:
– Supervisor daemon loads “flows” definitions and CVI models → orchestrates pipelines via SSCMA-Micro → communicates with hardware drivers.
– Web UI (static assets served by supervisor or separate web server) → calls Supervisor HTTP API.
– SSCMA-Node acts as autonomous agent interfacing camera and models → may publish to MQTT or RTSP.
– Audio plugin registers with ALSA → applications open ALSA device for audio I/O.
– Video demo opens V4L2/ISP via components/sophgo/video → streams out via RTSP.

c. Architectural patterns / design principles:
- Layered architecture:
­ Hardware drivers → portability layer → application logic → presentation/UI.
- Modular plugin design: audio_plugin splits core audio I/O and ALSA plugin.
- Microservices/daemons: SSCMA-Node and Supervisor as separate services communicating over network or IPC.
- CMake-driven build and packaging → reproducible cross-compile.

d. Key technologies / frameworks / libraries:
- C/C++ with CMake, custom macros under cmake/
- RISC-V musl GCC toolchain (via toolchain file)
- ALSA (audio), V4L2 or ISP APIs (video) from Sophgo SDK
- SSCMA-Micro SDK (components/sscma-micro)
- React + TypeScript + Vite (supervisor/www)
- MQTT, RTSP, WebSocket transports in SSCMA-Node

##### Detail advice
- Break the project into as many logical components as possible (build system, SDK, drivers, middleware, apps, UI).
- Cross-toolchain interactions and how each solution depends on the common components.
- Packaging and deployment steps to show end-to-end flow from code to running on SG200X.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Host Build Environment
    subgraph "Host Build Environment"
        CMakeDir["cmake/"]:::build
        Toolchain["RISC-V GCC Toolchain"]:::build
        SDK["ReCamera-OS SDK"]:::build
    end

    CMakeDir -->|uses| Toolchain
    CMakeDir -->|uses| SDK
    CMakeDir -->|"configure & build"| BuildArtifacts[".deb Packages"]:::build

    %% Deployment
    BuildArtifacts -->|"install .deb"| Deploy["Deploy to SG200X Device"]:::build

    %% Device Runtime
    subgraph "SG200X Device"
        direction TB

        subgraph "Hardware & Drivers"
            SoC["Sophgo SoC"]:::runtime
            AudioDrv["Sophgo Audio Driver"]:::runtime
            ALSAPlugin["ALSA Plugin Layer"]:::runtime
            VideoDrv["Sophgo Video Driver"]:::runtime
            CommonIPC["Sophgo Common IPC"]:::runtime
        end

        subgraph "Portability Layer"
            SSCMALayer["SSCMA-Micro Core API"]:::runtime
            PortSophgo["Sophgo Transport Porting"]:::runtime
        end

        subgraph "Applications"
            SupervisorD["Supervisor Daemon"]:::runtime
            SupervisorUI["Supervisor Web UI"]:::runtime
            SSCMANode["SSCMA-Node Agent"]:::runtime
            SSCMAModel["SSCMA-Model Runner"]:::runtime
            AudioDemo["Audio Demo"]:::runtime
            AudioPluginSol["Audio Plugin Sample"]:::runtime
            DeviceCtrl["Device Control"]:::runtime
            HelloWorld["HelloWorld"]:::runtime
            VideoDemo["Video Demo"]:::runtime
        end
    end

    %% External Clients
    subgraph "External Clients / Services"
        Browser["Web Browser"]:::external
        MQTTClient["MQTT Client"]:::external
        RTSPClient["RTSP Client"]:::external
        WSClient["WebSocket Client"]:::external
    end

    %% Runtime Relationships
    Deploy -->|"runs on"| SoC
    SupervisorUI -->|"HTTP API"| SupervisorD
    Browser -->|"HTTP"| SupervisorD
    SupervisorD -->|"orchestrates via"| SSCMALayer
    SSCMALayer -->|"uses"| AudioDrv
    SSCMALayer -->|"uses"| VideoDrv
    SSCMALayer -->|"uses"| CommonIPC

    SSCMANode -->|"uses"| SSCMALayer
    SSCMANode -->|"publishes"| MQTTClient
    SSCMANode -->|"streams"| RTSPClient
    SSCMANode -->|"serves WS"| WSClient

    AudioDemo -->|"audio I/O via"| ALSAPlugin
    AudioPluginSol -->|"plugin to ALSA"| ALSAPlugin
    ALSAPlugin -->|"drives"| AudioDrv

    VideoDemo -->|"v4l2/ISP via"| VideoDrv

    DeviceCtrl -->|"calls drivers"| CommonIPC
    HelloWorld -->|"calls drivers"| CommonIPC

    SSCMAModel -->|"runs models via"| SSCMALayer

    %% Click Events
    click CMakeDir "https://github.com/seeed-studio/sscma-example-sg200x/tree/main/cmake/"
    click AudioDrv "https://github.com/seeed-studio/sscma-example-sg200x/tree/main/components/sophgo/audio/"
    click ALSAPlugin "https://github.com/seeed-studio/sscma-example-sg200x/tree/main/components/sophgo/audio_plugin/"
    click CommonIPC "https://github.com/seeed-studio/sscma-example-sg200x/tree/main/components/sophgo/common/"
    click VideoDrv "https://github.com/seeed-studio/sscma-example-sg200x/tree/main/components/sophgo/video/"
    click SSCMALayer "https://github.com/seeed-studio/sscma-example-sg200x/tree/main/components/sscma-micro/sscma-micro/"
    click PortSophgo "https://github.com/seeed-studio/sscma-example-sg200x/tree/main/components/sscma-micro/porting/sophgo/"
    click HelloWorld "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/helloworld/main/main.cpp"
    click AudioDemo "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/audio/main/main.cpp"
    click AudioPluginSol "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/audio-plugin/main/main.cpp"
    click DeviceCtrl "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/device/main/main.cpp"
    click SSCMAModel "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/sscma-model/main/main.cpp"
    click SSCMANode "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/sscma-node/main/main.cpp"
    click SupervisorD "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/supervisor/main/CMakeLists.txt"
    click SupervisorUI "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/supervisor/www/src/App.tsx"
    click VideoDemo "https://github.com/seeed-studio/sscma-example-sg200x/blob/main/solutions/video_demo/main/main.cpp"

    %% Styles
    classDef build fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef runtime fill:#98FB98,stroke:#333,stroke-width:1px
    classDef external fill:#FFD580,stroke:#333,stroke-width:1px
```
