# ridddle-en/ffs-troubleshooting-system architecture

> Architecture diagram of the GitHub repository ridddle-en/ffs-troubleshooting-system, 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/ridddle-en/ffs-troubleshooting-system
- Repository: https://github.com/ridddle-en/ffs-troubleshooting-system

## Overview

This is a semi-automatic Form Fill and Seal troubleshooting system: ESP32 sensors collect machine and environment measurements, the Raspberry Pi gateway reads them over SPI, interprets telemetry, raises alerts, records history, and controls actuators; a web app exposes monitoring and operator controls. The graph preserves sensing, calibration, diagnostics, storage, and UI capabilities. Some subsystem links are documented only at the system level; those use README evidence, and unsampled implementation details are not inferred.

Main entry points: [`raspberry_pi/pi_backend.py`](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/pi_backend.py) (API and telemetry), [`raspberry_pi/main.py`](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/main.py) (Gateway startup), [`esp32/arduino/src/sensors.cpp`](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/sensors.cpp) (Sensor processing), [`raspberry_pi/spi_comms.py`](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/spi_comms.py) (SPI communications)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensing["ESP32 sensing"]
  node_sensors["Sensor processing<br/>[sensors.cpp]"]
  node_motor_sense["Motor sensing<br/>[motors.cpp]"]
  node_bag_sense["Bag detection<br/>[bag.cpp]"]
  node_loadcell["Load cell<br/>[loadcell.cpp]"]
  node_calibration["Sensor calibration<br/>[calibration.cpp]"]
  node_spi_esp["ESP32 SPI protocol<br/>[spi.cpp]"]
end

subgraph group_gateway["Pi gateway"]
  node_pi_main["Gateway startup<br/>[main.py]"]
  node_spi_pi["SPI communications<br/>[spi_comms.py]"]
  node_interpret["Telemetry interpretation<br/>[interpreter.py]"]
  node_backend["API and telemetry<br/>[pi_backend.py]"]
  node_alerts["Fault alerts<br/>[alerts.py]"]
  node_database[("History and logs<br/>[database.py]")]
  node_pi_motors["Actuator control<br/>[motors.py]"]
end

subgraph group_web["Web interface"]
  node_web_ui["Monitoring and controls UI<br/>[app.js]"]
  node_web_routes["Web application<br/>[app.py]"]
end

subgraph group_hardware["Machine hardware"]
  node_sensors_hw["Machine sensors"]
  node_actuators["Machine actuators"]
end

node_operator(("Machine operator"))
node_server["Web server"]

node_sensors_hw -->|"measure"| node_sensors
node_sensors -->|"provide readings"| node_spi_esp
node_motor_sense -.->|"supply motor data"| node_sensors
node_bag_sense -.->|"supply bag data"| node_sensors
node_loadcell -.->|"supply weight"| node_sensors
node_calibration -->|"calibrate"| node_loadcell
node_pi_main -->|"creates"| node_spi_pi
node_pi_main -->|"starts telemetry"| node_backend
node_pi_main -->|"initializes"| node_database
node_pi_main -->|"initializes"| node_alerts
node_pi_main -->|"initializes"| node_pi_motors
node_spi_esp -->|"exchange sensor data"| node_spi_pi
node_backend -->|"reads telemetry"| node_spi_pi
node_backend -->|"interprets readings"| node_interpret
node_backend -->|"applies controls"| node_pi_motors
node_backend -->|"evaluates readings"| node_alerts
node_backend -->|"stores telemetry"| node_database
node_backend -->|"serves history"| node_database
node_backend -->|"calibration commands"| node_spi_pi
node_pi_motors -->|"drives GPIO"| node_actuators
node_operator -->|"operates"| node_web_ui
node_web_ui -.->|"uses app"| node_web_routes
node_web_routes -.->|"requests API"| node_backend
node_server -->|"hosts"| node_web_routes

