# pranav-singhal-0403/local-model-router architecture

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

- Interactive diagram: https://gitdiagram.com/pranav-singhal-0403/local-model-router
- Repository: https://github.com/pranav-singhal-0403/local-model-router

## Overview

Local Model Router is a PDF-grounded chat application. Users upload PDFs to build an indexed knowledge base, ask questions in a conversation, and receive answers with document/page sources and latency details; they can also manage documents and saved chats. The graph separates frontend, API and persistence, and retrieval/generation responsibilities. The sampled code shows ingestion and chat orchestration; some document and application-state wiring is unsampled, so those links are omitted or marked unverified.

Main entry points: [`backend`](https://github.com/pranav-singhal-0403/local-model-router/tree/main/backend) (Retrieval strategies), [`backend/ingestion_pipeline.py`](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/ingestion_pipeline.py) (PDF ingestion), [`frontend/src/services/api.js`](https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/services/api.js) (HTTP client), [`backend/api/chat.py`](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/chat.py) (Chat endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web interface"]
  node_app["Workspace<br/>[App.jsx]"]
  node_chatui["Chat window<br/>[ChatWindow.jsx]"]
  node_docui["Document library"]
  node_message["Message view<br/>[Message.jsx]"]
  node_sourcecard["Source card<br/>[SourceCard.jsx]"]
  node_client["HTTP client<br/>[api.js]"]
end

subgraph group_api["API and history"]
  node_chatapi["Chat endpoint<br/>[chat.py]"]
  node_documentsapi["Document endpoints<br/>[documents.py]"]
  node_historyapi["History endpoints<br/>[history.py]"]
  node_healthapi["Health endpoint<br/>[health.py]"]
  node_history["Chat history service<br/>[chat_history.py]"]
  node_database["PostgreSQL access<br/>[database.py]"]
end

subgraph group_rag["RAG processing"]
  node_state["RAG application state<br/>[app_state.py]"]
  node_ingestion["PDF ingestion"]
  node_parser["PDF parser<br/>[pdf_parser.py]"]
  node_chunker["Text chunker<br/>[chunker.py]"]
  node_dense["Dense embeddings"]
  node_splade["SPLADE embeddings"]
  node_retrievers["Retrieval strategies"]
  node_generator["Answer generation"]
  node_prompt["Prompt builder<br/>[prompt_builder.py]"]
  node_ollama_client["Ollama client<br/>[ollama_client.py]"]
  node_qdrant_client["Vector store client<br/>[qdrant_client.py]"]
end

subgraph group_services["External services"]
  node_qdrant[("Qdrant")]
  node_postgres[("PostgreSQL")]
  node_ollama["Ollama model service"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_app -->|"shows chat"| node_chatui
node_app -->|"shows library"| node_docui
node_app -->|"manages chats"| node_client
node_chatui -->|"sends requests"| node_client
node_chatui -->|"renders messages"| node_message
node_chatui -->|"renders sources"| node_sourcecard
node_docui -->|"manages documents"| node_client
node_client -->|"posts chat"| node_chatapi
node_client -->|"calls document routes"| node_documentsapi
node_client -->|"calls history routes"| node_historyapi
node_client -->|"checks health"| node_healthapi
node_chatapi -->|"uses RAG state"| node_state
node_chatapi -->|"loads and saves"| node_history
node_chatapi -->|"retrieves chunks"| node_retrievers
node_chatapi -->|"generates answer"| node_generator
node_historyapi -->|"manages conversations"| node_history
node_history -->|"uses connections"| node_database
node_database -.->|"reads and writes"| node_postgres
node_documentsapi -.->|"indexes uploads"| node_ingestion
node_ingestion -->|"extracts pages"| node_parser
node_ingestion -->|"splits text"| node_chunker
node_ingestion -->|"encodes chunks"| node_dense
node_ingestion -->|"encodes chunks"| node_splade
node_ingestion -->|"upserts vectors"| node_qdrant_client
node_retrievers -->|"embeds queries"| node_dense
node_retrievers -->|"embeds queries"| node_splade
node_retrievers -->|"searches vectors"| node_qdrant_client
node_retrievers -->|"searches vectors"| node_qdrant_client
node_retrievers -->|"combines results"| node_retrievers
node_qdrant_client -.->|"stores and searches"| node_qdrant
node_generator -->|"builds prompt"| node_prompt
node_generator -->|"requests completion"| node_ollama_client
node_ollama_client -.->|"runs inference"| node_ollama
node_state -.->|"configures pipeline"| node_ingestion
node_state -.->|"configures retrieval"| node_retrievers

click node_app "https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/App.jsx"
click node_chatui "https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/components/ChatWindow.jsx"
click node_docui "https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/components/DocuemntLibrary.jsx"
click node_message "https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/components/Message.jsx"
click node_sourcecard "https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/components/SourceCard.jsx"
click node_client "https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/services/api.js"
click node_chatapi "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/chat.py"
click node_documentsapi "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/documents.py"
click node_historyapi "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/history.py"
click node_healthapi "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/health.py"
click node_state "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/app_state.py"
click node_ingestion "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/ingestion_pipeline.py"
click node_parser "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/pdf_parser.py"
click node_chunker "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/chunker.py"
click node_dense "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/embeddings_dense.py"
click node_splade "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/embeddings_splade.py"
click node_retrievers "https://github.com/pranav-singhal-0403/local-model-router/tree/main/backend"
click node_generator "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/answer_generator.py"
click node_prompt "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/prompt_builder.py"
click node_ollama_client "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/ollama_client.py"
click node_qdrant_client "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/qdrant_client.py"
click node_history "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/chat_history.py"
click node_database "https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/database.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_chatui,node_docui,node_message,node_sourcecard,node_client,node_user toneBlue
class node_chatapi,node_documentsapi,node_historyapi,node_healthapi,node_history,node_database toneAmber
class node_state,node_ingestion,node_parser,node_chunker,node_dense,node_splade,node_retrievers,node_generator,node_prompt,node_ollama_client,node_qdrant_client toneMint
class node_qdrant,node_postgres,node_ollama toneRose
```

## Components

### Web interface

- [Workspace](https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Chat window](https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/components/ChatWindow.jsx): `frontend/src/components/ChatWindow.jsx`
- [Document library](https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/components/DocuemntLibrary.jsx): `frontend/src/components/DocuemntLibrary.jsx`
- [Message view](https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/components/Message.jsx): `frontend/src/components/Message.jsx`
- [Source card](https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/components/SourceCard.jsx): `frontend/src/components/SourceCard.jsx`
- [HTTP client](https://github.com/pranav-singhal-0403/local-model-router/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### API and history

- [Chat endpoint](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/chat.py): `backend/api/chat.py`
- [Document endpoints](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/documents.py): `backend/api/documents.py`
- [History endpoints](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/history.py): `backend/api/history.py`
- [Health endpoint](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/api/health.py): `backend/api/health.py`
- [Chat history service](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/chat_history.py): `backend/chat_history.py`
- [PostgreSQL access](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/database.py): `backend/database.py`

### RAG processing

- [RAG application state](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/app_state.py): `backend/app_state.py`
- [PDF ingestion](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/ingestion_pipeline.py): `backend/ingestion_pipeline.py`
- [PDF parser](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/pdf_parser.py): `backend/pdf_parser.py`
- [Text chunker](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/chunker.py): `backend/chunker.py`
- [Dense embeddings](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/embeddings_dense.py): `backend/embeddings_dense.py`
- [SPLADE embeddings](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/embeddings_splade.py): `backend/embeddings_splade.py`
- [Retrieval strategies](https://github.com/pranav-singhal-0403/local-model-router/tree/main/backend): `backend`
- [Answer generation](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/answer_generator.py): `backend/answer_generator.py`
- [Prompt builder](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/prompt_builder.py): `backend/prompt_builder.py`
- [Ollama client](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/ollama_client.py): `backend/ollama_client.py`
- [Vector store client](https://github.com/pranav-singhal-0403/local-model-router/blob/main/backend/qdrant_client.py): `backend/qdrant_client.py`

### External services

- **Qdrant**
- **PostgreSQL**
- **Ollama model service**

### Other components

- **User**

## Connections

- User → Workspace: uses (evidence: `README.md`)
- Workspace → Chat window: shows chat (evidence: `frontend/src/App.jsx`)
- Workspace → Document library: shows library (evidence: `frontend/src/App.jsx`)
- Workspace → HTTP client: manages chats (evidence: `frontend/src/App.jsx`)
- Chat window → HTTP client: sends requests (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat window → Message view: renders messages (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat window → Source card: renders sources (evidence: `frontend/src/components/ChatWindow.jsx`)
- Document library → HTTP client: manages documents (evidence: `frontend/src/components/DocuemntLibrary.jsx`)
- HTTP client → Chat endpoint: posts chat (evidence: `frontend/src/services/api.js`)
- HTTP client → Document endpoints: calls document routes (evidence: `frontend/src/services/api.js`)
- HTTP client → History endpoints: calls history routes (evidence: `frontend/src/services/api.js`)
- HTTP client → Health endpoint: checks health (evidence: `frontend/src/services/api.js`)
- Chat endpoint → RAG application state: uses RAG state (evidence: `backend/api/chat.py`)
- Chat endpoint → Chat history service: loads and saves (evidence: `backend/api/chat.py`)
- Chat endpoint → Retrieval strategies: retrieves chunks (evidence: `backend/api/chat.py`)
- Chat endpoint → Answer generation: generates answer (evidence: `backend/api/chat.py`)
- History endpoints → Chat history service: manages conversations (evidence: `backend/main.py`)
- Chat history service → PostgreSQL access: uses connections (evidence: `backend/chat_history.py`)
- PostgreSQL access → PostgreSQL: reads and writes (evidence: `README.md`)
- Document endpoints → PDF ingestion: indexes uploads
- PDF ingestion → PDF parser: extracts pages (evidence: `backend/ingestion_pipeline.py`)
- PDF ingestion → Text chunker: splits text (evidence: `backend/ingestion_pipeline.py`)
- PDF ingestion → Dense embeddings: encodes chunks (evidence: `backend/ingestion_pipeline.py`)
- PDF ingestion → SPLADE embeddings: encodes chunks (evidence: `backend/ingestion_pipeline.py`)
- PDF ingestion → Vector store client: upserts vectors (evidence: `backend/ingestion_pipeline.py`)
- Retrieval strategies → Dense embeddings: embeds queries (evidence: `backend/retreiver_dense.py`)
- Retrieval strategies → SPLADE embeddings: embeds queries (evidence: `backend/retriever_splade.py`)
- Retrieval strategies → Vector store client: searches vectors (evidence: `backend/retreiver_dense.py`)
- Retrieval strategies → Vector store client: searches vectors (evidence: `backend/retriever_splade.py`)
- Retrieval strategies → Retrieval strategies: combines results (evidence: `backend/retriever_hybrid.py`)
- Vector store client → Qdrant: stores and searches (evidence: `README.md`)
- Answer generation → Prompt builder: builds prompt (evidence: `backend/answer_generator.py`)
- Answer generation → Ollama client: requests completion (evidence: `backend/answer_generator.py`)
- Ollama client → Ollama model service: runs inference (evidence: `README.md`)
- RAG application state → PDF ingestion: configures pipeline
- RAG application state → Retrieval strategies: configures retrieval (evidence: `backend/main.py`)
