# goutampatel18/nyaybandhu architecture

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

- Interactive diagram: https://gitdiagram.com/goutampatel18/nyaybandhu
- Repository: https://github.com/goutampatel18/nyaybandhu

## Overview

NyayBandhu is a React legal-information site backed by a FastAPI service and a local RAG assistant. The main workflow is a user asking a legal question, the frontend sending it to the chatbot API, and the backend retrieving relevant material before generating an answer. A separate ingestion workflow loads documents, chunks them, builds the FAISS index, and records document and embedding metadata. The README describes the overall retrieval-and-generation flow; unsampled chatbot internals and frontend API wiring are not asserted as verified calls.

Main entry points: [`backend/app/rag/pipeline.py`](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/pipeline.py) (Ingestion orchestrator), [`backend/app/main.py`](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/main.py) (FastAPI application), [`frontend/src/App.tsx`](https://github.com/goutampatel18/nyaybandhu/blob/main/frontend/src/App.tsx) (React application), [`backend/app/routes/documents.py`](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/documents.py) (Document endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["React application<br/>[App.tsx]"]
  node_routes["Page routes<br/>[appRoutes.tsx]"]
  node_chat_ui["Chat interface<br/>[Chatbot.tsx]"]
end

subgraph group_api["Backend API"]
  node_api_main["FastAPI application<br/>[main.py]"]
  node_chat_route["Chat endpoint<br/>[chatbot.py]"]
  node_document_route["Document endpoints<br/>[documents.py]"]
  node_library_route["Library endpoint<br/>[library.py]"]
  node_health_route["Health endpoint<br/>[health.py]"]
  node_document_service["Document operations<br/>[documents.py]"]
end

subgraph group_ingest["Document ingestion"]
  node_ingestion["Ingestion orchestrator<br/>[pipeline.py]"]
  node_loader["Document loader<br/>[loader.py]"]
  node_chunker["Text chunker<br/>[chunker.py]"]
end

subgraph group_rag["Retrieval and generation"]
  node_vector_store[("FAISS index<br/>[vector_store.py]")]
  node_embeddings["Embedding model<br/>[embeddings.py]"]
  node_answer_chain["Answer generation<br/>[chain.py]"]
end

subgraph group_data["Persistent data"]
  node_db_init["Database initialization<br/>[init_db.py]"]
  node_db_session["Database sessions<br/>[session.py]"]
  node_documents[("Document records<br/>[document.py]")]
  node_embedding_metadata[("Embedding metadata")]
  node_library_records[("Library records<br/>[library.py]")]
end

node_user(("Legal information seeker"))

node_user -->|"uses"| node_app
node_app -->|"renders"| node_routes
node_user -.->|"asks questions"| node_chat_ui
node_chat_ui -.->|"sends chat request"| node_chat_route
node_app -.->|"calls backend"| node_api_main
node_api_main -->|"registers"| node_chat_route
node_api_main -->|"registers"| node_document_route
node_api_main -->|"registers"| node_library_route
node_api_main -->|"registers"| node_health_route
node_api_main -->|"initializes"| node_db_init
node_chat_route -->|"uses"| node_db_session
node_document_route -->|"triggers"| node_ingestion
node_document_route -->|"delegates to"| node_document_service
node_document_service -->|"may ingest"| node_ingestion
node_ingestion -->|"loads files"| node_loader
node_ingestion -->|"chunks text"| node_chunker
node_ingestion -->|"builds and saves"| node_vector_store
node_vector_store -->|"uses"| node_embeddings
node_ingestion -->|"updates records"| node_documents
node_ingestion -->|"writes metadata"| node_embedding_metadata
node_db_init -->|"opens sessions"| node_db_session
node_db_init -->|"seeds reference data"| node_library_records
node_answer_chain -.->|"retrieves context"| node_vector_store
node_answer_chain -.->|"returns answer"| node_user

click node_app "https://github.com/goutampatel18/nyaybandhu/blob/main/frontend/src/App.tsx"
click node_routes "https://github.com/goutampatel18/nyaybandhu/blob/main/frontend/src/routes/appRoutes.tsx"
click node_chat_ui "https://github.com/goutampatel18/nyaybandhu/blob/main/frontend/src/components/Chatbot.tsx"
click node_api_main "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/main.py"
click node_chat_route "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/chatbot.py"
click node_document_route "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/documents.py"
click node_library_route "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/library.py"
click node_health_route "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/health.py"
click node_document_service "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/services/documents.py"
click node_ingestion "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/pipeline.py"
click node_loader "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/loader.py"
click node_chunker "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/chunker.py"
click node_vector_store "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/vector_store.py"
click node_embeddings "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/embeddings.py"
click node_answer_chain "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/chain.py"
click node_db_init "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/db/init_db.py"
click node_db_session "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/db/session.py"
click node_documents "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/models/document.py"
click node_embedding_metadata "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/models/embedding_metadata.py"
click node_library_records "https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/models/library.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_routes,node_chat_ui toneBlue
class node_api_main,node_chat_route,node_document_route,node_library_route,node_health_route,node_document_service toneAmber
class node_ingestion,node_loader,node_chunker toneMint
class node_vector_store,node_embeddings,node_answer_chain toneRose
class node_db_init,node_db_session,node_documents,node_embedding_metadata,node_library_records,node_user toneIndigo
```

## Components

### Web application

- [React application](https://github.com/goutampatel18/nyaybandhu/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Page routes](https://github.com/goutampatel18/nyaybandhu/blob/main/frontend/src/routes/appRoutes.tsx): `frontend/src/routes/appRoutes.tsx`
- [Chat interface](https://github.com/goutampatel18/nyaybandhu/blob/main/frontend/src/components/Chatbot.tsx): `frontend/src/components/Chatbot.tsx`

### Backend API

- [FastAPI application](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/main.py): `backend/app/main.py`
- [Chat endpoint](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/chatbot.py): `backend/app/routes/chatbot.py`
- [Document endpoints](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/documents.py): `backend/app/routes/documents.py`
- [Library endpoint](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/library.py): `backend/app/routes/library.py`
- [Health endpoint](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/routes/health.py): `backend/app/routes/health.py`
- [Document operations](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/services/documents.py): `backend/app/services/documents.py`

### Document ingestion

- [Ingestion orchestrator](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/pipeline.py): `backend/app/rag/pipeline.py`
- [Document loader](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/loader.py): `backend/app/rag/loader.py`
- [Text chunker](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/chunker.py): `backend/app/rag/chunker.py`

### Retrieval and generation

- [FAISS index](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/vector_store.py): `backend/app/rag/vector_store.py`
- [Embedding model](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/embeddings.py): `backend/app/rag/embeddings.py`
- [Answer generation](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/rag/chain.py): `backend/app/rag/chain.py`

### Persistent data

- [Database initialization](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/db/init_db.py): `backend/app/db/init_db.py`
- [Database sessions](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/db/session.py): `backend/app/db/session.py`
- [Document records](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/models/document.py): `backend/app/models/document.py`
- [Embedding metadata](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/models/embedding_metadata.py): `backend/app/models/embedding_metadata.py`
- [Library records](https://github.com/goutampatel18/nyaybandhu/blob/main/backend/app/models/library.py): `backend/app/models/library.py`

### Other components

- **Legal information seeker**

## Connections

- Legal information seeker → React application: uses (evidence: `README.md`)
- React application → Page routes: renders (evidence: `frontend/src/App.tsx`)
- Legal information seeker → Chat interface: asks questions
- Chat interface → Chat endpoint: sends chat request
- React application → FastAPI application: calls backend (evidence: `README.md`)
- FastAPI application → Chat endpoint: registers (evidence: `backend/app/main.py`)
- FastAPI application → Document endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI application → Library endpoint: registers (evidence: `backend/app/main.py`)
- FastAPI application → Health endpoint: registers (evidence: `backend/app/main.py`)
- FastAPI application → Database initialization: initializes (evidence: `backend/app/main.py`)
- Chat endpoint → Database sessions: uses (evidence: `backend/app/routes/chatbot.py`)
- Document endpoints → Ingestion orchestrator: triggers (evidence: `backend/app/routes/documents.py`)
- Document endpoints → Document operations: delegates to (evidence: `backend/app/routes/documents.py`)
- Document operations → Ingestion orchestrator: may ingest (evidence: `backend/app/services/documents.py`)
- Ingestion orchestrator → Document loader: loads files (evidence: `backend/app/rag/pipeline.py`)
- Ingestion orchestrator → Text chunker: chunks text (evidence: `backend/app/rag/pipeline.py`)
- Ingestion orchestrator → FAISS index: builds and saves (evidence: `backend/app/rag/pipeline.py`)
- FAISS index → Embedding model: uses (evidence: `backend/app/rag/vector_store.py`)
- Ingestion orchestrator → Document records: updates records (evidence: `backend/app/rag/pipeline.py`)
- Ingestion orchestrator → Embedding metadata: writes metadata (evidence: `backend/app/rag/pipeline.py`)
- Database initialization → Database sessions: opens sessions (evidence: `backend/app/db/init_db.py`)
- Database initialization → Library records: seeds reference data (evidence: `backend/app/db/init_db.py`)
- Answer generation → FAISS index: retrieves context (evidence: `README.md`)
- Answer generation → Legal information seeker: returns answer (evidence: `README.md`)
