# metadriverse/metadrive architecture

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

- Interactive diagram: https://gitdiagram.com/metadriverse/metadrive
- Repository: https://github.com/metadriverse/metadrive

## Overview

##### High-Level Architecture Overview
The system should be represented as a layered architecture with the following main components:

a. Core Engine Layer:
- Base Engine (/metadrive/engine/)
- Physics System
- Rendering Pipeline (/metadrive/render_pipeline/)
- Asset Management

b. Environment Layer:
- Base Environment
- Single-Agent Environments
- Multi-Agent Environments
- Real-World Environments (nuScenes, Waymo)

c. Component Layer:
- Vehicles
- Sensors
- Maps
- Traffic Systems
- Navigation Systems

##### Key Components and Relationships

**[Rendering Pipeline] ←→ [Core Engine] ←→ [Physics World]**
- ↑                    ↑               ↑

- [Asset Loader] ←→ [Component Manager] ←→ [Collision System]
- ↑                    ↑               ↑

**[Environment Manager] ←→ [Scene Manager] ←→ [Agent Manager]**

##### Detailed Component Breakdown

a. Sensor Systems (metadrive/component/sensors/):
- RGB Cameras
- Depth Cameras
- LiDAR
- Semantic Cameras
- Instance Cameras

b. Vehicle Systems (metadrive/component/vehicle/):
- Vehicle Models
- Controllers
- Physics Models
- Behavior Systems

c. Environment Generation:
- Procedural Generation
- Real-world Data Integration
- Scenario Management

##### Data Flow

**[Sensor Input] → [Environment State] → [Agent Decision] → [Vehicle Control]**
- ↑               ↑                      ↑                ↑
**[Rendering] ← [Physics Update] ← [Action Execution] ← [Control Commands]**

##### Integration Points

External integration points:
- ROS Bridge Interface
- Gymnasium API Integration
- Real-world Dataset Connectors

##### Implementation Details

Technical details in notes:
- Python-based implementation
- Panda3D for rendering
- Bullet Physics for simulation
- Support for multiple observation types
- Parallel environment capability

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core
        BE["Base Engine"]:::core
        PS["Physics System"]:::core
        RP["Rendering Pipeline"]:::core
        AM["Asset Management"]:::core
        CS["Collision System"]:::core
    end

    subgraph Components
        VS["Vehicle System"]:::component
        SS["Sensor System"]:::component
        MS["Map System"]:::component
        NS["Navigation System"]:::component
        TS["Traffic System"]:::component
    end

    subgraph Environment
        BaseEnv["Base Environment"]:::env
        MAEnv["Multi-Agent Environments"]:::env
        SceneM["Scene Manager"]:::env
    end

    subgraph Integration
        ROS["ROS Bridge Interface"]:::external
    end

    %% Core Layer Connections
    BE <--> PS
    BE <--> RP
    BE <--> AM
    PS <--> CS

    %% Component Layer Connections
    BE --> VS
    BE --> SS
    BE --> MS
    BE --> NS
    BE --> TS

    %% Environment Layer Connections
    BaseEnv --> BE
    MAEnv --> BaseEnv
    SceneM --> BE

    %% Integration Connections
    ROS --> BE

    %% Component Interactions
    VS <--> PS
    SS --> RP
    MS --> AM
    TS --> SceneM
    NS --> MS

    %% Styling
    classDef core fill:#2374ab
    classDef component fill:#48a9a6
    classDef env fill:#4ad66d
    classDef external fill:#666666

    %% Click Events
    click BE "https://github.com/metadriverse/metadrive/blob/main/metadrive/engine/base_engine.py"
    click PS "https://github.com/metadriverse/metadrive/blob/main/metadrive/engine/core/physics_world.py"
    click RP "https://github.com/metadriverse/metadrive/tree/main/metadrive/render_pipeline/"
    click AM "https://github.com/metadriverse/metadrive/blob/main/metadrive/engine/asset_loader.py"
    click VS "https://github.com/metadriverse/metadrive/tree/main/metadrive/component/vehicle/"
    click SS "https://github.com/metadriverse/metadrive/tree/main/metadrive/component/sensors/"
    click MS "https://github.com/metadriverse/metadrive/tree/main/metadrive/component/map/"
    click NS "https://github.com/metadriverse/metadrive/tree/main/metadrive/component/navigation_module/"
    click TS "https://github.com/metadriverse/metadrive/tree/main/metadrive/component/traffic_participants/"
    click BaseEnv "https://github.com/metadriverse/metadrive/blob/main/metadrive/envs/base_env.py"
    click MAEnv "https://github.com/metadriverse/metadrive/tree/main/metadrive/envs/marl_envs/"
    click SceneM "https://github.com/metadriverse/metadrive/tree/main/metadrive/manager/"
    click ROS "https://github.com/metadriverse/metadrive/tree/main/bridges/ros_bridge/"
    click CS "https://github.com/metadriverse/metadrive/blob/main/metadrive/engine/core/collision_callback.py"
```
