# trafficinc/sam-simulator architecture

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

- Interactive diagram: https://gitdiagram.com/trafficinc/sam-simulator
- Repository: https://github.com/trafficinc/sam-simulator

## Overview

This is a modular air-defense simulation lab: hostile units generate truth-state, the shield evaluates tracks and assigns defensive effectors, and the hub brokers role updates into an operator-facing dashboard and scenario assessment. The principal loop runs through separate Pilot and Shield clients exchanging snapshots with the Hub. The graph also preserves scenario authoring, shared contracts/configuration, and dashboard capabilities. Unsampled frontend and configuration details are included only where the README or tree supports their role; edges reflect documented or excerpted wiring.

Main entry points: [`hub/broker.py`](https://github.com/trafficinc/sam-simulator/blob/main/hub/broker.py) (WebSocket broker), [`scenarios/config_loader.py`](https://github.com/trafficinc/sam-simulator/blob/main/scenarios/config_loader.py) (Scenario loader), [`frontend/assets/app.js`](https://github.com/trafficinc/sam-simulator/blob/main/frontend/assets/app.js) (Tactical dashboard), [`hub/app.py`](https://github.com/trafficinc/sam-simulator/blob/main/hub/app.py) (Hub API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_hub_ui["Hub and dashboard"]
  node_hub_api["Hub API<br/>[app.py]"]
  node_broker["WebSocket broker<br/>[broker.py]"]
  node_world_state[("World state and assessment<br/>[messages.py]")]
  node_dashboard["Tactical dashboard<br/>[app.js]"]
end

subgraph group_hostile["Hostile simulation"]
  node_pilot_client["Pilot client<br/>[client.py]"]
  node_truth_model["Hostile truth model<br/>[truth.py]"]
  node_scenario_templates["Scenario templates<br/>[base.py]"]
  node_scenario_loader["Scenario loader<br/>[config_loader.py]"]
  node_raid_scenarios["Raid scenarios"]
  node_group_raid["Saturation raid"]
end

subgraph group_defense["Air defense"]
  node_shield_client["Shield client<br/>[client.py]"]
  node_doctrine_engine["Doctrine and engagement engine<br/>[logic.py]"]
end

subgraph group_contracts["Contracts and configuration"]
  node_role_contract["Role message contract<br/>[messages.py]"]
  node_sam_config["SAM battery configuration<br/>[sam_config.py]"]
  node_zone_config["Defended-zone configuration<br/>[zone_config.py]"]
  node_scenario_config["Scenario configuration"]
  node_defense_config["Defense configuration"]
end

node_operator(("Operator"))

node_operator -->|"operates"| node_dashboard
node_dashboard -.->|"requests controls"| node_hub_api
node_hub_api -->|"routes WebSockets"| node_broker
node_broker -->|"merges updates"| node_world_state
node_broker -->|"broadcasts snapshots"| node_dashboard
node_hub_api -->|"hosts interface"| node_dashboard
node_pilot_client -->|"sends role updates"| node_broker
node_broker -->|"broadcasts snapshots"| node_pilot_client
node_pilot_client -->|"generates tracks"| node_truth_model
node_truth_model -->|"uses templates"| node_scenario_templates
node_scenario_loader -->|"builds definitions"| node_scenario_templates
node_scenario_loader -->|"fallback definitions"| node_raid_scenarios
node_scenario_loader -->|"fallback definitions"| node_group_raid
node_scenario_loader -->|"loads JSON scenarios"| node_scenario_config
node_shield_client -->|"sends role updates"| node_broker
node_broker -->|"broadcasts snapshots"| node_shield_client
node_shield_client -->|"evaluates snapshots"| node_doctrine_engine
node_doctrine_engine -->|"uses snapshot helpers"| node_role_contract
node_doctrine_engine -->|"loads batteries"| node_sam_config
node_role_contract -->|"loads battery defaults"| node_sam_config
node_role_contract -->|"loads defended zones"| node_zone_config
node_sam_config -.->|"reads battery settings"| node_defense_config
node_zone_config -.->|"reads zone settings"| node_defense_config

click node_hub_api "https://github.com/trafficinc/sam-simulator/blob/main/hub/app.py"
click node_broker "https://github.com/trafficinc/sam-simulator/blob/main/hub/broker.py"
click node_world_state "https://github.com/trafficinc/sam-simulator/blob/main/shared/messages.py"
click node_dashboard "https://github.com/trafficinc/sam-simulator/blob/main/frontend/assets/app.js"
click node_pilot_client "https://github.com/trafficinc/sam-simulator/blob/main/pilot/client.py"
click node_truth_model "https://github.com/trafficinc/sam-simulator/blob/main/pilot/truth.py"
click node_scenario_templates "https://github.com/trafficinc/sam-simulator/blob/main/scenarios/base.py"
click node_scenario_loader "https://github.com/trafficinc/sam-simulator/blob/main/scenarios/config_loader.py"
click node_raid_scenarios "https://github.com/trafficinc/sam-simulator/blob/main/scenarios/default_layered_raid.py"
click node_group_raid "https://github.com/trafficinc/sam-simulator/blob/main/scenarios/group_saturation_raid.py"
click node_shield_client "https://github.com/trafficinc/sam-simulator/blob/main/shield/client.py"
click node_doctrine_engine "https://github.com/trafficinc/sam-simulator/blob/main/shield/logic.py"
click node_role_contract "https://github.com/trafficinc/sam-simulator/blob/main/shared/messages.py"
click node_sam_config "https://github.com/trafficinc/sam-simulator/blob/main/shared/sam_config.py"
click node_zone_config "https://github.com/trafficinc/sam-simulator/blob/main/shared/zone_config.py"
click node_scenario_config "https://github.com/trafficinc/sam-simulator/tree/main/config/scenarios"
click node_defense_config "https://github.com/trafficinc/sam-simulator/tree/main/config"

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_hub_api,node_broker,node_world_state,node_dashboard toneBlue
class node_pilot_client,node_truth_model,node_scenario_templates,node_scenario_loader,node_raid_scenarios,node_group_raid toneAmber
class node_shield_client,node_doctrine_engine toneMint
class node_role_contract,node_sam_config,node_zone_config,node_scenario_config,node_defense_config toneRose
class node_operator toneIndigo
```

## Components

### Hub and dashboard

- [Hub API](https://github.com/trafficinc/sam-simulator/blob/main/hub/app.py): `hub/app.py`
- [WebSocket broker](https://github.com/trafficinc/sam-simulator/blob/main/hub/broker.py): `hub/broker.py`
- [World state and assessment](https://github.com/trafficinc/sam-simulator/blob/main/shared/messages.py): `shared/messages.py`
- [Tactical dashboard](https://github.com/trafficinc/sam-simulator/blob/main/frontend/assets/app.js): `frontend/assets/app.js`

### Hostile simulation

- [Pilot client](https://github.com/trafficinc/sam-simulator/blob/main/pilot/client.py): `pilot/client.py`
- [Hostile truth model](https://github.com/trafficinc/sam-simulator/blob/main/pilot/truth.py): `pilot/truth.py`
- [Scenario templates](https://github.com/trafficinc/sam-simulator/blob/main/scenarios/base.py): `scenarios/base.py`
- [Scenario loader](https://github.com/trafficinc/sam-simulator/blob/main/scenarios/config_loader.py): `scenarios/config_loader.py`
- [Raid scenarios](https://github.com/trafficinc/sam-simulator/blob/main/scenarios/default_layered_raid.py): `scenarios/default_layered_raid.py`
- [Saturation raid](https://github.com/trafficinc/sam-simulator/blob/main/scenarios/group_saturation_raid.py): `scenarios/group_saturation_raid.py`

### Air defense

- [Shield client](https://github.com/trafficinc/sam-simulator/blob/main/shield/client.py): `shield/client.py`
- [Doctrine and engagement engine](https://github.com/trafficinc/sam-simulator/blob/main/shield/logic.py): `shield/logic.py`

### Contracts and configuration

- [Role message contract](https://github.com/trafficinc/sam-simulator/blob/main/shared/messages.py): `shared/messages.py`
- [SAM battery configuration](https://github.com/trafficinc/sam-simulator/blob/main/shared/sam_config.py): `shared/sam_config.py`
- [Defended-zone configuration](https://github.com/trafficinc/sam-simulator/blob/main/shared/zone_config.py): `shared/zone_config.py`
- [Scenario configuration](https://github.com/trafficinc/sam-simulator/tree/main/config/scenarios): `config/scenarios`
- [Defense configuration](https://github.com/trafficinc/sam-simulator/tree/main/config): `config`

### Other components

- **Operator**

## Connections

- Operator → Tactical dashboard: operates (evidence: `README.md`)
- Tactical dashboard → Hub API: requests controls (evidence: `README.md`)
- Hub API → WebSocket broker: routes WebSockets (evidence: `hub/app.py`)
- WebSocket broker → World state and assessment: merges updates (evidence: `hub/broker.py`)
- WebSocket broker → Tactical dashboard: broadcasts snapshots (evidence: `hub/broker.py`)
- Hub API → Tactical dashboard: hosts interface (evidence: `hub/app.py`)
- Pilot client → WebSocket broker: sends role updates (evidence: `README.md`)
- WebSocket broker → Pilot client: broadcasts snapshots (evidence: `hub/broker.py`)
- Pilot client → Hostile truth model: generates tracks (evidence: `pilot/client.py`)
- Hostile truth model → Scenario templates: uses templates (evidence: `pilot/truth.py`)
- Scenario loader → Scenario templates: builds definitions (evidence: `scenarios/config_loader.py`)
- Scenario loader → Raid scenarios: fallback definitions (evidence: `scenarios/config_loader.py`)
- Scenario loader → Saturation raid: fallback definitions (evidence: `scenarios/config_loader.py`)
- Scenario loader → Scenario configuration: loads JSON scenarios (evidence: `scenarios/config_loader.py`)
- Shield client → WebSocket broker: sends role updates (evidence: `README.md`)
- WebSocket broker → Shield client: broadcasts snapshots (evidence: `hub/broker.py`)
- Shield client → Doctrine and engagement engine: evaluates snapshots (evidence: `shield/client.py`)
- Doctrine and engagement engine → Role message contract: uses snapshot helpers (evidence: `shield/logic.py`)
- Doctrine and engagement engine → SAM battery configuration: loads batteries (evidence: `shield/logic.py`)
- Role message contract → SAM battery configuration: loads battery defaults (evidence: `shared/messages.py`)
- Role message contract → Defended-zone configuration: loads defended zones (evidence: `shared/messages.py`)
- SAM battery configuration → Defense configuration: reads battery settings
- Defended-zone configuration → Defense configuration: reads zone settings
