# anikaitar70/rag_reader architecture

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

- Interactive diagram: https://gitdiagram.com/anikaitar70/rag_reader
- Repository: https://github.com/anikaitar70/rag_reader

## Overview

Local Document Intelligence Engine accepts documents through a three-panel web UI, parses and indexes them locally, then answers questions from retrieved evidence with citations or abstains. Its documented capabilities include multiple document formats, structure-aware chunking and metadata, hybrid retrieval with reranking, SSE progress, selection-grounded questions, and optional local fact-only rewriting with entailment validation. Edges reflect the README and SOURCE INDEX relationships; unsampled implementation details and frontend wiring are not inferred beyond documented behavior.

Main entry points: [`backend/app/pipeline.py`](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/pipeline.py) (Ask pipeline), [`frontend/app/page.tsx`](https://github.com/anikaitar70/rag_reader/blob/main/frontend/app/page.tsx) (Web app), [`backend/app/main.py`](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/main.py) (FastAPI routes), [`backend/app/retrieval.py`](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/retrieval.py) (Hybrid search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Web experience"]
  node_web_app["Web app<br/>[page.tsx]"]
  node_document_ui["Document panel"]
  node_chat_ui["Chat panel<br/>[ChatPanel.tsx]"]
  node_pdf_viewer["PDF viewer<br/>[PdfViewerInner.tsx]"]
  node_selection["Selection ask"]
  node_evidence_ui["Evidence panel<br/>[EvidencePanel.tsx]"]
end

subgraph group_ingestion["Document ingestion"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_parsing["Document parsers<br/>[parsers.py]"]
  node_chunking["Structure chunking<br/>[chunking.py]"]
  node_metadata["Chunk metadata<br/>[metadata_gen.py]"]
  node_models["Domain models<br/>[models.py]"]
end

subgraph group_retrieval["Search and retrieval"]
  node_retrieval_index["Hybrid search<br/>[retrieval.py]"]
  node_embeddings["Local embeddings<br/>[embeddings.py]"]
  node_intent["Query intent<br/>[intent.py]"]
end

subgraph group_grounding["Evidence and answers"]
  node_pipeline["Ask pipeline<br/>[pipeline.py]"]
  node_sentence_rank["Sentence ranking<br/>[sentences.py]"]
  node_fact_extract["Fact extraction<br/>[extractor.py]"]
  node_evidence_graph["Evidence graph<br/>[graph.py]"]
  node_coverage["Coverage analysis<br/>[coverage.py]"]
  node_answer_format["Answer formatting<br/>[formatter.py]"]
  node_fact_rewrite["Optional fact rewrite<br/>[fact_rewrite.py]"]
  node_entailment["Entailment validation<br/>[entailment.py]"]
end

subgraph group_persistence["Local persistence"]
  node_store[("Document store<br/>[store.py]")]
end

node_user(("Document user"))
node_local_models["Local model runtimes"]

node_user -->|"uses"| node_web_app
node_web_app -->|"calls backend"| node_api
node_web_app -->|"shows documents"| node_document_ui
node_web_app -->|"shows chat"| node_chat_ui
node_web_app -->|"shows retrieved chunks"| node_evidence_ui
node_web_app -->|"shows PDF"| node_pdf_viewer
node_pdf_viewer -->|"offers selection ask"| node_selection
node_api -->|"parses upload"| node_parsing
node_api -->|"chunks parsed tree"| node_chunking
node_api -->|"persists documents"| node_store
node_api -->|"dispatches ask"| node_pipeline
node_parsing -->|"builds document tree"| node_models
node_chunking -->|"creates chunks"| node_models
node_metadata -->|"enriches chunks"| node_models
node_pipeline -->|"classifies query"| node_intent
node_pipeline -->|"retrieves chunks"| node_retrieval_index
node_retrieval_index -->|"embeds and reranks"| node_embeddings
node_retrieval_index -->|"loads indexed chunks"| node_store
node_pipeline -->|"ranks sentences"| node_sentence_rank
node_pipeline -->|"extracts facts"| node_fact_extract
node_pipeline -->|"deduplicates facts"| node_evidence_graph
node_pipeline -->|"scores evidence"| node_coverage
node_pipeline -->|"formats answer"| node_answer_format
node_pipeline -->|"optionally rewrites facts"| node_fact_rewrite
node_pipeline -->|"validates answer"| node_entailment
node_fact_rewrite -.->|"uses optional SLM"| node_local_models
node_entailment -.->|"optionally uses NLI"| node_local_models
node_embeddings -->|"loads local models"| node_local_models

click node_web_app "https://github.com/anikaitar70/rag_reader/blob/main/frontend/app/page.tsx"
click node_document_ui "https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/DocumentSidebar.tsx"
click node_chat_ui "https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/ChatPanel.tsx"
click node_pdf_viewer "https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/PdfViewerInner.tsx"
click node_selection "https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/SelectionToolbar.tsx"
click node_evidence_ui "https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/EvidencePanel.tsx"
click node_api "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/main.py"
click node_parsing "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/parsers.py"
click node_chunking "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/chunking.py"
click node_metadata "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/metadata_gen.py"
click node_models "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/models.py"
click node_store "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/store.py"
click node_retrieval_index "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/retrieval.py"
click node_embeddings "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/embeddings.py"
click node_intent "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/intent.py"
click node_pipeline "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/pipeline.py"
click node_sentence_rank "https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/sentences.py"
click node_fact_extract "https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/extractor.py"
click node_evidence_graph "https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/graph.py"
click node_coverage "https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/coverage.py"
click node_answer_format "https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/formatter.py"
click node_fact_rewrite "https://github.com/anikaitar70/rag_reader/blob/main/backend/app/fact_rewrite.py"
click node_entailment "https://github.com/anikaitar70/rag_reader/blob/main/backend/core/validation/entailment.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_app,node_document_ui,node_chat_ui,node_pdf_viewer,node_selection,node_evidence_ui,node_user toneBlue
class node_api,node_parsing,node_chunking,node_metadata,node_models toneAmber
class node_retrieval_index,node_embeddings,node_intent toneMint
class node_pipeline,node_sentence_rank,node_fact_extract,node_evidence_graph,node_coverage,node_answer_format,node_fact_rewrite,node_entailment toneRose
class node_store,node_local_models toneIndigo
```

## Components

### Web experience

- [Web app](https://github.com/anikaitar70/rag_reader/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Document panel](https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/DocumentSidebar.tsx): `frontend/components/DocumentSidebar.tsx`
- [Chat panel](https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/ChatPanel.tsx): `frontend/components/ChatPanel.tsx`
- [PDF viewer](https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/PdfViewerInner.tsx): `frontend/components/PdfViewerInner.tsx`
- [Selection ask](https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/SelectionToolbar.tsx): `frontend/components/SelectionToolbar.tsx`
- [Evidence panel](https://github.com/anikaitar70/rag_reader/blob/main/frontend/components/EvidencePanel.tsx): `frontend/components/EvidencePanel.tsx`

### Document ingestion

- [FastAPI routes](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/main.py): `backend/app/main.py`
- [Document parsers](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/parsers.py): `backend/app/parsers.py`
- [Structure chunking](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/chunking.py): `backend/app/chunking.py`
- [Chunk metadata](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/metadata_gen.py): `backend/app/metadata_gen.py`
- [Domain models](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/models.py): `backend/app/models.py`

### Search and retrieval

- [Hybrid search](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/retrieval.py): `backend/app/retrieval.py`
- [Local embeddings](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/embeddings.py): `backend/app/embeddings.py`
- [Query intent](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/intent.py): `backend/app/intent.py`

### Evidence and answers

- [Ask pipeline](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/pipeline.py): `backend/app/pipeline.py`
- [Sentence ranking](https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/sentences.py): `backend/core/evidence/sentences.py`
- [Fact extraction](https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/extractor.py): `backend/core/evidence/extractor.py`
- [Evidence graph](https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/graph.py): `backend/core/evidence/graph.py`
- [Coverage analysis](https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/coverage.py): `backend/core/evidence/coverage.py`
- [Answer formatting](https://github.com/anikaitar70/rag_reader/blob/main/backend/core/evidence/formatter.py): `backend/core/evidence/formatter.py`
- [Optional fact rewrite](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/fact_rewrite.py): `backend/app/fact_rewrite.py`
- [Entailment validation](https://github.com/anikaitar70/rag_reader/blob/main/backend/core/validation/entailment.py): `backend/core/validation/entailment.py`

### Local persistence

- [Document store](https://github.com/anikaitar70/rag_reader/blob/main/backend/app/store.py): `backend/app/store.py`

### Other components

- **Document user**
- **Local model runtimes**

## Connections

- Document user → Web app: uses (evidence: `README.md`)
- Web app → FastAPI routes: calls backend (evidence: `README.md`)
- Web app → Document panel: shows documents (evidence: `README.md`)
- Web app → Chat panel: shows chat (evidence: `README.md`)
- Web app → Evidence panel: shows retrieved chunks (evidence: `README.md`)
- Web app → PDF viewer: shows PDF (evidence: `README.md`)
- PDF viewer → Selection ask: offers selection ask (evidence: `README.md`)
- FastAPI routes → Document parsers: parses upload (evidence: `backend/app/main.py`)
- FastAPI routes → Structure chunking: chunks parsed tree (evidence: `backend/app/main.py`)
- FastAPI routes → Document store: persists documents (evidence: `backend/app/main.py`)
- FastAPI routes → Ask pipeline: dispatches ask (evidence: `backend/app/main.py`)
- Document parsers → Domain models: builds document tree (evidence: `backend/app/parsers.py`)
- Structure chunking → Domain models: creates chunks (evidence: `backend/app/chunking.py`)
- Chunk metadata → Domain models: enriches chunks (evidence: `backend/app/metadata_gen.py`)
- Ask pipeline → Query intent: classifies query (evidence: `backend/app/pipeline.py`)
- Ask pipeline → Hybrid search: retrieves chunks (evidence: `backend/app/pipeline.py`)
- Hybrid search → Local embeddings: embeds and reranks (evidence: `backend/app/retrieval.py`)
- Hybrid search → Document store: loads indexed chunks (evidence: `backend/app/retrieval.py`)
- Ask pipeline → Sentence ranking: ranks sentences (evidence: `backend/app/pipeline.py`)
- Ask pipeline → Fact extraction: extracts facts (evidence: `backend/app/pipeline.py`)
- Ask pipeline → Evidence graph: deduplicates facts (evidence: `backend/app/pipeline.py`)
- Ask pipeline → Coverage analysis: scores evidence (evidence: `backend/app/pipeline.py`)
- Ask pipeline → Answer formatting: formats answer (evidence: `backend/app/pipeline.py`)
- Ask pipeline → Optional fact rewrite: optionally rewrites facts (evidence: `backend/app/pipeline.py`)
- Ask pipeline → Entailment validation: validates answer (evidence: `backend/app/pipeline.py`)
- Optional fact rewrite → Local model runtimes: uses optional SLM (evidence: `backend/app/fact_rewrite.py`)
- Entailment validation → Local model runtimes: optionally uses NLI (evidence: `backend/core/validation/entailment.py`)
- Local embeddings → Local model runtimes: loads local models (evidence: `backend/app/embeddings.py`)
