# niloydebbarma-code/microplastic-detection architecture

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

- Interactive diagram: https://gitdiagram.com/niloydebbarma-code/microplastic-detection
- Repository: https://github.com/niloydebbarma-code/microplastic-detection

## Overview

This repository provides a microplastic-detection workflow: generate synthetic training images, train and evaluate a YOLOv8 model, then run inference from an ESP32-CAM stream or uploaded images in a Flask dashboard. The ESP32 also hosts camera controls and a browser interface. The graph includes the major documented training and inference capabilities; some internal firmware and dashboard details are based on partial excerpts, so only clearly supported connections are shown.

Main entry points: [`03_esp32_integration.py`](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/03_esp32_integration.py) (YOLO Inference), [`01_generate_synthetic_dataset.py`](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/01_generate_synthetic_dataset.py) (Synthetic Generator), [`02_train_yolov8_colab.py`](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/02_train_yolov8_colab.py) (Train and Evaluate), [`esp32_code/app_httpd.cpp`](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/app_httpd.cpp) (Camera HTTP Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Dataset Preparation"]
  node_generator["Synthetic Generator"]
end

subgraph group_model["Model Training"]
  node_training["Train and Evaluate"]
  node_weights["Trained Weights"]
end

subgraph group_device["Camera Device"]
  node_firmware["Camera Firmware"]
  node_pins["Camera Pin Mapping<br/>[camera_pins.h]"]
  node_httpserver["Camera HTTP Server<br/>[app_httpd.cpp]"]
  node_cameraui["Camera Web Controls<br/>[app_httpd.cpp]"]
end

subgraph group_runtime["Detection Runtime"]
  node_inference["YOLO Inference"]
  node_dashboard["Detection Dashboard"]
end

node_researcher(("Operator"))
node_hmpd[("HMPD Data")]
node_camera(("ESP32-CAM"))

node_researcher -->|"generates data"| node_generator
node_hmpd -->|"patch input"| node_generator
node_generator -->|"training images"| node_training
node_researcher -->|"trains model"| node_training
node_training -->|"saves weights"| node_weights
node_weights -->|"loads model"| node_inference
node_researcher -->|"starts detection"| node_inference
node_firmware -.->|"configures camera"| node_pins
node_firmware -.->|"starts server"| node_httpserver
node_camera -.->|"provides frames"| node_httpserver
node_httpserver -->|"serves controls"| node_cameraui
node_inference -->|"reads stream"| node_camera
node_inference -.->|"updates results"| node_dashboard
node_researcher -->|"views detections"| node_dashboard
node_researcher -->|"controls camera"| node_cameraui

click node_generator "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/01_generate_synthetic_dataset.py"
click node_training "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/02_train_yolov8_colab.py"
click node_weights "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/yolov8_microplastic_trained.pt"
click node_firmware "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/microplastic_detector.ino"
click node_pins "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/camera_pins.h"
click node_httpserver "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/app_httpd.cpp"
click node_cameraui "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/app_httpd.cpp"
click node_inference "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/03_esp32_integration.py"
click node_dashboard "https://github.com/niloydebbarma-code/microplastic-detection/blob/main/03_esp32_integration.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_generator toneBlue
class node_training,node_weights,node_hmpd toneAmber
class node_firmware,node_pins,node_httpserver,node_cameraui toneMint
class node_inference,node_dashboard toneRose
class node_researcher,node_camera toneIndigo
```

## Components

### Dataset Preparation

- [Synthetic Generator](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/01_generate_synthetic_dataset.py): `01_generate_synthetic_dataset.py`

### Model Training

- [Train and Evaluate](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/02_train_yolov8_colab.py): `02_train_yolov8_colab.py`
- [Trained Weights](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/yolov8_microplastic_trained.pt): `yolov8_microplastic_trained.pt`

### Camera Device

- [Camera Firmware](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/microplastic_detector.ino): `esp32_code/microplastic_detector.ino`
- [Camera Pin Mapping](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/camera_pins.h): `esp32_code/camera_pins.h`
- [Camera HTTP Server](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/app_httpd.cpp): `esp32_code/app_httpd.cpp`
- [Camera Web Controls](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/esp32_code/app_httpd.cpp): `esp32_code/app_httpd.cpp`

### Detection Runtime

- [YOLO Inference](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/03_esp32_integration.py): `03_esp32_integration.py`
- [Detection Dashboard](https://github.com/niloydebbarma-code/microplastic-detection/blob/main/03_esp32_integration.py): `03_esp32_integration.py`

### Other components

- **Operator**
- **HMPD Data**
- **ESP32-CAM**

## Connections

- Operator → Synthetic Generator: generates data (evidence: `README.md`)
- HMPD Data → Synthetic Generator: patch input (evidence: `README.md`)
- Synthetic Generator → Train and Evaluate: training images (evidence: `README.md`)
- Operator → Train and Evaluate: trains model (evidence: `README.md`)
- Train and Evaluate → Trained Weights: saves weights (evidence: `02_train_yolov8_colab.py`)
- Trained Weights → YOLO Inference: loads model (evidence: `README.md`)
- Operator → YOLO Inference: starts detection (evidence: `README.md`)
- Camera Firmware → Camera Pin Mapping: configures camera
- Camera Firmware → Camera HTTP Server: starts server
- ESP32-CAM → Camera HTTP Server: provides frames
- Camera HTTP Server → Camera Web Controls: serves controls (evidence: `esp32_code/app_httpd.cpp`)
- YOLO Inference → ESP32-CAM: reads stream (evidence: `03_esp32_integration.py`)
- YOLO Inference → Detection Dashboard: updates results (evidence: `03_esp32_integration.py`)
- Operator → Detection Dashboard: views detections (evidence: `README.md`)
- Operator → Camera Web Controls: controls camera (evidence: `esp32_code/app_httpd.cpp`)
