# apra-labs/aprapipes architecture

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

- Interactive diagram: https://gitdiagram.com/apra-labs/aprapipes
- Repository: https://github.com/apra-labs/aprapipes

## Overview

##### Project Type and Purpose
- ApraPipes is a C++-based multimedia processing framework (not a web app).
- It provides a modular “pipeline” abstraction: sources → transforms → sinks, with support for CPU and GPU (CUDA/NVENC/NPPI) modules and machine-learning toolkits.

##### High-Level Components
a. Pipeline Core
– PipeLine: orchestrates modules, manages frame queues, threading.
– ModuleFactory / Module: dynamic registration/load of processing blocks.
– Frame, FrameContainerQueue, Metadata: unified data model for images/video frames.
b. Sources (Input Modules)
– FileReaderModule, WebCamSource, RTSPClientSrc, NvArgusCamera, TestSignalGeneratorSrc, etc.
c. Transforms (Processing Modules)
– CPU-based: AffineTransform, ImageResizeCV, ColorConversionXForm, GaussianBlur, FacialLandmarksCV, etc.
– GPU-based: CCNPPI, EffectsNPPI, ResizeNPPI, OverlayNPPI, CUDA kernel modules (.cu files).
– Machine-learning: FaceDetectorXform, AudioToTextXForm, QRReader, etc.
d. Sinks (Output Modules)
– FileWriterModule, FramesMuxer, RTSPPusher, VirtualCameraSink, ExternalSinkModule, etc.
e. External Dependencies
– OpenCV, GTK (rendering), Nvidia Video Codec SDK, cuDNN, NPPI, Whisper (ML), third-party libs via vcpkg.
f. Build & CI
– CMake + vcpkg, cross-platform build scripts for Windows / Linux / Jetson, GitHub Actions for CI.
g. Tests & Docs
– aprapipesut (unit/integration tests), data/ for sample media, docs/ for HTML Sphinx output.

##### Relationships & Data Flow
– A Source produces frames → enqueues into FrameContainerQueue → Pipeline dispatches to Transform module(s) → outputs new frames or metadata → eventually routed to one or more Sink modules.
– Modules communicate via queues (ThreadSafeQue), often in parallel threads.
– GPU modules call into CUDA contexts, NPPI or custom kernels.
– ModuleFactory loads modules per configuration (e.g., XML or code), enabling extensibility.

##### Architectural Patterns
– Pipeline / Chain-of-Responsibility: each module processes and forwards data.
– Factory (ModuleFactory) for dynamic module instantiation.
– Producer-Consumer queues for concurrency and back-pressure.
– Pluggable backends: CPU vs. GPU (via compile-time flags).

