# joker-qp/leafai architecture

> Architecture diagram of the GitHub repository joker-qp/leafai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joker-qp/leafai
- Repository: https://github.com/joker-qp/leafai

## Overview

Leafai is a web-based plant-leaf disease diagnosis and active-learning system. Users submit one or more images, including camera captures, receive ranked plant/disease predictions with confidence warnings, and can confirm or correct labels. Confirmed and corrected images enter a data pool that can be used for fine-tuning; the repository also provides a separate PlantVillage training pipeline. The frontend and some documented capabilities are represented from the README and file tree; their source was not sampled, so uncertain internal wiring is omitted.

Main entry points: [`main.py`](https://github.com/joker-qp/leafai/blob/main/main.py) (FastAPI Service), [`retrain.py`](https://github.com/joker-qp/leafai/blob/main/retrain.py) (Pool Fine-Tuning), [`index.html`](https://github.com/joker-qp/leafai/blob/main/index.html) (Web UI), [`train_model.py`](https://github.com/joker-qp/leafai/blob/main/train_model.py) (PlantVillage Training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web Diagnosis"]
  node_webui["Web UI<br/>[index.html]"]
  node_api["FastAPI Service<br/>[main.py]"]
end

subgraph group_inference["Inference"]
  node_image["Image Preprocessing<br/>[predict.py]"]
  node_classifier["Disease Classifier<br/>[predict.py]"]
  node_model["Model Weights"]
  node_classes["Class Names<br/>[class_names.json]"]
end

subgraph group_feedback["Feedback Learning"]
  node_pending[("Pending Images")]
  node_pool[("Feedback Data Pool")]
  node_feedbacklog[("Feedback Log<br/>[feedback_log.jsonl]")]
end

subgraph group_training["Model Training"]
  node_retrain["Pool Fine-Tuning<br/>[retrain.py]"]
  node_archive[("Archived Pool")]
  node_train["PlantVillage Training<br/>[train_model.py]"]
end

node_user(("User"))
node_dataset[("PlantVillage Dataset")]

node_user -->|"submits images"| node_webui
node_webui -->|"uploads batch"| node_api
node_api -->|"requests prediction"| node_image
node_image -->|"prepares image"| node_classifier
node_classifier -->|"loads weights"| node_model
node_classifier -->|"loads labels"| node_classes
node_api -->|"returns results"| node_webui
node_api -->|"saves image"| node_pending
node_webui -->|"sends correction"| node_api
node_api -->|"reads image"| node_pending
node_api -->|"moves labeled image"| node_pool
node_api -->|"appends feedback"| node_feedbacklog
node_user -->|"starts retraining"| node_retrain
node_retrain -->|"loads images"| node_pool
node_retrain -->|"loads and updates"| node_model
node_retrain -->|"loads labels"| node_classes
node_retrain -->|"moves processed images"| node_archive
node_train -->|"downloads data"| node_dataset
node_train -->|"saves weights"| node_model
node_train -->|"saves labels"| node_classes

click node_webui "https://github.com/joker-qp/leafai/blob/main/index.html"
click node_api "https://github.com/joker-qp/leafai/blob/main/main.py"
click node_image "https://github.com/joker-qp/leafai/blob/main/predict.py"
click node_classifier "https://github.com/joker-qp/leafai/blob/main/predict.py"
click node_model "https://github.com/joker-qp/leafai/blob/main/models/leaf_disease_model.pth"
click node_classes "https://github.com/joker-qp/leafai/blob/main/models/class_names.json"
click node_pool "https://github.com/joker-qp/leafai/tree/main/data_pool"
click node_feedbacklog "https://github.com/joker-qp/leafai/blob/main/data/feedback_log.jsonl"
click node_retrain "https://github.com/joker-qp/leafai/blob/main/retrain.py"
click node_train "https://github.com/joker-qp/leafai/blob/main/train_model.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_webui,node_api,node_user toneBlue
class node_image,node_classifier,node_model,node_classes,node_dataset toneAmber
class node_pending,node_pool,node_feedbacklog toneMint
class node_retrain,node_archive,node_train toneRose
```

## Components

### Web Diagnosis

- [Web UI](https://github.com/joker-qp/leafai/blob/main/index.html): `index.html`
- [FastAPI Service](https://github.com/joker-qp/leafai/blob/main/main.py): `main.py`

### Inference

- [Image Preprocessing](https://github.com/joker-qp/leafai/blob/main/predict.py): `predict.py`
- [Disease Classifier](https://github.com/joker-qp/leafai/blob/main/predict.py): `predict.py`
- [Model Weights](https://github.com/joker-qp/leafai/blob/main/models/leaf_disease_model.pth): `models/leaf_disease_model.pth`
- [Class Names](https://github.com/joker-qp/leafai/blob/main/models/class_names.json): `models/class_names.json`

### Feedback Learning

- **Pending Images**
- [Feedback Data Pool](https://github.com/joker-qp/leafai/tree/main/data_pool): `data_pool`
- [Feedback Log](https://github.com/joker-qp/leafai/blob/main/data/feedback_log.jsonl): `data/feedback_log.jsonl`

### Model Training

- [Pool Fine-Tuning](https://github.com/joker-qp/leafai/blob/main/retrain.py): `retrain.py`
- **Archived Pool**
- [PlantVillage Training](https://github.com/joker-qp/leafai/blob/main/train_model.py): `train_model.py`

### Other components

- **User**
- **PlantVillage Dataset**

## Connections

- User → Web UI: submits images
- Web UI → FastAPI Service: uploads batch
- FastAPI Service → Image Preprocessing: requests prediction
- Image Preprocessing → Disease Classifier: prepares image
- Disease Classifier → Model Weights: loads weights
- Disease Classifier → Class Names: loads labels
- FastAPI Service → Web UI: returns results
- FastAPI Service → Pending Images: saves image
- Web UI → FastAPI Service: sends correction
- FastAPI Service → Pending Images: reads image
- FastAPI Service → Feedback Data Pool: moves labeled image
- FastAPI Service → Feedback Log: appends feedback
- User → Pool Fine-Tuning: starts retraining
- Pool Fine-Tuning → Feedback Data Pool: loads images
- Pool Fine-Tuning → Model Weights: loads and updates
- Pool Fine-Tuning → Class Names: loads labels
- Pool Fine-Tuning → Archived Pool: moves processed images
- PlantVillage Training → PlantVillage Dataset: downloads data
- PlantVillage Training → Model Weights: saves weights
- PlantVillage Training → Class Names: saves labels
