# pushpak1203/v2 architecture

> Architecture diagram of the GitHub repository pushpak1203/v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pushpak1203/v2
- Repository: https://github.com/pushpak1203/v2

## Overview

#### Purpose and execution modes
This repository simulates cooperative autonomous vehicles in MetaDrive. Vehicles exchange encrypted V2V state/messages, feed shared awareness into planning, and execute driving actions in a multi-agent environment. Primary runners are `main.py`, `main_autonomous_complex.py`, and `main_autonomous_idm.py`; `drive_in_real_env.py` is a separate real-environment driving-oriented entry point.

#### Simulation environment boundary
The MetaDrive integration owns scenario lifecycle, vehicle/environment setup, stepping, and observations/actions. It isolates simulator-specific APIs from planning and communications:
- `metadrive_env/env_manager.py`
- `metadrive_env/env_manager_with_idm.py`
- `metadrive_env/__init__.py`

The IDM-specific manager provides an alternate traffic/control mode used by the IDM runner, rather than the default autonomous scenario path.

#### Agent orchestration and control loop
Entrypoints assemble configuration, environment management, communication, and planning into the per-step simulation loop:
- `main.py`
- `main_autonomous_complex.py`
- `main_autonomous_idm.py`

The core control flow is: initialize scenario and agents → obtain local simulator state → receive peer V2V information → select/plan cooperative response → apply controls to MetaDrive → log outcomes → repeat until simulation termination.

#### Decision and path-planning layer
The decision engine converts vehicle state and received peer context into maneuver/action decisions. `planner.py` is the central planning interface/orchestrator, while Hybrid A* supplies path-search behavior and response planning handles reactions to detected/cooperative conditions:
- `decision_engine/planner.py`
- `decision_engine/hybrid_astar_planner.py`
- `decision_engine/response_planner.py`

This is the key boundary between high-level cooperative intent and low-level simulator actions.

#### V2V transport and security
The communication subsystem provides the inter-agent message boundary. Broadcasters publish vehicle/situational data; receivers ingest peer messages; encryption utilities protect message payloads:
- `communication/broadcaster.py`
- `communication/receiver.py`
- `communication/encryption_utils.py`

Encryption requires an external `secret.key` at runtime, as described by the README but not present in the tree. Logging configuration supports communication observability through `communication/logging_config.py`.

#### Configuration, runtime dependencies, and observability
Simulation parameters are centralized in `config/config.yaml`, allowing scenarios and behavior to be adjusted without changing orchestration code. The material runtime is Python with MetaDrive, plus dependencies declared in `requirements.txt`. Simulation output is retained in `logs/sim_log.txt`; communication logging is intended as a separate operational stream for latency, coordination, and safety evaluation.

#### Architectural variants
The repository intentionally supports multiple policy/scenario variants rather than one fixed application path:
- default multi-agent cooperative simulation: `main.py`
- complex cooperative scenario: `main_autonomous_complex.py`
- Intelligent Driver Model integration: `main_autonomous_idm.py`

All variants share the same broad environment → state sharing → decision/planning → control feedback loop, while selecting different environment managers and driving behavior.

