# jugal1406/cs26012-crop_disease_detection architecture

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

- Interactive diagram: https://gitdiagram.com/jugal1406/cs26012-crop_disease_detection
- Repository: https://github.com/jugal1406/cs26012-crop_disease_detection

## Overview

This is a farmer-facing crop disease detection and agronomic advisory platform. Farmers authenticate, manage farm profiles, submit leaf images, receive confidence-gated diagnoses enriched with weather context and localized advisory, then review scan history or download reports. The graph separates the React client, API/domain services, inference and advisory capabilities, and persistence. Several frontend pages and backend routes are unsampled; their feature branches are retained from the README, while uncertain call relationships are dashed. (74 words)

Main entry points: [`backend/services/diagnosis_service.py`](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/diagnosis_service.py) (Diagnosis orchestration), [`frontend/src/App.jsx`](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/App.jsx) (React application), [`backend/routers/scans.py`](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/scans.py) (Scan routes), [`backend/main.py`](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer application"]
  node_web["React application<br/>[App.jsx]"]
  node_authui["Authentication client<br/>[authService.js]"]
  node_diagnosisui["Diagnosis client"]
  node_farmui["Farm client<br/>[farmService.js]"]
  node_scanui["Scan client<br/>[scanService.js]"]
  node_weatherui["Weather client<br/>[weatherService.js]"]
end

subgraph group_api["API and domain services"]
  node_api["FastAPI application<br/>[main.py]"]
  node_authroutes["Authentication routes<br/>[auth.py]"]
  node_diagnoseroutes["Diagnosis routes<br/>[diagnose.py]"]
  node_farmroutes["Farm routes<br/>[farms.py]"]
  node_scanroutes["Scan routes<br/>[scans.py]"]
  node_dashboard["Dashboard service"]
  node_farmservice["Farm management<br/>[farm_service.py]"]
  node_authservice["Identity synchronization<br/>[auth_service.py]"]
end

subgraph group_diagnosis["Diagnosis and advisory"]
  node_inference["Leaf inference<br/>[inference.py]"]
  node_diagnosis["Diagnosis orchestration"]
  node_weather["Weather advisory context<br/>[weather_service.py]"]
  node_llm["Agronomic advisory<br/>[llm_service.py]"]
  node_pdf["Localized PDF reports<br/>[pdf_service.py]"]
end

subgraph group_data["Persistence"]
  node_database["Database sessions<br/>[database.py]"]
  node_repositories["Data repositories"]
  node_postgres[("PostgreSQL")]
end

node_farmer(("Farmer"))
node_authprovider(("Clerk"))
node_openmeteo(("Open-Meteo"))
node_groq(("Groq API"))

node_farmer -.->|"uses"| node_web
node_web -.->|"authenticates"| node_authui
node_authui -->|"gets tokens"| node_authprovider
node_authui -->|"syncs identity"| node_authroutes
node_web -.->|"submits scans"| node_diagnosisui
node_diagnosisui -.->|"requests diagnosis"| node_diagnoseroutes
node_web -.->|"manages farms"| node_farmui
node_farmui -.->|"requests farms"| node_farmroutes
node_web -.->|"reviews scans"| node_scanui
node_scanui -.->|"requests history"| node_scanroutes
node_weatherui -.->|"requests weather"| node_farmroutes
node_api -.->|"routes requests"| node_authroutes
node_api -.->|"routes requests"| node_diagnoseroutes
node_api -.->|"routes requests"| node_farmroutes
node_api -.->|"routes requests"| node_scanroutes
node_authroutes -->|"synchronizes user"| node_authservice
node_diagnoseroutes -.->|"requests diagnosis"| node_diagnosis
node_farmroutes -.->|"manages farm data"| node_farmservice
node_scanroutes -->|"gets advisory"| node_diagnosis
node_scanroutes -->|"generates report"| node_pdf
node_diagnosis -->|"classifies image"| node_inference
node_diagnosis -->|"fetches context"| node_weather
node_diagnosis -->|"generates advisory"| node_llm
node_weather -.->|"fetches weather"| node_openmeteo
node_llm -.->|"requests guidance"| node_groq
node_diagnosis -.->|"persists diagnosis"| node_repositories
node_scanroutes -->|"reads scan records"| node_repositories
node_database -->|"opens sessions"| node_postgres
node_repositories -.->|"uses sessions"| node_database
node_dashboard -.->|"reads summaries"| node_repositories

click node_web "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/authService.js"
click node_diagnosisui "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/diagnosisService.js"
click node_farmui "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/farmService.js"
click node_scanui "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/scanService.js"
click node_weatherui "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/weatherService.js"
click node_api "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/main.py"
click node_authroutes "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/auth.py"
click node_diagnoseroutes "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/diagnose.py"
click node_farmroutes "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/farms.py"
click node_scanroutes "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/scans.py"
click node_dashboard "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/dashboard_service.py"
click node_inference "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/inference.py"
click node_diagnosis "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/diagnosis_service.py"
click node_weather "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/weather_service.py"
click node_llm "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/llm_service.py"
click node_pdf "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/pdf_service.py"
click node_farmservice "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/farm_service.py"
click node_authservice "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/auth_service.py"
click node_database "https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/database.py"
click node_repositories "https://github.com/jugal1406/cs26012-crop_disease_detection/tree/main/backend/repositories"

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_web,node_authui,node_diagnosisui,node_farmui,node_scanui,node_weatherui toneBlue
class node_api,node_authroutes,node_diagnoseroutes,node_farmroutes,node_scanroutes,node_dashboard,node_farmservice,node_authservice toneAmber
class node_inference,node_diagnosis,node_weather,node_llm,node_pdf,node_groq toneMint
class node_database,node_repositories,node_postgres toneRose
class node_farmer,node_authprovider,node_openmeteo toneIndigo
```

## Components

### Farmer application

- [React application](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Authentication client](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/authService.js): `frontend/src/services/authService.js`
- [Diagnosis client](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/diagnosisService.js): `frontend/src/services/diagnosisService.js`
- [Farm client](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/farmService.js): `frontend/src/services/farmService.js`
- [Scan client](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/scanService.js): `frontend/src/services/scanService.js`
- [Weather client](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/frontend/src/services/weatherService.js): `frontend/src/services/weatherService.js`

### API and domain services

- [FastAPI application](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/main.py): `backend/main.py`
- [Authentication routes](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/auth.py): `backend/routers/auth.py`
- [Diagnosis routes](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/diagnose.py): `backend/routers/diagnose.py`
- [Farm routes](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/farms.py): `backend/routers/farms.py`
- [Scan routes](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/routers/scans.py): `backend/routers/scans.py`
- [Dashboard service](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/dashboard_service.py): `backend/services/dashboard_service.py`
- [Farm management](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/farm_service.py): `backend/services/farm_service.py`
- [Identity synchronization](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/auth_service.py): `backend/services/auth_service.py`

### Diagnosis and advisory

- [Leaf inference](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/inference.py): `backend/inference.py`
- [Diagnosis orchestration](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/diagnosis_service.py): `backend/services/diagnosis_service.py`
- [Weather advisory context](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/weather_service.py): `backend/services/weather_service.py`
- [Agronomic advisory](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/llm_service.py): `backend/services/llm_service.py`
- [Localized PDF reports](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/services/pdf_service.py): `backend/services/pdf_service.py`

### Persistence

- [Database sessions](https://github.com/jugal1406/cs26012-crop_disease_detection/blob/main/backend/database.py): `backend/database.py`
- [Data repositories](https://github.com/jugal1406/cs26012-crop_disease_detection/tree/main/backend/repositories): `backend/repositories`
- **PostgreSQL**

### Other components

- **Farmer**
- **Clerk**
- **Open-Meteo**
- **Groq API**

## Connections

- Farmer → React application: uses
- React application → Authentication client: authenticates
- Authentication client → Clerk: gets tokens (evidence: `frontend/src/services/authService.js`)
- Authentication client → Authentication routes: syncs identity (evidence: `frontend/src/services/authService.js`)
- React application → Diagnosis client: submits scans
- Diagnosis client → Diagnosis routes: requests diagnosis
- React application → Farm client: manages farms
- Farm client → Farm routes: requests farms
- React application → Scan client: reviews scans
- Scan client → Scan routes: requests history
- Weather client → Farm routes: requests weather
- FastAPI application → Authentication routes: routes requests
- FastAPI application → Diagnosis routes: routes requests
- FastAPI application → Farm routes: routes requests
- FastAPI application → Scan routes: routes requests
- Authentication routes → Identity synchronization: synchronizes user (evidence: `backend/routers/auth.py`)
- Diagnosis routes → Diagnosis orchestration: requests diagnosis
- Farm routes → Farm management: manages farm data
- Scan routes → Diagnosis orchestration: gets advisory (evidence: `backend/routers/scans.py`)
- Scan routes → Localized PDF reports: generates report (evidence: `backend/routers/scans.py`)
- Diagnosis orchestration → Leaf inference: classifies image (evidence: `backend/services/diagnosis_service.py`)
- Diagnosis orchestration → Weather advisory context: fetches context (evidence: `backend/services/diagnosis_service.py`)
- Diagnosis orchestration → Agronomic advisory: generates advisory (evidence: `backend/services/diagnosis_service.py`)
- Weather advisory context → Open-Meteo: fetches weather
- Agronomic advisory → Groq API: requests guidance
- Diagnosis orchestration → Data repositories: persists diagnosis (evidence: `backend/services/diagnosis_service.py`)
- Scan routes → Data repositories: reads scan records (evidence: `backend/routers/scans.py`)
- Database sessions → PostgreSQL: opens sessions (evidence: `backend/database.py`)
- Data repositories → Database sessions: uses sessions
- Dashboard service → Data repositories: reads summaries
