# carla-simulator/carla architecture

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

- Interactive diagram: https://gitdiagram.com/carla-simulator/carla
- Repository: https://github.com/carla-simulator/carla

## Overview

This project is the CARLA Simulator – an open‐source autonomous driving simulation platform built to support development, training, and validation of self-driving systems. Its structure is complex and multi-layered, with components implemented in C++ (LibCarla), Unreal Engine (in the Unreal directory for the CARLA Unreal plugin), Python (the PythonAPI), and ROS2 integration (in Ros2Native). The project also contains extensive documentation, build scripts (CMake, Docker, etc.), and testing frameworks.

- Unreal Engine Integration: Under the “Unreal” directory and its subdirectories (e.g., CarlaUnreal and its Plugins) lies the integration with Unreal Engine which renders the simulation and provides the user/editor interface.
- Python API: The PythonAPI directory provides Python bindings so users can control and interact with the simulator.
- ROS2 Interface: The Ros2Native directory (and related ROS bridge repositories in the ecosystem) connects the simulator with the Robot Operating System.
- Traffic Manager and AI Controls: Within LibCarla and possibly under trafficmanager directories there is functionality for actor control (vehicles, pedestrians, etc.).
- External Tools & Build/Deployment Tools: Include components like the build infrastructure (CMake configuration, Jenkins, Docker, etc.) and asset import tools.

##### Architectural Patterns and Design Principles
- Modularity: Show how components like the core simulation engine, sensor simulation, and actor management are separate modules that interact via well-defined interfaces.
- Flow from control commands to simulation processing, rendering, and sensor data output. This highlights the pipeline nature of simulation.
- Integration points where cross-communication (for example, Python API bridging between external simulation control and C++ simulation engine) occurs.

##### Relevant Technologies, Frameworks, and Libraries
- That C++ (LibCarla, Unreal plugin) forms the backbone.
- Unreal Engine 5.5 (with a dual branch system for UE5 and earlier UE4 versions) as the rendering framework.
- Python (via the Python API) and ROS2, which play crucial roles in interfacing and control.
- Mention that build tools like CMake, Ninja, Docker, and associated scripts are used to compile, build, and deploy the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Simulation Backend
    subgraph "Simulation Backend"
        SE("Simulator Engine (LibCarla)"):::simulation
        TM("Traffic Manager and AI Controls"):::simulation
    end

    %% Rendering & Visualization
    subgraph "Rendering & Visualization"
        UE("Unreal Engine Integration"):::rendering
    end

    %% API & Integration
    subgraph "API & Integration"
        PA("Python API"):::integration
        ROS("ROS2 Interface"):::integration
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        CMake("CMake"):::build
        BT("Util/BuildTools"):::build
    end

    %% Connections: API calls and simulation control
    PA -->|"API_Calls/Control_Commands"| SE
    SE -->|"Simulation_Data/Sensor_Streaming"| UE
    UE -->|"State_Feedback"| SE
    SE -->|"ROS2_Messages/Topic_Publication"| ROS
    SE -->|"Traffic/Behavior_Commands"| TM
    TM -->|"Traffic/Behavior_Commands"| SE

    %% Connections: Build and Deployment pipelines (from both external tools)
    CMake -->|"Build/Deployment"| SE
    CMake -->|"Build/Deployment"| UE
    CMake -->|"Build/Deployment"| PA
    CMake -->|"Build/Deployment"| ROS

    BT -->|"Build/Deployment"| SE
    BT -->|"Build/Deployment"| UE
    BT -->|"Build/Deployment"| PA
    BT -->|"Build/Deployment"| ROS

    %% Click Events for Component Mapping
    click SE "https://github.com/carla-simulator/carla/tree/ue5-dev/LibCarla"
    click UE "https://github.com/carla-simulator/carla/tree/ue5-dev/Unreal/CarlaUnreal"
    click PA "https://github.com/carla-simulator/carla/tree/ue5-dev/PythonAPI"
    click ROS "https://github.com/carla-simulator/carla/tree/ue5-dev/Ros2Native"
    click TM "https://github.com/carla-simulator/carla/tree/ue5-dev/LibCarla/source/carla/trafficmanager"
    click CMake "https://github.com/carla-simulator/carla/tree/ue5-dev/CMake"
    click BT "https://github.com/carla-simulator/carla/tree/ue5-dev/Util/BuildTools"

    %% Styles
    classDef simulation fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef rendering fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef integration fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef build fill:#ffffcc,stroke:#999900,stroke-width:2px;
```
