# vbasigamalu/agri-ai architecture

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

- Interactive diagram: https://gitdiagram.com/vbasigamalu/agri-ai
- Repository: https://github.com/vbasigamalu/agri-ai

## Overview

Agri-AI supports a farmer workflow from account access through crop-image disease analysis and advisory, with separate pest monitoring, forecasting, follow-up, outbreak mapping, and expert review capabilities. The graph shows documented UI-to-server entry points and sampled service ownership; unsampled routes and model wiring are represented only where the tree or README supports the subsystem, without guessing internal call chains.

Main entry points: [`backend/server.js`](https://github.com/vbasigamalu/agri-ai/blob/main/backend/server.js) (HTTP API), [`client/src/App.jsx`](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/App.jsx) (Application Shell), [`backend/services/chatbotService.js`](https://github.com/vbasigamalu/agri-ai/blob/main/backend/services/chatbotService.js) (Agricultural Chat), [`backend/routes/pestRoutes.js`](https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/pestRoutes.js) (Pest Endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer Application"]
  node_app["Application Shell<br/>[App.jsx]"]
  node_authui["Sign-in UI<br/>[AuthPage.jsx]"]
  node_diseaseui["Disease Scan UI<br/>[DiseaseTab.jsx]"]
  node_pestui["Pest Monitor UI<br/>[PestTab.jsx]"]
  node_forecastui["Forecast UI<br/>[ForecastTab.jsx]"]
  node_followui["Follow-up UI<br/>[FollowupTab.jsx]"]
  node_historyui["History UI<br/>[HistoryTab.jsx]"]
  node_mapui["Outbreak Map UI<br/>[OutbreakMapTab.jsx]"]
  node_expertui["Expert Review UI<br/>[ExpertTab.jsx]"]
end

subgraph group_analysis["Crop Analysis"]
  node_vision["Vision Pipeline<br/>[index.js]"]
  node_classifier["Disease Classifier<br/>[classifier.js]"]
  node_cropdata["Disease Guidance<br/>[cropDatabase.js]"]
  node_storage["Scan Artifacts<br/>[storage.js]"]
  node_pestroutes["Pest Endpoints<br/>[pestRoutes.js]"]
  node_pestdetect["Pest Detection<br/>[pestDetector.js]"]
end

subgraph group_advisory["Advisory and Risk"]
  node_risk["Risk Engine<br/>[riskEngine.js]"]
  node_forecast["Forecast Endpoints<br/>[forecastRoutes.js]"]
  node_chat["Agricultural Chat<br/>[chatbotService.js]"]
  node_knowledge["Knowledge Service"]
end

subgraph group_operations["Monitoring and Review"]
  node_followservice["Follow-up Service<br/>[followupService.js]"]
  node_spatialroutes["Spatial Endpoints<br/>[spatialRoutes.js]"]
  node_spatial["Spatial Analysis<br/>[spatial.js]"]
  node_expertroutes["Expert Review Endpoints<br/>[expertRoutes.js]"]
  node_queue["Case Queue<br/>[queue.js]"]
end

subgraph group_platform["Backend Services"]
  node_server["HTTP API<br/>[server.js]"]
  node_database["Database Access<br/>[dbHelper.js]"]
  node_mongo[("MongoDB<br/>[postgres.js]")]
end

node_farmer(("Farmer"))
node_weather["Weather API"]
node_groq["Groq AI"]

node_farmer -->|"uses"| node_app
node_app -->|"shows"| node_authui
node_app -->|"shows"| node_diseaseui
node_app -->|"shows"| node_pestui
node_app -->|"shows"| node_forecastui
node_app -->|"shows"| node_followui
node_app -->|"shows"| node_historyui
node_app -->|"shows"| node_mapui
node_app -->|"shows"| node_expertui
node_authui -->|"requests"| node_server
node_diseaseui -->|"submits scan"| node_server
node_server -->|"processes image"| node_vision
node_server -->|"classifies"| node_classifier
node_server -->|"gets guidance"| node_cropdata
node_server -.->|"fetches weather"| node_weather
node_server -->|"persists scan"| node_mongo
node_pestui -->|"requests"| node_pestroutes
node_pestroutes -->|"detects pest"| node_pestdetect
node_pestroutes -->|"stores reports"| node_database
node_forecastui -->|"requests"| node_forecast
node_forecast -->|"computes risk"| node_risk
node_followui -->|"requests"| node_server
node_server -->|"handles follow-up"| node_followservice
node_historyui -->|"requests"| node_server
node_mapui -->|"requests"| node_spatialroutes
node_spatialroutes -->|"queries reports"| node_spatial
node_expertui -->|"requests"| node_expertroutes
node_expertroutes -->|"enqueues cases"| node_queue
node_pestroutes -->|"escalates cases"| node_queue
node_expertroutes -->|"reads and updates"| node_database
node_chat -->|"loads case context"| node_database
node_chat -->|"searches guidance"| node_knowledge
node_chat -.->|"fetches context"| node_weather
node_chat -.->|"requests answer"| node_groq
node_server -.->|"requests chat"| node_groq
node_database -->|"accesses records"| node_mongo
node_vision -->|"saves artifacts"| node_storage

click node_app "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/App.jsx"
click node_authui "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/AuthPage.jsx"
click node_diseaseui "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/DiseaseTab.jsx"
click node_pestui "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/PestTab.jsx"
click node_forecastui "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/ForecastTab.jsx"
click node_followui "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/FollowupTab.jsx"
click node_historyui "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/HistoryTab.jsx"
click node_mapui "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/OutbreakMapTab.jsx"
click node_expertui "https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/ExpertTab.jsx"
click node_server "https://github.com/vbasigamalu/agri-ai/blob/main/backend/server.js"
click node_vision "https://github.com/vbasigamalu/agri-ai/blob/main/backend/vision/index.js"
click node_classifier "https://github.com/vbasigamalu/agri-ai/blob/main/backend/classifier.js"
click node_cropdata "https://github.com/vbasigamalu/agri-ai/blob/main/backend/cropDatabase.js"
click node_storage "https://github.com/vbasigamalu/agri-ai/blob/main/backend/vision/storage.js"
click node_pestroutes "https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/pestRoutes.js"
click node_pestdetect "https://github.com/vbasigamalu/agri-ai/blob/main/backend/pestDetector.js"
click node_risk "https://github.com/vbasigamalu/agri-ai/blob/main/backend/forecasting/riskEngine.js"
click node_forecast "https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/forecastRoutes.js"
click node_chat "https://github.com/vbasigamalu/agri-ai/blob/main/backend/services/chatbotService.js"
click node_knowledge "https://github.com/vbasigamalu/agri-ai/blob/main/backend/services/knowledgeBaseService.js"
click node_followservice "https://github.com/vbasigamalu/agri-ai/blob/main/backend/services/followupService.js"
click node_spatialroutes "https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/spatialRoutes.js"
click node_spatial "https://github.com/vbasigamalu/agri-ai/blob/main/backend/spatial.js"
click node_expertroutes "https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/expertRoutes.js"
click node_queue "https://github.com/vbasigamalu/agri-ai/blob/main/backend/jobs/queue.js"
click node_database "https://github.com/vbasigamalu/agri-ai/blob/main/backend/dbHelper.js"
click node_mongo "https://github.com/vbasigamalu/agri-ai/blob/main/backend/postgres.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_app,node_authui,node_diseaseui,node_pestui,node_forecastui,node_followui,node_historyui,node_mapui,node_expertui toneBlue
class node_vision,node_classifier,node_cropdata,node_storage,node_pestroutes,node_pestdetect toneAmber
class node_risk,node_forecast,node_chat,node_knowledge,node_weather toneMint
class node_followservice,node_spatialroutes,node_spatial,node_expertroutes,node_queue toneRose
class node_server,node_database,node_mongo,node_farmer,node_groq toneIndigo
```

## Components

### Farmer Application

- [Application Shell](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Sign-in UI](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/AuthPage.jsx): `client/src/components/AuthPage.jsx`
- [Disease Scan UI](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/DiseaseTab.jsx): `client/src/components/DiseaseTab.jsx`
- [Pest Monitor UI](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/PestTab.jsx): `client/src/components/PestTab.jsx`
- [Forecast UI](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/ForecastTab.jsx): `client/src/components/ForecastTab.jsx`
- [Follow-up UI](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/FollowupTab.jsx): `client/src/components/FollowupTab.jsx`
- [History UI](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/HistoryTab.jsx): `client/src/components/HistoryTab.jsx`
- [Outbreak Map UI](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/OutbreakMapTab.jsx): `client/src/components/OutbreakMapTab.jsx`
- [Expert Review UI](https://github.com/vbasigamalu/agri-ai/blob/main/client/src/components/ExpertTab.jsx): `client/src/components/ExpertTab.jsx`

### Crop Analysis

- [Vision Pipeline](https://github.com/vbasigamalu/agri-ai/blob/main/backend/vision/index.js): `backend/vision/index.js`
- [Disease Classifier](https://github.com/vbasigamalu/agri-ai/blob/main/backend/classifier.js): `backend/classifier.js`
- [Disease Guidance](https://github.com/vbasigamalu/agri-ai/blob/main/backend/cropDatabase.js): `backend/cropDatabase.js`
- [Scan Artifacts](https://github.com/vbasigamalu/agri-ai/blob/main/backend/vision/storage.js): `backend/vision/storage.js`
- [Pest Endpoints](https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/pestRoutes.js): `backend/routes/pestRoutes.js`
- [Pest Detection](https://github.com/vbasigamalu/agri-ai/blob/main/backend/pestDetector.js): `backend/pestDetector.js`

### Advisory and Risk

- [Risk Engine](https://github.com/vbasigamalu/agri-ai/blob/main/backend/forecasting/riskEngine.js): `backend/forecasting/riskEngine.js`
- [Forecast Endpoints](https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/forecastRoutes.js): `backend/routes/forecastRoutes.js`
- [Agricultural Chat](https://github.com/vbasigamalu/agri-ai/blob/main/backend/services/chatbotService.js): `backend/services/chatbotService.js`
- [Knowledge Service](https://github.com/vbasigamalu/agri-ai/blob/main/backend/services/knowledgeBaseService.js): `backend/services/knowledgeBaseService.js`

### Monitoring and Review

- [Follow-up Service](https://github.com/vbasigamalu/agri-ai/blob/main/backend/services/followupService.js): `backend/services/followupService.js`
- [Spatial Endpoints](https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/spatialRoutes.js): `backend/routes/spatialRoutes.js`
- [Spatial Analysis](https://github.com/vbasigamalu/agri-ai/blob/main/backend/spatial.js): `backend/spatial.js`
- [Expert Review Endpoints](https://github.com/vbasigamalu/agri-ai/blob/main/backend/routes/expertRoutes.js): `backend/routes/expertRoutes.js`
- [Case Queue](https://github.com/vbasigamalu/agri-ai/blob/main/backend/jobs/queue.js): `backend/jobs/queue.js`

### Backend Services

- [HTTP API](https://github.com/vbasigamalu/agri-ai/blob/main/backend/server.js): `backend/server.js`
- [Database Access](https://github.com/vbasigamalu/agri-ai/blob/main/backend/dbHelper.js): `backend/dbHelper.js`
- [MongoDB](https://github.com/vbasigamalu/agri-ai/blob/main/backend/postgres.js): `backend/postgres.js`

### Other components

- **Farmer**
- **Weather API**
- **Groq AI**

## Connections

- Farmer → Application Shell: uses
- Application Shell → Sign-in UI: shows
- Application Shell → Disease Scan UI: shows
- Application Shell → Pest Monitor UI: shows
- Application Shell → Forecast UI: shows
- Application Shell → Follow-up UI: shows
- Application Shell → History UI: shows
- Application Shell → Outbreak Map UI: shows
- Application Shell → Expert Review UI: shows
- Sign-in UI → HTTP API: requests
- Disease Scan UI → HTTP API: submits scan
- HTTP API → Vision Pipeline: processes image
- HTTP API → Disease Classifier: classifies
- HTTP API → Disease Guidance: gets guidance
- HTTP API → Weather API: fetches weather
- HTTP API → MongoDB: persists scan
- Pest Monitor UI → Pest Endpoints: requests
- Pest Endpoints → Pest Detection: detects pest
- Pest Endpoints → Database Access: stores reports
- Forecast UI → Forecast Endpoints: requests
- Forecast Endpoints → Risk Engine: computes risk
- Follow-up UI → HTTP API: requests
- HTTP API → Follow-up Service: handles follow-up
- History UI → HTTP API: requests
- Outbreak Map UI → Spatial Endpoints: requests
- Spatial Endpoints → Spatial Analysis: queries reports
- Expert Review UI → Expert Review Endpoints: requests
- Expert Review Endpoints → Case Queue: enqueues cases
- Pest Endpoints → Case Queue: escalates cases
- Expert Review Endpoints → Database Access: reads and updates
- Agricultural Chat → Database Access: loads case context
- Agricultural Chat → Knowledge Service: searches guidance
- Agricultural Chat → Weather API: fetches context
- Agricultural Chat → Groq AI: requests answer
- HTTP API → Groq AI: requests chat
- Database Access → MongoDB: accesses records
- Vision Pipeline → Scan Artifacts: saves artifacts