Main entry points: [`metadrive_env/env_manager.py`](https://github.com/pushpak1203/v2/blob/main/metadrive_env/env_manager.py) (Environment manager), [`decision_engine/planner.py`](https://github.com/pushpak1203/v2/blob/main/decision_engine/planner.py) (Planning orchestrator), [`metadrive_env/env_manager_with_idm.py`](https://github.com/pushpak1203/v2/blob/main/metadrive_env/env_manager_with_idm.py) (IDM environment manager), [`metadrive_env/__init__.py`](https://github.com/pushpak1203/v2/blob/main/metadrive_env/__init__.py) (MetaDrive environment API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entrypoints["Simulation Runners"]
  node_main["Default simulation<br/>Python runner<br/>[main.py]"]
  node_complex_runner["Complex scenario<br/>Python runner"]
  node_idm_runner["IDM simulation<br/>Python runner"]
  node_real_drive["Real-environment drive<br/>Python runner"]
end

subgraph group_environment["MetaDrive Boundary"]
  node_env_manager["Environment manager<br/>MetaDrive adapter<br/>[env_manager.py]"]
  node_idm_env_manager["IDM environment manager<br/>MetaDrive adapter"]
  node_metadrive_package["MetaDrive environment API<br/>Package boundary<br/>[__init__.py]"]
end

subgraph group_communication["Secure V2V"]
  node_broadcaster["V2V broadcaster<br/>Message publisher<br/>[broadcaster.py]"]
  node_receiver["V2V receiver<br/>Message consumer<br/>[receiver.py]"]
  node_encryption{{"Payload encryption<br/>Security utility"}}
end

subgraph group_planning["Cooperative Planning"]
  node_planner["Planning orchestrator<br/>Decision engine<br/>[planner.py]"]
  node_hybrid_astar["Hybrid A* search<br/>Path planner"]
  node_response_planner["Response planner<br/>Maneuver planner"]
end

node_config["Simulation config<br/>YAML configuration<br/>[config.yaml]"]
node_sim_log["Simulation log<br/>Runtime output<br/>[sim_log.txt]"]
node_requirements["Python dependencies<br/>Dependency manifest<br/>[requirements.txt]"]

node_main -->|"loads"| node_config
node_complex_runner -->|"loads"| node_config
node_idm_runner -->|"loads"| node_config
node_main -->|"runs"| node_env_manager
node_complex_runner -->|"runs"| node_env_manager
node_idm_runner -->|"runs"| node_idm_env_manager
node_env_manager -->|"uses"| node_metadrive_package
node_idm_env_manager -->|"uses"| node_metadrive_package
node_env_manager -->|"provides local state"| node_broadcaster
node_broadcaster -->|"encrypts payload"| node_encryption
node_encryption -->|"protects messages"| node_receiver
node_receiver -->|"supplies peer context"| node_planner
node_env_manager -->|"supplies observations"| node_planner
node_planner -->|"searches paths"| node_hybrid_astar
node_planner -->|"selects response"| node_response_planner
node_planner -->|"applies controls"| node_env_manager
node_planner -->|"applies controls"| node_idm_env_manager
node_env_manager -->|"logs outcomes"| node_sim_log
node_idm_env_manager -->|"logs outcomes"| node_sim_log
node_requirements -.->|"declares dependency"| node_metadrive_package

click node_main "https://github.com/pushpak1203/v2/blob/main/main.py"
click node_complex_runner "https://github.com/pushpak1203/v2/blob/main/main_autonomous_complex.py"
click node_idm_runner "https://github.com/pushpak1203/v2/blob/main/main_autonomous_idm.py"
click node_real_drive "https://github.com/pushpak1203/v2/blob/main/drive_in_real_env.py"
click node_config "https://github.com/pushpak1203/v2/blob/main/config/config.yaml"
click node_env_manager "https://github.com/pushpak1203/v2/blob/main/metadrive_env/env_manager.py"
click node_idm_env_manager "https://github.com/pushpak1203/v2/blob/main/metadrive_env/env_manager_with_idm.py"
click node_metadrive_package "https://github.com/pushpak1203/v2/blob/main/metadrive_env/__init__.py"
click node_broadcaster "https://github.com/pushpak1203/v2/blob/main/communication/broadcaster.py"
click node_receiver "https://github.com/pushpak1203/v2/blob/main/communication/receiver.py"
click node_encryption "https://github.com/pushpak1203/v2/blob/main/communication/encryption_utils.py"
click node_planner "https://github.com/pushpak1203/v2/blob/main/decision_engine/planner.py"
click node_hybrid_astar "https://github.com/pushpak1203/v2/blob/main/decision_engine/hybrid_astar_planner.py"
click node_response_planner "https://github.com/pushpak1203/v2/blob/main/decision_engine/response_planner.py"
click node_sim_log "https://github.com/pushpak1203/v2/blob/main/logs/sim_log.txt"
click node_requirements "https://github.com/pushpak1203/v2/blob/main/requirements.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_complex_runner,node_idm_runner,node_real_drive toneBlue
class node_env_manager,node_idm_env_manager,node_metadrive_package toneAmber
class node_broadcaster,node_receiver,node_encryption toneMint
class node_planner,node_hybrid_astar,node_response_planner toneRose
class node_config,node_sim_log,node_requirements toneNeutral
```

## Components

### Simulation Runners

Select cooperative scenario and control variant.

- [Default simulation](https://github.com/pushpak1203/v2/blob/main/main.py): Python runner · `main.py`
- [Complex scenario](https://github.com/pushpak1203/v2/blob/main/main_autonomous_complex.py): Python runner · `main_autonomous_complex.py`
- [IDM simulation](https://github.com/pushpak1203/v2/blob/main/main_autonomous_idm.py): Python runner · `main_autonomous_idm.py`
- [Real-environment drive](https://github.com/pushpak1203/v2/blob/main/drive_in_real_env.py): Python runner · Separate driving-oriented entry point. · `drive_in_real_env.py`

### MetaDrive Boundary

Owns simulator lifecycle, state, and action integration.

- [Environment manager](https://github.com/pushpak1203/v2/blob/main/metadrive_env/env_manager.py): MetaDrive adapter · Default scenario lifecycle and simulator integration. · `metadrive_env/env_manager.py`
- [IDM environment manager](https://github.com/pushpak1203/v2/blob/main/metadrive_env/env_manager_with_idm.py): MetaDrive adapter · Alternate IDM traffic and control mode. · `metadrive_env/env_manager_with_idm.py`
- [MetaDrive environment API](https://github.com/pushpak1203/v2/blob/main/metadrive_env/__init__.py): Package boundary · `metadrive_env/__init__.py`

### Secure V2V

Shares protected peer vehicle and situational data.

- [V2V broadcaster](https://github.com/pushpak1203/v2/blob/main/communication/broadcaster.py): Message publisher · `communication/broadcaster.py`
- [V2V receiver](https://github.com/pushpak1203/v2/blob/main/communication/receiver.py): Message consumer · `communication/receiver.py`
- [Payload encryption](https://github.com/pushpak1203/v2/blob/main/communication/encryption_utils.py): Security utility · Requires the external secret.key at runtime. · `communication/encryption_utils.py`

### Cooperative Planning

Converts local and shared state into driving controls.

- [Planning orchestrator](https://github.com/pushpak1203/v2/blob/main/decision_engine/planner.py): Decision engine · Combines local state and peer context into cooperative actions. · `decision_engine/planner.py`
- [Hybrid A* search](https://github.com/pushpak1203/v2/blob/main/decision_engine/hybrid_astar_planner.py): Path planner · `decision_engine/hybrid_astar_planner.py`
- [Response planner](https://github.com/pushpak1203/v2/blob/main/decision_engine/response_planner.py): Maneuver planner · `decision_engine/response_planner.py`

### Other components

- [Simulation config](https://github.com/pushpak1203/v2/blob/main/config/config.yaml): YAML configuration · `config/config.yaml`
- [Simulation log](https://github.com/pushpak1203/v2/blob/main/logs/sim_log.txt): Runtime output · `logs/sim_log.txt`
- [Python dependencies](https://github.com/pushpak1203/v2/blob/main/requirements.txt): Dependency manifest · Declares Python and MetaDrive runtime dependencies. · `requirements.txt`

## Connections

- Default simulation → Simulation config: loads
- Complex scenario → Simulation config: loads
- IDM simulation → Simulation config: loads
- Default simulation → Environment manager: runs
- Complex scenario → Environment manager: runs
- IDM simulation → IDM environment manager: runs
- Environment manager → MetaDrive environment API: uses
- IDM environment manager → MetaDrive environment API: uses
- Environment manager → V2V broadcaster: provides local state
- V2V broadcaster → Payload encryption: encrypts payload
- Payload encryption → V2V receiver: protects messages
- V2V receiver → Planning orchestrator: supplies peer context
- Environment manager → Planning orchestrator: supplies observations
- Planning orchestrator → Hybrid A* search: searches paths
- Planning orchestrator → Response planner: selects response
- Planning orchestrator → Environment manager: applies controls
- Planning orchestrator → IDM environment manager: applies controls
- Environment manager → Simulation log: logs outcomes
- IDM environment manager → Simulation log: logs outcomes
- Python dependencies → MetaDrive environment API: declares dependency
