# rajshekharbind/smart-agriculture-query-and-advisory-system architecture

> Architecture diagram of the GitHub repository rajshekharbind/smart-agriculture-query-and-advisory-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rajshekharbind/smart-agriculture-query-and-advisory-system
- Repository: https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system

## Overview

AgroSathi AI is a mobile-first agricultural assistance platform. Farmers use its React interface to access advisory chat, voice, document Q&A, and farm-planning tools; the interface calls a FastAPI backend that routes requests to ML, language-model, retrieval, and persistent-data services. The README also documents disease, soil, crop/seed, pest, weather, market, schemes, and community capabilities, represented here as capability areas. Some page and router implementations were not sampled, so their internal call paths are not asserted.

Main entry points: [`backend/app/main.py`](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/main.py) (FastAPI entry), [`backend/app/llm.py`](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/llm.py) (LLM wrapper), [`frontend/src/App.jsx`](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/App.jsx) (App shell), [`backend/app/routers/auth.py`](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/auth.py) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer interface"]
  node_app["App shell<br/>[App.jsx]"]
  node_pages["Farm pages"]
  node_chatui["Chat page<br/>[ChatPage.jsx]"]
  node_chatcontext["Chat state<br/>[ChatContext.jsx]"]
  node_documentcontext["Document state"]
  node_services["API services"]
  node_api_client["HTTP client<br/>[api.js]"]
end

