# kushagrittan/sahaybot architecture

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

- Interactive diagram: https://gitdiagram.com/kushagrittan/sahaybot
- Repository: https://github.com/kushagrittan/sahaybot

## Overview

SahayBot is a bilingual cooperative-governance and legal-assistance chatbot. A user submits text or browser-recognized speech through the chat UI; the app calls the FastAPI query endpoint, which retrieves document context from Chroma and uses Ollama to generate a grounded answer with source metadata. Users can also upload PDFs: the API invokes ingestion, which loads and chunks documents, embeds them, and updates the vector store. The README also describes Hindi/English voice interaction and page citations. The map reflects sampled source; unsampled UI and runtime details are represented only where documented.

Main entry points: [`backend/ingest.py`](https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py) (Ingestion pipeline), [`backend/main.py`](https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py) (FastAPI endpoints), [`frontend/src/App.tsx`](https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/App.tsx) (Chat app), [`frontend/src/services/api.ts`](https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/services/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat interface"]
  node_input["Message input<br/>[MessageInput.tsx]"]
  node_app["Chat app<br/>[App.tsx]"]
  node_chat["Chat display<br/>[ChatWindow.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API orchestration"]
  node_fastapi["FastAPI endpoints<br/>[main.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_ingest["Ingestion pipeline<br/>[ingest.py]"]
  node_pdfs["PDF documents<br/>[.gitkeep]"]
  node_pdf_loader["PDF loading<br/>[ingest.py]"]
  node_chunker["Text chunking<br/>[ingest.py]"]
  node_embedder["Multilingual embeddings<br/>[ingest.py]"]
  node_manifest["Ingestion manifest<br/>[ingest.py]"]
end

subgraph group_answering["Grounded answering"]
  node_vector_store[("Chroma vector store<br/>[main.py]")]
  node_retrieval["Retrieval QA<br/>[main.py]"]
  node_prompt["Grounding prompt<br/>[main.py]"]
  node_answer["Answer and sources<br/>[main.py]"]
end

node_user(("User"))
node_speech["Browser speech APIs"]
node_ollama["Ollama LLM"]

node_user -->|"enters question"| node_input
node_input -->|"sends text"| node_app
node_input -.->|"uses speech input"| node_speech
node_app -.->|"speaks answer"| node_speech
node_app -->|"renders messages"| node_chat
node_app -->|"requests query or upload"| node_api_client
node_api_client -->|"calls endpoint"| node_fastapi
node_fastapi -->|"invokes ingestion"| node_ingest
node_ingest -->|"reads PDFs"| node_pdfs
node_ingest -->|"reads and updates hashes"| node_manifest
node_ingest -->|"loads pages"| node_pdf_loader
node_ingest -->|"splits documents"| node_chunker
node_ingest -->|"creates embeddings"| node_embedder
node_ingest -->|"adds chunks"| node_vector_store
node_fastapi -->|"opens store"| node_vector_store
node_fastapi -->|"builds and invokes chain"| node_retrieval
node_retrieval -->|"retrieves context"| node_vector_store
node_fastapi -->|"configures grounding"| node_prompt
node_retrieval -->|"generates answer"| node_ollama
node_fastapi -->|"packages answer and citations"| node_answer
node_answer -->|"returns response"| node_api_client
node_api_client -->|"returns data"| node_app

click node_input "https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/components/MessageInput.tsx"
click node_app "https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/App.tsx"
click node_chat "https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/components/ChatWindow.tsx"
click node_api_client "https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/services/api.ts"
click node_fastapi "https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py"
click node_ingest "https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py"
click node_pdfs "https://github.com/kushagrittan/sahaybot/blob/main/data/.gitkeep"
click node_pdf_loader "https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py"
click node_chunker "https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py"
click node_embedder "https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py"
click node_manifest "https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py"
click node_vector_store "https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py"
click node_retrieval "https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py"
click node_prompt "https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py"
click node_answer "https://github.com/kushagrittan/sahaybot/blob/main/backend/main.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_input,node_app,node_chat,node_api_client,node_user,node_speech toneBlue
class node_fastapi toneAmber
class node_ingest,node_pdfs,node_pdf_loader,node_chunker,node_embedder,node_manifest toneMint
class node_vector_store,node_retrieval,node_prompt,node_answer toneRose
class node_ollama toneIndigo
```

## Components

### Chat interface

- [Message input](https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/components/MessageInput.tsx): `frontend/src/components/MessageInput.tsx`
- [Chat app](https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Chat display](https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/components/ChatWindow.tsx): `frontend/src/components/ChatWindow.tsx`
- [API client](https://github.com/kushagrittan/sahaybot/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`

### API orchestration

- [FastAPI endpoints](https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py): `backend/main.py`

### Document ingestion

- [Ingestion pipeline](https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py): `backend/ingest.py`
- [PDF documents](https://github.com/kushagrittan/sahaybot/blob/main/data/.gitkeep): `data/.gitkeep`
- [PDF loading](https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py): `backend/ingest.py`
- [Text chunking](https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py): `backend/ingest.py`
- [Multilingual embeddings](https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py): `backend/ingest.py`
- [Ingestion manifest](https://github.com/kushagrittan/sahaybot/blob/main/backend/ingest.py): `backend/ingest.py`

### Grounded answering

- [Chroma vector store](https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py): `backend/main.py`
- [Retrieval QA](https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py): `backend/main.py`
- [Grounding prompt](https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py): `backend/main.py`
- [Answer and sources](https://github.com/kushagrittan/sahaybot/blob/main/backend/main.py): `backend/main.py`

### Other components

- **User**
- **Browser speech APIs**
- **Ollama LLM**

## Connections

- User → Message input: enters question
- Message input → Chat app: sends text
- Message input → Browser speech APIs: uses speech input
- Chat app → Browser speech APIs: speaks answer
- Chat app → Chat display: renders messages
- Chat app → API client: requests query or upload
- API client → FastAPI endpoints: calls endpoint
- FastAPI endpoints → Ingestion pipeline: invokes ingestion
- Ingestion pipeline → PDF documents: reads PDFs
- Ingestion pipeline → Ingestion manifest: reads and updates hashes
- Ingestion pipeline → PDF loading: loads pages
- Ingestion pipeline → Text chunking: splits documents
- Ingestion pipeline → Multilingual embeddings: creates embeddings
- Ingestion pipeline → Chroma vector store: adds chunks
- FastAPI endpoints → Chroma vector store: opens store
- FastAPI endpoints → Retrieval QA: builds and invokes chain
- Retrieval QA → Chroma vector store: retrieves context
- FastAPI endpoints → Grounding prompt: configures grounding
- Retrieval QA → Ollama LLM: generates answer
- FastAPI endpoints → Answer and sources: packages answer and citations
- Answer and sources → API client: returns response
- API client → Chat app: returns data
