# andre-stemper/atmonsat architecture

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

- Interactive diagram: https://gitdiagram.com/andre-stemper/atmonsat
- Repository: https://github.com/andre-stemper/atmonsat

## Overview

AtMonSat is a host/target anomaly-detection testbed with a portable C++ algorithm and PC and STM32 backends. The principal workflow sends datapoints from the host through a target data link and object protocol; a datapoint callback runs the detector, which interpolates and windows sensor values, invokes a TensorFlow Lite Micro model, scores prediction error with Mahalanobis distance, and applies a threshold before returning detection and timing results. The README documents these stages; some backend implementations and the host notebooks are not in the supplied tree or excerpts, so uncertain runtime links are dashed.

Main entry points: [`firmwares/atmonsat_common_sources/protocol.h`](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol.h) (Object protocol), [`firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc`](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc) (Anomaly detector), [`firmwares/atmonsat_common_sources/atmonsat_testbench.cc`](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_testbench.cc) (Backend callbacks), [`firmwares/atmonsat_common_sources/protocol_datalink_pipe.cc`](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol_datalink_pipe.cc) (PC pipe link)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host testbed"]
  node_host_control["Notebook control"]
end

subgraph group_transport["Target communication"]
  node_protocol["Object protocol<br/>[protocol.h]"]
  node_definitions["Protocol commands"]
  node_pipe_link["PC pipe link"]
  node_uart_link["STM32 USART link"]
end

subgraph group_detection["Detection pipeline"]
  node_callback["Backend callbacks"]
  node_detector["Anomaly detector"]
  node_interpolator["ISLCC interpolation"]
  node_windows["Data windows<br/>[datawindow.h]"]
  node_datapoint["Datapoint values<br/>[datapoint.h]"]
  node_model["TFLite model<br/>[atmonsat_model.cc]"]
  node_mahalanobis["Mahalanobis score<br/>[mahalanobis.h]"]
  node_threshold["Anomaly threshold<br/>[threshold.h]"]
  node_output["Output reporting"]
end

subgraph group_runtime["Platform runtime"]
  node_native_entry["PC backend<br/>[main_native.cc]"]
  node_stm_entry["STM32 backend<br/>[main_stm32.cc]"]
  node_freertos_entry["FreeRTOS backend"]
  node_time_metric["Execution timing<br/>[time_metric.h]"]
end

node_host_user(("Experiment operator"))

node_host_user -->|"configures experiment"| node_host_control
node_host_control -.->|"selects PC link"| node_pipe_link
node_host_control -.->|"selects target link"| node_uart_link
node_pipe_link -->|"transports bytes"| node_protocol
node_uart_link -->|"forwards bytes"| node_protocol
node_protocol -->|"uses command IDs"| node_definitions
node_protocol -->|"dispatches objects"| node_callback
node_callback -->|"runs iteration"| node_detector
node_callback -->|"measures execution"| node_time_metric
node_detector -->|"interpolates inputs"| node_interpolator
node_detector -->|"forms input windows"| node_windows
node_detector -->|"invokes inference"| node_model
node_detector -->|"scores prediction error"| node_mahalanobis
node_detector -->|"decides anomaly"| node_threshold
node_interpolator -->|"processes datapoints"| node_datapoint
node_windows -->|"stores datapoints"| node_datapoint
node_detector -.->|"reports results"| node_output
node_callback -->|"returns replies"| node_protocol
node_native_entry -.->|"uses backend protocol"| node_protocol
node_stm_entry -.->|"uses backend protocol"| node_protocol
node_freertos_entry -.->|"uses backend protocol"| node_protocol

