# d-nithinteja/plant-aid architecture

> Architecture diagram of the GitHub repository d-nithinteja/plant-aid, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/d-nithinteja/plant-aid
- Repository: https://github.com/d-nithinteja/plant-aid

## Overview

Plant-Aid is a plant-disease diagnosis and treatment-advisory application, with a React interface in this tree and a FastAPI backend. The principal workflow accepts a plant image, runs disease inference, returns a confidence-qualified diagnosis and remedies, and lets the user explicitly save and later review history. Separate capabilities include account/OTP authentication, disease guidance, administration, and model training and evaluation. The README documents the diagnostic stages and explicit history-save action; source-index references support many internal links. Unsampled implementation details and some UI-to-API wiring are not asserted.

Main entry points: [`backend/app/main.py`](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/main.py) (FastAPI application), [`frontend/src/App.tsx`](https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/App.tsx) (Web application), [`backend/app/database.py`](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/database.py) (SQL database), [`backend/app/routers/inference.py`](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/inference.py) (Inference routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_app["Web application<br/>[App.tsx]"]
  node_auth_ui["Sign-in and OTP<br/>[AuthContext.tsx]"]
  node_scan_ui["Scan interface<br/>[ScanPage.tsx]"]
  node_history_ui["Diagnosis history<br/>[HistoryPage.tsx]"]
  node_guide_ui["Disease guide"]
  node_admin_ui["Admin console<br/>[AdminPage.tsx]"]
end

subgraph group_api["API workflows"]
  node_api_server["FastAPI application<br/>[main.py]"]
  node_auth_api["Authentication routes<br/>[auth.py]"]
  node_inference_api["Inference routes<br/>[inference.py]"]
  node_history_api["History routes<br/>[history.py]"]
  node_remedy_api["Remedy routes<br/>[remedy.py]"]
  node_admin_api["Admin routes<br/>[admin.py]"]
  node_security["JWT and access control<br/>[security.py]"]
  node_otp["OTP delivery<br/>[otp_service.py]"]
end

subgraph group_diagnosis["Diagnosis services"]
  node_ml_engine["Inference engine<br/>[ml_engine.py]"]
  node_disease_lookup["Disease catalog lookup<br/>[disease_lookup.py]"]
end

subgraph group_data["Application data"]
  node_storage["Image storage<br/>[storage.py]"]
  node_db[("SQL database<br/>[database.py]")]
  node_models["Domain records<br/>[models.py]"]
end

subgraph group_ml["Model lifecycle"]
  node_taxonomy["Disease class catalog<br/>[ml_config.py]"]
  node_dataset["Dataset loading<br/>[dataset.py]"]
  node_model["Classifier architecture<br/>[model.py]"]
  node_training["Model training<br/>[train.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_export["Model export<br/>[export.py]"]
  node_gradcam["Grad-CAM tooling<br/>[gradcam.py]"]
end

node_farmer(("Farmer or agronomist"))

node_farmer -.->|"uses"| node_app
node_app -->|"provides"| node_auth_ui
node_app -->|"routes to"| node_scan_ui
node_app -->|"routes to"| node_history_ui
node_app -->|"routes to"| node_guide_ui
node_app -->|"routes to"| node_admin_ui
node_auth_ui -.->|"calls API"| node_api_server
node_scan_ui -.->|"calls API"| node_api_server
node_api_server -->|"registers"| node_auth_api
node_api_server -->|"registers"| node_inference_api
node_api_server -->|"registers"| node_history_api
node_api_server -->|"registers"| node_remedy_api
node_api_server -->|"registers"| node_admin_api
node_auth_api -->|"imports"| node_security
node_auth_api -->|"uses"| node_otp
node_inference_api -->|"runs inference"| node_ml_engine
node_inference_api -->|"stores image"| node_storage
node_inference_api -.->|"looks up remedies"| node_disease_lookup
node_history_api -->|"uses media storage"| node_storage
node_history_api -->|"uses lookup"| node_disease_lookup
node_remedy_api -->|"uses lookup"| node_disease_lookup
node_admin_api -->|"uses media storage"| node_storage
node_admin_api -->|"uses lookup"| node_disease_lookup
node_auth_api -->|"queries data"| node_db
node_inference_api -->|"queries data"| node_db
node_history_api -->|"queries data"| node_db
node_remedy_api -->|"queries data"| node_db
node_admin_api -->|"queries data"| node_db
node_db -->|"maps records"| node_models
node_ml_engine -->|"loads classes"| node_taxonomy
node_training -->|"loads samples"| node_dataset
node_training -->|"builds classifier"| node_model
node_training -->|"uses class list"| node_taxonomy
node_evaluation -->|"uses dataset"| node_dataset
node_evaluation -->|"uses classifier"| node_model
node_export -->|"uses dataset"| node_dataset
node_export -->|"uses classifier"| node_model
node_export -->|"uses Grad-CAM"| node_gradcam
node_export -->|"exports labels"| node_taxonomy

click node_app "https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/App.tsx"
click node_auth_ui "https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/context/AuthContext.tsx"
click node_scan_ui "https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/pages/ScanPage.tsx"
click node_history_ui "https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/pages/HistoryPage.tsx"
click node_guide_ui "https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/pages/DiseaseGuidePage.tsx"
click node_admin_ui "https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/pages/AdminPage.tsx"
click node_api_server "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/main.py"
click node_auth_api "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/auth.py"
click node_inference_api "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/inference.py"
click node_history_api "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/history.py"
click node_remedy_api "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/remedy.py"
click node_admin_api "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/admin.py"
click node_security "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/security.py"
click node_otp "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/services/otp_service.py"
click node_ml_engine "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/services/ml_engine.py"
click node_disease_lookup "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/services/disease_lookup.py"
click node_storage "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/services/storage.py"
click node_db "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/database.py"
click node_models "https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/models.py"
click node_taxonomy "https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/ml_config.py"
click node_dataset "https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/dataset.py"
click node_model "https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/model.py"
click node_training "https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/train.py"
click node_evaluation "https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/evaluate.py"
click node_export "https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/export.py"
click node_gradcam "https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/gradcam.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_app,node_auth_ui,node_scan_ui,node_history_ui,node_guide_ui,node_admin_ui toneBlue
class node_api_server,node_auth_api,node_inference_api,node_history_api,node_remedy_api,node_admin_api,node_security,node_otp toneAmber
class node_ml_engine,node_disease_lookup toneMint
class node_storage,node_db,node_models toneRose
class node_taxonomy,node_dataset,node_model,node_training,node_evaluation,node_export,node_gradcam,node_farmer toneIndigo
```

## Components

### User interface

- [Web application](https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Sign-in and OTP](https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Scan interface](https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/pages/ScanPage.tsx): `frontend/src/pages/ScanPage.tsx`
- [Diagnosis history](https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/pages/HistoryPage.tsx): `frontend/src/pages/HistoryPage.tsx`
- [Disease guide](https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/pages/DiseaseGuidePage.tsx): `frontend/src/pages/DiseaseGuidePage.tsx`
- [Admin console](https://github.com/d-nithinteja/plant-aid/blob/main/frontend/src/pages/AdminPage.tsx): `frontend/src/pages/AdminPage.tsx`

### API workflows

- [FastAPI application](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication routes](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Inference routes](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/inference.py): `backend/app/routers/inference.py`
- [History routes](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/history.py): `backend/app/routers/history.py`
- [Remedy routes](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/remedy.py): `backend/app/routers/remedy.py`
- [Admin routes](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/routers/admin.py): `backend/app/routers/admin.py`
- [JWT and access control](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/security.py): `backend/app/security.py`
- [OTP delivery](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/services/otp_service.py): `backend/app/services/otp_service.py`

### Diagnosis services

- [Inference engine](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/services/ml_engine.py): `backend/app/services/ml_engine.py`
- [Disease catalog lookup](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/services/disease_lookup.py): `backend/app/services/disease_lookup.py`

### Application data

- [Image storage](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/services/storage.py): `backend/app/services/storage.py`
- [SQL database](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/database.py): `backend/app/database.py`
- [Domain records](https://github.com/d-nithinteja/plant-aid/blob/main/backend/app/models.py): `backend/app/models.py`

### Model lifecycle

- [Disease class catalog](https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/ml_config.py): `backend/ml/ml_config.py`
- [Dataset loading](https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/dataset.py): `backend/ml/dataset.py`
- [Classifier architecture](https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/model.py): `backend/ml/model.py`
- [Model training](https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/train.py): `backend/ml/train.py`
- [Model evaluation](https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/evaluate.py): `backend/ml/evaluate.py`
- [Model export](https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/export.py): `backend/ml/export.py`
- [Grad-CAM tooling](https://github.com/d-nithinteja/plant-aid/blob/main/backend/ml/gradcam.py): `backend/ml/gradcam.py`

### Other components

- **Farmer or agronomist**

## Connections

- Farmer or agronomist → Web application: uses
- Web application → Sign-in and OTP: provides (evidence: `frontend/src/App.tsx`)
- Web application → Scan interface: routes to (evidence: `frontend/src/App.tsx`)
- Web application → Diagnosis history: routes to (evidence: `frontend/src/App.tsx`)
- Web application → Disease guide: routes to (evidence: `frontend/src/App.tsx`)
- Web application → Admin console: routes to (evidence: `frontend/src/App.tsx`)
- Sign-in and OTP → FastAPI application: calls API
- Scan interface → FastAPI application: calls API
- FastAPI application → Authentication routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → Inference routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → History routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → Remedy routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → Admin routes: registers (evidence: `backend/app/main.py`)
- Authentication routes → JWT and access control: imports (evidence: `backend/app/routers/auth.py`)
- Authentication routes → OTP delivery: uses (evidence: `backend/app/routers/auth.py`)
- Inference routes → Inference engine: runs inference (evidence: `backend/app/routers/inference.py`)
- Inference routes → Image storage: stores image (evidence: `backend/app/routers/inference.py`)
- Inference routes → Disease catalog lookup: looks up remedies
- History routes → Image storage: uses media storage (evidence: `backend/app/routers/history.py`)
- History routes → Disease catalog lookup: uses lookup (evidence: `backend/app/routers/history.py`)
- Remedy routes → Disease catalog lookup: uses lookup (evidence: `backend/app/routers/remedy.py`)
- Admin routes → Image storage: uses media storage (evidence: `backend/app/routers/admin.py`)
- Admin routes → Disease catalog lookup: uses lookup (evidence: `backend/app/routers/admin.py`)
- Authentication routes → SQL database: queries data (evidence: `backend/app/routers/auth.py`)
- Inference routes → SQL database: queries data (evidence: `backend/app/routers/inference.py`)
- History routes → SQL database: queries data (evidence: `backend/app/routers/history.py`)
- Remedy routes → SQL database: queries data (evidence: `backend/app/routers/remedy.py`)
- Admin routes → SQL database: queries data (evidence: `backend/app/routers/admin.py`)
- SQL database → Domain records: maps records (evidence: `backend/app/database.py`)
- Inference engine → Disease class catalog: loads classes (evidence: `backend/app/services/ml_engine.py`)
- Model training → Dataset loading: loads samples (evidence: `backend/ml/train.py`)
- Model training → Classifier architecture: builds classifier (evidence: `backend/ml/train.py`)
- Model training → Disease class catalog: uses class list (evidence: `backend/ml/train.py`)
- Model evaluation → Dataset loading: uses dataset (evidence: `backend/ml/evaluate.py`)
- Model evaluation → Classifier architecture: uses classifier (evidence: `backend/ml/evaluate.py`)
- Model export → Dataset loading: uses dataset (evidence: `backend/ml/export.py`)
- Model export → Classifier architecture: uses classifier (evidence: `backend/ml/export.py`)
- Model export → Grad-CAM tooling: uses Grad-CAM (evidence: `backend/ml/export.py`)
- Model export → Disease class catalog: exports labels (evidence: `backend/ml/export.py`)
