# libremelon/csi_stress_detector architecture

> Architecture diagram of the GitHub repository libremelon/csi_stress_detector, 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/libremelon/csi_stress_detector
- Repository: https://github.com/libremelon/csi_stress_detector

## Overview

This repository estimates heart rate from Wi-Fi CSI and pairs CSI samples with Galaxy Watch readings for supervised training. The main workflow is ESP-NOW transmission, CSI capture over serial, host-side parsing and signal shaping, then either labeled-data collection or prediction with a trained LSTM. Watch telemetry is received and logged separately, and train.py builds a model from the collected files. The menu and firmware setup are documented but not mapped as product components. Firmware excerpts show CSI output and transmission; host links beyond shown behavior are limited to README documentation.

Main entry points: [`read_and_process_csi.py`](https://github.com/libremelon/csi_stress_detector/blob/main/read_and_process_csi.py) (CSI parser and processor), [`csi_recv/main/app_main.c`](https://github.com/libremelon/csi_stress_detector/blob/main/csi_recv/main/app_main.c) (CSI receiver), [`watch/watch_hr.py`](https://github.com/libremelon/csi_stress_detector/blob/main/watch/watch_hr.py) (Watch HR receiver), [`train.py`](https://github.com/libremelon/csi_stress_detector/blob/main/train.py) (LSTM trainer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["ESP32 telemetry"]
  node_tx["CSI transmitter<br/>[app_main.c]"]
  node_rx["CSI receiver<br/>[app_main.c]"]
end

subgraph group_host["Host CSI processing"]
  node_processor["CSI parser and processor"]
  node_predict["Live HR estimate"]
end

subgraph group_hr["Heart-rate reference"]
  node_watch["Watch HR receiver<br/>[watch_hr.py]"]
  node_hrlog["HR log"]
end

subgraph group_model["Model lifecycle"]
  node_training["Labeled training data"]
  node_trainer["LSTM trainer<br/>[train.py]"]
  node_modelstore["Saved HR model"]
end

node_operator(("Operator"))
node_serial["USB serial"]
node_galaxy["Galaxy Watch app"]

node_operator -.->|"runs firmware"| node_tx
node_operator -.->|"runs firmware"| node_rx
node_tx -.->|"sends ESP-NOW"| node_rx
node_rx -->|"prints CSI"| node_serial
node_serial -.->|"streams CSI"| node_processor
node_galaxy -.->|"sends HR"| node_watch
node_watch -->|"logs readings"| node_hrlog
node_operator -->|"starts receiver"| node_watch
node_processor -->|"reads latest BPM"| node_hrlog
node_processor -->|"writes paired samples"| node_training
node_operator -.->|"starts training"| node_trainer
node_training -->|"loads data"| node_trainer
node_trainer -->|"saves model"| node_modelstore
node_processor -->|"predicts live HR"| node_predict
node_modelstore -.->|"loads for inference"| node_processor

click node_tx "https://github.com/libremelon/csi_stress_detector/blob/main/csi_send/main/app_main.c"
click node_rx "https://github.com/libremelon/csi_stress_detector/blob/main/csi_recv/main/app_main.c"
click node_processor "https://github.com/libremelon/csi_stress_detector/blob/main/read_and_process_csi.py"
click node_watch "https://github.com/libremelon/csi_stress_detector/blob/main/watch/watch_hr.py"
click node_trainer "https://github.com/libremelon/csi_stress_detector/blob/main/train.py"
click node_predict "https://github.com/libremelon/csi_stress_detector/blob/main/read_and_process_csi.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_tx,node_rx toneBlue
class node_processor,node_predict toneAmber
class node_watch,node_hrlog toneMint
class node_training,node_trainer,node_modelstore toneRose
class node_operator,node_serial,node_galaxy toneIndigo
```

## Components

### ESP32 telemetry

- [CSI transmitter](https://github.com/libremelon/csi_stress_detector/blob/main/csi_send/main/app_main.c): `csi_send/main/app_main.c`
- [CSI receiver](https://github.com/libremelon/csi_stress_detector/blob/main/csi_recv/main/app_main.c): `csi_recv/main/app_main.c`

### Host CSI processing

- [CSI parser and processor](https://github.com/libremelon/csi_stress_detector/blob/main/read_and_process_csi.py): `read_and_process_csi.py`
- [Live HR estimate](https://github.com/libremelon/csi_stress_detector/blob/main/read_and_process_csi.py): `read_and_process_csi.py`

### Heart-rate reference

- [Watch HR receiver](https://github.com/libremelon/csi_stress_detector/blob/main/watch/watch_hr.py): `watch/watch_hr.py`
- **HR log**

### Model lifecycle

- **Labeled training data**
- [LSTM trainer](https://github.com/libremelon/csi_stress_detector/blob/main/train.py): `train.py`
- **Saved HR model**

### Other components

- **Operator**
- **USB serial**
- **Galaxy Watch app**

## Connections

- Operator → CSI transmitter: runs firmware (evidence: `README.md`)
- Operator → CSI receiver: runs firmware (evidence: `README.md`)
- CSI transmitter → CSI receiver: sends ESP-NOW (evidence: `README.md`)
- CSI receiver → USB serial: prints CSI (evidence: `csi_recv/main/app_main.c`)
- USB serial → CSI parser and processor: streams CSI (evidence: `README.md`)
- Galaxy Watch app → Watch HR receiver: sends HR (evidence: `README.md`)
- Watch HR receiver → HR log: logs readings (evidence: `watch/watch_hr.py`)
- Operator → Watch HR receiver: starts receiver (evidence: `watch/watch_hr.py`)
- CSI parser and processor → HR log: reads latest BPM (evidence: `read_and_process_csi.py`)
- CSI parser and processor → Labeled training data: writes paired samples (evidence: `read_and_process_csi.py`)
- Operator → LSTM trainer: starts training (evidence: `README.md`)
- Labeled training data → LSTM trainer: loads data (evidence: `train.py`)
- LSTM trainer → Saved HR model: saves model (evidence: `train.py`)
- CSI parser and processor → Live HR estimate: predicts live HR (evidence: `read_and_process_csi.py`)
- Saved HR model → CSI parser and processor: loads for inference
