# havish06/sadsv architecture

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

- Interactive diagram: https://gitdiagram.com/havish06/sadsv
- Repository: https://github.com/havish06/sadsv

## Overview

1. This repository is a sensor-first ADAS simulator centered on a single orchestration loop. The main runtime entrypoints are `main.py` and `run_simulator.py`, which start the simulator defined in `simulation/enhanced_simulator.py`. The README indicates the current focus is on safety features like drowsiness detection, alcohol ignition lock, adaptive cruise control, and assisted lane changes.

2. The highest-level architectural boundary is the simulation engine in `simulation/`. `enhanced_simulator.py` appears to be the active coordinator, while `simulation/simulator.py` is likely a simpler/base variant. `traffic_generator.py` supplies surrounding traffic scenarios, so the simulator is not just rendering a scene; it is generating world state, updating actors, and evaluating safety logic continuously.

3. The world model lives in `world/` and provides the physical environment: `road.py`, `traffic_light.py`, `clock.py`, and `world.py`. This layer defines the static and temporal simulation context that sensors and vehicles read from. It is the boundary between abstract ADAS logic and the road/traffic conditions being simulated.

4. Vehicle state is separated into `vehicles/`, with `ego_vehicle.py` for the controlled car and `npc_vehicle.py` for other traffic participants. `vehicle.py` is the shared abstraction. This split matters because most safety decisions are ego-centric: the ego vehicle is the one whose throttle, braking, lane changes, and overrides are controlled by the ADAS logic.

5. Sensor logic is isolated in `sensors/`, and this is the main perception layer of the system. It includes driver-facing and environment-facing checks: `driver_monitor.py`, `alcohol_sensor.py`, `distance_sensor.py`, `blind_spot_sensor.py`, `lane_sensor.py`, and `collision_warning.py`. These modules turn raw simulator state into safety signals such as drowsiness, intoxication lockout, safe following distance, lane availability, and collision risk.

6. Decision-making sits in `decision/`, which is where sensor outputs become control actions. `state_machine.py` is the central arbitration layer, and `lane_change.py` handles lane-change assist behavior. The README’s “priority-aware HUD” implies this layer also determines which safety module currently owns control, and when assist mode can override or yield to the driver.

7. The control flow is effectively: world and traffic update -> sensors evaluate ego/driver/environment -> decision state machine selects a safety response -> ego vehicle control is adjusted. Important safety behaviors called out by the README include emergency safe-stop for drowsiness, ignition lock for alcohol detection, ACC with sensor validation, and lane-change aborts when blind-spot or hazard conditions arise.

8. Human interaction is handled in `input/driver_input.py`. Keyboard controls toggle assist mode, enable/disable alcohol lock simulation, request lane changes, confirm maneuvers, manually change speed when assist is off, pause, reset, and exit. This layer is the boundary between operator intent and simulator autonomy.

9. Output and operator feedback are split across `visualization/` and `utils/audio.py`. `visualization/renderer.py` is responsible for displaying road geometry, lane markers, safety state, and the HUD that shows module ownership. The README also mentions a live OpenCV eye-monitor window when camera mode is enabled, so the visualization layer includes a real-time driver-facing feedback path, not just static rendering.

10. Configuration and cross-cutting support are centralized in `config/` and `utils/`. `config/config.py`, `sim_config.py`, and `thresholds.py` hold tunable simulation parameters and safety thresholds, which are crucial because the ADAS behavior is threshold-driven. `utils/logger.py` provides traceability, and `utils/audio.py` likely supports alerting. The `assets/` directory supplies UI/media resources used by the renderer and alerts.