click node_sensors "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/sensors.cpp"
click node_motor_sense "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/motors.cpp"
click node_bag_sense "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/bag.cpp"
click node_loadcell "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/loadcell.cpp"
click node_calibration "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/calibration.cpp"
click node_spi_esp "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/spi.cpp"
click node_pi_main "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/main.py"
click node_spi_pi "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/spi_comms.py"
click node_interpret "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/interpreter.py"
click node_backend "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/pi_backend.py"
click node_alerts "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/alerts.py"
click node_database "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/database.py"
click node_pi_motors "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/motors.py"
click node_web_ui "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/web/app/static/js/app.js"
click node_web_routes "https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/web/app/app.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_sensors,node_motor_sense,node_bag_sense,node_loadcell,node_calibration,node_spi_esp toneBlue
class node_pi_main,node_spi_pi,node_interpret,node_backend,node_alerts,node_database,node_pi_motors toneAmber
class node_web_ui,node_web_routes,node_server toneMint
class node_sensors_hw,node_actuators toneRose
class node_operator toneIndigo
```

## Components

### ESP32 sensing

- [Sensor processing](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/sensors.cpp): `esp32/arduino/src/sensors.cpp`
- [Motor sensing](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/motors.cpp): `esp32/arduino/src/motors.cpp`
- [Bag detection](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/bag.cpp): `esp32/arduino/src/bag.cpp`
- [Load cell](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/loadcell.cpp): `esp32/arduino/src/loadcell.cpp`
- [Sensor calibration](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/calibration.cpp): `esp32/arduino/src/calibration.cpp`
- [ESP32 SPI protocol](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/esp32/arduino/src/spi.cpp): `esp32/arduino/src/spi.cpp`

### Pi gateway

- [Gateway startup](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/main.py): `raspberry_pi/main.py`
- [SPI communications](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/spi_comms.py): `raspberry_pi/spi_comms.py`
- [Telemetry interpretation](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/interpreter.py): `raspberry_pi/interpreter.py`
- [API and telemetry](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/pi_backend.py): `raspberry_pi/pi_backend.py`
- [Fault alerts](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/alerts.py): `raspberry_pi/alerts.py`
- [History and logs](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/database.py): `raspberry_pi/database.py`
- [Actuator control](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/raspberry_pi/motors.py): `raspberry_pi/motors.py`

### Web interface

- [Monitoring and controls UI](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/web/app/static/js/app.js): `web/app/static/js/app.js`
- [Web application](https://github.com/ridddle-en/ffs-troubleshooting-system/blob/main/web/app/app.py): `web/app/app.py`

### Machine hardware

- **Machine sensors**
- **Machine actuators**

### Other components

- **Machine operator**
- **Web server**

## Connections

- Machine sensors → Sensor processing: measure (evidence: `README.md`)
- Sensor processing → ESP32 SPI protocol: provide readings (evidence: `esp32/arduino/src/sensors.cpp`)
- Motor sensing → Sensor processing: supply motor data
- Bag detection → Sensor processing: supply bag data
- Load cell → Sensor processing: supply weight
- Sensor calibration → Load cell: calibrate
- Gateway startup → SPI communications: creates (evidence: `raspberry_pi/main.py`)
- Gateway startup → API and telemetry: starts telemetry (evidence: `raspberry_pi/main.py`)
- Gateway startup → History and logs: initializes (evidence: `raspberry_pi/main.py`)
- Gateway startup → Fault alerts: initializes (evidence: `raspberry_pi/main.py`)
- Gateway startup → Actuator control: initializes (evidence: `raspberry_pi/main.py`)
- ESP32 SPI protocol → SPI communications: exchange sensor data (evidence: `README.md`)
- API and telemetry → SPI communications: reads telemetry (evidence: `raspberry_pi/pi_backend.py`)
- API and telemetry → Telemetry interpretation: interprets readings (evidence: `raspberry_pi/pi_backend.py`)
- API and telemetry → Actuator control: applies controls (evidence: `raspberry_pi/pi_backend.py`)
- API and telemetry → Fault alerts: evaluates readings (evidence: `raspberry_pi/pi_backend.py`)
- API and telemetry → History and logs: stores telemetry (evidence: `raspberry_pi/pi_backend.py`)
- API and telemetry → History and logs: serves history (evidence: `raspberry_pi/pi_backend.py`)
- API and telemetry → SPI communications: calibration commands (evidence: `raspberry_pi/pi_backend.py`)
- Actuator control → Machine actuators: drives GPIO (evidence: `README.md`)
- Machine operator → Monitoring and controls UI: operates (evidence: `README.md`)
- Monitoring and controls UI → Web application: uses app
- Web application → API and telemetry: requests API
- Web server → Web application: hosts (evidence: `README.md`)
