# shawnhymel/tinyml-example-anomaly-detection architecture

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

- Interactive diagram: https://gitdiagram.com/shawnhymel/tinyml-example-anomaly-detection
- Repository: https://github.com/shawnhymel/tinyml-example-anomaly-detection

## Overview

This repository is an end-to-end TinyML anomaly-detection example for electric motors: ESP32 accelerometer samples are collected, analyzed for useful features, used to train either a Mahalanobis-distance model or an autoencoder, and deployed to a server or ESP32. The README documents the overall workflow and alternatives; source excerpts show HTTP collection and server-side inference. Training notebooks, device sketches, and most conversion/deployment internals were not sampled, so their connections are limited to documented workflow links.

Main entry points: [`datasets`](https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/datasets) (CSV datasets), [`mahalanobis_distance/anomaly-detection-training-md-deploy.py`](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/anomaly-detection-training-md-deploy.py) (MD deployment conversion), [`autoencoder/anomaly-detection-tflite-conversion.ipynb`](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/anomaly-detection-tflite-conversion.ipynb) (TFLite conversion), [`mahalanobis_distance/esp32_deploy_md/md_model-moving.h`](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/esp32_deploy_md/md_model-moving.h) (MD model parameters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_acquisition["Data acquisition"]
  node_capture_sketch["Capture firmware"]
  node_capture_server["Sample collector"]
  node_sample_files[("CSV datasets")]
end

subgraph group_modeling["Analysis and training"]
  node_feature_analysis["Feature analysis"]
  node_md_training["Mahalanobis training"]
  node_ae_training["Autoencoder training"]
  node_md_conversion["MD deployment conversion"]
  node_ae_conversion["TFLite conversion"]
  node_c_writer["C array writer<br/>[c_writer.py]"]
end

subgraph group_inference["Inference"]
  node_md_server["MD inference server"]
  node_ae_server["Autoencoder inference server"]
end

subgraph group_deployment["Embedded deployment"]
  node_md_firmware["MD ESP32 deployment"]
  node_md_model["MD model parameters<br/>[md_model-moving.h]"]
  node_ae_firmware["Autoencoder ESP32 deployment"]
  node_ae_model["TFLite model array<br/>[fan_low_model.h]"]
  node_md_test["MD ESP32 test"]
  node_ae_test["Autoencoder ESP32 test"]
end

node_sensor(("ESP32 accelerometer"))

node_sensor -->|"measures motion"| node_capture_sketch
node_capture_sketch -->|"posts samples"| node_capture_server
node_capture_server -->|"writes CSV"| node_sample_files
node_sample_files -->|"analyzed as"| node_feature_analysis
node_sample_files -->|"trains from"| node_md_training
node_sample_files -->|"trains from"| node_ae_training
node_md_training -->|"exports model"| node_md_conversion
node_ae_training -->|"converts model"| node_ae_conversion
node_md_conversion -.->|"uses writer"| node_c_writer
node_ae_conversion -.->|"uses writer"| node_c_writer
node_sensor -.->|"sends samples"| node_md_server
node_sensor -.->|"sends samples"| node_ae_server
node_md_conversion -.->|"provides model"| node_md_server
node_ae_conversion -.->|"provides model"| node_ae_server
node_md_conversion -.->|"exports parameters"| node_md_model
node_ae_conversion -.->|"exports model"| node_ae_model
node_md_model -.->|"compiled into"| node_md_firmware
node_ae_model -.->|"compiled into"| node_ae_firmware
node_md_model -.->|"used by test"| node_md_test
node_ae_model -.->|"used by test"| node_ae_test

click node_capture_sketch "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/data_collection/esp32_accel_post/esp32_accel_post.ino"
click node_capture_server "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/data_collection/http_accel_server.py"
click node_sample_files "https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/datasets"
click node_feature_analysis "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/data_collection/anomaly-detection-feature-analysis.ipynb"
click node_md_training "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/anomaly-detection-training-mahalanobis-distance.ipynb"
click node_ae_training "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/anomaly-detection-training-autoencoder.ipynb"
click node_md_conversion "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/anomaly-detection-training-md-deploy.py"
click node_ae_conversion "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/anomaly-detection-tflite-conversion.ipynb"
click node_c_writer "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/utils/c_writer.py"
click node_md_server "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/http_server_anomaly_detection_md.py"
click node_ae_server "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/http_server_anomaly_detection_tflite.py"
click node_md_firmware "https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/mahalanobis_distance/esp32_deploy_md"
click node_md_model "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/esp32_deploy_md/md_model-moving.h"
click node_ae_firmware "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/esp32_deploy_tflite/esp32_deploy_tflite.ino"
click node_ae_model "https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/esp32_deploy_tflite/fan_low_model.h"
click node_md_test "https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/mahalanobis_distance/esp32_test_md"
click node_ae_test "https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/autoencoder/esp32_test_tflite"

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_capture_sketch,node_capture_server,node_sample_files toneBlue
class node_feature_analysis,node_md_training,node_ae_training,node_md_conversion,node_ae_conversion,node_c_writer toneAmber
class node_md_server,node_ae_server toneMint
class node_md_firmware,node_md_model,node_ae_firmware,node_ae_model,node_md_test,node_ae_test toneRose
class node_sensor toneIndigo
```

## Components

### Data acquisition

- [Capture firmware](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/data_collection/esp32_accel_post/esp32_accel_post.ino): `data_collection/esp32_accel_post/esp32_accel_post.ino`
- [Sample collector](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/data_collection/http_accel_server.py): `data_collection/http_accel_server.py`
- [CSV datasets](https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/datasets): `datasets`

### Analysis and training

- [Feature analysis](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/data_collection/anomaly-detection-feature-analysis.ipynb): `data_collection/anomaly-detection-feature-analysis.ipynb`
- [Mahalanobis training](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/anomaly-detection-training-mahalanobis-distance.ipynb): `mahalanobis_distance/anomaly-detection-training-mahalanobis-distance.ipynb`
- [Autoencoder training](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/anomaly-detection-training-autoencoder.ipynb): `autoencoder/anomaly-detection-training-autoencoder.ipynb`
- [MD deployment conversion](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/anomaly-detection-training-md-deploy.py): `mahalanobis_distance/anomaly-detection-training-md-deploy.py`
- [TFLite conversion](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/anomaly-detection-tflite-conversion.ipynb): `autoencoder/anomaly-detection-tflite-conversion.ipynb`
- [C array writer](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/utils/c_writer.py): `utils/c_writer.py`

### Inference

- [MD inference server](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/http_server_anomaly_detection_md.py): `mahalanobis_distance/http_server_anomaly_detection_md.py`
- [Autoencoder inference server](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/http_server_anomaly_detection_tflite.py): `autoencoder/http_server_anomaly_detection_tflite.py`

### Embedded deployment

- [MD ESP32 deployment](https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/mahalanobis_distance/esp32_deploy_md): `mahalanobis_distance/esp32_deploy_md`
- [MD model parameters](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/mahalanobis_distance/esp32_deploy_md/md_model-moving.h): `mahalanobis_distance/esp32_deploy_md/md_model-moving.h`
- [Autoencoder ESP32 deployment](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/esp32_deploy_tflite/esp32_deploy_tflite.ino): `autoencoder/esp32_deploy_tflite/esp32_deploy_tflite.ino`
- [TFLite model array](https://github.com/shawnhymel/tinyml-example-anomaly-detection/blob/master/autoencoder/esp32_deploy_tflite/fan_low_model.h): `autoencoder/esp32_deploy_tflite/fan_low_model.h`
- [MD ESP32 test](https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/mahalanobis_distance/esp32_test_md): `mahalanobis_distance/esp32_test_md`
- [Autoencoder ESP32 test](https://github.com/shawnhymel/tinyml-example-anomaly-detection/tree/master/autoencoder/esp32_test_tflite): `autoencoder/esp32_test_tflite`

### Other components

- **ESP32 accelerometer**

## Connections

- ESP32 accelerometer → Capture firmware: measures motion (evidence: `README.md`)
- Capture firmware → Sample collector: posts samples (evidence: `README.md`)
- Sample collector → CSV datasets: writes CSV (evidence: `data_collection/http_accel_server.py`)
- CSV datasets → Feature analysis: analyzed as (evidence: `README.md`)
- CSV datasets → Mahalanobis training: trains from (evidence: `README.md`)
- CSV datasets → Autoencoder training: trains from (evidence: `README.md`)
- Mahalanobis training → MD deployment conversion: exports model (evidence: `README.md`)
- Autoencoder training → TFLite conversion: converts model (evidence: `README.md`)
- MD deployment conversion → C array writer: uses writer
- TFLite conversion → C array writer: uses writer
- ESP32 accelerometer → MD inference server: sends samples
- ESP32 accelerometer → Autoencoder inference server: sends samples
- MD deployment conversion → MD inference server: provides model
- TFLite conversion → Autoencoder inference server: provides model
- MD deployment conversion → MD model parameters: exports parameters
- TFLite conversion → TFLite model array: exports model
- MD model parameters → MD ESP32 deployment: compiled into
- TFLite model array → Autoencoder ESP32 deployment: compiled into
- MD model parameters → MD ESP32 test: used by test
- TFLite model array → Autoencoder ESP32 test: used by test
