# unitreerobotics/unitree_sdk2 architecture

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

- Interactive diagram: https://gitdiagram.com/unitreerobotics/unitree_sdk2
- Repository: https://github.com/unitreerobotics/unitree_sdk2

## Overview

Based on our analysis of the file tree and the README, this project is the Unitree robot SDK version 2 – a C++ robotics software development kit that provides API support for a range of Unitree robot models (such as b2, g1, go2, h1, etc.). Its purpose is to enable developers to build applications that control and interact with these robots. The repository is organized into core source headers (under include/unitree), pre-built static libraries (in lib), a collection of examples demonstrating usage (under example), and a comprehensive integration with DDS for the communication layer, along with third-party components.

##### And Label Main Components
- Core SDK Library: Represent the core functionalities (e.g., common utilities, thread, time, logging, file system, error/exception handling) found within the include/unitree/common and various include directories.
- Communication & Messaging Layer: Create a component for the DDS integration. This includes the DDS-related code in include/unitree/common/dds as well as the IDL definition files in include/unitree/idl. Also, note the integration with third-party DDS libraries (thirdparty folder).
- Build & Deployment Infrastructure: Include a component for the build system and installation procedures (the CMakeLists.txt at the root and within examples, plus the CI configuration in the .github/workflows directory). This emphasizes the use of CMake as well as the multi-architecture support (aarch64 and x86_64).

##### Relationships & Data Flow
- That the Application Examples use the Core SDK Library to interact with the robot-specific modules.
- That the SDK wraps third-party DDS functionalities and provides a layer of abstraction for client/server communications.
- How CMake scripts and configuration files integrate all these components during the build and installation processes.

##### Architectural Patterns and Design Principles
- Layered Architecture: Show separate layers for (a) utility/core functions, (b) communication/messaging, (c) robot-specific APIs, and (d) application examples.
- Modular Design: Stress that the robot modules (b2, g1, go2, h1) are independently organized, allowing developers to pick the right APIs per robot family.
- Client-Server Model: Indicate that there is a clear separation between legacy client side interactions and the internal server implementations (as seen in include/unitree/robot/client and include/unitree/robot/server).
- DDS Integration: Make clear how the DDS layer encapsulates communication, which is fundamental to the SDK’s operations.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Application Layer
    subgraph "Application Layer"
        EXAMPLES["Example Applications"]:::app
    end

    %% Robot API Layer
    subgraph "Robot API Layer"
        ROBOT["Robot API Modules (b2, g1, go2, h1, ...)"]:::robot
    end

    %% Core SDK and Communication Layer
    subgraph "Core & Communication Layer"
        CORE["Core SDK (Utilities, Logging, Threading, etc.)"]:::core
        DDS["DDS Integration"]:::comm
        IDL["IDL Definitions"]:::comm
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        INFRA["Build & Deployment Infrastructure"]:::infra
        THIRD["Third-Party Dependencies"]:::thirdparty
    end

    %% Relationships
    EXAMPLES -->|"uses"| ROBOT
    EXAMPLES -->|"uses"| CORE

    CORE -->|"wraps"| DDS
    CORE -->|"wraps"| IDL

    ROBOT -->|"communicates_via"| DDS
    ROBOT -->|"communicates_via"| IDL

    INFRA -->|"integrates"| CORE
    INFRA -->|"integrates"| ROBOT
    INFRA -->|"integrates"| EXAMPLES
    INFRA -->|"uses"| THIRD

    THIRD -->|"supports"| DDS
    THIRD -->|"supports"| IDL

    %% Click Events
    click CORE "https://github.com/unitreerobotics/unitree_sdk2/tree/main/include/unitree/common"
    click DDS "https://github.com/unitreerobotics/unitree_sdk2/tree/main/include/unitree/common/dds"
    click IDL "https://github.com/unitreerobotics/unitree_sdk2/tree/main/include/unitree/idl"
    click ROBOT "https://github.com/unitreerobotics/unitree_sdk2/tree/main/include/unitree/robot"
    click EXAMPLES "https://github.com/unitreerobotics/unitree_sdk2/tree/main/example"
    click INFRA "https://github.com/unitreerobotics/unitree_sdk2/blob/main/CMakeLists.txt"
    click THIRD "https://github.com/unitreerobotics/unitree_sdk2/tree/main/thirdparty"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef comm fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef robot fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef app fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef infra fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef thirdparty fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
