# luxonis/depthai architecture

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

- Interactive diagram: https://gitdiagram.com/luxonis/depthai
- Repository: https://github.com/luxonis/depthai

## Overview

##### Project Type & Purpose
- This is a full-featured demo application for DepthAI. It not only demonstrates different AI models and camera pipelines (such as UVC streaming and video recording) but also acts as a backbone for rapid prototyping on OAK camera hardware.
- The project contains both demo applications (apps/uvc, apps/record) and the underlying DepthAI SDK library (in depthai_sdk) with various integrations (such as ROS) and utilities for tasks like calibration, neural network (NN) configurations, hardware interactions, and visualization.

##### Analyzing the File Structure for Architectural Clues
- Top-Level Directories: Notice distinct directories like apps, depthai_sdk, gui, launcher, and resources. Each plays a separate role:
- apps: Contains application-specific entry points (e.g., record and uvc demos).
- depthai_sdk: Contains the core SDK code including components, managers, NN model definitions, integrations (ROS, Roboflow, etc.), recorders, visualizers, and other utilities.
- gui: Provides a QT-based graphical interface.
- launcher: Hosts a separate launcher module with its own scripts to initiate the demo, especially on Windows.
- resources: Contains neural network (NN) models and calibration boards.
- The extensive subdirectories within depthai_sdk (such as components, managers, readers, recorders, and integrations) indicate that the system is modular in nature and follows clean layering principles.

##### Main Components
a. User Interface Layer:
- CLI / Console: Invoked via command-line arguments in depthai_demo.py.
- GUI: The QT-based interface (in gui/) for a clickable, user-friendly experience.
- Launcher: The launcher module (in launcher/) that helps initialize the demo apps.

b. Application Layer:
- DepthAI Demo Application: The central script (depthai_demo.py) that routes commands for different demo areas (like UVC streaming or recording).
- Apps: “uvc” and “record” apps under the apps/ directory, which enable distinct functionalities (streaming pipelines and multi-format video recording).

c. SDK / Core Library Layer:
- DepthAI SDK: The core library (depthai_sdk/) offering a rich set of modules.
- Components: e.g., camera_component, imu_component, nn_component, stereo_component.
- Managers: e.g., pipeline_manager, encoding_manager, preview_manager, nnet_manager – these manage individual aspects of the workflow.
- NN Models: Folder “nn_models” provides predefined neural network configurations and handlers for models like YOLO, MobileNet, etc.
- Integrations: ROS and other external integrations to communicate with third-party systems.
- Readers & Recorders: Abstractions to read inputs (from webcams or file sources) and to record outputs (to mp4, MCAP, or ROS bag files).
- Trigger Actions: Modules implementing triggers and actions based on sensor input or detections.

d. Hardware & External Interfaces:
- OAK Camera Hardware: Highlight the physical depth camera devices that get managed by the SDK.
- Docker and OS-level Dependencies: Illustrate the containerization aspect (via Dockerfile, installation scripts) and OS integration (e.g., calibration scripts and autostart).

e. Resource Storage:
- Resources Directory: Houses neural network blobs, JSON configurations, calibration boards, etc.

##### Relationships and Data Flows
- Demo Application interacting with the SDK’s core modules (managers, components, NN models) which in turn communicate with both the hardware (camera devices) and external integration services.
- From the hardware through the SDK’s reader components.
- Through internal processing modules (like NN inference, image encoding).
- Then output through visualizers or recorders.
- Feedback loops such as triggers activating actions (through the trigger_action modules).
- Optionally incorporate deployment/control flows (for Docker usage and installation scripts) as a supporting layer.

