# joejaffal/mini_motorways architecture

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

- Interactive diagram: https://gitdiagram.com/joejaffal/mini_motorways
- Repository: https://github.com/joejaffal/mini_motorways

## Overview

Mini Motorways Simulation Lab provides two Unity traffic-construction apps, a shared simulation core and a line-oriented headless host; a separate Python project experiments with reinforcement-learning policies against that host. The main workflow is to reset a city, observe it, issue construction actions and advance simulation, with optional training and evaluation around gameplay. The README documents significant Original/Custom rule differences and training capabilities. Some core simulator and Unity source was not included, so those components and links are based on README statements; edges otherwise follow shown calls or documented interfaces.

Main entry points: [`training/train.py`](https://github.com/joejaffal/mini_motorways/blob/main/training/train.py) (Primitive PPO runner), [`simulation/Headless/Program.cs`](https://github.com/joejaffal/mini_motorways/blob/main/simulation/Headless/Program.cs) (JSON host), [`training/signal_agent.py`](https://github.com/joejaffal/mini_motorways/blob/main/training/signal_agent.py) (Signal policy), [`training/environment.py`](https://github.com/joejaffal/mini_motorways/blob/main/training/environment.py) (Gym environment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_play["Simulation runtime"]
  node_unity_apps["Unity apps"]
  node_sim_core["Traffic simulation core"]
  node_headless["JSON host<br/>[Program.cs]"]
end

subgraph group_learn["Training and policies"]
  node_training_env["Gym environment<br/>[environment.py]"]
  node_goal_env["Goal and signal environments<br/>[goal_agent.py]"]
  node_signal_agent["Signal policy<br/>[signal_agent.py]"]
  node_spatial_policy["Spatial policies<br/>[spatial_policy.py]"]
  node_train_runner["Primitive PPO runner<br/>[train.py]"]
  node_goal_runner["Goal PPO runner<br/>[train_goal.py]"]
  node_parallel_hosts["Parallel host workers<br/>[parallel.py]"]
  node_reward_logic["Reward shaping<br/>[rewards.py]"]
  node_progress["Training progress<br/>[progress.py]"]
  node_migration["Checkpoint migration<br/>[migration.py]"]
  node_upgrade_rules["Upgrade rules<br/>[upgrade_rules.py]"]
end

subgraph group_legacy["Legacy playground"]
  node_legacy_main["C++ demo and trainer<br/>[main.cpp]"]
  node_legacy_env["C++ environment"]
  node_legacy_renderer["C++ renderer<br/>[renderer.cpp]"]
end

subgraph group_tools["Validation and evidence"]
  node_verify_maps["Five-map verification"]
  node_readiness["Training readiness check"]
  node_reference_probe["Reference probe<br/>[Program.cs]"]
end

node_user(("Player or operator"))

node_user -->|"plays"| node_unity_apps
node_unity_apps -->|"uses shared core"| node_sim_core
node_user -->|"sends JSON commands"| node_headless
node_headless -->|"advances simulation"| node_sim_core
node_training_env -->|"sends commands"| node_headless
node_training_env -->|"reads observations"| node_headless
node_goal_env -->|"extends environment"| node_training_env
node_signal_agent -->|"extends goal environment"| node_goal_env
node_signal_agent -->|"creates workers"| node_parallel_hosts
node_train_runner -->|"creates environment"| node_training_env
node_train_runner -->|"selects policy"| node_spatial_policy
node_train_runner -->|"warm starts"| node_migration
node_train_runner -->|"reports training"| node_progress
node_train_runner -->|"runs workers"| node_parallel_hosts
node_train_runner -->|"uses rewards"| node_reward_logic
node_goal_runner -->|"trains goal policy"| node_goal_env
node_goal_runner -->|"supports signal policy"| node_signal_agent
node_goal_env -->|"uses rewards"| node_reward_logic
node_signal_agent -->|"checks upgrades"| node_upgrade_rules
node_legacy_main -->|"runs episodes"| node_legacy_env
node_legacy_main -.->|"renders demo"| node_legacy_renderer
node_legacy_renderer -->|"renders state"| node_legacy_env
node_verify_maps -.->|"tests rule sets"| node_headless
node_readiness -->|"checks playground"| node_headless
node_reference_probe -.->|"probes reference"| node_sim_core

click node_unity_apps "https://github.com/joejaffal/mini_motorways/tree/main/simulation"
click node_sim_core "https://github.com/joejaffal/mini_motorways/tree/main/simulation/Assets/Simulation"
click node_headless "https://github.com/joejaffal/mini_motorways/blob/main/simulation/Headless/Program.cs"
click node_training_env "https://github.com/joejaffal/mini_motorways/blob/main/training/environment.py"
click node_goal_env "https://github.com/joejaffal/mini_motorways/blob/main/training/goal_agent.py"
click node_signal_agent "https://github.com/joejaffal/mini_motorways/blob/main/training/signal_agent.py"
click node_spatial_policy "https://github.com/joejaffal/mini_motorways/blob/main/training/spatial_policy.py"
click node_train_runner "https://github.com/joejaffal/mini_motorways/blob/main/training/train.py"
click node_goal_runner "https://github.com/joejaffal/mini_motorways/blob/main/training/train_goal.py"
click node_parallel_hosts "https://github.com/joejaffal/mini_motorways/blob/main/training/parallel.py"
click node_reward_logic "https://github.com/joejaffal/mini_motorways/blob/main/training/rewards.py"
click node_progress "https://github.com/joejaffal/mini_motorways/blob/main/training/progress.py"
click node_migration "https://github.com/joejaffal/mini_motorways/blob/main/training/migration.py"
click node_upgrade_rules "https://github.com/joejaffal/mini_motorways/blob/main/training/upgrade_rules.py"
click node_legacy_main "https://github.com/joejaffal/mini_motorways/blob/main/legacy/cpp/main.cpp"
click node_legacy_env "https://github.com/joejaffal/mini_motorways/blob/main/legacy/cpp/mini_motorways_env.cpp"
click node_legacy_renderer "https://github.com/joejaffal/mini_motorways/blob/main/legacy/cpp/renderer.cpp"
click node_verify_maps "https://github.com/joejaffal/mini_motorways/blob/main/scripts/verify_five_maps.py"
click node_readiness "https://github.com/joejaffal/mini_motorways/blob/main/scripts/check_training_readiness.py"
click node_reference_probe "https://github.com/joejaffal/mini_motorways/blob/main/scripts/ReferenceProbe/Program.cs"

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_unity_apps,node_sim_core,node_headless toneBlue
class node_training_env,node_goal_env,node_signal_agent,node_spatial_policy,node_train_runner,node_goal_runner,node_parallel_hosts,node_reward_logic,node_progress,node_migration,node_upgrade_rules toneAmber
class node_legacy_main,node_legacy_env,node_legacy_renderer toneMint
class node_verify_maps,node_readiness,node_reference_probe toneRose
class node_user toneIndigo
```

## Components

### Simulation runtime

- [Unity apps](https://github.com/joejaffal/mini_motorways/tree/main/simulation): `simulation`
- [Traffic simulation core](https://github.com/joejaffal/mini_motorways/tree/main/simulation/Assets/Simulation): `simulation/Assets/Simulation`
- [JSON host](https://github.com/joejaffal/mini_motorways/blob/main/simulation/Headless/Program.cs): `simulation/Headless/Program.cs`

### Training and policies

- [Gym environment](https://github.com/joejaffal/mini_motorways/blob/main/training/environment.py): `training/environment.py`
- [Goal and signal environments](https://github.com/joejaffal/mini_motorways/blob/main/training/goal_agent.py): `training/goal_agent.py`
- [Signal policy](https://github.com/joejaffal/mini_motorways/blob/main/training/signal_agent.py): `training/signal_agent.py`
- [Spatial policies](https://github.com/joejaffal/mini_motorways/blob/main/training/spatial_policy.py): `training/spatial_policy.py`
- [Primitive PPO runner](https://github.com/joejaffal/mini_motorways/blob/main/training/train.py): `training/train.py`
- [Goal PPO runner](https://github.com/joejaffal/mini_motorways/blob/main/training/train_goal.py): `training/train_goal.py`
- [Parallel host workers](https://github.com/joejaffal/mini_motorways/blob/main/training/parallel.py): `training/parallel.py`
- [Reward shaping](https://github.com/joejaffal/mini_motorways/blob/main/training/rewards.py): `training/rewards.py`
- [Training progress](https://github.com/joejaffal/mini_motorways/blob/main/training/progress.py): `training/progress.py`
- [Checkpoint migration](https://github.com/joejaffal/mini_motorways/blob/main/training/migration.py): `training/migration.py`
- [Upgrade rules](https://github.com/joejaffal/mini_motorways/blob/main/training/upgrade_rules.py): `training/upgrade_rules.py`

### Legacy playground

- [C++ demo and trainer](https://github.com/joejaffal/mini_motorways/blob/main/legacy/cpp/main.cpp): `legacy/cpp/main.cpp`
- [C++ environment](https://github.com/joejaffal/mini_motorways/blob/main/legacy/cpp/mini_motorways_env.cpp): `legacy/cpp/mini_motorways_env.cpp`
- [C++ renderer](https://github.com/joejaffal/mini_motorways/blob/main/legacy/cpp/renderer.cpp): `legacy/cpp/renderer.cpp`

### Validation and evidence

- [Five-map verification](https://github.com/joejaffal/mini_motorways/blob/main/scripts/verify_five_maps.py): `scripts/verify_five_maps.py`
- [Training readiness check](https://github.com/joejaffal/mini_motorways/blob/main/scripts/check_training_readiness.py): `scripts/check_training_readiness.py`
- [Reference probe](https://github.com/joejaffal/mini_motorways/blob/main/scripts/ReferenceProbe/Program.cs): `scripts/ReferenceProbe/Program.cs`

### Other components

- **Player or operator**

## Connections

- Player or operator → Unity apps: plays (evidence: `README.md`)
- Unity apps → Traffic simulation core: uses shared core (evidence: `README.md`)
- Player or operator → JSON host: sends JSON commands (evidence: `README.md`)
- JSON host → Traffic simulation core: advances simulation (evidence: `README.md`)
- Gym environment → JSON host: sends commands (evidence: `training/environment.py`)
- Gym environment → JSON host: reads observations (evidence: `README.md`)
- Goal and signal environments → Gym environment: extends environment (evidence: `training/goal_agent.py`)
- Signal policy → Goal and signal environments: extends goal environment (evidence: `training/signal_agent.py`)
- Signal policy → Parallel host workers: creates workers (evidence: `training/signal_agent.py`)
- Primitive PPO runner → Gym environment: creates environment (evidence: `training/train.py`)
- Primitive PPO runner → Spatial policies: selects policy (evidence: `training/train.py`)
- Primitive PPO runner → Checkpoint migration: warm starts (evidence: `training/train.py`)
- Primitive PPO runner → Training progress: reports training (evidence: `training/train.py`)
- Primitive PPO runner → Parallel host workers: runs workers (evidence: `training/train.py`)
- Primitive PPO runner → Reward shaping: uses rewards (evidence: `training/train.py`)
- Goal PPO runner → Goal and signal environments: trains goal policy (evidence: `training/train_goal.py`)
- Goal PPO runner → Signal policy: supports signal policy (evidence: `training/train_goal.py`)
- Goal and signal environments → Reward shaping: uses rewards (evidence: `training/goal_agent.py`)
- Signal policy → Upgrade rules: checks upgrades (evidence: `training/signal_agent.py`)
- C++ demo and trainer → C++ environment: runs episodes (evidence: `legacy/cpp/main.cpp`)
- C++ demo and trainer → C++ renderer: renders demo
- C++ renderer → C++ environment: renders state (evidence: `legacy/cpp/renderer.cpp`)
- Five-map verification → JSON host: tests rule sets (evidence: `README.md`)
- Training readiness check → JSON host: checks playground (evidence: `README.md`)
- Reference probe → Traffic simulation core: probes reference
