# aymenhamzik/traffix3 architecture

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

- Interactive diagram: https://gitdiagram.com/aymenhamzik/traffix3
- Repository: https://github.com/aymenhamzik/traffix3

## Overview

TraffiX is a simulated hierarchical traffic-control product for a schematic central-Tunis network, with a live API and persona-based frontend. The principal workflow is scenario selection, demand generation, simulation and sensing, junction-level arbitration under network coordination, then live state and decision-log presentation. Experiments and Synapse language features are additional product branches. Connections follow the README and visible excerpts; several unsampled implementations are represented at their existing directory paths, so unshown internal calls are omitted.

Main entry points: [`traffix/orchestration/master.py`](https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/master.py) (Junction master), [`traffix/agents/network/explainer.py`](https://github.com/aymenhamzik/traffix3/blob/main/traffix/agents/network/explainer.py) (Decision explainer), [`traffix/api/server.py`](https://github.com/aymenhamzik/traffix3/blob/main/traffix/api/server.py) (Backend API), [`frontend/src/api.js`](https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/api.js) (Frontend API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_scenario["Scenario and demand"]
  node_demand["Demand generator<br/>[generator.py]"]
  node_calendar["Calendar model<br/>[calendar_model.py]"]
end

subgraph group_runtime["Simulation runtime"]
  node_sim["SUMO simulation<br/>[backend.py]"]
  node_sensors["Sensor layer<br/>[sensors.py]"]
  node_world["World events<br/>[world.py]"]
  node_executor["Light executor<br/>[executor.py]"]
end

subgraph group_control["Hierarchical control"]
  node_agentbase["Agent framework<br/>[base.py]"]
  node_junction_agents["Junction agents"]
  node_observation["Junction observation<br/>[observation.py]"]
  node_master["Junction master<br/>[master.py]"]
  node_safety["Safety rules<br/>[safety_rules.py]"]
  node_network_agents["Network agents"]
  node_supermaster["Network supermaster<br/>[supermaster.py]"]
  node_system["System assembly<br/>[system.py]"]
end

subgraph group_insight["Insights and language"]
  node_log[("Decision log<br/>[decision_log.py]")]
  node_narrator["Decision narration<br/>[narrate.py]"]
  node_explainer["Decision explainer<br/>[explainer.py]"]
  node_synapse["Language model client<br/>[llm.py]"]
  node_alert_copilot["Alerts and copilot"]
  node_evaluation["Experiment runner<br/>[runner.py]"]
  node_monitor["Persona metrics<br/>[monitor.py]"]
  node_training["Model training"]
end

subgraph group_experience["API and experience"]
  node_live["Live API<br/>[live.py]"]
  node_server["Backend API<br/>[server.py]"]
  node_frontend["Persona interface<br/>[App.jsx]"]
  node_api_client["Frontend API client<br/>[api.js]"]
  node_feed["Decision feed<br/>[Feed.jsx]"]
  node_networkmap["Network map<br/>[NetworkMap.jsx]"]
  node_i18n["Frontend languages<br/>[i18n.js]"]
end

node_user(("Scenario user"))

node_user -->|"selects scenario"| node_frontend
node_frontend -->|"requests state"| node_api_client
node_api_client -->|"calls API"| node_server
node_server -->|"controls live run"| node_live
node_live -.->|"runs system"| node_system
node_system -->|"assembles masters"| node_master
node_system -.->|"assembles coordinator"| node_supermaster
node_demand -->|"uses calendar"| node_calendar
node_demand -->|"supplies traffic"| node_sim
node_sim -.->|"feeds readings"| node_sensors
node_world -.->|"applies events"| node_sim
node_sensors -->|"provides observations"| node_junction_agents
node_junction_agents -->|"uses features"| node_observation
node_master -->|"collects requests"| node_junction_agents
node_master -->|"checks safety"| node_safety
node_master -->|"writes light"| node_executor
node_supermaster -->|"runs agents"| node_network_agents
node_supermaster -->|"sends directives"| node_master
node_master -->|"records decisions"| node_log
node_live -->|"exposes decisions"| node_log
node_server -->|"serves explanation"| node_explainer
node_explainer -->|"cites entries"| node_log
node_explainer -->|"uses templates"| node_narrator
node_explainer -.->|"uses optional LLM"| node_synapse
node_alert_copilot -.->|"uses optional LLM"| node_synapse
node_server -->|"serves copilot"| node_alert_copilot
node_api_client -->|"provides feed data"| node_feed
node_api_client -->|"provides map data"| node_networkmap
node_frontend -->|"sets language"| node_i18n
node_evaluation -->|"runs simulation"| node_system
node_evaluation -->|"collects metrics"| node_monitor
node_training -->|"generates training traffic"| node_demand
node_training -->|"uses simulation runs"| node_evaluation

click node_demand "https://github.com/aymenhamzik/traffix3/blob/main/traffix/demand/generator.py"
click node_calendar "https://github.com/aymenhamzik/traffix3/blob/main/traffix/demand/calendar_model.py"
click node_sim "https://github.com/aymenhamzik/traffix3/blob/main/traffix/simulation/backend.py"
click node_sensors "https://github.com/aymenhamzik/traffix3/blob/main/traffix/simulation/sensors.py"
click node_world "https://github.com/aymenhamzik/traffix3/blob/main/traffix/simulation/world.py"
click node_executor "https://github.com/aymenhamzik/traffix3/blob/main/traffix/simulation/executor.py"
click node_agentbase "https://github.com/aymenhamzik/traffix3/blob/main/traffix/agents/base.py"
click node_junction_agents "https://github.com/aymenhamzik/traffix3/tree/main/traffix/agents/junction"
click node_observation "https://github.com/aymenhamzik/traffix3/blob/main/traffix/agents/junction/observation.py"
click node_master "https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/master.py"
click node_safety "https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/safety_rules.py"
click node_network_agents "https://github.com/aymenhamzik/traffix3/tree/main/traffix/agents/network"
click node_supermaster "https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/supermaster.py"
click node_system "https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/system.py"
click node_log "https://github.com/aymenhamzik/traffix3/blob/main/traffix/core/decision_log.py"
click node_narrator "https://github.com/aymenhamzik/traffix3/blob/main/traffix/core/narrate.py"
click node_explainer "https://github.com/aymenhamzik/traffix3/blob/main/traffix/agents/network/explainer.py"
click node_synapse "https://github.com/aymenhamzik/traffix3/blob/main/traffix/synapse/llm.py"
click node_alert_copilot "https://github.com/aymenhamzik/traffix3/tree/main/traffix/synapse"
click node_live "https://github.com/aymenhamzik/traffix3/blob/main/traffix/api/live.py"
click node_server "https://github.com/aymenhamzik/traffix3/blob/main/traffix/api/server.py"
click node_frontend "https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/App.jsx"
click node_api_client "https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/api.js"
click node_feed "https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/components/Feed.jsx"
click node_networkmap "https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/components/NetworkMap.jsx"
click node_i18n "https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/i18n.js"
click node_evaluation "https://github.com/aymenhamzik/traffix3/blob/main/traffix/evaluation/runner.py"
click node_monitor "https://github.com/aymenhamzik/traffix3/blob/main/traffix/evaluation/monitor.py"
click node_training "https://github.com/aymenhamzik/traffix3/tree/main/traffix/training"

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_demand,node_calendar,node_user toneBlue
class node_sim,node_sensors,node_world,node_executor toneAmber
class node_agentbase,node_junction_agents,node_observation,node_master,node_safety,node_network_agents,node_supermaster,node_system toneMint
class node_log,node_narrator,node_explainer,node_synapse,node_alert_copilot,node_evaluation,node_monitor,node_training toneRose
class node_live,node_server,node_frontend,node_api_client,node_feed,node_networkmap,node_i18n toneIndigo
```

## Components

### Scenario and demand

- [Demand generator](https://github.com/aymenhamzik/traffix3/blob/main/traffix/demand/generator.py): `traffix/demand/generator.py`
- [Calendar model](https://github.com/aymenhamzik/traffix3/blob/main/traffix/demand/calendar_model.py): `traffix/demand/calendar_model.py`

### Simulation runtime

- [SUMO simulation](https://github.com/aymenhamzik/traffix3/blob/main/traffix/simulation/backend.py): `traffix/simulation/backend.py`
- [Sensor layer](https://github.com/aymenhamzik/traffix3/blob/main/traffix/simulation/sensors.py): `traffix/simulation/sensors.py`
- [World events](https://github.com/aymenhamzik/traffix3/blob/main/traffix/simulation/world.py): `traffix/simulation/world.py`
- [Light executor](https://github.com/aymenhamzik/traffix3/blob/main/traffix/simulation/executor.py): `traffix/simulation/executor.py`

### Hierarchical control

- [Agent framework](https://github.com/aymenhamzik/traffix3/blob/main/traffix/agents/base.py): `traffix/agents/base.py`
- [Junction agents](https://github.com/aymenhamzik/traffix3/tree/main/traffix/agents/junction): `traffix/agents/junction`
- [Junction observation](https://github.com/aymenhamzik/traffix3/blob/main/traffix/agents/junction/observation.py): `traffix/agents/junction/observation.py`
- [Junction master](https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/master.py): `traffix/orchestration/master.py`
- [Safety rules](https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/safety_rules.py): `traffix/orchestration/safety_rules.py`
- [Network agents](https://github.com/aymenhamzik/traffix3/tree/main/traffix/agents/network): `traffix/agents/network`
- [Network supermaster](https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/supermaster.py): `traffix/orchestration/supermaster.py`
- [System assembly](https://github.com/aymenhamzik/traffix3/blob/main/traffix/orchestration/system.py): `traffix/orchestration/system.py`

### Insights and language

- [Decision log](https://github.com/aymenhamzik/traffix3/blob/main/traffix/core/decision_log.py): `traffix/core/decision_log.py`
- [Decision narration](https://github.com/aymenhamzik/traffix3/blob/main/traffix/core/narrate.py): `traffix/core/narrate.py`
- [Decision explainer](https://github.com/aymenhamzik/traffix3/blob/main/traffix/agents/network/explainer.py): `traffix/agents/network/explainer.py`
- [Language model client](https://github.com/aymenhamzik/traffix3/blob/main/traffix/synapse/llm.py): `traffix/synapse/llm.py`
- [Alerts and copilot](https://github.com/aymenhamzik/traffix3/tree/main/traffix/synapse): `traffix/synapse`
- [Experiment runner](https://github.com/aymenhamzik/traffix3/blob/main/traffix/evaluation/runner.py): `traffix/evaluation/runner.py`
- [Persona metrics](https://github.com/aymenhamzik/traffix3/blob/main/traffix/evaluation/monitor.py): `traffix/evaluation/monitor.py`
- [Model training](https://github.com/aymenhamzik/traffix3/tree/main/traffix/training): `traffix/training`

### API and experience

- [Live API](https://github.com/aymenhamzik/traffix3/blob/main/traffix/api/live.py): `traffix/api/live.py`
- [Backend API](https://github.com/aymenhamzik/traffix3/blob/main/traffix/api/server.py): `traffix/api/server.py`
- [Persona interface](https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Frontend API client](https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/api.js): `frontend/src/api.js`
- [Decision feed](https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/components/Feed.jsx): `frontend/src/components/Feed.jsx`
- [Network map](https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/components/NetworkMap.jsx): `frontend/src/components/NetworkMap.jsx`
- [Frontend languages](https://github.com/aymenhamzik/traffix3/blob/main/frontend/src/i18n.js): `frontend/src/i18n.js`

### Other components

- **Scenario user**

## Connections

- Scenario user → Persona interface: selects scenario (evidence: `README.md`)
- Persona interface → Frontend API client: requests state (evidence: `frontend/src/App.jsx`)
- Frontend API client → Backend API: calls API (evidence: `frontend/src/api.js`)
- Backend API → Live API: controls live run (evidence: `traffix/api/server.py`)
- Live API → System assembly: runs system
- System assembly → Junction master: assembles masters (evidence: `README.md`)
- System assembly → Network supermaster: assembles coordinator
- Demand generator → Calendar model: uses calendar (evidence: `traffix/demand/generator.py`)
- Demand generator → SUMO simulation: supplies traffic (evidence: `README.md`)
- SUMO simulation → Sensor layer: feeds readings (evidence: `traffix/simulation/sensors.py`)
- World events → SUMO simulation: applies events (evidence: `traffix/simulation/world.py`)
- Sensor layer → Junction agents: provides observations
- Junction agents → Junction observation: uses features (evidence: `traffix/agents/junction/rl_light.py`)
- Junction master → Junction agents: collects requests (evidence: `traffix/orchestration/master.py`)
- Junction master → Safety rules: checks safety (evidence: `README.md`)
- Junction master → Light executor: writes light (evidence: `README.md`)
- Network supermaster → Network agents: runs agents (evidence: `README.md`)
- Network supermaster → Junction master: sends directives (evidence: `README.md`)
- Junction master → Decision log: records decisions (evidence: `traffix/orchestration/master.py`)
- Live API → Decision log: exposes decisions
- Backend API → Decision explainer: serves explanation (evidence: `traffix/api/server.py`)
- Decision explainer → Decision log: cites entries (evidence: `traffix/agents/network/explainer.py`)
- Decision explainer → Decision narration: uses templates (evidence: `traffix/agents/network/explainer.py`)
- Decision explainer → Language model client: uses optional LLM (evidence: `traffix/agents/network/explainer.py`)
- Alerts and copilot → Language model client: uses optional LLM (evidence: `README.md`)
- Backend API → Alerts and copilot: serves copilot (evidence: `traffix/api/server.py`)
- Frontend API client → Decision feed: provides feed data (evidence: `frontend/src/pages/Analyst.jsx`)
- Frontend API client → Network map: provides map data (evidence: `frontend/src/components/NetworkMap.jsx`)
- Persona interface → Frontend languages: sets language (evidence: `frontend/src/App.jsx`)
- Experiment runner → System assembly: runs simulation (evidence: `traffix/evaluation/runner.py`)
- Experiment runner → Persona metrics: collects metrics (evidence: `traffix/evaluation/runner.py`)
- Model training → Demand generator: generates training traffic (evidence: `traffix/training/datagen.py`)
- Model training → Experiment runner: uses simulation runs (evidence: `traffix/training/datagen.py`)
