# Architecture data flow

This file describes the step-by-step data flow for a single inspection cycle and for retraining.

## Normal inspection cycle

1. **Sole enters camera view.**
2. **Position determination** fires a trigger (sensor or AI).
3. **Video stream → frame** captures one still frame from the active camera.
4. **Image preparing** normalizes, filters, crops, resizes, and rotates the frame according to the channel config.
5. **Main Server** receives the prepared image.
6. **Main Server** routes the image to the matching **YOLO instance** for that channel.
7. **YOLO instance** loads weights from **AI Model** and runs inference.
8. **YOLO instance** returns:
   - detected defect classes;
   - bounding boxes;
   - confidence scores.
9. **Main Server** builds an event record:
   - sole ID;
   - channel ID;
   - timestamp;
   - original image reference;
   - annotated image reference;
   - defect probability / class.
10. **Main Server** writes the event to **DB**.
11. **WEB UI** fetches and displays the event.
12. **Expert / operator** reviews the result and marks it **correct** or **incorrect**.
13. **WEB UI** sends the label back to **Main Server**, which updates the event in **DB**.

## Retraining flow

1. **Operator** selects a date range in the WEB UI retraining panel.
2. **WEB UI** requests retraining from **Main Server**.
3. **Main Server** queries **DB** for verified events in the selected range.
4. **Main Server** assembles / augments images into the **Learning Dataset**.
5. Optionally, **Artificial image generator** adds synthetic disturbances.
6. **Learning module** trains / fine-tunes a model on the dataset.
7. **Learning module** stores new weights in **AI Model**.
8. **YOLO instances** can be reloaded with the new weights (hot-reload or restart).
9. **WEB UI** shows retraining status and metrics.

## Development / debug flow

1. **Fake input data** produces frames offline.
2. **OR gate** selects between real camera pipeline and fake input.
3. Selected frames go through **Image preparing** and then the same inference path.
4. Results are stored in DB and shown in WEB UI, exactly like production.

## File / data references

- Event record keeps references, not embedded binary images (unless required).
- Images should be stored on disk with stable paths; DB stores the paths.
- Annotated images are generated after inference and saved alongside originals.
