# gouravagarwal2716/agronex-ai architecture

> Architecture diagram of the GitHub repository gouravagarwal2716/agronex-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gouravagarwal2716/agronex-ai
- Repository: https://github.com/gouravagarwal2716/agronex-ai

## Overview

Agronex AI is a farmer-facing crop intelligence and parametric-insurance platform. Farmers register, submit a leaf photo and location, and receive a diagnosis, damage and spread estimates, grounded advice, and follow-up actions. The backend pipeline orchestrates the documented model stages; the web app also exposes scan history, alerts, insights, crop recommendations, voice/chat assistance, and claim PDFs. Several route and model implementations were not excerpted, so those capabilities and stage links rely on README documentation rather than inspected route code.

Main entry points: [`backend/app/services/pipeline.py`](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/pipeline.py) (Analysis pipeline), [`frontend/src/App.jsx`](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/App.jsx) (Web application), [`frontend/src/services/api.js`](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/services/api.js) (API client), [`backend/app/main.py`](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Farmer web app"]
  node_app["Web application<br/>[App.jsx]"]
  node_onboarding["Welcome and onboarding<br/>[Onboarding.jsx]"]
  node_scan_page["Scan submission<br/>[Scan.jsx]"]
  node_results["Results and claim view<br/>[Results.jsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.jsx]"]
  node_history_page["History and insights<br/>[History.jsx]"]
  node_bot["Kisan Mitra chat<br/>[AgriBotWidget.jsx]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["Backend API"]
  node_backend["FastAPI application<br/>[main.py]"]
  node_scan_routes["Scan and chat routes<br/>[scan.py]"]
  node_history_routes["History and alert routes"]
  node_insurance["Insurance claims<br/>[insurance.py]"]
  node_whatsapp["WhatsApp dispatch<br/>[whatsapp.py]"]
end

subgraph group_analysis["Crop analysis"]
  node_pipeline["Analysis pipeline<br/>[pipeline.py]"]
  node_gatekeeper["Leaf gatekeeper<br/>[gatekeeper.py]"]
  node_segmentation["Lesion segmentation<br/>[segmentation.py]"]
  node_classifier["Disease classifier<br/>[classifier.py]"]
  node_location["Weather and soil context<br/>[location.py]"]
  node_forecast["Spread forecasting<br/>[forecaster.py]"]
  node_yield["Yield loss estimate<br/>[yield_estimator.py]"]
  node_fusion["Risk fusion and urgency<br/>[fusion.py]"]
  node_urgency["Urgency scoring<br/>[urgency_scorer.py]"]
  node_presymptomatic["Early risk model<br/>[presymptomatic.py]"]
end

subgraph group_services["Advisory services"]
  node_rag["Grounded advisory<br/>[rag.py]"]
  node_voice["Regional voice<br/>[voice.py]"]
  node_recommendations["Crop recommendations"]
  node_rag_store[("FAISS knowledge index")]
end

subgraph group_persistence["Identity and records"]
  node_auth["Authentication routes<br/>[auth.py]"]
  node_security["Token security<br/>[security.py]"]
  node_crud["Record operations<br/>[crud.py]"]
  node_models["Database models<br/>[models.py]"]
  node_session[("Database session<br/>[session.py]")]
end

node_farmer(("Farmer"))
node_weather_services["Weather and soil APIs"]

node_farmer -->|"uses"| node_app
node_app -->|"routes to"| node_onboarding
node_app -->|"routes to"| node_scan_page
node_app -->|"routes to"| node_results
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_history_page
node_app -->|"renders"| node_bot
node_onboarding -.->|"uses"| node_api_client
node_scan_page -.->|"submits scan"| node_api_client
node_results -->|"requests scan"| node_api_client
node_bot -->|"sends chat"| node_api_client
node_api_client -->|"calls API"| node_backend
node_backend -.->|"registers routes"| node_scan_routes
node_backend -.->|"registers routes"| node_history_routes
node_backend -.->|"registers routes"| node_insurance
node_scan_routes -.->|"runs analysis"| node_pipeline
node_pipeline -->|"validates image"| node_gatekeeper
node_pipeline -->|"measures lesions"| node_segmentation
node_pipeline -->|"classifies disease"| node_classifier
node_pipeline -->|"fetches context"| node_location
node_location -.->|"queries"| node_weather_services
node_pipeline -->|"forecasts spread"| node_forecast
node_pipeline -->|"estimates loss"| node_yield
node_pipeline -->|"fuses risk"| node_fusion
node_pipeline -->|"scores urgency"| node_urgency
node_pipeline -->|"uses model"| node_presymptomatic
node_pipeline -->|"generates advice"| node_rag
node_rag -->|"retrieves guidance"| node_rag_store
node_pipeline -->|"generates speech"| node_voice
node_pipeline -->|"dispatches report"| node_whatsapp
node_scan_routes -.->|"offers crops"| node_recommendations
node_history_page -->|"loads records"| node_api_client
node_results -->|"downloads claim"| node_insurance
node_onboarding -->|"registers or logs in"| node_auth
node_auth -->|"reads and creates"| node_crud
node_auth -->|"creates token"| node_security
node_auth -->|"uses database session"| node_session
node_session -->|"initializes tables"| node_models
node_crud -.->|"persists records"| node_models

click node_app "https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/App.jsx"
click node_onboarding "https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/Onboarding.jsx"
click node_scan_page "https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/Scan.jsx"
click node_results "https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/Results.jsx"
click node_dashboard "https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/Dashboard.jsx"
click node_history_page "https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/History.jsx"
click node_bot "https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/components/chat/AgriBotWidget.jsx"
click node_api_client "https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/services/api.js"
click node_backend "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/main.py"
click node_scan_routes "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/scan.py"
click node_history_routes "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/history_alerts_insights.py"
click node_insurance "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/insurance.py"
click node_whatsapp "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/whatsapp.py"
click node_pipeline "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/pipeline.py"
click node_gatekeeper "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/gatekeeper.py"
click node_segmentation "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/segmentation.py"
click node_classifier "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/classifier.py"
click node_location "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/location.py"
click node_forecast "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/forecaster.py"
click node_yield "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/yield_estimator.py"
click node_fusion "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/fusion.py"
click node_urgency "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/urgency_scorer.py"
click node_presymptomatic "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/presymptomatic.py"
click node_rag "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/rag.py"
click node_voice "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/voice.py"
click node_recommendations "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/crop_recommendation.py"
click node_auth "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/auth.py"
click node_security "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/core/security.py"
click node_crud "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/database/crud.py"
click node_models "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/database/models.py"
click node_session "https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/database/session.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_onboarding,node_scan_page,node_results,node_dashboard,node_history_page,node_bot,node_api_client toneBlue
class node_backend,node_scan_routes,node_history_routes,node_insurance,node_whatsapp toneAmber
class node_pipeline,node_gatekeeper,node_segmentation,node_classifier,node_location,node_forecast,node_yield,node_fusion,node_urgency,node_presymptomatic,node_weather_services toneMint
class node_rag,node_voice,node_recommendations,node_rag_store toneRose
class node_auth,node_security,node_crud,node_models,node_session,node_farmer toneIndigo
```

## Components

### Farmer web app

- [Web application](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Welcome and onboarding](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/Onboarding.jsx): `frontend/src/pages/Onboarding.jsx`
- [Scan submission](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/Scan.jsx): `frontend/src/pages/Scan.jsx`
- [Results and claim view](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/Results.jsx): `frontend/src/pages/Results.jsx`
- [Dashboard](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [History and insights](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/pages/History.jsx): `frontend/src/pages/History.jsx`
- [Kisan Mitra chat](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/components/chat/AgriBotWidget.jsx): `frontend/src/components/chat/AgriBotWidget.jsx`
- [API client](https://github.com/gouravagarwal2716/agronex-ai/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Backend API

- [FastAPI application](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Scan and chat routes](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/scan.py): `backend/app/api/routes/scan.py`
- [History and alert routes](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/history_alerts_insights.py): `backend/app/api/routes/history_alerts_insights.py`
- [Insurance claims](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/insurance.py): `backend/app/api/routes/insurance.py`
- [WhatsApp dispatch](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/whatsapp.py): `backend/app/api/routes/whatsapp.py`

### Crop analysis

- [Analysis pipeline](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/pipeline.py): `backend/app/services/pipeline.py`
- [Leaf gatekeeper](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/gatekeeper.py): `backend/app/models/inference/gatekeeper.py`
- [Lesion segmentation](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/segmentation.py): `backend/app/models/inference/segmentation.py`
- [Disease classifier](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/classifier.py): `backend/app/models/inference/classifier.py`
- [Weather and soil context](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/location.py): `backend/app/services/location.py`
- [Spread forecasting](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/forecaster.py): `backend/app/models/inference/forecaster.py`
- [Yield loss estimate](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/yield_estimator.py): `backend/app/models/inference/yield_estimator.py`
- [Risk fusion and urgency](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/fusion.py): `backend/app/models/inference/fusion.py`
- [Urgency scoring](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/urgency_scorer.py): `backend/app/models/inference/urgency_scorer.py`
- [Early risk model](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/models/inference/presymptomatic.py): `backend/app/models/inference/presymptomatic.py`

### Advisory services

- [Grounded advisory](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/rag.py): `backend/app/services/rag.py`
- [Regional voice](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/voice.py): `backend/app/services/voice.py`
- [Crop recommendations](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/services/crop_recommendation.py): `backend/app/services/crop_recommendation.py`
- **FAISS knowledge index**

### Identity and records

- [Authentication routes](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/api/routes/auth.py): `backend/app/api/routes/auth.py`
- [Token security](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Record operations](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/database/crud.py): `backend/app/database/crud.py`
- [Database models](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/database/models.py): `backend/app/database/models.py`
- [Database session](https://github.com/gouravagarwal2716/agronex-ai/blob/main/backend/app/database/session.py): `backend/app/database/session.py`

### Other components

- **Farmer**
- **Weather and soil APIs**

## Connections

- Farmer → Web application: uses
- Web application → Welcome and onboarding: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Scan submission: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Results and claim view: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Web application → History and insights: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Kisan Mitra chat: renders (evidence: `frontend/src/App.jsx`)
- Welcome and onboarding → API client: uses
- Scan submission → API client: submits scan
- Results and claim view → API client: requests scan (evidence: `frontend/src/pages/Results.jsx`)
- Kisan Mitra chat → API client: sends chat (evidence: `frontend/src/components/chat/AgriBotWidget.jsx`)
- API client → FastAPI application: calls API (evidence: `frontend/src/services/api.js`)
- FastAPI application → Scan and chat routes: registers routes
- FastAPI application → History and alert routes: registers routes
- FastAPI application → Insurance claims: registers routes
- Scan and chat routes → Analysis pipeline: runs analysis
- Analysis pipeline → Leaf gatekeeper: validates image (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → Lesion segmentation: measures lesions (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → Disease classifier: classifies disease (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → Weather and soil context: fetches context (evidence: `backend/app/services/pipeline.py`)
- Weather and soil context → Weather and soil APIs: queries
- Analysis pipeline → Spread forecasting: forecasts spread (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → Yield loss estimate: estimates loss (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → Risk fusion and urgency: fuses risk (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → Urgency scoring: scores urgency (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → Early risk model: uses model (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → Grounded advisory: generates advice (evidence: `backend/app/services/pipeline.py`)
- Grounded advisory → FAISS knowledge index: retrieves guidance (evidence: `backend/app/services/rag.py`)
- Analysis pipeline → Regional voice: generates speech (evidence: `backend/app/services/pipeline.py`)
- Analysis pipeline → WhatsApp dispatch: dispatches report (evidence: `backend/app/services/pipeline.py`)
- Scan and chat routes → Crop recommendations: offers crops
- History and insights → API client: loads records (evidence: `frontend/src/services/api.js`)
- Results and claim view → Insurance claims: downloads claim
- Welcome and onboarding → Authentication routes: registers or logs in
- Authentication routes → Record operations: reads and creates (evidence: `backend/app/api/routes/auth.py`)
- Authentication routes → Token security: creates token (evidence: `backend/app/api/routes/auth.py`)
- Authentication routes → Database session: uses database session (evidence: `backend/app/api/routes/auth.py`)
- Database session → Database models: initializes tables (evidence: `backend/app/database/session.py`)
- Record operations → Database models: persists records
