# nnstreamer/nnstreamer-example architecture

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

- Interactive diagram: https://gitdiagram.com/nnstreamer/nnstreamer-example
- Repository: https://github.com/nnstreamer/nnstreamer-example

## Overview

##### Project type and purpose
- This is an “example”—monorepo-style” toolkit showcasing how to build apps with nnstreamer/GStreamer across multiple platforms (Ubuntu native, bash scripts, Tizen GUI/.NET/Web, Android Java/Kotlin, IoT). It contains dozens of sample applications, scripts and templates illustrating pipeline creation, model invocation, and platform integration.

##### File‐structure analysis
- Top-level directories group by target platform or role:
- native/ & bash_script/ – Linux C/C++/Python binaries and gst-launch recipes
- Tizen.native/, Tizen.NET/, Tizen.web/, Tizen.platform/ – Tizen GUI (C/C++), .NET C# apps, Web apps, IoT packages
- android/ & android/kotlin_app/ – Android NDK (C/C++) and JNI-free Java/Kotlin examples
- packaging/, debian/, meson.build, .github/ – build, packaging, CI configs
- Every example subfolder houses source code, resources (model files: .tflite, .onnx), build scripts (meson.build, Gradle), and platform manifests (AndroidManifest.xml, tizen-manifest.xml).

##### Key README insights
- Describes supported platforms, build flows (PPA, gbs, Meson, Gradle), and categorizes examples by pipeline features: appsrc, tensor_decoder modes, networking (tcpclientsrc/tcpserversink), nnstreamer APIs.

