# ahsan47-hq/weed-detection-app architecture

> Architecture diagram of the GitHub repository ahsan47-hq/weed-detection-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahsan47-hq/weed-detection-app
- Repository: https://github.com/ahsan47-hq/weed-detection-app

## Overview

Precision Weed Detection is a React interface backed by a FastAPI image-analysis API. The user selects or drops a field image, submits it for ONNX YOLOv8-Seg inference, and receives an annotated segmentation image and prediction metrics; the UI presents the result, legend, and species guidance. The excerpts show the API orchestration, model preprocessing/postprocessing, and rendering. README documents the broader capabilities; links for unexcerpted result components are limited to documented or directly visible relationships.

Main entry points: [`frontend/src/App.jsx`](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/App.jsx) (Analysis page), [`backend/app/routes.py`](https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/routes.py) (API routes), [`frontend/src/components/SpeciesInfo.jsx`](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/SpeciesInfo.jsx) (Species guidance), [`frontend/src/components/UploadCard.jsx`](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/UploadCard.jsx) (Image upload)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web interface"]
  node_react["React entry<br/>[main.jsx]"]
  node_app["Analysis page<br/>[App.jsx]"]
  node_upload["Image upload<br/>[UploadCard.jsx]"]
  node_results["Prediction summary<br/>[ResultCard.jsx]"]
  node_legend["Mask legend<br/>[Legend.jsx]"]
  node_species["Species guidance<br/>[SpeciesInfo.jsx]"]
  node_speciesdata["Weed reference data<br/>[weedInfo.js]"]
end

subgraph group_api["Prediction API"]
  node_api["FastAPI app<br/>[main.py]"]
  node_routes["API routes<br/>[routes.py]"]
  node_schema["Response schema<br/>[schemas.py]"]
end

subgraph group_inference["Segmentation inference"]
  node_predictor["ONNX predictor<br/>[predictor.py]"]
  node_model["ONNX model<br/>[best.onnx]"]
  node_visualizer["Mask renderer<br/>[visualizer.py]"]
end

node_user(("Field user"))
node_backend["Inference API"]

node_user -->|"selects image"| node_upload
node_react -->|"renders"| node_app
node_app -->|"renders"| node_upload
node_app -->|"renders results"| node_results
node_app -->|"renders legend"| node_legend
node_app -->|"renders guidance"| node_species
node_species -->|"looks up species"| node_speciesdata
node_upload -->|"posts image"| node_backend
node_backend -.->|"serves API"| node_api
node_api -->|"registers routes"| node_routes
node_routes -->|"runs prediction"| node_predictor
node_routes -->|"renders masks"| node_visualizer
node_routes -->|"validates response"| node_schema
node_predictor -.->|"loads model"| node_model
node_results -.->|"shows metrics"| node_user
node_legend -.->|"explains colors"| node_user
node_species -.->|"shows guidance"| node_user

click node_react "https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/main.jsx"
click node_app "https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/App.jsx"
click node_upload "https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/UploadCard.jsx"
click node_results "https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/ResultCard.jsx"
click node_legend "https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/Legend.jsx"
click node_species "https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/SpeciesInfo.jsx"
click node_speciesdata "https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/data/weedInfo.js"
click node_api "https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/main.py"
click node_routes "https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/routes.py"
click node_schema "https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/schemas.py"
click node_predictor "https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/predictor.py"
click node_model "https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/models/best.onnx"
click node_visualizer "https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/visualizer.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_react,node_app,node_upload,node_results,node_legend,node_species,node_speciesdata,node_user toneBlue
class node_api,node_routes,node_schema toneAmber
class node_predictor,node_model,node_visualizer,node_backend toneMint
```

## Components

### Web interface

- [React entry](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/main.jsx): `frontend/src/main.jsx`
- [Analysis page](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Image upload](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/UploadCard.jsx): `frontend/src/components/UploadCard.jsx`
- [Prediction summary](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/ResultCard.jsx): `frontend/src/components/ResultCard.jsx`
- [Mask legend](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/Legend.jsx): `frontend/src/components/Legend.jsx`
- [Species guidance](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/components/SpeciesInfo.jsx): `frontend/src/components/SpeciesInfo.jsx`
- [Weed reference data](https://github.com/ahsan47-hq/weed-detection-app/blob/main/frontend/src/data/weedInfo.js): `frontend/src/data/weedInfo.js`

### Prediction API

- [FastAPI app](https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/main.py): `backend/app/main.py`
- [API routes](https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/routes.py): `backend/app/routes.py`
- [Response schema](https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### Segmentation inference

- [ONNX predictor](https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/predictor.py): `backend/app/predictor.py`
- [ONNX model](https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/models/best.onnx): `backend/models/best.onnx`
- [Mask renderer](https://github.com/ahsan47-hq/weed-detection-app/blob/main/backend/app/visualizer.py): `backend/app/visualizer.py`

### Other components

- **Field user**
- **Inference API**

## Connections

- Field user → Image upload: selects image (evidence: `frontend/src/components/UploadCard.jsx`)
- React entry → Analysis page: renders (evidence: `frontend/src/main.jsx`)
- Analysis page → Image upload: renders (evidence: `frontend/src/App.jsx`)
- Analysis page → Prediction summary: renders results (evidence: `frontend/src/App.jsx`)
- Analysis page → Mask legend: renders legend (evidence: `frontend/src/App.jsx`)
- Analysis page → Species guidance: renders guidance (evidence: `frontend/src/App.jsx`)
- Species guidance → Weed reference data: looks up species (evidence: `frontend/src/components/SpeciesInfo.jsx`)
- Image upload → Inference API: posts image (evidence: `frontend/src/components/UploadCard.jsx`)
- Inference API → FastAPI app: serves API (evidence: `README.md`)
- FastAPI app → API routes: registers routes (evidence: `backend/app/main.py`)
- API routes → ONNX predictor: runs prediction (evidence: `backend/app/routes.py`)
- API routes → Mask renderer: renders masks (evidence: `backend/app/routes.py`)
- API routes → Response schema: validates response (evidence: `backend/app/routes.py`)
- ONNX predictor → ONNX model: loads model
- Prediction summary → Field user: shows metrics
- Mask legend → Field user: explains colors
- Species guidance → Field user: shows guidance
