# theothernico27/rag-doc-qa architecture

> Architecture diagram of the GitHub repository theothernico27/rag-doc-qa, 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/theothernico27/rag-doc-qa
- Repository: https://github.com/theothernico27/rag-doc-qa

## Overview

RAG Document Q&A ingests one text-based PDF at a time, extracts page text, chunks it with page metadata, embeds the chunks locally, and replaces the stored vectors. For questions, the server embeds the query, retrieves the top matching passages, builds a constrained prompt, and asks a local LLM to answer from those passages. The UI presents the answer alongside retrieved excerpts, page numbers, and similarity scores. The route and core library excerpts support the wiring shown; persistence is an in-memory store backed by a JSON file, as documented.

Main entry points: [`app/api/query/route.ts`](https://github.com/theothernico27/rag-doc-qa/blob/main/app/api/query/route.ts) (Query route), [`app/api/upload/route.ts`](https://github.com/theothernico27/rag-doc-qa/blob/main/app/api/upload/route.ts) (Upload route), [`app/page.tsx`](https://github.com/theothernico27/rag-doc-qa/blob/main/app/page.tsx) (Upload and Q&A), [`src/lib/embeddings.ts`](https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/embeddings.ts) (Embedding client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser UI"]
  node_ui["Upload and Q&amp;A<br/>[page.tsx]"]
end

subgraph group_api["API routes"]
  node_upload["Upload route<br/>[route.ts]"]
  node_query["Query route<br/>[route.ts]"]
end

subgraph group_rag["RAG pipeline"]
  node_pdf["PDF extraction<br/>[route.ts]"]
  node_chunking["Page chunking<br/>[chunking.ts]"]
  node_embeddings["Embedding client<br/>[embeddings.ts]"]
  node_vectorstore[("Vector search and store<br/>[vectorStore.ts]")]
  node_prompt["Grounded prompt<br/>[prompt.ts]"]
end

subgraph group_local["Local infrastructure"]
  node_ollama{{"Ollama models"}}
end

node_user(("User"))

node_user -->|"uses"| node_ui
node_ui -->|"POST upload"| node_upload
node_ui -->|"POST question"| node_query
node_upload -->|"extracts pages"| node_pdf
node_upload -->|"chunks pages"| node_chunking
node_upload -->|"embeds chunks"| node_embeddings
node_upload -->|"replaces vectors"| node_vectorstore
node_query -->|"checks and searches"| node_vectorstore
node_query -->|"embeds question"| node_embeddings
node_query -->|"assembles context"| node_prompt
node_query -->|"generates answer"| node_ollama
node_embeddings -->|"requests embeddings"| node_ollama
node_query -->|"returns answer and sources"| node_ui

click node_ui "https://github.com/theothernico27/rag-doc-qa/blob/main/app/page.tsx"
click node_upload "https://github.com/theothernico27/rag-doc-qa/blob/main/app/api/upload/route.ts"
click node_query "https://github.com/theothernico27/rag-doc-qa/blob/main/app/api/query/route.ts"
click node_pdf "https://github.com/theothernico27/rag-doc-qa/blob/main/app/api/upload/route.ts"
click node_chunking "https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/chunking.ts"
click node_embeddings "https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/embeddings.ts"
click node_vectorstore "https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/vectorStore.ts"
click node_prompt "https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/prompt.ts"

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_ui,node_user toneBlue
class node_upload,node_query toneAmber
class node_pdf,node_chunking,node_embeddings,node_vectorstore,node_prompt toneMint
class node_ollama toneRose
```

## Components

### Browser UI

- [Upload and Q&A](https://github.com/theothernico27/rag-doc-qa/blob/main/app/page.tsx): `app/page.tsx`

### API routes

- [Upload route](https://github.com/theothernico27/rag-doc-qa/blob/main/app/api/upload/route.ts): `app/api/upload/route.ts`
- [Query route](https://github.com/theothernico27/rag-doc-qa/blob/main/app/api/query/route.ts): `app/api/query/route.ts`

### RAG pipeline

- [PDF extraction](https://github.com/theothernico27/rag-doc-qa/blob/main/app/api/upload/route.ts): `app/api/upload/route.ts`
- [Page chunking](https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/chunking.ts): `src/lib/chunking.ts`
- [Embedding client](https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/embeddings.ts): `src/lib/embeddings.ts`
- [Vector search and store](https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/vectorStore.ts): `src/lib/vectorStore.ts`
- [Grounded prompt](https://github.com/theothernico27/rag-doc-qa/blob/main/src/lib/prompt.ts): `src/lib/prompt.ts`

### Local infrastructure

- **Ollama models**

### Other components

- **User**

## Connections

- User → Upload and Q&A: uses
- Upload and Q&A → Upload route: POST upload
- Upload and Q&A → Query route: POST question
- Upload route → PDF extraction: extracts pages
- Upload route → Page chunking: chunks pages
- Upload route → Embedding client: embeds chunks
- Upload route → Vector search and store: replaces vectors
- Query route → Vector search and store: checks and searches
- Query route → Embedding client: embeds question
- Query route → Grounded prompt: assembles context
- Query route → Ollama models: generates answer
- Embedding client → Ollama models: requests embeddings
- Query route → Upload and Q&A: returns answer and sources