Main entry points: [`simulation/enhanced_simulator.py`](https://github.com/havish06/sadsv/blob/main/simulation/enhanced_simulator.py) (Enhanced sim), [`decision/state_machine.py`](https://github.com/havish06/sadsv/blob/main/decision/state_machine.py) (State machine), [`world/world.py`](https://github.com/havish06/sadsv/blob/main/world/world.py) (World), [`decision/lane_change.py`](https://github.com/havish06/sadsv/blob/main/decision/lane_change.py) (Lane change)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entrypoints"]
  node_main_py["main.py<br/>entrypoint<br/>[main.py]"]
  node_run_simulator_py["run_simulator.py<br/>entrypoint<br/>[run_simulator.py]"]
end

subgraph group_core["Simulation Core"]
  node_enhanced_simulator["Enhanced sim<br/>orchestrator"]
  node_base_simulator["Base sim<br/>sim core<br/>[simulator.py]"]
  node_traffic_generator["Traffic gen<br/>scenario source"]
end

subgraph group_perception["Perception"]
  node_driver_monitor["Driver monitor<br/>sensor<br/>[driver_monitor.py]"]
  node_alcohol_sensor["Alcohol sensor<br/>[alcohol_sensor.py]"]
  node_distance_sensor["Distance sensor<br/>[distance_sensor.py]"]
  node_blind_spot_sensor["Blind spot<br/>sensor"]
  node_lane_sensor["Lane sensor<br/>[lane_sensor.py]"]
  node_collision_warning["Collision warn<br/>sensor"]
end

subgraph group_control["Decision & Control"]
  node_state_machine["State machine<br/>arbiter<br/>[state_machine.py]"]
  node_lane_change["Lane change<br/>assist logic<br/>[lane_change.py]"]
end

subgraph group_model["World & Vehicles"]
  node_world_model["World<br/>environment model<br/>[world.py]"]
  node_road["Road<br/>geometry<br/>[road.py]"]
  node_traffic_light(("Signals<br/>traffic state<br/>[traffic_light.py]"))
  node_clock(("Clock<br/>timebase<br/>[clock.py]"))
  node_vehicle_base["Vehicle<br/>actor base<br/>[vehicle.py]"]
  node_ego_vehicle["Ego vehicle<br/>controlled actor<br/>[ego_vehicle.py]"]
  node_npc_vehicle["NPC vehicle<br/>traffic actor<br/>[npc_vehicle.py]"]
end

subgraph group_io["I/O & Feedback"]
  node_driver_input["Driver input<br/>operator I/O<br/>[driver_input.py]"]
  node_renderer["Renderer<br/>visual output<br/>[renderer.py]"]
  node_audio(("Audio<br/>alerting<br/>[audio.py]"))
  node_logger(("Logger<br/>telemetry<br/>[logger.py]"))
end

subgraph group_support["Configuration"]
  node_config["Config<br/>[config.py]"]
  node_sim_config["Sim config<br/>scenario config<br/>[sim_config.py]"]
  node_thresholds["Thresholds<br/>safety config<br/>[thresholds.py]"]
end

node_main_py -->|"starts"| node_enhanced_simulator
node_run_simulator_py -->|"starts"| node_enhanced_simulator
node_enhanced_simulator -->|"spawns traffic"| node_traffic_generator
node_enhanced_simulator -->|"updates world"| node_world_model
node_enhanced_simulator -->|"updates actors"| node_vehicle_base
node_base_simulator -->|"uses"| node_world_model
node_world_model -->|"contains"| node_road
node_world_model -->|"contains"| node_traffic_light
node_world_model -->|"advances"| node_clock
node_vehicle_base -->|"specializes"| node_ego_vehicle
node_vehicle_base -->|"specializes"| node_npc_vehicle
node_enhanced_simulator -->|"reads"| node_driver_monitor
node_enhanced_simulator -->|"reads"| node_alcohol_sensor
node_enhanced_simulator -->|"reads"| node_distance_sensor
node_enhanced_simulator -->|"reads"| node_blind_spot_sensor
node_enhanced_simulator -->|"reads"| node_lane_sensor
node_enhanced_simulator -->|"reads"| node_collision_warning
node_driver_monitor -->|"signals"| node_state_machine
node_alcohol_sensor -->|"signals"| node_state_machine
node_distance_sensor -->|"signals"| node_state_machine
node_blind_spot_sensor -->|"blocks"| node_lane_change
node_lane_sensor -->|"guides"| node_lane_change
node_collision_warning -->|"signals"| node_state_machine
node_state_machine -->|"authorizes"| node_lane_change
node_state_machine -->|"commands"| node_ego_vehicle
node_lane_change -->|"steers"| node_ego_vehicle
node_driver_input -->|"requests"| node_state_machine
node_driver_input -->|"manual control"| node_ego_vehicle
node_enhanced_simulator -->|"renders"| node_renderer
node_enhanced_simulator -->|"alerts"| node_audio
node_enhanced_simulator -->|"logs"| node_logger
node_enhanced_simulator -->|"uses"| node_config
node_enhanced_simulator -->|"uses"| node_sim_config
node_enhanced_simulator -->|"uses"| node_thresholds

click node_main_py "https://github.com/havish06/sadsv/blob/main/main.py"
click node_run_simulator_py "https://github.com/havish06/sadsv/blob/main/run_simulator.py"
click node_enhanced_simulator "https://github.com/havish06/sadsv/blob/main/simulation/enhanced_simulator.py"
click node_base_simulator "https://github.com/havish06/sadsv/blob/main/simulation/simulator.py"
click node_traffic_generator "https://github.com/havish06/sadsv/blob/main/simulation/traffic_generator.py"
click node_world_model "https://github.com/havish06/sadsv/blob/main/world/world.py"
click node_road "https://github.com/havish06/sadsv/blob/main/world/road.py"
click node_traffic_light "https://github.com/havish06/sadsv/blob/main/world/traffic_light.py"
click node_clock "https://github.com/havish06/sadsv/blob/main/world/clock.py"
click node_vehicle_base "https://github.com/havish06/sadsv/blob/main/vehicles/vehicle.py"
click node_ego_vehicle "https://github.com/havish06/sadsv/blob/main/vehicles/ego_vehicle.py"
click node_npc_vehicle "https://github.com/havish06/sadsv/blob/main/vehicles/npc_vehicle.py"
click node_driver_monitor "https://github.com/havish06/sadsv/blob/main/sensors/driver_monitor.py"
click node_alcohol_sensor "https://github.com/havish06/sadsv/blob/main/sensors/alcohol_sensor.py"
click node_distance_sensor "https://github.com/havish06/sadsv/blob/main/sensors/distance_sensor.py"
click node_blind_spot_sensor "https://github.com/havish06/sadsv/blob/main/sensors/blind_spot_sensor.py"
click node_lane_sensor "https://github.com/havish06/sadsv/blob/main/sensors/lane_sensor.py"
click node_collision_warning "https://github.com/havish06/sadsv/blob/main/sensors/collision_warning.py"
click node_state_machine "https://github.com/havish06/sadsv/blob/main/decision/state_machine.py"
click node_lane_change "https://github.com/havish06/sadsv/blob/main/decision/lane_change.py"
click node_driver_input "https://github.com/havish06/sadsv/blob/main/input/driver_input.py"
click node_renderer "https://github.com/havish06/sadsv/blob/main/visualization/renderer.py"
click node_audio "https://github.com/havish06/sadsv/blob/main/utils/audio.py"
click node_logger "https://github.com/havish06/sadsv/blob/main/utils/logger.py"
click node_config "https://github.com/havish06/sadsv/blob/main/config/config.py"
click node_sim_config "https://github.com/havish06/sadsv/blob/main/config/sim_config.py"
click node_thresholds "https://github.com/havish06/sadsv/blob/main/config/thresholds.py"

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_py,node_run_simulator_py,node_config,node_sim_config,node_thresholds toneBlue
class node_enhanced_simulator,node_base_simulator,node_traffic_generator toneAmber
class node_driver_monitor,node_alcohol_sensor,node_distance_sensor,node_blind_spot_sensor,node_lane_sensor,node_collision_warning toneMint
class node_state_machine,node_lane_change toneRose
class node_world_model,node_road,node_traffic_light,node_clock,node_vehicle_base,node_ego_vehicle,node_npc_vehicle toneIndigo
class node_driver_input,node_renderer,node_audio,node_logger toneTeal
```

## Components

### Entrypoints

Process startup and top-level simulator launch.

- [main.py](https://github.com/havish06/sadsv/blob/main/main.py): entrypoint · Primary launch script for the simulator. · `main.py`
- [run_simulator.py](https://github.com/havish06/sadsv/blob/main/run_simulator.py): entrypoint · Alternate launch script for running the simulator. · `run_simulator.py`

### Simulation Core

Main runtime loop and traffic generation.

- [Enhanced sim](https://github.com/havish06/sadsv/blob/main/simulation/enhanced_simulator.py): orchestrator · Active coordinator for the ADAS simulation loop. · `simulation/enhanced_simulator.py`
- [Base sim](https://github.com/havish06/sadsv/blob/main/simulation/simulator.py): sim core · Simpler or legacy simulator variant. · `simulation/simulator.py`
- [Traffic gen](https://github.com/havish06/sadsv/blob/main/simulation/traffic_generator.py): scenario source · Builds surrounding traffic and world situations. · `simulation/traffic_generator.py`

### Perception

Sensor and driver-state checks feeding safety logic.

- [Driver monitor](https://github.com/havish06/sadsv/blob/main/sensors/driver_monitor.py): sensor · Detects drowsiness and driver attention state. · `sensors/driver_monitor.py`
- [Alcohol sensor](https://github.com/havish06/sadsv/blob/main/sensors/alcohol_sensor.py): sensor · Checks intoxication and ignition lock conditions. · `sensors/alcohol_sensor.py`
- [Distance sensor](https://github.com/havish06/sadsv/blob/main/sensors/distance_sensor.py): sensor · Measures following distance for ACC and safety. · `sensors/distance_sensor.py`
- [Blind spot](https://github.com/havish06/sadsv/blob/main/sensors/blind_spot_sensor.py): sensor · Detects adjacent-lane hazards for lane changes. · `sensors/blind_spot_sensor.py`
- [Lane sensor](https://github.com/havish06/sadsv/blob/main/sensors/lane_sensor.py): sensor · Tracks lane position and lane availability. · `sensors/lane_sensor.py`
- [Collision warn](https://github.com/havish06/sadsv/blob/main/sensors/collision_warning.py): sensor · Raises imminent collision risk signals. · `sensors/collision_warning.py`

### Decision & Control

Arbitration and maneuver logic that turns signals into actions.

- [State machine](https://github.com/havish06/sadsv/blob/main/decision/state_machine.py): arbiter · Prioritizes safety modules and selects responses. · `decision/state_machine.py`
- [Lane change](https://github.com/havish06/sadsv/blob/main/decision/lane_change.py): assist logic · Coordinates assisted lane-change behavior and aborts. · `decision/lane_change.py`

### World & Vehicles

Simulation state for roads, time, traffic, and actors.

- [World](https://github.com/havish06/sadsv/blob/main/world/world.py): environment model · Container for roads, lights, and simulation time. · `world/world.py`
- [Road](https://github.com/havish06/sadsv/blob/main/world/road.py): geometry · Lane and roadway structure used by sensors and control. · `world/road.py`
- [Signals](https://github.com/havish06/sadsv/blob/main/world/traffic_light.py): traffic state · Traffic light state used by the simulator. · `world/traffic_light.py`
- [Clock](https://github.com/havish06/sadsv/blob/main/world/clock.py): timebase · Advances simulation time and pacing. · `world/clock.py`
- [Vehicle](https://github.com/havish06/sadsv/blob/main/vehicles/vehicle.py): actor base · Shared vehicle abstraction. · `vehicles/vehicle.py`
- [Ego vehicle](https://github.com/havish06/sadsv/blob/main/vehicles/ego_vehicle.py): controlled actor · Primary vehicle under ADAS control. · `vehicles/ego_vehicle.py`
- [NPC vehicle](https://github.com/havish06/sadsv/blob/main/vehicles/npc_vehicle.py): traffic actor · Other traffic participants in the scene. · `vehicles/npc_vehicle.py`

### I/O & Feedback

Human input, visualization, alerts, and logging.

- [Driver input](https://github.com/havish06/sadsv/blob/main/input/driver_input.py): operator I/O · Keyboard controls for assist, maneuvers, pause, and reset. · `input/driver_input.py`
- [Renderer](https://github.com/havish06/sadsv/blob/main/visualization/renderer.py): visual output · Draws road, actors, safety state, and HUD feedback. · `visualization/renderer.py`
- [Audio](https://github.com/havish06/sadsv/blob/main/utils/audio.py): alerting · Supports audible warnings and feedback. · `utils/audio.py`
- [Logger](https://github.com/havish06/sadsv/blob/main/utils/logger.py): telemetry · Provides trace logging and diagnostics. · `utils/logger.py`

### Configuration

Cross-cutting tuning and runtime parameters.

- [Config](https://github.com/havish06/sadsv/blob/main/config/config.py): runtime config · Central simulation parameters. · `config/config.py`
- [Sim config](https://github.com/havish06/sadsv/blob/main/config/sim_config.py): scenario config · Simulation-specific settings and defaults. · `config/sim_config.py`
- [Thresholds](https://github.com/havish06/sadsv/blob/main/config/thresholds.py): safety config · Sensor and ADAS trigger thresholds. · `config/thresholds.py`

## Connections

- main.py → Enhanced sim: starts · Launches the primary simulator runtime.
- run_simulator.py → Enhanced sim: starts · Alternative entrypoint into the same runtime.
- Enhanced sim → Traffic gen: spawns traffic · Generates surrounding vehicles and scenarios.
- Enhanced sim → World: updates world · Advances the simulated environment each loop.
- Enhanced sim → Vehicle: updates actors · Coordinates vehicle state and motion.
- Base sim → World: uses · Base simulator relies on the same environment model.
- World → Road: contains · Holds roadway and lane geometry.
- World → Signals: contains · Tracks signal state in the world.
- World → Clock: advances · Uses the clock to step simulation time.
- Vehicle → Ego vehicle: specializes · Shared vehicle abstraction for the controlled car.
- Vehicle → NPC vehicle: specializes · Shared vehicle abstraction for traffic actors.
- Enhanced sim → Driver monitor: reads · Consumes driver attention state.
- Enhanced sim → Alcohol sensor: reads · Consumes intoxication state.
- Enhanced sim → Distance sensor: reads · Consumes following-distance signals.
- Enhanced sim → Blind spot: reads · Consumes adjacent-lane hazard signals.
- Enhanced sim → Lane sensor: reads · Consumes lane position and lane availability.
- Enhanced sim → Collision warn: reads · Consumes collision-risk warnings.
- Driver monitor → State machine: signals · Feeds drowsiness and attention outcomes into arbitration.
- Alcohol sensor → State machine: signals · Feeds ignition-lock conditions into arbitration.
- Distance sensor → State machine: signals · Feeds ACC and safety distance checks.
- Blind spot → Lane change: blocks · Can veto unsafe lane changes.
- Lane sensor → Lane change: guides · Provides lane availability and alignment data.
- Collision warn → State machine: signals · Triggers emergency response paths.
- State machine → Lane change: authorizes · Selects lane-change assist when safe.
- State machine → Ego vehicle: commands · Adjusts ego control for stop, ACC, or assist.
- Lane change → Ego vehicle: steers · Applies lane-change maneuver control.
- Driver input → State machine: requests · Driver toggles assist and maneuver intent.
- Driver input → Ego vehicle: manual control · Can directly affect speed or pause-driven behavior.
- Enhanced sim → Renderer: renders · Provides world and safety state to the HUD.
- Enhanced sim → Audio: alerts · Emits warnings and safety prompts.
- Enhanced sim → Logger: logs · Records simulation and safety events.
- Enhanced sim → Config: uses · Loads core parameters.
- Enhanced sim → Sim config: uses · Loads scenario/runtime settings.
- Enhanced sim → Thresholds: uses · Uses safety trigger thresholds.
