# cvanworm/chirpi architecture

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

- Interactive diagram: https://gitdiagram.com/cvanworm/chirpi
- Repository: https://github.com/cvanworm/chirpi

## Overview

CHIRP is an ESP32-S3 peer-to-peer networking system evaluated by host-driven experiments. The main workflow is: the controller broadcasts JOIN/LEAVE commands over Wi-Fi/UDP; nodes discover peers and run synchronized CHIRP rounds over ESP-NOW; nodes return metrics over UDP for CSV logging. The optional, deprecated monitor provides a separate diagnostic dashboard. Relationships for unsampled firmware are included only where the README documents them; monitor diagnostic transmission is explicitly described as not implemented.

Main entry points: [`Chirp_Main/Node_Code/main/round_task.c`](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/round_task.c) (Round scheduling), [`Chirp_Main/Experiment_Controller_Code/net/network_manager.py`](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/net/network_manager.py) (UDP command manager), [`Chirp_Main/Experiment_Controller_Code/main.py`](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/main.py) (Controller CLI), [`Chirp_Main/Experiment_Controller_Code/utils/metric_handler.py`](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/utils/metric_handler.py) (Metric CSV logging)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_controller["Experiment controller"]
  node_experiment["Experiment scenarios"]
  node_controller_entry["Controller CLI<br/>[main.py]"]
  node_network_manager["UDP command manager<br/>[network_manager.py]"]
  node_lan_ip["LAN address lookup<br/>[get_lan_ip.py]"]
  node_udp_listener["UDP metric listener<br/>[udp_listener.py]"]
  node_metric_handler[("Metric CSV logging<br/>[metric_handler.py]")]
end

subgraph group_nodes["CHIRP node firmware"]
  node_node_entry["Firmware startup<br/>[main.c]"]
  node_wifi_control["Wi-Fi setup<br/>[wifi_control.c]"]
  node_udp_control["UDP command handling<br/>[wifi_udp_control.c]"]
  node_control_task["Node control task<br/>[control_task.c]"]
  node_peer_discovery["Peer discovery<br/>[peer_manager.c]"]
  node_espnow_transport["ESP-NOW transport<br/>[espnow_comm.c]"]
  node_round_task["Round scheduling<br/>[round_task.c]"]
  node_chirp_algorithm["CHIRP targeting<br/>[alg.c]"]
  node_metrics["Node metrics<br/>[metrics.c]"]
end

subgraph group_monitor["Diagnostic monitor"]
  node_monitor_entry["Monitor startup<br/>[main.c]"]
  node_monitor_comms["Monitor communications<br/>[esp_comms.c]"]
  node_monitor_state["Monitor state<br/>[monitor.c]"]
  node_monitor_web["Dashboard service<br/>[monitor_web.c]"]
  node_dashboard["Web dashboard<br/>[app.js]"]
end

node_operator(("Experiment operator"))
node_nodes_network(("ESP32-S3 node network"))
node_host_network(("Wi-Fi / UDP network"))

node_operator -->|"runs"| node_controller_entry
node_controller_entry -->|"selects"| node_experiment
node_controller_entry -->|"starts"| node_network_manager
node_controller_entry -->|"configures"| node_metric_handler
node_network_manager -->|"gets address"| node_lan_ip
node_network_manager -->|"broadcasts commands"| node_host_network
node_host_network -->|"delivers commands"| node_udp_control
node_network_manager -.->|"receives metrics"| node_udp_listener
node_udp_listener -.->|"dispatches packets"| node_metric_handler
node_metric_handler -->|"writes CSV"| node_metric_handler
node_node_entry -->|"initializes Wi-Fi"| node_wifi_control
node_node_entry -->|"starts listener"| node_udp_control
node_udp_control -.->|"routes commands"| node_control_task
node_control_task -.->|"starts discovery"| node_peer_discovery
node_peer_discovery -->|"sends discovery"| node_espnow_transport
node_control_task -.->|"starts rounds"| node_round_task
node_round_task -->|"computes targets"| node_chirp_algorithm
node_round_task -->|"reads peers"| node_peer_discovery
node_round_task -->|"sends round data"| node_espnow_transport
node_round_task -->|"records timing"| node_metrics
node_node_entry -->|"connects Wi-Fi"| node_host_network
node_metrics -->|"returns metrics"| node_host_network
node_host_network -->|"delivers metrics"| node_network_manager
node_monitor_entry -->|"starts monitor task"| node_monitor_state
node_monitor_entry -.->|"initializes communications"| node_monitor_comms
node_monitor_state -.->|"starts dashboard service"| node_monitor_web
node_monitor_web -.->|"serves interface"| node_dashboard
node_nodes_network -.->|"sends diagnostics"| node_monitor_comms

