# goez35/smart-traffic architecture

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

- Interactive diagram: https://gitdiagram.com/goez35/smart-traffic
- Repository: https://github.com/goez35/smart-traffic

## Overview

Smart Traffic Light is a four-lane IoT monitoring and adaptive signal-control system. In the main workflow, a cloud worker processes sensor readings, chooses adaptive timing and signal phases, and persists lane state and cycle history; the dashboard reads that state, displays monitoring and logs, and lets an operator submit a manual override. ESP32 communication, live-state APIs, and browser auto-refresh are also product capabilities. The worker and several integrations are only partially sampled, so uncertain links are dashed rather than asserted as verified calls.

Main entry points: [`index.php`](https://github.com/goez35/smart-traffic/blob/main/index.php) (Dashboard page), [`traffic_db.sql`](https://github.com/goez35/smart-traffic/blob/main/traffic_db.sql) (MySQL traffic state), [`includes/simpang_grid.php`](https://github.com/goez35/smart-traffic/blob/main/includes/simpang_grid.php) (Lane controls), [`worker_mqtt.php`](https://github.com/goez35/smart-traffic/blob/main/worker_mqtt.php) (Adaptive MQTT worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Adaptive Control"]
  node_worker["Adaptive MQTT worker<br/>[worker_mqtt.php]"]
  node_manual["Manual override handler<br/>[update_manual.php]"]
end

subgraph group_web["Dashboard &amp; APIs"]
  node_dashboard["Dashboard page<br/>[index.php]"]
  node_laneview["Lane controls<br/>[simpang_grid.php]"]
  node_historyview["Cycle &amp; event logs<br/>[log_table.php]"]
  node_hero["Live status summary<br/>[hero.php]"]
  node_liveapi["Live-state API<br/>[api_live_state.php]"]
  node_deviceapi["ESP32 API<br/>[api_esp32.php]"]
end

subgraph group_state["Persistence"]
  node_database[("MySQL traffic state<br/>[traffic_db.sql]")]
  node_dbinit["Schema initializer<br/>[db_init.php]"]
  node_dbconnect["Database connection<br/>[koneksi.php]"]
end

subgraph group_device["Device &amp; Messaging"]
  node_esp32["ESP32 signal controller"]
  node_mqttclient["PHP MQTT client<br/>[MqttClient.php]"]
end

subgraph group_simulation["Simulation"]
  node_simpage["Web simulation<br/>[simulasi.php]"]
  node_localsim["Local traffic simulator<br/>[simulasi_lokal.php]"]
end

node_operator(("Traffic operator"))
node_browser(("Web browser"))
node_mqtt["MQTT broker"]

node_operator -->|"uses dashboard"| node_browser
node_browser -->|"opens"| node_dashboard
node_dashboard -->|"loads connection"| node_dbconnect
node_dbconnect -->|"initializes schema"| node_dbinit
node_dashboard -->|"reads lane state &amp; logs"| node_database
node_dashboard -->|"renders"| node_hero
node_dashboard -->|"renders"| node_laneview
node_dashboard -->|"renders"| node_historyview
node_browser -->|"submits override"| node_laneview
node_laneview -->|"posts form"| node_manual
node_worker -->|"reads &amp; writes state"| node_database
node_worker -->|"uses client"| node_mqttclient
node_mqttclient -.->|"exchanges messages"| node_mqtt
node_esp32 -.->|"publishes sensor &amp; signal data"| node_mqtt
node_deviceapi -->|"accesses device state"| node_database
node_liveapi -->|"reads live state"| node_database
node_browser -.->|"refreshes status"| node_liveapi
node_browser -->|"opens simulation"| node_simpage
node_localsim -->|"reads config &amp; writes simulated state"| node_database

click node_worker "https://github.com/goez35/smart-traffic/blob/main/worker_mqtt.php"
click node_manual "https://github.com/goez35/smart-traffic/blob/main/update_manual.php"
click node_dashboard "https://github.com/goez35/smart-traffic/blob/main/index.php"
click node_laneview "https://github.com/goez35/smart-traffic/blob/main/includes/simpang_grid.php"
click node_historyview "https://github.com/goez35/smart-traffic/blob/main/includes/log_table.php"
click node_hero "https://github.com/goez35/smart-traffic/blob/main/includes/hero.php"
click node_liveapi "https://github.com/goez35/smart-traffic/blob/main/api_live_state.php"
click node_deviceapi "https://github.com/goez35/smart-traffic/blob/main/api_esp32.php"
click node_database "https://github.com/goez35/smart-traffic/blob/main/traffic_db.sql"
click node_dbinit "https://github.com/goez35/smart-traffic/blob/main/includes/db_init.php"
click node_dbconnect "https://github.com/goez35/smart-traffic/blob/main/koneksi.php"
click node_esp32 "https://github.com/goez35/smart-traffic/blob/main/esp32/smart_traffic_esp32/smart_traffic_esp32.ino"
click node_mqttclient "https://github.com/goez35/smart-traffic/blob/main/includes/MqttClient.php"
click node_simpage "https://github.com/goez35/smart-traffic/blob/main/simulasi.php"
click node_localsim "https://github.com/goez35/smart-traffic/blob/main/simulasi_lokal.php"

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_worker,node_manual,node_browser toneBlue
class node_dashboard,node_laneview,node_historyview,node_hero,node_liveapi,node_deviceapi toneAmber
class node_database,node_dbinit,node_dbconnect toneMint
class node_esp32,node_mqttclient toneRose
class node_simpage,node_localsim,node_operator,node_mqtt toneIndigo
```

## Components

### Adaptive Control

- [Adaptive MQTT worker](https://github.com/goez35/smart-traffic/blob/main/worker_mqtt.php): `worker_mqtt.php`
- [Manual override handler](https://github.com/goez35/smart-traffic/blob/main/update_manual.php): `update_manual.php`

### Dashboard & APIs

- [Dashboard page](https://github.com/goez35/smart-traffic/blob/main/index.php): `index.php`
- [Lane controls](https://github.com/goez35/smart-traffic/blob/main/includes/simpang_grid.php): `includes/simpang_grid.php`
- [Cycle & event logs](https://github.com/goez35/smart-traffic/blob/main/includes/log_table.php): `includes/log_table.php`
- [Live status summary](https://github.com/goez35/smart-traffic/blob/main/includes/hero.php): `includes/hero.php`
- [Live-state API](https://github.com/goez35/smart-traffic/blob/main/api_live_state.php): `api_live_state.php`
- [ESP32 API](https://github.com/goez35/smart-traffic/blob/main/api_esp32.php): `api_esp32.php`

### Persistence

- [MySQL traffic state](https://github.com/goez35/smart-traffic/blob/main/traffic_db.sql): `traffic_db.sql`
- [Schema initializer](https://github.com/goez35/smart-traffic/blob/main/includes/db_init.php): `includes/db_init.php`
- [Database connection](https://github.com/goez35/smart-traffic/blob/main/koneksi.php): `koneksi.php`

### Device & Messaging

- [ESP32 signal controller](https://github.com/goez35/smart-traffic/blob/main/esp32/smart_traffic_esp32/smart_traffic_esp32.ino): `esp32/smart_traffic_esp32/smart_traffic_esp32.ino`
- [PHP MQTT client](https://github.com/goez35/smart-traffic/blob/main/includes/MqttClient.php): `includes/MqttClient.php`

### Simulation

- [Web simulation](https://github.com/goez35/smart-traffic/blob/main/simulasi.php): `simulasi.php`
- [Local traffic simulator](https://github.com/goez35/smart-traffic/blob/main/simulasi_lokal.php): `simulasi_lokal.php`

### Other components

- **Traffic operator**
- **Web browser**
- **MQTT broker**

## Connections

- Traffic operator → Web browser: uses dashboard (evidence: `README.md`)
- Web browser → Dashboard page: opens (evidence: `README.md`)
- Dashboard page → Database connection: loads connection (evidence: `index.php`)
- Database connection → Schema initializer: initializes schema (evidence: `koneksi.php`)
- Dashboard page → MySQL traffic state: reads lane state & logs (evidence: `index.php`)
- Dashboard page → Live status summary: renders (evidence: `index.php`)
- Dashboard page → Lane controls: renders (evidence: `index.php`)
- Dashboard page → Cycle & event logs: renders (evidence: `index.php`)
- Web browser → Lane controls: submits override (evidence: `includes/simpang_grid.php`)
- Lane controls → Manual override handler: posts form (evidence: `includes/simpang_grid.php`)
- Adaptive MQTT worker → MySQL traffic state: reads & writes state (evidence: `worker_mqtt.php`)
- Adaptive MQTT worker → PHP MQTT client: uses client (evidence: `worker_mqtt.php`)
- PHP MQTT client → MQTT broker: exchanges messages
- ESP32 signal controller → MQTT broker: publishes sensor & signal data
- ESP32 API → MySQL traffic state: accesses device state (evidence: `api_esp32.php`)
- Live-state API → MySQL traffic state: reads live state (evidence: `api_live_state.php`)
- Web browser → Live-state API: refreshes status
- Web browser → Web simulation: opens simulation
- Local traffic simulator → MySQL traffic state: reads config & writes simulated state (evidence: `simulasi_lokal.php`)
