# md-shaon-khan/farmer-s-friend architecture

> Architecture diagram of the GitHub repository md-shaon-khan/farmer-s-friend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/md-shaon-khan/farmer-s-friend
- Repository: https://github.com/md-shaon-khan/farmer-s-friend

## Overview

Paddy Check accepts a leaf photo, rejects images that do not pass the paddy gate, classifies accepted leaves by pathogen category, and returns similar reference images plus attention-based localization for diseased leaves. The backend also serves the browser UI and reference thumbnails. Core inference and routing relationships are visible in the sampled source; frontend request wiring is not shown, so that connection is marked unverified.

Main entry points: [`Backend/ml/pipeline.py`](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/pipeline.py) (Prediction pipeline), [`Backend/ml/feature_extractor.py`](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/feature_extractor.py) (Similarity engine), [`Backend/routers/predict.py`](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/routers/predict.py) (Prediction endpoint), [`Frontend/index.html`](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/index.html) (Home page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application entry"]
  node_webapp["FastAPI app<br/>[main.py]"]
  node_predict_api["Prediction endpoint<br/>[predict.py]"]
  node_response["Prediction response<br/>[predict.py]"]
end

subgraph group_inference["Leaf inference"]
  node_settings["Runtime settings<br/>[config.py]"]
  node_image_utils["Image preprocessing<br/>[image_utils.py]"]
  node_pipeline["Prediction pipeline<br/>[pipeline.py]"]
  node_paddy["Paddy gatekeeper<br/>[paddy_detector.py]"]
  node_disease["Pathogen classifier"]
end

subgraph group_analysis["Image analysis"]
  node_localization["Attention localization<br/>[spot_detector.py]"]
  node_similarity["Similarity engine"]
  node_gallery[("Reference gallery")]
end

subgraph group_interface["Browser interface"]
  node_home["Home page<br/>[index.html]"]
  node_classify_page["Classification page<br/>[classify.html]"]
  node_classify_ui["Classification UI<br/>[classify.js]"]
  node_shared_ui["Shared page behavior<br/>[main.js]"]
end

node_person(("Grower"))

node_person -->|"opens"| node_home
node_person -.->|"submits photo"| node_classify_page
node_home -.->|"offers classification"| node_classify_page
node_classify_page -.->|"loads script"| node_classify_ui
node_classify_ui -.->|"requests prediction"| node_predict_api
node_webapp -->|"registers routes"| node_predict_api
node_webapp -->|"serves frontend"| node_home
node_predict_api -->|"runs pipeline"| node_pipeline
node_predict_api -->|"validates response"| node_response
node_pipeline -->|"checks paddy"| node_paddy
node_pipeline -->|"classifies leaf"| node_disease
node_pipeline -->|"finds matches"| node_similarity
node_pipeline -->|"localizes disease"| node_localization
node_pipeline -->|"decodes image"| node_image_utils
node_paddy -->|"decodes and transforms"| node_image_utils
node_disease -->|"decodes and transforms"| node_image_utils
node_similarity -->|"decodes and transforms"| node_image_utils
node_pipeline -->|"reads settings"| node_settings
node_paddy -->|"reads settings"| node_settings
node_disease -->|"reads settings"| node_settings
node_similarity -->|"reads settings"| node_settings
node_similarity -->|"loads and caches embeddings"| node_gallery
node_webapp -->|"serves reference images"| node_gallery
node_classify_ui -.->|"renders results"| node_response
node_shared_ui -.->|"marks page loaded"| node_home

click node_webapp "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/main.py"
click node_predict_api "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/routers/predict.py"
click node_response "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/schemas/predict.py"
click node_settings "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/config.py"
click node_image_utils "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/utils/image_utils.py"
click node_pipeline "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/pipeline.py"
click node_paddy "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/paddy_detector.py"
click node_disease "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/disease_classifier.py"
click node_localization "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/spot_detector.py"
click node_similarity "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/feature_extractor.py"
click node_gallery "https://github.com/md-shaon-khan/farmer-s-friend/tree/main/Backend/data"
click node_home "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/index.html"
click node_classify_page "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/pages/classify.html"
click node_classify_ui "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/js/classify.js"
click node_shared_ui "https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/js/main.js"

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_webapp,node_predict_api,node_response toneBlue
class node_settings,node_image_utils,node_pipeline,node_paddy,node_disease toneAmber
class node_localization,node_similarity,node_gallery toneMint
class node_home,node_classify_page,node_classify_ui,node_shared_ui toneRose
class node_person toneIndigo
```

## Components

### Application entry

- [FastAPI app](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/main.py): `Backend/main.py`
- [Prediction endpoint](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/routers/predict.py): `Backend/routers/predict.py`
- [Prediction response](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/schemas/predict.py): `Backend/schemas/predict.py`

### Leaf inference

- [Runtime settings](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/config.py): `Backend/config.py`
- [Image preprocessing](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/utils/image_utils.py): `Backend/utils/image_utils.py`
- [Prediction pipeline](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/pipeline.py): `Backend/ml/pipeline.py`
- [Paddy gatekeeper](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/paddy_detector.py): `Backend/ml/paddy_detector.py`
- [Pathogen classifier](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/disease_classifier.py): `Backend/ml/disease_classifier.py`

### Image analysis

- [Attention localization](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/spot_detector.py): `Backend/ml/spot_detector.py`
- [Similarity engine](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Backend/ml/feature_extractor.py): `Backend/ml/feature_extractor.py`
- [Reference gallery](https://github.com/md-shaon-khan/farmer-s-friend/tree/main/Backend/data): `Backend/data`

### Browser interface

- [Home page](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/index.html): `Frontend/index.html`
- [Classification page](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/pages/classify.html): `Frontend/pages/classify.html`
- [Classification UI](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/js/classify.js): `Frontend/js/classify.js`
- [Shared page behavior](https://github.com/md-shaon-khan/farmer-s-friend/blob/main/Frontend/js/main.js): `Frontend/js/main.js`

### Other components

- **Grower**

## Connections

- Grower → Home page: opens (evidence: `README.md`)
- Grower → Classification page: submits photo
- Home page → Classification page: offers classification
- Classification page → Classification UI: loads script
- Classification UI → Prediction endpoint: requests prediction
- FastAPI app → Prediction endpoint: registers routes (evidence: `Backend/main.py`)
- FastAPI app → Home page: serves frontend (evidence: `Backend/main.py`)
- Prediction endpoint → Prediction pipeline: runs pipeline (evidence: `Backend/routers/predict.py`)
- Prediction endpoint → Prediction response: validates response (evidence: `Backend/routers/predict.py`)
- Prediction pipeline → Paddy gatekeeper: checks paddy (evidence: `Backend/ml/pipeline.py`)
- Prediction pipeline → Pathogen classifier: classifies leaf (evidence: `Backend/ml/pipeline.py`)
- Prediction pipeline → Similarity engine: finds matches (evidence: `Backend/ml/pipeline.py`)
- Prediction pipeline → Attention localization: localizes disease (evidence: `Backend/ml/pipeline.py`)
- Prediction pipeline → Image preprocessing: decodes image (evidence: `Backend/ml/pipeline.py`)
- Paddy gatekeeper → Image preprocessing: decodes and transforms (evidence: `Backend/ml/paddy_detector.py`)
- Pathogen classifier → Image preprocessing: decodes and transforms (evidence: `Backend/ml/disease_classifier.py`)
- Similarity engine → Image preprocessing: decodes and transforms (evidence: `Backend/ml/feature_extractor.py`)
- Prediction pipeline → Runtime settings: reads settings (evidence: `Backend/ml/pipeline.py`)
- Paddy gatekeeper → Runtime settings: reads settings (evidence: `Backend/ml/paddy_detector.py`)
- Pathogen classifier → Runtime settings: reads settings (evidence: `Backend/ml/disease_classifier.py`)
- Similarity engine → Runtime settings: reads settings (evidence: `Backend/ml/feature_extractor.py`)
- Similarity engine → Reference gallery: loads and caches embeddings (evidence: `Backend/ml/feature_extractor.py`)
- FastAPI app → Reference gallery: serves reference images (evidence: `Backend/main.py`)
- Classification UI → Prediction response: renders results
- Shared page behavior → Home page: marks page loaded