click node_experiment "https://github.com/cvanworm/chirpi/tree/main/Chirp_Main/Experiment_Controller_Code/experiments"
click node_controller_entry "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/main.py"
click node_network_manager "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/net/network_manager.py"
click node_lan_ip "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/net/get_lan_ip.py"
click node_udp_listener "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/net/udp_listener.py"
click node_metric_handler "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/utils/metric_handler.py"
click node_node_entry "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/main.c"
click node_wifi_control "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/wifi_control.c"
click node_udp_control "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/wifi_udp_control.c"
click node_control_task "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/control_task.c"
click node_peer_discovery "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/peer_manager.c"
click node_espnow_transport "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/espnow_comm.c"
click node_round_task "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/round_task.c"
click node_chirp_algorithm "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/alg.c"
click node_metrics "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/metrics.c"
click node_monitor_entry "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/main.c"
click node_monitor_comms "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/esp_comms.c"
click node_monitor_state "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/monitor.c"
click node_monitor_web "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/monitor_web.c"
click node_dashboard "https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/webserver/app.js"

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_experiment,node_controller_entry,node_network_manager,node_lan_ip,node_udp_listener,node_metric_handler toneBlue
class node_node_entry,node_wifi_control,node_udp_control,node_control_task,node_peer_discovery,node_espnow_transport,node_round_task,node_chirp_algorithm,node_metrics toneAmber
class node_monitor_entry,node_monitor_comms,node_monitor_state,node_monitor_web,node_dashboard toneMint
class node_operator,node_nodes_network,node_host_network toneIndigo
```

## Components

### Experiment controller

- [Experiment scenarios](https://github.com/cvanworm/chirpi/tree/main/Chirp_Main/Experiment_Controller_Code/experiments): `Chirp_Main/Experiment_Controller_Code/experiments`
- [Controller CLI](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/main.py): `Chirp_Main/Experiment_Controller_Code/main.py`
- [UDP command manager](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/net/network_manager.py): `Chirp_Main/Experiment_Controller_Code/net/network_manager.py`
- [LAN address lookup](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/net/get_lan_ip.py): `Chirp_Main/Experiment_Controller_Code/net/get_lan_ip.py`
- [UDP metric listener](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/net/udp_listener.py): `Chirp_Main/Experiment_Controller_Code/net/udp_listener.py`
- [Metric CSV logging](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Experiment_Controller_Code/utils/metric_handler.py): `Chirp_Main/Experiment_Controller_Code/utils/metric_handler.py`

### CHIRP node firmware

- [Firmware startup](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/main.c): `Chirp_Main/Node_Code/main/main.c`
- [Wi-Fi setup](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/wifi_control.c): `Chirp_Main/Node_Code/main/wifi_control.c`
- [UDP command handling](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/wifi_udp_control.c): `Chirp_Main/Node_Code/main/wifi_udp_control.c`
- [Node control task](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/control_task.c): `Chirp_Main/Node_Code/main/control_task.c`
- [Peer discovery](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/peer_manager.c): `Chirp_Main/Node_Code/main/peer_manager.c`
- [ESP-NOW transport](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/espnow_comm.c): `Chirp_Main/Node_Code/main/espnow_comm.c`
- [Round scheduling](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/round_task.c): `Chirp_Main/Node_Code/main/round_task.c`
- [CHIRP targeting](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/alg.c): `Chirp_Main/Node_Code/main/alg.c`
- [Node metrics](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Node_Code/main/metrics.c): `Chirp_Main/Node_Code/main/metrics.c`

### Diagnostic monitor

- [Monitor startup](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/main.c): `Chirp_Main/Monitor_Code/src/main.c`
- [Monitor communications](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/esp_comms.c): `Chirp_Main/Monitor_Code/src/esp_comms.c`
- [Monitor state](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/monitor.c): `Chirp_Main/Monitor_Code/src/monitor.c`
- [Dashboard service](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/monitor_web.c): `Chirp_Main/Monitor_Code/src/monitor_web.c`
- [Web dashboard](https://github.com/cvanworm/chirpi/blob/main/Chirp_Main/Monitor_Code/src/webserver/app.js): `Chirp_Main/Monitor_Code/src/webserver/app.js`

### Other components

- **Experiment operator**
- **ESP32-S3 node network**
- **Wi-Fi / UDP network**

## Connections

- Experiment operator → Controller CLI: runs (evidence: `README.md`)
- Controller CLI → Experiment scenarios: selects (evidence: `Chirp_Main/Experiment_Controller_Code/main.py`)
- Controller CLI → UDP command manager: starts (evidence: `Chirp_Main/Experiment_Controller_Code/main.py`)
- Controller CLI → Metric CSV logging: configures (evidence: `Chirp_Main/Experiment_Controller_Code/main.py`)
- UDP command manager → LAN address lookup: gets address (evidence: `Chirp_Main/Experiment_Controller_Code/net/network_manager.py`)
- UDP command manager → Wi-Fi / UDP network: broadcasts commands (evidence: `Chirp_Main/Experiment_Controller_Code/net/network_manager.py`)
- Wi-Fi / UDP network → UDP command handling: delivers commands (evidence: `README.md`)
- UDP command manager → UDP metric listener: receives metrics
- UDP metric listener → Metric CSV logging: dispatches packets
- Metric CSV logging → Metric CSV logging: writes CSV (evidence: `Chirp_Main/Experiment_Controller_Code/utils/metric_handler.py`)
- Firmware startup → Wi-Fi setup: initializes Wi-Fi (evidence: `Chirp_Main/Node_Code/main/main.c`)
- Firmware startup → UDP command handling: starts listener (evidence: `Chirp_Main/Node_Code/main/main.c`)
- UDP command handling → Node control task: routes commands
- Node control task → Peer discovery: starts discovery (evidence: `README.md`)
- Peer discovery → ESP-NOW transport: sends discovery (evidence: `Chirp_Main/Node_Code/main/peer_manager.c`)
- Node control task → Round scheduling: starts rounds (evidence: `README.md`)
- Round scheduling → CHIRP targeting: computes targets (evidence: `Chirp_Main/Node_Code/main/round_task.c`)
- Round scheduling → Peer discovery: reads peers (evidence: `Chirp_Main/Node_Code/main/round_task.c`)
- Round scheduling → ESP-NOW transport: sends round data (evidence: `Chirp_Main/Node_Code/main/round_task.c`)
- Round scheduling → Node metrics: records timing (evidence: `Chirp_Main/Node_Code/main/round_task.c`)
- Firmware startup → Wi-Fi / UDP network: connects Wi-Fi (evidence: `README.md`)
- Node metrics → Wi-Fi / UDP network: returns metrics (evidence: `README.md`)
- Wi-Fi / UDP network → UDP command manager: delivers metrics (evidence: `README.md`)
- Monitor startup → Monitor state: starts monitor task (evidence: `Chirp_Main/Monitor_Code/src/main.c`)
- Monitor startup → Monitor communications: initializes communications
- Monitor state → Dashboard service: starts dashboard service
- Dashboard service → Web dashboard: serves interface (evidence: `README.md`)
- ESP32-S3 node network → Monitor communications: sends diagnostics (evidence: `README.md`)
