# sm-joe/localrag architecture

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

- Interactive diagram: https://gitdiagram.com/sm-joe/localrag
- Repository: https://github.com/sm-joe/localrag

## Overview

LocalRAG is a Docker-first local document RAG chatbot with persistent conversation history. The main workflow is browser upload or chat, FastAPI routing, document indexing or retrieval-grounded generation, and results with citations; PostgreSQL persists conversations while Qdrant stores document vectors. The graph preserves the documented UI, filename-aware retrieval, and conversation capabilities. Some route internals are only partly excerpted, so edges that rely on documented rather than sampled behavior cite the README.

Main entry points: [`apps/api/app/services/ingestion.py`](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/ingestion.py) (Ingestion service), [`apps/web/app/page.tsx`](https://github.com/sm-joe/localrag/blob/main/apps/web/app/page.tsx) (Web workspace), [`apps/api/app/main.py`](https://github.com/sm-joe/localrag/blob/main/apps/api/app/main.py) (FastAPI app), [`apps/api/app/routes/chat.py`](https://github.com/sm-joe/localrag/blob/main/apps/api/app/routes/chat.py) (Chat endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Web interface"]
  node_web["Web workspace<br/>[page.tsx]"]
end

subgraph group_api["API and history"]
  node_api_entry["FastAPI app<br/>[main.py]"]
  node_chat_route["Chat endpoint<br/>[chat.py]"]
  node_conversation_route["Conversation management<br/>[conversations.py]"]
  node_document_route["Document endpoints<br/>[documents.py]"]
  node_db_access["Database access<br/>[db.py]"]
  node_conversation_models["History models<br/>[models.py]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_indexing["Document indexing"]
  node_ingestion["Ingestion service<br/>[ingestion.py]"]
  node_parser["Document parser<br/>[parser.py]"]
  node_chunker["Text chunker<br/>[chunker.py]"]
  node_embedding["Embedding service<br/>[embeddings.py]"]
  node_vector_store["Vector store<br/>[vector_store.py]"]
  node_qdrant[("Qdrant")]
end

subgraph group_answers["Grounded answers"]
  node_rag["RAG orchestration<br/>[rag.py]"]
  node_retrieval["Document retrieval<br/>[retrieval.py]"]
  node_llm["LLM service<br/>[llm.py]"]
  node_ollama["Local Ollama"]
end

node_browser(("Browser user"))

node_browser -->|"uses"| node_web
node_web -->|"calls API"| node_api_entry
node_api_entry -->|"registers"| node_document_route
node_api_entry -->|"registers"| node_chat_route
node_api_entry -->|"registers"| node_conversation_route
node_document_route -->|"indexes uploads"| node_ingestion
node_ingestion -->|"parses files"| node_parser
node_ingestion -->|"chunks text"| node_chunker
node_ingestion -->|"embeds chunks"| node_embedding
node_ingestion -->|"stores vectors"| node_vector_store
node_embedding -->|"requests embeddings"| node_ollama
node_vector_store -->|"reads and writes"| node_qdrant
node_chat_route -->|"requests answer"| node_rag
node_rag -->|"retrieves evidence"| node_retrieval
node_rag -->|"generates answer"| node_llm
node_retrieval -->|"embeds query"| node_embedding
node_retrieval -->|"searches vectors"| node_vector_store
node_llm -->|"generates locally"| node_ollama
node_chat_route -->|"persists history"| node_db_access
node_conversation_route -->|"manages history"| node_postgres
node_chat_route -->|"records messages"| node_conversation_models
node_conversation_route -->|"manages records"| node_conversation_models
node_db_access -->|"connects"| node_postgres
node_web -->|"uploads and lists"| node_document_route
node_web -->|"restores history"| node_conversation_route

click node_web "https://github.com/sm-joe/localrag/blob/main/apps/web/app/page.tsx"
click node_api_entry "https://github.com/sm-joe/localrag/blob/main/apps/api/app/main.py"
click node_chat_route "https://github.com/sm-joe/localrag/blob/main/apps/api/app/routes/chat.py"
click node_conversation_route "https://github.com/sm-joe/localrag/blob/main/apps/api/app/routes/conversations.py"
click node_document_route "https://github.com/sm-joe/localrag/blob/main/apps/api/app/routes/documents.py"
click node_db_access "https://github.com/sm-joe/localrag/blob/main/apps/api/app/db.py"
click node_conversation_models "https://github.com/sm-joe/localrag/blob/main/apps/api/app/models.py"
click node_ingestion "https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/ingestion.py"
click node_parser "https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/parser.py"
click node_chunker "https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/chunker.py"
click node_embedding "https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/embeddings.py"
click node_vector_store "https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/vector_store.py"
click node_rag "https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/rag.py"
click node_retrieval "https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/retrieval.py"
click node_llm "https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/llm.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_web,node_browser toneBlue
class node_api_entry,node_chat_route,node_conversation_route,node_document_route,node_db_access,node_conversation_models,node_postgres toneAmber
class node_ingestion,node_parser,node_chunker,node_embedding,node_vector_store,node_qdrant toneMint
class node_rag,node_retrieval,node_llm,node_ollama toneRose
```

## Components

### Web interface

- [Web workspace](https://github.com/sm-joe/localrag/blob/main/apps/web/app/page.tsx): `apps/web/app/page.tsx`

### API and history

- [FastAPI app](https://github.com/sm-joe/localrag/blob/main/apps/api/app/main.py): `apps/api/app/main.py`
- [Chat endpoint](https://github.com/sm-joe/localrag/blob/main/apps/api/app/routes/chat.py): `apps/api/app/routes/chat.py`
- [Conversation management](https://github.com/sm-joe/localrag/blob/main/apps/api/app/routes/conversations.py): `apps/api/app/routes/conversations.py`
- [Document endpoints](https://github.com/sm-joe/localrag/blob/main/apps/api/app/routes/documents.py): `apps/api/app/routes/documents.py`
- [Database access](https://github.com/sm-joe/localrag/blob/main/apps/api/app/db.py): `apps/api/app/db.py`
- [History models](https://github.com/sm-joe/localrag/blob/main/apps/api/app/models.py): `apps/api/app/models.py`
- **PostgreSQL**

### Document indexing

- [Ingestion service](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/ingestion.py): `apps/api/app/services/ingestion.py`
- [Document parser](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/parser.py): `apps/api/app/services/parser.py`
- [Text chunker](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/chunker.py): `apps/api/app/services/chunker.py`
- [Embedding service](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/embeddings.py): `apps/api/app/services/embeddings.py`
- [Vector store](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/vector_store.py): `apps/api/app/services/vector_store.py`
- **Qdrant**

### Grounded answers

- [RAG orchestration](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/rag.py): `apps/api/app/services/rag.py`
- [Document retrieval](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/retrieval.py): `apps/api/app/services/retrieval.py`
- [LLM service](https://github.com/sm-joe/localrag/blob/main/apps/api/app/services/llm.py): `apps/api/app/services/llm.py`
- **Local Ollama**

### Other components

- **Browser user**

## Connections

- Browser user → Web workspace: uses (evidence: `README.md`)
- Web workspace → FastAPI app: calls API (evidence: `README.md`)
- FastAPI app → Document endpoints: registers (evidence: `apps/api/app/main.py`)
- FastAPI app → Chat endpoint: registers (evidence: `apps/api/app/main.py`)
- FastAPI app → Conversation management: registers (evidence: `apps/api/app/main.py`)
- Document endpoints → Ingestion service: indexes uploads (evidence: `README.md`)
- Ingestion service → Document parser: parses files (evidence: `apps/api/app/services/ingestion.py`)
- Ingestion service → Text chunker: chunks text (evidence: `apps/api/app/services/ingestion.py`)
- Ingestion service → Embedding service: embeds chunks (evidence: `apps/api/app/services/ingestion.py`)
- Ingestion service → Vector store: stores vectors (evidence: `apps/api/app/services/ingestion.py`)
- Embedding service → Local Ollama: requests embeddings (evidence: `apps/api/app/services/embeddings.py`)
- Vector store → Qdrant: reads and writes (evidence: `README.md`)
- Chat endpoint → RAG orchestration: requests answer (evidence: `apps/api/app/routes/chat.py`)
- RAG orchestration → Document retrieval: retrieves evidence (evidence: `apps/api/app/services/rag.py`)
- RAG orchestration → LLM service: generates answer (evidence: `apps/api/app/services/rag.py`)
- Document retrieval → Embedding service: embeds query (evidence: `apps/api/app/services/retrieval.py`)
- Document retrieval → Vector store: searches vectors (evidence: `apps/api/app/services/retrieval.py`)
- LLM service → Local Ollama: generates locally (evidence: `apps/api/app/services/llm.py`)
- Chat endpoint → Database access: persists history (evidence: `apps/api/app/routes/chat.py`)
- Conversation management → PostgreSQL: manages history (evidence: `README.md`)
- Chat endpoint → History models: records messages (evidence: `apps/api/app/routes/chat.py`)
- Conversation management → History models: manages records (evidence: `README.md`)
- Database access → PostgreSQL: connects (evidence: `apps/api/app/db.py`)
- Web workspace → Document endpoints: uploads and lists (evidence: `README.md`)
- Web workspace → Conversation management: restores history (evidence: `README.md`)
