# microsoft/airsim architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/airsim
- Repository: https://github.com/microsoft/airsim

## Overview

##### Main Components
- Simulation Engine Integration Layer:
– Unreal Engine (core simulation environment; see the “Unreal” directory and plugin code in Unreal/Plugins/AirSim).
– Experimental Unity plugin (found under the “Unity” folder).
- Core Simulation Library – AirLib:
– Organized into subcomponents such as “api”, “common”, “physics”, “sensors”, “safety”, and “vehicles”.
– Contains modules that implement vehicle-specific simulations, sensor modeling, physical computations, and safety (e.g., geofence checks).
- Communication and API Layer:
– RPC libraries (with base classes in AirLib/include/api) to expose simulation controls and sensor data.
– External API servers and clients (see AirLib/src/api and files like RpcLibServerBase.cpp and RpcLibClientBase.cpp).
- Client Interfaces and Tools:
– Python Client (PythonClient folder) for programmatic control.
– ROS and ROS2 integrations (directories “ros” and “ros2”) that include launch files, msg/srv definitions, and wrappers.
– Additional demo and utility projects such as DroneServer, DroneShell, and examples listed in the “Examples” directory.
- Auxiliary and Integration Components:
– MavLinkCom for communication with flight controllers.
– Azure and Docker folders for cloud/CI setup.
– LogViewer and additional UI components for visualization and debugging.

##### Establish Relationships and Data Flow
- A bidirectional connection between the Simulation Core and the Engine Integration Layer – they exchange commands and simulation state.
- The API layer (RPC servers, API adaptors) sits on top of AirLib connecting external clients (Python programs, ROS nodes, MavLink components, vehicle control consoles like DroneShell) with the simulation core.
- Clients send instructions (via API calls or RPC) to control vehicles or request sensor data; the simulation core processes these and responds back through the API layer.
- Relationships between the simulation’s modular components (e.g., sensors, physics engine, vehicle models, safety checks) that are combined to create the full simulation state.
- External connectivity for hardware-in-the-loop support (PX4 & ArduPilot integration) and customization through configuration files (settings in AirLib/include/common and docs).

##### Architectural Patterns and Design Principles
- Layered Architecture – separate the simulation engine integration, simulation core (AirLib), API/external communication, and client applications.
- Modular and Extensible Design – AirLib is organized into several directories (e.g., “sensors”, “vehicles”, “physics”) that clearly indicate separation of concerns.
- RPC Pattern – for programmatic control over simulation (via RPC libraries and APIs).
- Cross-platform and Multi-language Support – support for C++, Python, ROS, and C# clearly indicate heterogeneous client connections.
- Plugin-Based Integration – with Unreal and Unity, the system is built as a plugin that can be added to different environments.

##### Relevant Technologies, Frameworks, and Libraries
- Unreal Engine and Unity as simulation/rendering engines.
- C++ core libraries (AirLib, DroneServer, DroneShell, MavLinkCom).
- RPC frameworks (for example, the use of RPC adaptation via RpcLib libraries).
- ROS and ROS2 for integrating simulation with standard robotics middleware.
- Python for API-based control and reinforcement learning experiments.
- Docker and Azure elements for CI/CD and deployment.
- Build systems (CMake and Visual Studio) clearly present in the file tree.

##### Elements
- Use clear, descriptive labels for each component (e.g., “AirLib Simulation Core”, “Unreal Engine Plugin”, “RPC API Server”, “Python Client Interface”, “ROS Integration Layer”).
– From client interfaces (e.g., Python scripts, ROS nodes) to the API layer and then to the AirLib core.
– From simulation core back to UI components or logging systems.
- Notes on configuration files and build scripts (shown in directories like “cmake”, “docker”, “build.cmd/sh”) that hint at deployment and integration processes.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Interfaces Layer
    subgraph "Client Interfaces"
        PC["Python Client Interface"]:::client
        ROS["ROS Integration"]:::client
        ROS2["ROS2 Integration"]:::client
        DS["DroneServer"]:::client
        DSh["DroneShell"]:::client
        MavLink["MavLink Communication"]:::client
    end

    %% Communication and API Layer
    subgraph "Communication and API Layer"
        APIInclude["RPC API (Include)"]:::api
        APISrc["RPC API (Src)"]:::api
    end

    %% Simulation Core Layer
    subgraph "AirLib Simulation Core"
        AirLibCore["AirLib Simulation Core"]:::core
    end

    %% Simulation Engine Integration Layer
    subgraph "Simulation Engine Integration"
        Unreal["Unreal Engine Plugin"]:::integration
        Unity["Unity Plugin"]:::integration
    end

    %% Auxiliary Components
    subgraph "Auxiliary Components"
        LogViewer["Logging & Visualization UI"]:::aux
        Azure["Azure Integration"]:::aux
        Docker["Docker Integration"]:::aux
    end

    %% Connections from Clients to API Layer
    PC -->|"sends commands"| APIInclude
    ROS -->|"sends commands"| APIInclude
    ROS2 -->|"sends commands"| APIInclude
    DS -->|"sends commands"| APIInclude
    DSh -->|"sends commands"| APIInclude
    MavLink -->|"sends commands"| APIInclude

    %% Internal API Layer connection
    APIInclude -->|"processes"| APISrc
    APISrc -->|"routes requests"| AirLibCore

    %% Bidirectional connection between Simulation Core and Integration Plugins
    AirLibCore <-->|"exchanges state"| Unreal
    AirLibCore <-->|"exchanges state"| Unity

    %% Connections to Auxiliary Components
    AirLibCore -->|"logs data"| LogViewer
    AirLibCore -->|"triggers CI"| Azure
    AirLibCore -->|"triggers CI"| Docker

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef api fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef core fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef integration fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef aux fill:#d1ecf1,stroke:#333,stroke-width:2px;

    %% Click Events
    click Unreal "https://github.com/microsoft/airsim/tree/main/Unreal/Plugins/AirSim"
    click Unity "https://github.com/microsoft/airsim/tree/main/Unity"
    click AirLibCore "https://github.com/microsoft/airsim/tree/main/AirLib"
    click APIInclude "https://github.com/microsoft/airsim/tree/main/AirLib/include/api"
    click APISrc "https://github.com/microsoft/airsim/tree/main/AirLib/src/api"
    click PC "https://github.com/microsoft/airsim/tree/main/PythonClient"
    click ROS "https://github.com/microsoft/airsim/tree/main/ros"
    click ROS2 "https://github.com/microsoft/airsim/tree/main/ros2"
    click DS "https://github.com/microsoft/airsim/tree/main/DroneServer"
    click DSh "https://github.com/microsoft/airsim/tree/main/DroneShell"
    click MavLink "https://github.com/microsoft/airsim/tree/main/MavLinkCom"
    click LogViewer "https://github.com/microsoft/airsim/tree/main/LogViewer"
    click Azure "https://github.com/microsoft/airsim/tree/main/azure"
    click Docker "https://github.com/microsoft/airsim/tree/main/docker"
```