##### Main components
a. Platforms (containers/columns):
- Ubuntu Native (C/C++/Python)
- gst-launch Scripts (bash)
- Tizen GUI (Native C/C++), Tizen .NET (C#), Tizen Web (HTML/JS)
- Tizen IoT (platform packages)
- Android (JNI/C++, Java API, Kotlin)
- Common Build/Packaging/CI
b. Core Library & Pipeline Engine
- nnstreamer (GStreamer + Tensor filters)
- External services/repos (Ubuntu PPA, Tizen OBS/RPM)
c. Model Artifacts
- .tflite, .onnx, labels.txt, vocab.txt
d. Hardware / Data Sources
- v4l2src (camera), tensor_src_tizensensor (accelerometer), appsrc (text), amcsrc/ahc2src (Android media/camera)
e. Output / UI Layers
- GTK/CairoOverlay (native), tizenwlsink (IoT), WebCanvas/HTML UI, Android SurfaceView, .NET UI

##### Relationships & interactions
- Each example app → invokes nnstreamer pipeline API or gst-launch → loads model artifact → consumes hardware/data source → processes tensors → decodes/overlays results → renders to UI or outputs to stdout/log.
- Offloading examples additionally connect via networking modules (tcpserversink/tcpclientsrc) to remote inference services.

##### Architectural patterns & design principles
- Modular monorepo: platform slices with identical high-level flow (Source → nnstreamer pipeline → Sink/UI).
- Plugin extensibility: tensor_decoder, tensor_converter, custom subplugins under templates/.
- Multi-language bindings: C/C++, Python, C#, Java, Kotlin, Web JS – all share the same NNStreamer core.
- Cross‐platform manifest/build isolation: Meson for Linux/Tizen native, Gradle for Android, npm for Web, gbs/PPA integration.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Swimlane: Ubuntu Native & Scripts
    subgraph "Ubuntu Native & Scripts"
        direction TB
        Native["Ubuntu Native Examples"]:::native
        Bash["gst-launch Scripts"]:::scripts
        Native -->|invokes NNStreamer API| Core
        Bash -->|invokes gst-launch| Core
        click Native "https://github.com/nnstreamer/nnstreamer-example/tree/main/native/"
        click Bash "https://github.com/nnstreamer/nnstreamer-example/tree/main/bash_script/"
    end

    %% Central Core and Model Repo
    Core["nnstreamer/GStreamer Core"]:::core
    ModelRepo["Model Artifacts<br/>(.tflite, .onnx, labels.txt)"]:::model
    Core -->|loads models| ModelRepo
    click ModelRepo "https://github.com/nnstreamer/nnstreamer-example/blob/main/nnst_exam.json"

    %% Swimlane: Tizen Platforms
    subgraph "Tizen Platforms"
        direction TB
        TizNative["Tizen GUI (C/C++)"]:::tizen
        TizNet["Tizen .NET (C#)"]:::tizen
        TizWeb["Tizen Web (HTML/JS)"]:::tizen
        TizIoT["Tizen IoT Packages"]:::tizen
        TizNative -->|invokes Core| Core
        TizNet -->|invokes Core| Core
        TizWeb -->|invokes Core| Core
        TizIoT -->|invokes Core| Core
        click TizNative "https://github.com/nnstreamer/nnstreamer-example/tree/main/Tizen.native/"
        click TizNet "https://github.com/nnstreamer/nnstreamer-example/tree/main/Tizen.NET/"
        click TizWeb "https://github.com/nnstreamer/nnstreamer-example/tree/main/Tizen.web/"
        click TizIoT "https://github.com/nnstreamer/nnstreamer-example/tree/main/Tizen.platform/"
    end

    %% Swimlane: Android Platforms
    subgraph "Android Platforms"
        direction TB
        AJava["Java API Examples"]:::android
        ACapi["C API (JNI) Examples"]:::android
        AMedia["Media-SSD Example"]:::android
        AMulti["Multi-Model & Network Examples"]:::android
        ASSD["SSD Autocapture Example"]:::android
        AKotlin["Kotlin Llama2 Example"]:::android
        AMS["Multi-Device Shared Lib & JNI"]:::android
        AJava -->|invokes Core| Core
        ACapi -->|invokes Core| Core
        AMedia -->|invokes Core| Core
        AMulti -->|invokes Core| Core
        ASSD -->|invokes Core| Core
        AKotlin -->|invokes Core| Core
        AMS -->|invokes Core| Core
        click AJava "https://github.com/nnstreamer/nnstreamer-example/tree/main/android/example_app/api-sample/"
        click ACapi "https://github.com/nnstreamer/nnstreamer-example/tree/main/android/example_app/capi-sample/"
        click AMedia "https://github.com/nnstreamer/nnstreamer-example/tree/main/android/example_app/nnstreamer-media-ssd/"
        click AMulti "https://github.com/nnstreamer/nnstreamer-example/tree/main/android/example_app/nnstreamer-multi/"
        click ASSD "https://github.com/nnstreamer/nnstreamer-example/tree/main/android/example_app/nnstreamer-ssd-autocapture/"
        click AKotlin "https://github.com/nnstreamer/nnstreamer-example/tree/main/android/kotlin_app/llama2/"
        click AMS "https://github.com/nnstreamer/nnstreamer-example/tree/main/android/multi_device_shared_lib/"
    end

    %% Swimlane: Build / Packaging / CI
    subgraph "Build / Packaging / CI"
        direction TB
        Meson["Meson build (meson.build)"]:::pkg
        Deb["Debian Packaging"]:::pkg
        RPM["RPM/NPM Packaging Templates"]:::pkg
        CI["CI Workflows & QA"]:::pkg
        CI -->|triggers| Meson
        Meson -->|builds Core| Core
        Deb -->|packages| Meson
        RPM -->|uses templates| Meson
        click Meson "https://github.com/nnstreamer/nnstreamer-example/blob/main/meson.build"
        click Deb "https://github.com/nnstreamer/nnstreamer-example/tree/main/debian/"
        click RPM "https://github.com/nnstreamer/nnstreamer-example/tree/main/packaging/"
        click RPM "https://github.com/nnstreamer/nnstreamer-example/tree/main/templates/tensor_filter_subplugin/"
        click CI "https://github.com/nnstreamer/nnstreamer-example/tree/main/.github/workflows/"
    end

    %% Styles
    classDef native fill:#D0E6FF,stroke:#4A90E2,stroke-width:1px;
    classDef scripts fill:#D0E6FF,stroke:#4A90E2,stroke-width:1px;
    classDef tizen fill:#D0F0D8,stroke:#28A745,stroke-width:1px;
    classDef android fill:#FFE5CC,stroke:#FF8C00,stroke-width:1px;
    classDef pkg fill:#E2E2E2,stroke:#888888,stroke-width:1px;
    classDef core fill:#FFF2CC,stroke:#D4A017,stroke-width:1px,stroke-dasharray: 5 5;
    classDef model fill:#F0F0F0,stroke:#AAAAAA,stroke-width:1px,stroke-dasharray: 2 2;
```
