# mwasifanwar/autodrive-sim architecture

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

- Interactive diagram: https://gitdiagram.com/mwasifanwar/autodrive-sim
- Repository: https://github.com/mwasifanwar/autodrive-sim

## Overview

##### Project Type and Purpose
- This is an end-to-end autonomous driving simulation framework (“autodrive-sim”) that integrates perception, planning, and control modules atop a realistic driving environment.
- It supports reinforcement-learning-based control and classical control strategies to develop and evaluate self-driving policies.

##### High-Level File-Structure Analysis
- Top-level directories:
- control: PID and MPC controllers plus a generic controller API
- environment: car dynamics, traffic simulator, overall simulator
- perception: detector, lane detection, segmentation, tracker
- planning: behavior, motion, path planners
- rl: RL agents (DQN, PPO, TD3) and base Agent class
- scripts: CLI entry points for training, evaluation, benchmarking, demo
- utils: configuration, logging, visualization helpers
- Key config: requirements.txt, setup.py, utils/config.py
- Patterns: modular separation of sensing→planning→actuation, pluggable RL vs. classical controllers, sim environment boundary.

##### README Insights
- Emphasizes “realistic simulation environment” and plug-and-play of perception, planning, and control using both RL and computer-vision methods.

1. Simulator Environment
– CarDynamics
– TrafficSimulator
– Visualizer (from utils/visualization)
2. Perception Module
– Image/State Input
– Detector, LaneDetection, Segmentation, Tracker
3. Planning Module
– BehaviorPlanner
– PathPlanner
– MotionPlanner
4. Control Module
– PIDController
– MPCController
– Controller interface
5. RL Agent
– Base Agent + DQN, PPO, TD3 implementations
6. Utilities & Scripts
– Config Loader
– Logger
– Training/Evaluation Scripts (train.py, evaluate.py, demo.py, etc.)
- Simulator → raw sensor data (images, states) → Perception
- Perception → environmental representation (objects, lanes, occupancy) → Planning
- Planning → trajectory/waypoints → Control
- Control → actuator commands → Simulator
- For RL training: Simulator ←→ RL Agent (state, reward, next state, done)
- Scripts orchestrate end-to-end runs, training loops, evaluation loops
c. Architectural Patterns & Principles:
- Modular pipeline (Sensing → Perception → Planning → Control)
- Pluggable controllers and planners adhering to common interfaces
- Separation of concerns between classical control and RL-based policies
- Config-driven instantiation (via utils/config.py)
d. Key Technologies & Libraries:
- Python (core language)
- Reinforcement Learning algorithms: DQN, PPO, TD3
- Simulation components (custom)
- Common tooling: logging, visualization, config management

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Simulator Environment"
        sim["Simulator\n(simulator.py)"]:::sim
        dynamics["CarDynamics\n(car_dynamics.py)"]:::sim
        traffic["TrafficSimulator\n(traffic_simulator.py)"]:::sim
        viz["Visualizer\n(utils/visualization.py)"]:::sim
    end

    subgraph "Perception Module"
        det["Detector\n(perception/detector.py)"]:::per
        lane["LaneDetection\n(perception/lane_detection.py)"]:::per
        seg["Segmentation\n(perception/segmentation.py)"]:::per
        track["Tracker\n(perception/tracker.py)"]:::per
    end

    subgraph "Planning Module"
        behavior["BehaviorPlanner\n(planning/behavior_planner.py)"]:::plan
        path["PathPlanner\n(planning/path_planner.py)"]:::plan
        motion["MotionPlanner\n(planning/motion_planner.py)"]:::plan
    end

    subgraph "Control Module"
        iface["Controller Interface\n(control/controller.py)"]:::ctrl
        pid["PIDController\n(control/pid.py)"]:::ctrl
        mpc["MPCController\n(control/mpc_controller.py)"]:::ctrl
    end

    subgraph "RL Agent"
        base["Agent Base\n(rl/agent.py)"]:::rl
        dqn["DQN\n(rl/dqn.py)"]:::rl
        ppo["PPO\n(rl/ppo.py)"]:::rl
        td3["TD3\n(rl/td3.py)"]:::rl
    end

    subgraph "Utilities"
        config["Config Loader\n(utils/config.py)"]:::util
        logger["Logger\n(utils/logger.py)"]:::util
        vis_helpers["Visualization\n(utils/visualization.py)"]:::util
    end

    subgraph "Scripts"
        st["train.py"]:::script
        st2["train_td3.py"]:::script
        eval["evaluate.py"]:::script
        demo["demo.py"]:::script
        bench["benchmark.py"]:::script
    end

    sim -->|"sensor_data"| det
    det -->|"detections"| lane
    lane -->|"lanes"| seg
    seg -->|"masks"| track
    track -->|"perception_output"| behavior

    behavior -->|"behavior_plan"| path
    path -->|"path_waypoints"| motion
    motion -->|"trajectory"| iface

    iface -->|"control_commands"| sim

    sim <-->|"state, reward"| base
    base -->|"actions"| sim

    st --> sim
    st --> det
    st --> behavior
    st --> iface
    st --> base

    classDef sim fill:#A6CEE3,stroke:#000
    classDef per fill:#B2DF8A,stroke:#000
    classDef plan fill:#FDBF6F,stroke:#000
    classDef ctrl fill:#FB9A99,stroke:#000
    classDef rl fill:#CAB2D6,stroke:#000
    classDef util fill:#D9D9D9,stroke:#000
    classDef script fill:#D9D9D9,stroke:#000,stroke-dasharray: 5 5

    click sim "https://github.com/mwasifanwar/autodrive-sim/blob/main/environment/simulator.py"
    click dynamics "https://github.com/mwasifanwar/autodrive-sim/blob/main/environment/car_dynamics.py"
    click traffic "https://github.com/mwasifanwar/autodrive-sim/blob/main/environment/traffic_simulator.py"
    click viz "https://github.com/mwasifanwar/autodrive-sim/blob/main/utils/visualization.py"
    click det "https://github.com/mwasifanwar/autodrive-sim/blob/main/perception/detector.py"
    click lane "https://github.com/mwasifanwar/autodrive-sim/blob/main/perception/lane_detection.py"
    click seg "https://github.com/mwasifanwar/autodrive-sim/blob/main/perception/segmentation.py"
    click track "https://github.com/mwasifanwar/autodrive-sim/blob/main/perception/tracker.py"
    click behavior "https://github.com/mwasifanwar/autodrive-sim/blob/main/planning/behavior_planner.py"
    click path "https://github.com/mwasifanwar/autodrive-sim/blob/main/planning/path_planner.py"
    click motion "https://github.com/mwasifanwar/autodrive-sim/blob/main/planning/motion_planner.py"
    click iface "https://github.com/mwasifanwar/autodrive-sim/blob/main/control/controller.py"
    click pid "https://github.com/mwasifanwar/autodrive-sim/blob/main/control/pid.py"
    click mpc "https://github.com/mwasifanwar/autodrive-sim/blob/main/control/mpc_controller.py"
    click base "https://github.com/mwasifanwar/autodrive-sim/blob/main/rl/agent.py"
    click dqn "https://github.com/mwasifanwar/autodrive-sim/blob/main/rl/dqn.py"
    click ppo "https://github.com/mwasifanwar/autodrive-sim/blob/main/rl/ppo.py"
    click td3 "https://github.com/mwasifanwar/autodrive-sim/blob/main/rl/td3.py"
    click config "https://github.com/mwasifanwar/autodrive-sim/blob/main/utils/config.py"
    click logger "https://github.com/mwasifanwar/autodrive-sim/blob/main/utils/logger.py"
    click vis_helpers "https://github.com/mwasifanwar/autodrive-sim/blob/main/utils/visualization.py"
    click st "https://github.com/mwasifanwar/autodrive-sim/blob/main/scripts/train.py"
    click st2 "https://github.com/mwasifanwar/autodrive-sim/blob/main/scripts/train_td3.py"
    click eval "https://github.com/mwasifanwar/autodrive-sim/blob/main/scripts/evaluate.py"
    click demo "https://github.com/mwasifanwar/autodrive-sim/blob/main/scripts/demo.py"
    click bench "https://github.com/mwasifanwar/autodrive-sim/blob/main/scripts/benchmark.py"
```
