# bharathkumarreddy007/local-rag-chat architecture

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

- Interactive diagram: https://gitdiagram.com/bharathkumarreddy007/local-rag-chat
- Repository: https://github.com/bharathkumarreddy007/local-rag-chat

## Overview

Local RAG Chat is a single-user browser chatbot: users choose general chat or document Q&A, optionally manage/index documents, then receive streamed answers and retrieved excerpts. The backend validates requests, coordinates retrieval and local model calls, while the browser keeps conversation history and supports exports. Its RAG stages include parsing, chunking, embedding, persistent indexing, retrieval, and grounded prompting. The graph reflects the sampled source and README; finer route/UI wiring and some implementation details are documented but not fully excerpted.

Main entry points: [`app/rag.py`](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py) (RAG store), [`app/static/app.js`](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/app.js) (Chat and settings), [`app/main.py`](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/main.py) (Chat orchestration), [`app/static/index.html`](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/index.html) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser experience"]
  node_web_ui["Chat interface<br/>[index.html]"]
  node_browser_logic["Chat and settings<br/>[app.js]"]
  node_chat_history[("Local chat history<br/>[app.js]")]
  node_style["Interface styling<br/>[style.css]"]
end

subgraph group_api["HTTP application"]
  node_http_api["FastAPI routes<br/>[main.py]"]
  node_chat_flow["Chat orchestration<br/>[main.py]"]
  node_compat_api["OpenAI-compatible API<br/>[main.py]"]
end

subgraph group_rag["Retrieval pipeline"]
  node_rag_store["RAG store<br/>[rag.py]"]
  node_document_parser["Document parsing<br/>[rag.py]"]
  node_chunking["Text chunking<br/>[rag.py]"]
  node_embedding["Embedding requests<br/>[rag.py]"]
  node_retrieval["Passage retrieval<br/>[rag.py]"]
  node_grounded_prompt["Grounded prompting<br/>[rag.py]"]
end

subgraph group_integrations["Local services and data"]
  node_vector_index[("Persistent vector index<br/>[rag.py]")]
  node_ollama["Ollama models"]
  node_seed_documents["Included documents"]
end

node_user(("Single user"))

node_user -->|"uses"| node_web_ui
node_web_ui -->|"loads"| node_browser_logic
node_browser_logic -->|"calls"| node_http_api
node_browser_logic -->|"persists"| node_chat_history
node_web_ui -.->|"styles with"| node_style
node_http_api -->|"dispatches"| node_chat_flow
node_http_api -->|"routes to"| node_compat_api
node_chat_flow -->|"retrieves via"| node_rag_store
node_chat_flow -->|"builds prompt"| node_grounded_prompt
node_chat_flow -->|"streams chat"| node_ollama
node_compat_api -->|"reuses"| node_chat_flow
node_rag_store -->|"parses with"| node_document_parser
node_rag_store -->|"splits text"| node_chunking
node_rag_store -->|"embeds chunks"| node_embedding
node_embedding -->|"requests vectors"| node_ollama
node_rag_store -->|"reads and writes"| node_vector_index
node_rag_store -->|"queries"| node_retrieval
node_retrieval -->|"embeds query"| node_embedding
node_retrieval -->|"searches"| node_vector_index
node_http_api -->|"indexes on request"| node_seed_documents
node_browser_logic -->|"requests indexing"| node_seed_documents
node_grounded_prompt -->|"uses passages"| node_retrieval
node_browser_logic -.->|"selects models via API"| node_ollama

click node_web_ui "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/index.html"
click node_browser_logic "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/app.js"
click node_chat_history "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/app.js"
click node_style "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/style.css"
click node_http_api "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/main.py"
click node_chat_flow "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/main.py"
click node_compat_api "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/main.py"
click node_rag_store "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py"
click node_document_parser "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py"
click node_chunking "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py"
click node_embedding "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py"
click node_retrieval "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py"
click node_grounded_prompt "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py"
click node_vector_index "https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py"
click node_seed_documents "https://github.com/bharathkumarreddy007/local-rag-chat/tree/main/data/documents"

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_ui,node_browser_logic,node_chat_history,node_style,node_user toneBlue
class node_http_api,node_chat_flow,node_compat_api toneAmber
class node_rag_store,node_document_parser,node_chunking,node_embedding,node_retrieval,node_grounded_prompt toneMint
class node_vector_index,node_ollama,node_seed_documents toneRose
```

## Components

### Browser experience

- [Chat interface](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/index.html): `app/static/index.html`
- [Chat and settings](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/app.js): `app/static/app.js`
- [Local chat history](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/app.js): `app/static/app.js`
- [Interface styling](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/static/style.css): `app/static/style.css`

### HTTP application

- [FastAPI routes](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/main.py): `app/main.py`
- [Chat orchestration](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/main.py): `app/main.py`
- [OpenAI-compatible API](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/main.py): `app/main.py`

### Retrieval pipeline

- [RAG store](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py): `app/rag.py`
- [Document parsing](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py): `app/rag.py`
- [Text chunking](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py): `app/rag.py`
- [Embedding requests](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py): `app/rag.py`
- [Passage retrieval](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py): `app/rag.py`
- [Grounded prompting](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py): `app/rag.py`

### Local services and data

- [Persistent vector index](https://github.com/bharathkumarreddy007/local-rag-chat/blob/main/app/rag.py): `app/rag.py`
- **Ollama models**
- [Included documents](https://github.com/bharathkumarreddy007/local-rag-chat/tree/main/data/documents): `data/documents`

### Other components

- **Single user**

## Connections

- Single user → Chat interface: uses (evidence: `README.md`)
- Chat interface → Chat and settings: loads
- Chat and settings → FastAPI routes: calls (evidence: `app/static/app.js`)
- Chat and settings → Local chat history: persists (evidence: `app/static/app.js`)
- Chat interface → Interface styling: styles with
- FastAPI routes → Chat orchestration: dispatches (evidence: `app/main.py`)
- FastAPI routes → OpenAI-compatible API: routes to (evidence: `app/main.py`)
- Chat orchestration → RAG store: retrieves via (evidence: `app/main.py`)
- Chat orchestration → Grounded prompting: builds prompt (evidence: `app/main.py`)
- Chat orchestration → Ollama models: streams chat (evidence: `app/main.py`)
- OpenAI-compatible API → Chat orchestration: reuses (evidence: `app/main.py`)
- RAG store → Document parsing: parses with (evidence: `app/rag.py`)
- RAG store → Text chunking: splits text (evidence: `app/rag.py`)
- RAG store → Embedding requests: embeds chunks (evidence: `app/rag.py`)
- Embedding requests → Ollama models: requests vectors (evidence: `app/rag.py`)
- RAG store → Persistent vector index: reads and writes (evidence: `app/rag.py`)
- RAG store → Passage retrieval: queries (evidence: `app/rag.py`)
- Passage retrieval → Embedding requests: embeds query (evidence: `app/rag.py`)
- Passage retrieval → Persistent vector index: searches (evidence: `app/rag.py`)
- FastAPI routes → Included documents: indexes on request (evidence: `app/main.py`)
- Chat and settings → Included documents: requests indexing (evidence: `app/static/app.js`)
- Grounded prompting → Passage retrieval: uses passages (evidence: `app/rag.py`)
- Chat and settings → Ollama models: selects models via API
