# awslabs/aws-streamer architecture

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

- Interactive diagram: https://gitdiagram.com/awslabs/aws-streamer
- Repository: https://github.com/awslabs/aws-streamer

## Overview

##### Project type and purpose
- The project is a collection of video processing and streaming tools designed for the AWS platform. It supports processing of video streams, live preview, video recording, ML inference, and integration with AWS services such as Kinesis Video Streams (KVS).
- It can work in a variety of deployment environments (edge, AWS Lambda, ECS, IoT Greengrass) so the design must account for both local processing and cloud integrations.

##### File structure
- The top-level files (Dockerfile, CMakeLists.txt, build.sh, setup.py) indicate that the project uses both Python and C/C++ (for GStreamer plugins) and supports containerized/cloud builds.
- The main source directory ("awstreamer") contains submodules like:
- gst_pipeline – for configuring and managing various GStreamer pipelines (e.g., appsrc, dvr, cv pipelines).
- gst_plugins – holds custom GStreamer plugins (with different implementations such as cvmlfilter, mxnet, and others in Python), indicating plug-in based modularity.
- gst_metadata – for handling metadata extraction or embedding, likely used during video stream processing.
- gst_configurer – provides functionality to generate and manage configurations for GStreamer based streaming.
- gst_viewer – for previewing streams in a browser, implying a web-based interface.
- utils – includes helper scripts for AWS integrations, GStreamer hacks, video processing, etc.

a. Core Components:
- Client/Controller Module: Represented by the main interface (awstreamer/client.py) that starts or schedules pipelines.
- Pipeline Manager: (awstreamer/gst_pipeline) Showing different pipeline types (appsrc_pipeline, dvr_pipeline, cv_pipeline, etc.) that perform the heavy lifting of streaming, processing, and content recording.
- GStreamer Plugins: Custom plugins under awstreamer/gst_plugins that provide specialized processing (e.g., ML inference with mxnet, image filtering with cvmlfilter, etc.).
- Configuration Utilities: (awstreamer/gst_configurer) for templating and setting up the pipelines dynamically via JSON configurations.
- Metadata and Utility Libraries: (awstreamer/gst_metadata and awstreamer/utils) handling stream meta information and common AWS or video processing functions.

b. AWS and External Services:
- External Tools: In the configuration, external dependencies such as DeepStream and locally installed OS packages are required.

##### Relationships and interactions
- Within the Pipeline Manager, show subdivisions for specific pipelines (e.g., video pipeline for streaming, DVR pipeline for recording, ML inference pipeline).
- Interactions between pipelines and GStreamer plugins. For example, an ML pipeline could route its video frames to the mxnet plugin or to the cvmlfilter.
- Demonstrate data flows where video input (camera streams, file sources) enter the pipeline, get processed (inference, filtering, segmentation), and then exit via different sinks (KVS, local storage, web viewer).
- Configuration component (gst_configurer) to both the client and pipeline manager, illustrating that JSON-defined configurations drive pipeline behavior.
- Utility components (aws.py, video.py) that support video file management (merging, file listing) and AWS integrations.

##### Architectural Patterns and Design Principles
- Modular Design: Highlight a plugin-based architecture where each GStreamer component or plugin is a self-contained module.
- Separation of Concerns: Clearly separate configuration, pipeline creation/management, processing (plugins), and utility functions.
- Scalability: Indicate that multiple pipelines can run concurrently and that the system is designed to scale across edge devices and cloud environments.
- Extensibility: The design should leave open “hooks” or extension points for custom plugins or configurations, as seen in the directory structure (especially the various plugin folders).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Components
    client["Client/Controller"]:::client
    config["Configuration Utilities"]:::config
    pipeman["Pipeline Manager"]:::pipeline
    utils["Utility Functions"]:::utils
    metadata["Metadata Handler"]:::metadata
    plugins["GStreamer Plugins"]:::plugin
    viewer["Web Viewer"]:::viewer

    %% Pipelines Subgraph within Pipeline Manager
    subgraph "Pipelines"
        stream["Streaming Pipeline"]:::pipeline
        dvr["Recording Pipeline"]:::pipeline
        inference["ML Inference Pipeline"]:::pipeline
    end

    %% AWS Services Subgraph
    subgraph "AWS Services"
        kvs["Kinesis Video Streams (KVS)"]:::aws
        s3["S3 Storage"]:::aws
        lambda["Lambda Functions"]:::aws
        greengrass["IoT Greengrass"]:::aws
        ecs["ECS Deployment"]:::aws
    end

    %% Relationships and Data Flows
    client -->|"issues"| pipeman
    config -->|"configures"| pipeman
    pipeman -->|"initiates"| stream
    pipeman -->|"initiates"| dvr
    pipeman -->|"initiates"| inference

    stream -->|"uses"| plugins
    inference -->|"uses"| plugins

    stream -->|"addsMeta"| metadata
    stream -->|"livePreview"| viewer

    stream -->|"streamsTo"| kvs
    dvr -->|"recordsTo"| s3
    dvr -->|"deploysTo"| ecs
    inference -->|"invokes"| lambda
    inference -->|"invokes"| greengrass

    utils -->|"supports"| config
    utils -->|"awsSupport"| kvs
    utils -->|"awsSupport"| s3
    utils -->|"awsSupport"| lambda
    utils -->|"awsSupport"| greengrass
    utils -->|"awsSupport"| ecs

    %% Click Events for Component Mapping
    click client "https://github.com/awslabs/aws-streamer/blob/master/awstreamer/client.py"
    click pipeman "https://github.com/awslabs/aws-streamer/tree/master/awstreamer/gst_pipeline"
    click plugins "https://github.com/awslabs/aws-streamer/tree/master/awstreamer/gst_plugins"
    click config "https://github.com/awslabs/aws-streamer/tree/master/awstreamer/gst_configurer"
    click metadata "https://github.com/awslabs/aws-streamer/tree/master/awstreamer/gst_metadata"
    click viewer "https://github.com/awslabs/aws-streamer/tree/master/awstreamer/gst_viewer"
    click utils "https://github.com/awslabs/aws-streamer/tree/master/awstreamer/utils"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef pipeline fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef plugin fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef config fill:#F5CBA7,stroke:#943126,stroke-width:2px;
    classDef metadata fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef viewer fill:#FAD7A0,stroke:#D68910,stroke-width:2px;
    classDef utils fill:#D5DBDB,stroke:#566573,stroke-width:2px;
    classDef aws fill:#D1F2EB,stroke:#117864,stroke-width:2px;
```
