# francescopace/espectre architecture

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

- Interactive diagram: https://gitdiagram.com/francescopace/espectre
- Repository: https://github.com/francescopace/espectre

## Overview

ESPectre is an on-device Wi-Fi motion-sensing platform with C++ and MicroPython runtimes, several firmware frontends, and host-side device and research tools. Its main workflow captures Wi-Fi CSI, evaluates motion locally, then exposes occupancy and diagnostics through a chosen integration. The graph preserves the documented firmware paths and research capabilities. Several subsystem links are supported by the README rather than sampled implementation; unsampled wiring is not inferred.

Main entry points: [`src/cpp/frontend/native/espectre/native_frontend.cpp`](https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/native/espectre/native_frontend.cpp) (Native frontend), [`src/cpp/runtime/esp_idf/csi_pipeline.cpp`](https://github.com/francescopace/espectre/blob/main/src/cpp/runtime/esp_idf/csi_pipeline.cpp) (CSI acquisition), [`src/cpp/runtime/esp_idf/runtime_frontend_controller.cpp`](https://github.com/francescopace/espectre/blob/main/src/cpp/runtime/esp_idf/runtime_frontend_controller.cpp) (Runtime control), [`src/python/espectre_cli/app.py`](https://github.com/francescopace/espectre/blob/main/src/python/espectre_cli/app.py) (ESPectre CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensing["Sensing runtime"]
  node_csi["CSI acquisition<br/>[csi_pipeline.cpp]"]
  node_runtime["Runtime control"]
end

subgraph group_algorithms["Detection algorithms"]
  node_policy["Runtime policy<br/>[runtime_policy.py]"]
  node_cppdetectors["C++ detectors<br/>[base_detector.cpp]"]
  node_microdetector["MicroPython detector"]
end

subgraph group_frontends["Firmware frontends"]
  node_native["Native frontend"]
  node_mqtt["MQTT integration"]
  node_http["Direct HTTP API"]
  node_esphome["ESPHome entities<br/>[espectre.cpp]"]
  node_matter["Matter frontend"]
  node_micro["Micro-ESPectre<br/>[runtime_main.py]"]
  node_ota["HTTPS updates"]
end

subgraph group_host["Host tools"]
  node_cli["ESPectre CLI<br/>[app.py]"]
  node_discovery["Device discovery"]
end

subgraph group_research["Research workflow"]
  node_collection["CSI collection<br/>[csi_io.py]"]
  node_dataset["Dataset metadata"]
  node_training["Model training<br/>[training.py]"]
  node_replay["Temporal replay<br/>[temporal_replay.py]"]
  node_analysis["Detector analysis"]
end

node_operator(("Device operator"))

node_operator -->|"senses motion"| node_csi
node_csi -->|"evaluates CSI"| node_cppdetectors
node_operator -->|"configures device"| node_runtime
node_runtime -.->|"serves frontend"| node_native
node_native -->|"offers MQTT"| node_mqtt
node_native -->|"offers HTTP API"| node_http
node_operator -->|"uses ESPHome"| node_esphome
node_operator -->|"commissions sensor"| node_matter
node_operator -->|"runs MicroPython"| node_micro
node_operator -->|"updates firmware"| node_ota
node_operator -->|"controls device"| node_cli
node_cli -->|"discovers devices"| node_discovery
node_operator -->|"collects CSI"| node_collection
node_collection -->|"loads metadata"| node_dataset
node_operator -->|"trains models"| node_training
node_operator -->|"replays captures"| node_replay
node_operator -->|"compares detectors"| node_analysis
node_microdetector -.->|"shares policy"| node_policy

click node_csi "https://github.com/francescopace/espectre/blob/main/src/cpp/runtime/esp_idf/csi_pipeline.cpp"
click node_runtime "https://github.com/francescopace/espectre/blob/main/src/cpp/runtime/esp_idf/runtime_frontend_controller.cpp"
click node_policy "https://github.com/francescopace/espectre/blob/main/tools/lib/runtime_policy.py"
click node_cppdetectors "https://github.com/francescopace/espectre/blob/main/src/cpp/core/base_detector.cpp"
click node_microdetector "https://github.com/francescopace/espectre/blob/main/src/python/micro_espectre/lightweight_detector.py"
click node_native "https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/native/espectre/native_frontend.cpp"
click node_mqtt "https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/native/espectre/native_mqtt_frontend.cpp"
click node_http "https://github.com/francescopace/espectre/blob/main/src/cpp/runtime/direct_http_protocol.cpp"
click node_esphome "https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/esphome/components/espectre/espectre.cpp"
click node_matter "https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/matter/espectre/matter_frontend.cpp"
click node_micro "https://github.com/francescopace/espectre/blob/main/src/python/micro_espectre/runtime_main.py"
click node_ota "https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/ota_service_https.cpp"
click node_cli "https://github.com/francescopace/espectre/blob/main/src/python/espectre_cli/app.py"
click node_discovery "https://github.com/francescopace/espectre/blob/main/src/python/espectre_cli/device_discovery.py"
click node_collection "https://github.com/francescopace/espectre/blob/main/tools/lib/csi_io.py"
click node_dataset "https://github.com/francescopace/espectre/blob/main/tools/lib/dataset_metadata.py"
click node_training "https://github.com/francescopace/espectre/blob/main/tools/lib/ml_training/training.py"
click node_replay "https://github.com/francescopace/espectre/blob/main/tools/lib/temporal_replay.py"
click node_analysis "https://github.com/francescopace/espectre/blob/main/tools/compare_detection_methods.py"

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_csi,node_runtime toneBlue
class node_policy,node_cppdetectors,node_microdetector toneAmber
class node_native,node_mqtt,node_http,node_esphome,node_matter,node_micro,node_ota toneMint
class node_cli,node_discovery toneRose
class node_collection,node_dataset,node_training,node_replay,node_analysis,node_operator toneIndigo
```

## Components

### Sensing runtime

- [CSI acquisition](https://github.com/francescopace/espectre/blob/main/src/cpp/runtime/esp_idf/csi_pipeline.cpp): `src/cpp/runtime/esp_idf/csi_pipeline.cpp`
- [Runtime control](https://github.com/francescopace/espectre/blob/main/src/cpp/runtime/esp_idf/runtime_frontend_controller.cpp): `src/cpp/runtime/esp_idf/runtime_frontend_controller.cpp`

### Detection algorithms

- [Runtime policy](https://github.com/francescopace/espectre/blob/main/tools/lib/runtime_policy.py): `tools/lib/runtime_policy.py`
- [C++ detectors](https://github.com/francescopace/espectre/blob/main/src/cpp/core/base_detector.cpp): `src/cpp/core/base_detector.cpp`
- [MicroPython detector](https://github.com/francescopace/espectre/blob/main/src/python/micro_espectre/lightweight_detector.py): `src/python/micro_espectre/lightweight_detector.py`

### Firmware frontends

- [Native frontend](https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/native/espectre/native_frontend.cpp): `src/cpp/frontend/native/espectre/native_frontend.cpp`
- [MQTT integration](https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/native/espectre/native_mqtt_frontend.cpp): `src/cpp/frontend/native/espectre/native_mqtt_frontend.cpp`
- [Direct HTTP API](https://github.com/francescopace/espectre/blob/main/src/cpp/runtime/direct_http_protocol.cpp): `src/cpp/runtime/direct_http_protocol.cpp`
- [ESPHome entities](https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/esphome/components/espectre/espectre.cpp): `src/cpp/frontend/esphome/components/espectre/espectre.cpp`
- [Matter frontend](https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/matter/espectre/matter_frontend.cpp): `src/cpp/frontend/matter/espectre/matter_frontend.cpp`
- [Micro-ESPectre](https://github.com/francescopace/espectre/blob/main/src/python/micro_espectre/runtime_main.py): `src/python/micro_espectre/runtime_main.py`
- [HTTPS updates](https://github.com/francescopace/espectre/blob/main/src/cpp/frontend/ota_service_https.cpp): `src/cpp/frontend/ota_service_https.cpp`

### Host tools

- [ESPectre CLI](https://github.com/francescopace/espectre/blob/main/src/python/espectre_cli/app.py): `src/python/espectre_cli/app.py`
- [Device discovery](https://github.com/francescopace/espectre/blob/main/src/python/espectre_cli/device_discovery.py): `src/python/espectre_cli/device_discovery.py`

### Research workflow

- [CSI collection](https://github.com/francescopace/espectre/blob/main/tools/lib/csi_io.py): `tools/lib/csi_io.py`
- [Dataset metadata](https://github.com/francescopace/espectre/blob/main/tools/lib/dataset_metadata.py): `tools/lib/dataset_metadata.py`
- [Model training](https://github.com/francescopace/espectre/blob/main/tools/lib/ml_training/training.py): `tools/lib/ml_training/training.py`
- [Temporal replay](https://github.com/francescopace/espectre/blob/main/tools/lib/temporal_replay.py): `tools/lib/temporal_replay.py`
- [Detector analysis](https://github.com/francescopace/espectre/blob/main/tools/compare_detection_methods.py): `tools/compare_detection_methods.py`

### Other components

- **Device operator**

## Connections

- Device operator → CSI acquisition: senses motion
- CSI acquisition → C++ detectors: evaluates CSI
- Device operator → Runtime control: configures device
- Runtime control → Native frontend: serves frontend
- Native frontend → MQTT integration: offers MQTT
- Native frontend → Direct HTTP API: offers HTTP API
- Device operator → ESPHome entities: uses ESPHome
- Device operator → Matter frontend: commissions sensor
- Device operator → Micro-ESPectre: runs MicroPython
- Device operator → HTTPS updates: updates firmware (evidence: `src/cpp/frontend/ota_service_https.cpp`)
- Device operator → ESPectre CLI: controls device
- ESPectre CLI → Device discovery: discovers devices (evidence: `src/python/espectre_cli/app.py`)
- Device operator → CSI collection: collects CSI
- CSI collection → Dataset metadata: loads metadata (evidence: `tools/lib/csi_io.py`)
- Device operator → Model training: trains models
- Device operator → Temporal replay: replays captures
- Device operator → Detector analysis: compares detectors
- MicroPython detector → Runtime policy: shares policy