click node_native_entry "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/main_native.cc"
click node_stm_entry "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/main_stm32.cc"
click node_freertos_entry "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/main_stm32_freertos.cc"
click node_protocol "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol.h"
click node_definitions "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol_definitions.h"
click node_pipe_link "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol_datalink_pipe.cc"
click node_uart_link "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol_datalink_stm32_usart.cc"
click node_callback "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_testbench.cc"
click node_detector "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc"
click node_interpolator "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/islcc_interpolator.h"
click node_windows "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/datawindow.h"
click node_datapoint "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/datapoint.h"
click node_model "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_model.cc"
click node_mahalanobis "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/mahalanobis.h"
click node_threshold "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/threshold.h"
click node_output "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_output_handler.cc"
click node_time_metric "https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/time_metric.h"

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_host_control toneBlue
class node_protocol,node_definitions,node_pipe_link,node_uart_link toneAmber
class node_callback,node_detector,node_interpolator,node_windows,node_datapoint,node_model,node_mahalanobis,node_threshold,node_output toneMint
class node_native_entry,node_stm_entry,node_freertos_entry,node_time_metric toneRose
class node_host_user toneIndigo
```

## Components

### Host testbed

- **Notebook control**

### Target communication

- [Object protocol](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol.h): `firmwares/atmonsat_common_sources/protocol.h`
- [Protocol commands](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol_definitions.h): `firmwares/atmonsat_common_sources/protocol_definitions.h`
- [PC pipe link](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol_datalink_pipe.cc): `firmwares/atmonsat_common_sources/protocol_datalink_pipe.cc`
- [STM32 USART link](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/protocol_datalink_stm32_usart.cc): `firmwares/atmonsat_common_sources/protocol_datalink_stm32_usart.cc`

### Detection pipeline

- [Backend callbacks](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_testbench.cc): `firmwares/atmonsat_common_sources/atmonsat_testbench.cc`
- [Anomaly detector](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc): `firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc`
- [ISLCC interpolation](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/islcc_interpolator.h): `firmwares/atmonsat_common_sources/islcc_interpolator.h`
- [Data windows](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/datawindow.h): `firmwares/atmonsat_common_sources/datawindow.h`
- [Datapoint values](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/datapoint.h): `firmwares/atmonsat_common_sources/datapoint.h`
- [TFLite model](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_model.cc): `firmwares/atmonsat_common_sources/atmonsat_model.cc`
- [Mahalanobis score](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/mahalanobis.h): `firmwares/atmonsat_common_sources/mahalanobis.h`
- [Anomaly threshold](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/threshold.h): `firmwares/atmonsat_common_sources/threshold.h`
- [Output reporting](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/atmonsat_output_handler.cc): `firmwares/atmonsat_common_sources/atmonsat_output_handler.cc`

### Platform runtime

- [PC backend](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/main_native.cc): `firmwares/atmonsat_common_sources/main_native.cc`
- [STM32 backend](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/main_stm32.cc): `firmwares/atmonsat_common_sources/main_stm32.cc`
- [FreeRTOS backend](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/main_stm32_freertos.cc): `firmwares/atmonsat_common_sources/main_stm32_freertos.cc`
- [Execution timing](https://github.com/andre-stemper/atmonsat/blob/main/firmwares/atmonsat_common_sources/time_metric.h): `firmwares/atmonsat_common_sources/time_metric.h`

### Other components

- **Experiment operator**

## Connections

- Experiment operator → Notebook control: configures experiment
- Notebook control → PC pipe link: selects PC link
- Notebook control → STM32 USART link: selects target link
- PC pipe link → Object protocol: transports bytes
- STM32 USART link → Object protocol: forwards bytes
- Object protocol → Protocol commands: uses command IDs (evidence: `firmwares/atmonsat_common_sources/protocol.h`)
- Object protocol → Backend callbacks: dispatches objects
- Backend callbacks → Anomaly detector: runs iteration
- Backend callbacks → Execution timing: measures execution
- Anomaly detector → ISLCC interpolation: interpolates inputs (evidence: `firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc`)
- Anomaly detector → Data windows: forms input windows (evidence: `firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc`)
- Anomaly detector → TFLite model: invokes inference
- Anomaly detector → Mahalanobis score: scores prediction error (evidence: `firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc`)
- Anomaly detector → Anomaly threshold: decides anomaly (evidence: `firmwares/atmonsat_common_sources/atmonsat_anomaly_detection.cc`)
- ISLCC interpolation → Datapoint values: processes datapoints (evidence: `firmwares/atmonsat_common_sources/islcc_interpolator.h`)
- Data windows → Datapoint values: stores datapoints (evidence: `firmwares/atmonsat_common_sources/datawindow.h`)
- Anomaly detector → Output reporting: reports results
- Backend callbacks → Object protocol: returns replies
- PC backend → Object protocol: uses backend protocol
- STM32 backend → Object protocol: uses backend protocol
- FreeRTOS backend → Object protocol: uses backend protocol