subgraph group_api["API and identity"]
  node_backend["FastAPI entry<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_security["Security controls<br/>[security.py]"]
end

subgraph group_intelligence["AI and retrieval"]
  node_ml["ML services<br/>[ml_services.py]"]
  node_prediction["Disease prediction<br/>[prediction.py]"]
  node_llm["LLM wrapper<br/>[llm.py]"]
  node_processor["Document extraction"]
  node_rag["RAG search<br/>[local_faiss.py]"]
end

subgraph group_farm["Farm capabilities"]
  node_agri_router["Agriculture routes<br/>[agri_info.py]"]
  node_tools_router["AI tool routes<br/>[ai_tools.py]"]
  node_farm_router["Farm operations<br/>[farm_ops.py]"]
  node_docs_router["Document and voice<br/>[documents_voice.py]"]
  node_other_capabilities["Chat, weather, markets, schemes, calendar, profit, guides, community"]
end

subgraph group_state["Persistent state"]
  node_db[("Application database<br/>[database.py]")]
end

node_farmer(("Farmer"))

node_farmer -->|"uses"| node_app
node_app -->|"displays"| node_pages
node_app -->|"checks health"| node_api_client
node_chatui -->|"uses state"| node_chatcontext
node_chatcontext -->|"requests chat"| node_services
node_documentcontext -->|"requests documents"| node_services
node_services -->|"sends requests"| node_api_client
node_api_client -->|"calls API"| node_backend
node_backend -->|"registers router"| node_auth
node_backend -->|"registers router"| node_agri_router
node_backend -->|"registers router"| node_tools_router
node_backend -->|"registers router"| node_farm_router
node_backend -->|"registers router"| node_docs_router
node_auth -->|"reads and writes"| node_db
node_auth -->|"authenticates"| node_security
node_agri_router -->|"requests guidance"| node_llm
node_tools_router -->|"invokes models"| node_ml
node_tools_router -->|"validates uploads"| node_security
node_docs_router -->|"uses retrieval"| node_rag
node_docs_router -->|"validates uploads"| node_security
node_farm_router -->|"reads and writes"| node_db
node_ml -->|"generates advice"| node_llm
node_prediction -->|"uses vision advice"| node_llm
node_rag -.->|"answers with context"| node_llm
node_processor -.->|"prepares documents"| node_rag
node_farmer -->|"uses"| node_other_capabilities

click node_app "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/App.jsx"
click node_pages "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/tree/main/frontend/src/pages"
click node_chatui "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/pages/ChatPage.jsx"
click node_chatcontext "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/context/ChatContext.jsx"
click node_documentcontext "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/context/DocumentContext.jsx"
click node_services "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/tree/main/frontend/src/services"
click node_api_client "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/services/api.js"
click node_backend "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/main.py"
click node_auth "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/auth.py"
click node_security "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/security.py"
click node_agri_router "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/agri_info.py"
click node_tools_router "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/ai_tools.py"
click node_farm_router "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/farm_ops.py"
click node_docs_router "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/documents_voice.py"
click node_ml "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/models/ml_services.py"
click node_prediction "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/models/prediction.py"
click node_llm "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/llm.py"
click node_processor "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/rag/document_processor.py"
click node_rag "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/rag/local_faiss.py"
click node_db "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/database.py"
click node_other_capabilities "https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/tree/main/frontend/src/pages"

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_pages,node_chatui,node_chatcontext,node_documentcontext,node_services,node_api_client toneBlue
class node_backend,node_auth,node_security toneAmber
class node_ml,node_prediction,node_llm,node_processor,node_rag toneMint
class node_agri_router,node_tools_router,node_farm_router,node_docs_router,node_other_capabilities toneRose
class node_db,node_farmer toneIndigo
```

## Components

### Farmer interface

- [App shell](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Farm pages](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/tree/main/frontend/src/pages): `frontend/src/pages`
- [Chat page](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/pages/ChatPage.jsx): `frontend/src/pages/ChatPage.jsx`
- [Chat state](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/context/ChatContext.jsx): `frontend/src/context/ChatContext.jsx`
- [Document state](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/context/DocumentContext.jsx): `frontend/src/context/DocumentContext.jsx`
- [API services](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/tree/main/frontend/src/services): `frontend/src/services`
- [HTTP client](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### API and identity

- [FastAPI entry](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Security controls](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/security.py): `backend/app/security.py`

### AI and retrieval

- [ML services](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/models/ml_services.py): `backend/app/models/ml_services.py`
- [Disease prediction](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/models/prediction.py): `backend/app/models/prediction.py`
- [LLM wrapper](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/llm.py): `backend/app/llm.py`
- [Document extraction](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/rag/document_processor.py): `backend/app/rag/document_processor.py`
- [RAG search](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/rag/local_faiss.py): `backend/app/rag/local_faiss.py`

### Farm capabilities

- [Agriculture routes](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/agri_info.py): `backend/app/routers/agri_info.py`
- [AI tool routes](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/ai_tools.py): `backend/app/routers/ai_tools.py`
- [Farm operations](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/farm_ops.py): `backend/app/routers/farm_ops.py`
- [Document and voice](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/routers/documents_voice.py): `backend/app/routers/documents_voice.py`
- [Chat, weather, markets, schemes, calendar, profit, guides, community](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/tree/main/frontend/src/pages): `frontend/src/pages`

### Persistent state

- [Application database](https://github.com/rajshekharbind/smart-agriculture-query-and-advisory-system/blob/main/backend/app/database.py): `backend/app/database.py`

### Other components

- **Farmer**

## Connections

- Farmer → App shell: uses
- App shell → Farm pages: displays (evidence: `frontend/src/App.jsx`)
- App shell → HTTP client: checks health (evidence: `frontend/src/App.jsx`)
- Chat page → Chat state: uses state (evidence: `frontend/src/pages/ChatPage.jsx`)
- Chat state → API services: requests chat (evidence: `frontend/src/context/ChatContext.jsx`)
- Document state → API services: requests documents (evidence: `frontend/src/context/DocumentContext.jsx`)
- API services → HTTP client: sends requests (evidence: `frontend/src/services/agriService.js`)
- HTTP client → FastAPI entry: calls API (evidence: `frontend/src/services/api.js`)
- FastAPI entry → Authentication: registers router (evidence: `backend/app/main.py`)
- FastAPI entry → Agriculture routes: registers router (evidence: `backend/app/main.py`)
- FastAPI entry → AI tool routes: registers router (evidence: `backend/app/main.py`)
- FastAPI entry → Farm operations: registers router (evidence: `backend/app/main.py`)
- FastAPI entry → Document and voice: registers router (evidence: `backend/app/main.py`)
- Authentication → Application database: reads and writes (evidence: `backend/app/routers/auth.py`)
- Authentication → Security controls: authenticates (evidence: `backend/app/routers/auth.py`)
- Agriculture routes → LLM wrapper: requests guidance (evidence: `backend/app/routers/agri_info.py`)
- AI tool routes → ML services: invokes models (evidence: `backend/app/routers/ai_tools.py`)
- AI tool routes → Security controls: validates uploads (evidence: `backend/app/routers/ai_tools.py`)
- Document and voice → RAG search: uses retrieval (evidence: `backend/app/routers/documents_voice.py`)
- Document and voice → Security controls: validates uploads (evidence: `backend/app/routers/documents_voice.py`)
- Farm operations → Application database: reads and writes (evidence: `backend/app/routers/farm_ops.py`)
- ML services → LLM wrapper: generates advice (evidence: `backend/app/models/ml_services.py`)
- Disease prediction → LLM wrapper: uses vision advice (evidence: `backend/app/models/prediction.py`)
- RAG search → LLM wrapper: answers with context (evidence: `backend/app/rag/local_faiss.py`)
- Document extraction → RAG search: prepares documents
- Farmer → Chat, weather, markets, schemes, calendar, profit, guides, community: uses
