# gpt-lab-summer-2026/trash-sorter architecture

> Architecture diagram of the GitHub repository gpt-lab-summer-2026/trash-sorter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gpt-lab-summer-2026/trash-sorter
- Repository: https://github.com/gpt-lab-summer-2026/trash-sorter

## Overview

Trash Sorter is a camera-driven hardware system: the main loop calibrates a reference image, waits for an item, classifies it, moves the actuator to a bin, records the sort, and updates the LCD. Separate branches handle button input and optional monitor visualization; the ESP32 firmware provides the actuator endpoint. The graph follows calls visible in the excerpts and capabilities documented in the README; hardware links documented but not shown in sampled implementation are cited to the README.

Main entry points: [`main.py`](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/main.py) (Main loop), [`config.py`](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/config.py) (Runtime settings), [`detector.py`](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/detector.py) (Trash classifier), [`sorter.py`](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/sorter.py) (Bin selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Sort workflow"]
  node_main["Main loop<br/>[main.py]"]
  node_config["Runtime settings<br/>[config.py]"]
end

subgraph group_vision["Vision"]
  node_camera["Camera processing<br/>[camera.py]"]
  node_detector["Trash classifier<br/>[detector.py]"]
  node_labels["Bin mapping<br/>[labels.py]"]
  node_model["YOLO model<br/>[best.onnx]"]
end

subgraph group_actuation["Actuation"]
  node_sorter["Bin selection<br/>[sorter.py]"]
  node_serial["ESP serial control<br/>[connect_esp.py]"]
  node_firmware["ESP32 controller<br/>[esp32c6.ino]"]
end

subgraph group_interface["User interface"]
  node_buttons["Button input<br/>[buttons.py]"]
  node_screen["LCD status<br/>[screen.py]"]
  node_visualizer["Monitor overlay<br/>[visualizer.py]"]
end

subgraph group_state["Sort records"]
  node_records[("Sort history<br/>[sorted.csv]")]
end

node_user(("Operator"))
node_actuator["Servo joint"]
node_display["Monitor window"]
node_camera_device["Camera"]

node_user -->|"places item"| node_camera_device
node_camera_device -.->|"provides frames"| node_main
node_main -->|"captures and calibrates"| node_camera
node_main -->|"classifies frame"| node_detector
node_detector -->|"maps category"| node_labels
node_detector -->|"runs inference"| node_model
node_detector -->|"reads settings"| node_config
node_main -->|"reads settings"| node_config
node_main -->|"sorts detection"| node_sorter
node_sorter -->|"sets position"| node_serial
node_main -->|"connects and resets"| node_serial
node_serial -->|"sends commands"| node_firmware
node_firmware -->|"controls servos"| node_actuator
node_sorter -->|"appends sort"| node_records
node_main -->|"clears history"| node_records
node_main -->|"updates status"| node_screen
node_screen -->|"reads count"| node_records
node_user -->|"presses controls"| node_buttons
node_main -->|"checks input"| node_buttons
node_main -->|"renders overlay"| node_visualizer
node_visualizer -->|"draws window"| node_display
node_screen -->|"reads pin settings"| node_config
node_buttons -->|"reads pin settings"| node_config
node_serial -->|"reads serial settings"| node_config
node_sorter -->|"reads servo settings"| node_config

click node_main "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/main.py"
click node_camera "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/camera.py"
click node_detector "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/detector.py"
click node_labels "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/labels.py"
click node_model "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/models/best.onnx"
click node_config "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/config.py"
click node_sorter "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/sorter.py"
click node_serial "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/connect_esp.py"
click node_firmware "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/esp32c6/esp32c6.ino"
click node_buttons "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/buttons.py"
click node_screen "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/screen.py"
click node_visualizer "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/visualizer.py"
click node_records "https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/sorted.csv"

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_main,node_config toneBlue
class node_camera,node_detector,node_labels,node_model toneAmber
class node_sorter,node_serial,node_firmware toneMint
class node_buttons,node_screen,node_visualizer toneRose
class node_records,node_user,node_actuator,node_display,node_camera_device toneIndigo
```

## Components

### Sort workflow

- [Main loop](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/main.py): `main.py`
- [Runtime settings](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/config.py): `config.py`

### Vision

- [Camera processing](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/camera.py): `camera.py`
- [Trash classifier](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/detector.py): `detector.py`
- [Bin mapping](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/labels.py): `labels.py`
- [YOLO model](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/models/best.onnx): `models/best.onnx`

### Actuation

- [Bin selection](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/sorter.py): `sorter.py`
- [ESP serial control](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/connect_esp.py): `connect_esp.py`
- [ESP32 controller](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/esp32c6/esp32c6.ino): `esp32c6/esp32c6.ino`

### User interface

- [Button input](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/buttons.py): `buttons.py`
- [LCD status](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/screen.py): `screen.py`
- [Monitor overlay](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/visualizer.py): `visualizer.py`

### Sort records

- [Sort history](https://github.com/gpt-lab-summer-2026/trash-sorter/blob/master/sorted.csv): `sorted.csv`

### Other components

- **Operator**
- **Servo joint**
- **Monitor window**
- **Camera**

## Connections

- Operator → Camera: places item (evidence: `README.md`)
- Camera → Main loop: provides frames
- Main loop → Camera processing: captures and calibrates (evidence: `main.py`)
- Main loop → Trash classifier: classifies frame (evidence: `main.py`)
- Trash classifier → Bin mapping: maps category (evidence: `detector.py`)
- Trash classifier → YOLO model: runs inference (evidence: `detector.py`)
- Trash classifier → Runtime settings: reads settings (evidence: `detector.py`)
- Main loop → Runtime settings: reads settings (evidence: `main.py`)
- Main loop → Bin selection: sorts detection (evidence: `main.py`)
- Bin selection → ESP serial control: sets position (evidence: `sorter.py`)
- Main loop → ESP serial control: connects and resets (evidence: `main.py`)
- ESP serial control → ESP32 controller: sends commands (evidence: `README.md`)
- ESP32 controller → Servo joint: controls servos (evidence: `README.md`)
- Bin selection → Sort history: appends sort (evidence: `sorter.py`)
- Main loop → Sort history: clears history (evidence: `main.py`)
- Main loop → LCD status: updates status (evidence: `main.py`)
- LCD status → Sort history: reads count (evidence: `screen.py`)
- Operator → Button input: presses controls (evidence: `README.md`)
- Main loop → Button input: checks input (evidence: `main.py`)
- Main loop → Monitor overlay: renders overlay (evidence: `main.py`)
- Monitor overlay → Monitor window: draws window
- LCD status → Runtime settings: reads pin settings (evidence: `screen.py`)
- Button input → Runtime settings: reads pin settings (evidence: `buttons.py`)
- ESP serial control → Runtime settings: reads serial settings (evidence: `connect_esp.py`)
- Bin selection → Runtime settings: reads servo settings (evidence: `sorter.py`)