##### Architectural Patterns or Principles
- Modularity & Separation of Concerns: Each major functionality (UI, processing, hardware abstraction) is in its own module.
- Extensibility & Integration: The SDK is designed for integration (e.g., ROS, custom NN models) and rapid prototyping.
- Layered Architecture: Distinct layers for UI, demo/application logic, and core SDK functionality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI1["CLI/Console"] 
        UI2["GUI Interface"]
        UI3["Launcher Module"]
    end

    %% Application Layer
    subgraph "Application Layer"
        APP1["DepthAI Demo App"]
        APP2["UVC App"]
        APP3["Record App"]
    end

    %% SDK / Core Library
    subgraph "SDK / Core Library"
        SDK1["Core SDK Code"]
        SDK2["Components"]
        SDK3["Managers"]
        SDK4["NN Models"]
        SDK5["Integrations"]
        SDK6["Readers & Recorders"]
        SDK7["Visualizers"]
        SDK8["Trigger Actions"]
    end

    %% Hardware & External Interface
    subgraph "Hardware & External Interface"
        HW1["OAK Camera Interface"]
    end

    %% Resource Storage
    subgraph "Resource Storage"
        RES1["Resources"]
    end

    %% Connections from UI Layer to Application Layer
    UI1 -->|"sends command"| APP1
    UI2 -->|"sends command"| APP1
    UI3 -->|"sends command"| APP1

    %% Connections within Application Layer
    APP1 -->|"selects mode"| APP2
    APP1 -->|"selects mode"| APP3
    APP1 -->|"invokes modules"| SDK1

    %% Connections within SDK / Core Library
    SDK1 -->|"manages"| SDK2
    SDK1 -->|"manages"| SDK3
    SDK1 -->|"utilizes"| SDK4
    SDK1 -->|"integrates"| SDK5
    SDK1 -->|"handles I/O"| SDK6
    SDK1 -->|"renders output"| SDK7
    SDK1 -->|"triggers actions"| SDK8

    %% Connections to Hardware and Resources
    SDK1 -->|"controls"| HW1
    SDK1 -->|"accesses"| RES1

    %% Styling Classes
    class UI1,UI2,UI3 ui
    class APP1,APP2,APP3 app
    class SDK1,SDK2,SDK3,SDK4,SDK5,SDK6,SDK7,SDK8 core
    class HW1 ext
    class RES1 resource

    %% Class Definitions
    classDef ui fill:#DDEEFF,stroke:#000000,stroke-width:2px;
    classDef app fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef core fill:#C0FFC0,stroke:#006400,stroke-width:2px;
    classDef ext fill:#FFCCCB,stroke:#FF0000,stroke-width:2px;
    classDef resource fill:#E6E6FA,stroke:#800080,stroke-width:2px;

    %% Click Events
    click UI1 "https://github.com/luxonis/depthai/blob/main/depthai_helpers/cli_utils.py"
    click UI2 "https://github.com/luxonis/depthai/tree/main/gui/"
    click UI3 "https://github.com/luxonis/depthai/tree/main/launcher/"

    click APP1 "https://github.com/luxonis/depthai/blob/main/depthai_demo.py"
    click APP2 "https://github.com/luxonis/depthai/tree/main/apps/uvc/"
    click APP3 "https://github.com/luxonis/depthai/tree/main/apps/record/"

    click SDK1 "https://github.com/luxonis/depthai/tree/main/depthai_sdk/"
    click SDK2 "https://github.com/luxonis/depthai/tree/main/depthai_sdk/src/depthai_sdk/components/"
    click SDK3 "https://github.com/luxonis/depthai/tree/main/depthai_sdk/src/depthai_sdk/managers/"
    click SDK4 "https://github.com/luxonis/depthai/tree/main/depthai_sdk/src/depthai_sdk/nn_models/"
    click SDK5 "https://github.com/luxonis/depthai/tree/main/depthai_sdk/src/depthai_sdk/integrations/"
    click SDK6 "https://github.com/luxonis/depthai/tree/main/depthai_sdk/src/depthai_sdk/readers/"
    click SDK7 "https://github.com/luxonis/depthai/tree/main/depthai_sdk/src/depthai_sdk/visualize/"
    click SDK8 "https://github.com/luxonis/depthai/tree/main/depthai_sdk/src/depthai_sdk/trigger_action/"

    click HW1 "https://github.com/luxonis/depthai/blob/main/depthai_sdk/src/depthai_sdk/oak_camera.py"
    click RES1 "https://github.com/luxonis/depthai/tree/main/resources/"
```
