# dsaiteja007/kisan-ai-sahayak architecture

> Architecture diagram of the GitHub repository dsaiteja007/kisan-ai-sahayak, 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/dsaiteja007/kisan-ai-sahayak
- Repository: https://github.com/dsaiteja007/kisan-ai-sahayak

## Overview

Sampurn Kisan AI is an agricultural assistant with a web interface and a FastAPI service. The principal chat workflow hydrates farmer context, runs an agent orchestrator, formats a cited response, and updates memory. The interface also exposes crop, fertilizer, weather, market, soil, satellite, and government-scheme features. Sampled source confirms memory and document-ingestion internals; several API and agent subsystems are represented by tree paths only, so their internal wiring is not inferred.

Main entry points: [`src/memory/manager.py`](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/manager.py) (Memory manager), [`src/services/chat_service.py`](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/services/chat_service.py) (Chat service), [`src/rag/ingestion.py`](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/ingestion.py) (Document ingestion), [`frontend/src/App.jsx`](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/frontend/src/App.jsx) (Web application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Farmer interface"]
  node_web["Web application<br/>[App.jsx]"]
  node_global["Shared farm context<br/>[GlobalContext.jsx]"]
  node_pages["Farming feature pages"]
end

subgraph group_api["API service"]
  node_weather_api["Weather endpoint<br/>[agriculture.py]"]
  node_fastapi["FastAPI application<br/>[app.py]"]
  node_chat_api["Chat endpoint<br/>[chat.py]"]
  node_agriculture_api["Agriculture endpoints<br/>[agriculture.py]"]
end

subgraph group_agent["Assistant runtime"]
  node_chat_service["Chat service<br/>[chat_service.py]"]
  node_orchestrator["Agent orchestrator<br/>[graph.py]"]
  node_agent_nodes["Agent nodes<br/>[nodes.py]"]
  node_router["Intent routing"]
  node_tools["Agriculture tools"]
  node_tool_registry["Tool registry<br/>[registry.py]"]
  node_prompts["Prompt construction<br/>[builder.py]"]
  node_llm["LLM providers"]
end

subgraph group_knowledge["Knowledge and memory"]
  node_memory_manager["Memory manager<br/>[manager.py]"]
  node_working_memory["Working memory<br/>[working_memory.py]"]
  node_short_memory["Short-term memory<br/>[short_term.py]"]
  node_long_memory["Long-term memory<br/>[long_term.py]"]
  node_semantic_memory["Semantic memory<br/>[semantic_memory.py]"]
  node_summarizer["History summarizer<br/>[summarizer.py]"]
  node_ingestion["Document ingestion<br/>[ingestion.py]"]
  node_retrieval["Document retrieval<br/>[retriever.py]"]
  node_vector_store[("Vector store<br/>[vector_store.py]")]
  node_embeddings["Embedding manager<br/>[embeddings.py]"]
  node_splitter["Text splitter<br/>[text_splitter.py]"]
end

subgraph group_integrations["Agriculture integrations"]
  node_api_clients["Agriculture API clients"]
end

node_farmer(("Farmer"))
node_external_services["Agriculture data services"]

node_farmer -->|"uses"| node_web
node_web -->|"routes to"| node_pages
node_web -->|"provides context"| node_global
node_global -->|"fetches weather"| node_weather_api
node_farmer -->|"API requests"| node_fastapi
node_fastapi -->|"mounts routes"| node_chat_api
node_fastapi -->|"mounts routes"| node_agriculture_api
node_chat_api -->|"processes chat"| node_chat_service
node_chat_service -->|"hydrates and updates"| node_memory_manager
node_chat_service -->|"executes"| node_orchestrator
node_chat_service -->|"returns response"| node_farmer
node_memory_manager -->|"reads and writes"| node_short_memory
node_memory_manager -->|"reads and writes"| node_long_memory
node_memory_manager -->|"reads and writes"| node_semantic_memory
node_memory_manager -->|"checks history"| node_summarizer
node_memory_manager -->|"hydrates"| node_working_memory
node_orchestrator -->|"dispatches"| node_agent_nodes
node_ingestion -->|"splits text"| node_splitter
node_ingestion -->|"creates vectors"| node_embeddings
node_ingestion -->|"upserts documents"| node_vector_store
node_api_clients -->|"calls APIs"| node_external_services

click node_web "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/frontend/src/App.jsx"
click node_global "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/frontend/src/context/GlobalContext.jsx"
click node_pages "https://github.com/dsaiteja007/kisan-ai-sahayak/tree/main/frontend/src/pages"
click node_weather_api "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/api/v1/agriculture.py"
click node_fastapi "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/api/app.py"
click node_chat_api "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/api/v1/chat.py"
click node_agriculture_api "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/api/v1/agriculture.py"
click node_chat_service "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/services/chat_service.py"
click node_orchestrator "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/orchestrator/graph.py"
click node_agent_nodes "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/orchestrator/nodes.py"
click node_router "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/orchestrator/router_interface.py"
click node_tools "https://github.com/dsaiteja007/kisan-ai-sahayak/tree/main/src/tools/implementations"
click node_tool_registry "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/tools/registry.py"
click node_prompts "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/prompts/builder.py"
click node_llm "https://github.com/dsaiteja007/kisan-ai-sahayak/tree/main/src/llm/providers"
click node_memory_manager "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/manager.py"
click node_working_memory "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/working_memory.py"
click node_short_memory "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/short_term.py"
click node_long_memory "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/long_term.py"
click node_semantic_memory "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/semantic_memory.py"
click node_summarizer "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/summarizer.py"
click node_ingestion "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/ingestion.py"
click node_retrieval "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/retriever.py"
click node_vector_store "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/vector_store.py"
click node_embeddings "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/embeddings.py"
click node_splitter "https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/text_splitter.py"
click node_api_clients "https://github.com/dsaiteja007/kisan-ai-sahayak/tree/main/src/integrations"

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_global,node_pages toneBlue
class node_weather_api,node_fastapi,node_chat_api,node_agriculture_api toneAmber
class node_chat_service,node_orchestrator,node_agent_nodes,node_router,node_tools,node_tool_registry,node_prompts,node_llm toneMint
class node_memory_manager,node_working_memory,node_short_memory,node_long_memory,node_semantic_memory,node_summarizer,node_ingestion,node_retrieval,node_vector_store,node_embeddings,node_splitter toneRose
class node_api_clients,node_farmer,node_external_services toneIndigo
```

## Components

### Farmer interface

- [Web application](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Shared farm context](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/frontend/src/context/GlobalContext.jsx): `frontend/src/context/GlobalContext.jsx`
- [Farming feature pages](https://github.com/dsaiteja007/kisan-ai-sahayak/tree/main/frontend/src/pages): `frontend/src/pages`

### API service

- [Weather endpoint](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/api/v1/agriculture.py): `src/api/v1/agriculture.py`
- [FastAPI application](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/api/app.py): `src/api/app.py`
- [Chat endpoint](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/api/v1/chat.py): `src/api/v1/chat.py`
- [Agriculture endpoints](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/api/v1/agriculture.py): `src/api/v1/agriculture.py`

### Assistant runtime

- [Chat service](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/services/chat_service.py): `src/services/chat_service.py`
- [Agent orchestrator](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/orchestrator/graph.py): `src/orchestrator/graph.py`
- [Agent nodes](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/orchestrator/nodes.py): `src/orchestrator/nodes.py`
- [Intent routing](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/orchestrator/router_interface.py): `src/orchestrator/router_interface.py`
- [Agriculture tools](https://github.com/dsaiteja007/kisan-ai-sahayak/tree/main/src/tools/implementations): `src/tools/implementations`
- [Tool registry](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/tools/registry.py): `src/tools/registry.py`
- [Prompt construction](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/prompts/builder.py): `src/prompts/builder.py`
- [LLM providers](https://github.com/dsaiteja007/kisan-ai-sahayak/tree/main/src/llm/providers): `src/llm/providers`

### Knowledge and memory

- [Memory manager](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/manager.py): `src/memory/manager.py`
- [Working memory](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/working_memory.py): `src/memory/working_memory.py`
- [Short-term memory](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/short_term.py): `src/memory/short_term.py`
- [Long-term memory](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/long_term.py): `src/memory/long_term.py`
- [Semantic memory](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/semantic_memory.py): `src/memory/semantic_memory.py`
- [History summarizer](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/memory/summarizer.py): `src/memory/summarizer.py`
- [Document ingestion](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/ingestion.py): `src/rag/ingestion.py`
- [Document retrieval](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/retriever.py): `src/rag/retriever.py`
- [Vector store](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/vector_store.py): `src/rag/vector_store.py`
- [Embedding manager](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/embeddings.py): `src/rag/embeddings.py`
- [Text splitter](https://github.com/dsaiteja007/kisan-ai-sahayak/blob/main/src/rag/text_splitter.py): `src/rag/text_splitter.py`

### Agriculture integrations

- [Agriculture API clients](https://github.com/dsaiteja007/kisan-ai-sahayak/tree/main/src/integrations): `src/integrations`

### Other components

- **Farmer**
- **Agriculture data services**

## Connections

- Farmer → Web application: uses
- Web application → Farming feature pages: routes to
- Web application → Shared farm context: provides context
- Shared farm context → Weather endpoint: fetches weather
- Farmer → FastAPI application: API requests
- FastAPI application → Chat endpoint: mounts routes
- FastAPI application → Agriculture endpoints: mounts routes
- Chat endpoint → Chat service: processes chat
- Chat service → Memory manager: hydrates and updates
- Chat service → Agent orchestrator: executes
- Chat service → Farmer: returns response
- Memory manager → Short-term memory: reads and writes
- Memory manager → Long-term memory: reads and writes
- Memory manager → Semantic memory: reads and writes
- Memory manager → History summarizer: checks history
- Memory manager → Working memory: hydrates
- Agent orchestrator → Agent nodes: dispatches
- Document ingestion → Text splitter: splits text
- Document ingestion → Embedding manager: creates vectors
- Document ingestion → Vector store: upserts documents
- Agriculture API clients → Agriculture data services: calls APIs