##### Depth & Detail
– Include sub-components where valuable: FrameFactory, MetadataFactory
– Note key CMake scripts and build targets in a side section
– Don’t overload with every .cpp; abstract modules by category

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "1. Sources"
        FRM["FileReaderModule"]:::modules
        WCS["WebCamSource"]:::modules
        RTSP["RTSPClientSrc"]:::modules
        NVC["NvArgusCamera"]:::modules
        TSG["TestSignalGeneratorSrc"]:::modules
        ACS["AudioCaptureSrc"]:::modules
        MPR["Mp4ReaderSource"]:::modules
    end

    subgraph "2. Transforms"
        AT["AffineTransform"]:::modules
        IRCV["ImageResizeCV"]:::modules
        CCX["ColorConversionXForm"]:::modules
        GB["GaussianBlur"]:::modules
        FL["FacialLandmarksCV"]:::modules
        CCN["CCNPPI (GPU)"]:::modules
        ENP["EffectsNPPI (GPU)"]:::modules
        RNP["ResizeNPPI (GPU)"]:::modules
        ONP["OverlayNPPI (GPU)"]:::modules
        FD["FaceDetectorXform (ML)"]:::modules
        ATX["AudioToTextXForm (ML)"]:::modules
        QR["QRReader (ML)"]:::modules
    end

    subgraph "3. Sinks"
        FWM["FileWriterModule"]:::modules
        FMX["FramesMuxer"]:::modules
        RTP["RTSPPusher"]:::modules
        VCS["VirtualCameraSink"]:::modules
        ESM["ExternalSinkModule"]:::modules
    end

    subgraph "Core Engine"
        PL["PipeLine"]:::core
        MF["ModuleFactory"]:::core
        MOD["Module"]:::core
        FRQ["Frame & Queue"]:::core
        META["Metadata"]:::core
    end

    subgraph "GPU Compute"
        CUDA["CUDA Kernels/NPPI/Codec SDK"]:::external
    end

    subgraph "Build & CI"
        CMAKE["CMake & vcpkg"]:::build
        GHA["GitHub Actions"]:::build
    end

    subgraph "Tests & Docs"
        TEST["Unit/Integration Tests"]:::tests
        DOC["Sphinx Docs"]:::tests
    end

    %% Data Flow
    FRM -->|"Frame+Metadata"| PL
    WCS -->|"Frame+Metadata"| PL
    RTSP -->|"Frame+Metadata"| PL
    NVC -->|"Frame+Metadata"| PL
    TSG -->|"Frame+Metadata"| PL
    ACS -->|"Frame+Metadata"| PL
    MPR -->|"Frame+Metadata"| PL

    PL -->|"dispatch"| AT
    PL -->|"dispatch"| IRCV
    PL -->|"dispatch"| CCX
    PL -->|"dispatch"| GB
    PL -->|"dispatch"| FL
    PL -->|"dispatch"| CCN
    PL -->|"dispatch"| ENP
    PL -->|"dispatch"| RNP
    PL -->|"dispatch"| ONP
    PL -->|"dispatch"| FD
    PL -->|"dispatch"| ATX
    PL -->|"dispatch"| QR

    CCN -->|"GPU call"| CUDA
    ENP -->|"GPU call"| CUDA
    ONP -->|"GPU call"| CUDA

    AT -->|"result"| PL
    IRCV -->|"result"| PL
    CCX -->|"result"| PL
    GB -->|"result"| PL
    FL -->|"result"| PL
    RNP -->|"result"| PL
    FD -->|"result"| PL
    ATX -->|"result"| PL
    QR -->|"result"| PL
    CUDA -->|"result"| PL

    PL -->|"frame output"| FWM
    PL -->|"frame output"| FMX
    PL -->|"frame output"| RTP
    PL -->|"frame output"| VCS
    PL -->|"frame output"| ESM

    %% Core Relationships
    PL --> MF
    MF --> MOD
    PL --> FRQ
    PL --> META

    %% Build & CI
    CMAKE -->|build scripts| PL
    CMAKE -->|build scripts| MF
    CMAKE -->|build scripts| AT
    GHA -->|CI trigger| CMAKE

    %% Tests & Docs
    TEST -->|validate| PL
    DOC -->|generate| PL

    %% Click Events
    click PL "https://github.com/apra-labs/aprapipes/blob/main/base/include/PipeLine.h"
    click MF "https://github.com/apra-labs/aprapipes/blob/main/base/include/ModuleFactory.h"
    click MOD "https://github.com/apra-labs/aprapipes/blob/main/base/include/Module.h"
    click FRQ "https://github.com/apra-labs/aprapipes/blob/main/base/include/FrameContainerQueue.h"
    click META "https://github.com/apra-labs/aprapipes/blob/main/base/include/FrameMetadata.h"
    click FRM "https://github.com/apra-labs/aprapipes/blob/main/base/include/FileReaderModule.h"
    click WCS "https://github.com/apra-labs/aprapipes/blob/main/base/include/WebCamSource.h"
    click RTSP "https://github.com/apra-labs/aprapipes/blob/main/base/include/RTSPClientSrc.h"
    click NVC "https://github.com/apra-labs/aprapipes/blob/main/base/include/NvArgusCamera.h"
    click TSG "https://github.com/apra-labs/aprapipes/blob/main/base/include/TestSignalGeneratorSrc.h"
    click ACS "https://github.com/apra-labs/aprapipes/blob/main/base/include/AudioCaptureSrc.h"
    click MPR "https://github.com/apra-labs/aprapipes/blob/main/base/include/Mp4ReaderSource.h"
    click AT "https://github.com/apra-labs/aprapipes/blob/main/base/include/AffineTransform.h"
    click IRCV "https://github.com/apra-labs/aprapipes/blob/main/base/include/ImageResizeCV.h"
    click CCX "https://github.com/apra-labs/aprapipes/blob/main/base/include/ColorConversionXForm.h"
    click GB "https://github.com/apra-labs/aprapipes/blob/main/base/include/GaussianBlur.h"
    click FL "https://github.com/apra-labs/aprapipes/blob/main/base/include/FacialLandmarksCV.h"
    click CCN "https://github.com/apra-labs/aprapipes/blob/main/base/include/CCNPPI.h"
    click ENP "https://github.com/apra-labs/aprapipes/blob/main/base/include/EffectsNPPI.h"
    click RNP "https://github.com/apra-labs/aprapipes/blob/main/base/include/ResizeNPPI.h"
    click ONP "https://github.com/apra-labs/aprapipes/blob/main/base/include/OverlayNPPI.h"
    click FD "https://github.com/apra-labs/aprapipes/blob/main/base/include/FaceDetectorXform.h"
    click ATX "https://github.com/apra-labs/aprapipes/blob/main/base/include/AudioToTextXForm.h"
    click QR "https://github.com/apra-labs/aprapipes/blob/main/base/include/QRReader.h"
    click FWM "https://github.com/apra-labs/aprapipes/blob/main/base/include/FileWriterModule.h"
    click FMX "https://github.com/apra-labs/aprapipes/blob/main/base/include/FramesMuxer.h"
    click RTP "https://github.com/apra-labs/aprapipes/blob/main/base/include/RTSPPusher.h"
    click VCS "https://github.com/apra-labs/aprapipes/blob/main/base/include/VirtualCameraSink.h"
    click ESM "https://github.com/apra-labs/aprapipes/blob/main/base/include/ExternalSinkModule.h"
    click CMAKE "https://github.com/apra-labs/aprapipes/blob/main/base/CMakeLists.txt"
    click GHA "https://github.com/apra-labs/aprapipes/blob/main/.github/workflows/CI-*.yml"
    click TEST "https://github.com/apra-labs/aprapipes/blob/main/base/test/utmain.cpp"
    click DOC "https://github.com/apra-labs/aprapipes/blob/main/docs/source/index.rst"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000;
    classDef modules fill:#FFA500,stroke:#000;
    classDef external fill:#90EE90,stroke:#000;
    classDef build fill:#D3D3D3,stroke:#000;
    classDef tests fill:#E6E6FA,stroke:#000;
```
