# vikramaditya005/docurag architecture

> Architecture diagram of the GitHub repository vikramaditya005/docurag, 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/vikramaditya005/docurag
- Repository: https://github.com/vikramaditya005/docurag

## Overview

DocuRAG turns uploaded or locally supplied documents into searchable multimodal chunks, retrieves evidence, and returns cited, confidence-scored answers. Its main runtime is the pipeline: ingestion and indexing, hybrid retrieval and reranking, generation, then verification. A Django web/API layer adds authenticated document and query workflows. The README also documents an optional multi-agent route and fallback, though its graph implementation is not present in the supplied tree. Connections below are limited to excerpted calls and README claims; unsampled wiring is not inferred.

Main entry points: [`docurag/pipeline.py`](https://github.com/vikramaditya005/docurag/blob/main/docurag/pipeline.py) (Pipeline router), [`docurag/ingest/coordinator.py`](https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/coordinator.py) (Ingestion coordinator), [`backend/api/views.py`](https://github.com/vikramaditya005/docurag/blob/main/backend/api/views.py) (Web API), [`docurag/index/store.py`](https://github.com/vikramaditya005/docurag/blob/main/docurag/index/store.py) (Chunk index)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_webui["Web UI<br/>[app.js]"]
  node_api["Web API<br/>[views.py]"]
  node_accounts["Account forms<br/>[forms.py]"]
  node_documents[("Document records<br/>[models.py]")]
end

subgraph group_ingest["Document ingestion"]
  node_ingestcoord["Ingestion coordinator<br/>[coordinator.py]"]
  node_loaders["Format loaders<br/>[pdf_loader.py]"]
  node_textloader["Text and tables<br/>[text.py]"]
  node_vision["Figure vision<br/>[vision.py]"]
  node_chunks["Semantic chunking<br/>[chunker.py]"]
end

subgraph group_retrieval["Search and indexing"]
  node_embedder["Text embedder<br/>[embedder.py]"]
  node_store[("Chunk index<br/>[store.py]")]
  node_dense[("Dense index<br/>[vector_store.py]")]
  node_sparse[("BM25 index<br/>[bm25_store.py]")]
  node_hybrid["Hybrid retrieval<br/>[hybrid.py]"]
  node_reranker["Cross-encoder reranker<br/>[rerank.py]"]
end

subgraph group_answers["Answer workflow"]
  node_pipeline["Pipeline router<br/>[pipeline.py]"]
  node_generator["Grounded generation<br/>[answer.py]"]
  node_verifier["Answer verification<br/>[verify.py]"]
  node_confidence["Confidence scoring<br/>[confidence.py]"]
  node_contracts["Data contracts<br/>[schemas.py]"]
end

subgraph group_agents["Agent orchestration"]
  node_agentflow["Multi-agent route"]
  node_agentservers["MCP tool servers"]
end

node_user(("User / CLI"))
node_gemini["Gemini service"]

node_user -.->|"uses"| node_webui
node_webui -.->|"requests"| node_api
node_user -.->|"uploads / asks"| node_api
node_api -->|"reads / writes"| node_documents
node_api -->|"ingests / queries"| node_pipeline
node_pipeline -->|"ingests documents"| node_ingestcoord
node_ingestcoord -->|"routes formats"| node_loaders
node_ingestcoord -->|"loads text"| node_textloader
node_ingestcoord -->|"describes figures"| node_vision
node_ingestcoord -->|"chunks pages"| node_chunks
node_ingestcoord -->|"writes chunks"| node_store
node_ingestcoord -->|"embeds chunks"| node_embedder
node_store -->|"updates"| node_dense
node_store -->|"updates"| node_sparse
node_pipeline -->|"retrieves evidence"| node_hybrid
node_pipeline -->|"uses index"| node_store
node_pipeline -->|"embeds queries"| node_embedder
node_hybrid -->|"reranks candidates"| node_reranker
node_pipeline -->|"generates answer"| node_generator
node_pipeline -->|"verifies citations"| node_verifier
node_pipeline -.->|"scores confidence"| node_confidence
node_pipeline -.->|"routes optionally"| node_agentflow
node_agentflow -.->|"uses tools"| node_agentservers
node_agentflow -.->|"falls back"| node_pipeline
node_generator -->|"generates with"| node_gemini
node_vision -->|"transcribes with"| node_gemini

click node_webui "https://github.com/vikramaditya005/docurag/blob/main/backend/static/js/app.js"
click node_api "https://github.com/vikramaditya005/docurag/blob/main/backend/api/views.py"
click node_accounts "https://github.com/vikramaditya005/docurag/blob/main/backend/config/forms.py"
click node_documents "https://github.com/vikramaditya005/docurag/blob/main/backend/api/models.py"
click node_pipeline "https://github.com/vikramaditya005/docurag/blob/main/docurag/pipeline.py"
click node_ingestcoord "https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/coordinator.py"
click node_loaders "https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/pdf_loader.py"
click node_textloader "https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/text.py"
click node_vision "https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/vision.py"
click node_chunks "https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/chunker.py"
click node_embedder "https://github.com/vikramaditya005/docurag/blob/main/docurag/index/embedder.py"
click node_store "https://github.com/vikramaditya005/docurag/blob/main/docurag/index/store.py"
click node_dense "https://github.com/vikramaditya005/docurag/blob/main/docurag/index/vector_store.py"
click node_sparse "https://github.com/vikramaditya005/docurag/blob/main/docurag/index/bm25_store.py"
click node_hybrid "https://github.com/vikramaditya005/docurag/blob/main/docurag/retrieve/hybrid.py"
click node_reranker "https://github.com/vikramaditya005/docurag/blob/main/docurag/retrieve/rerank.py"
click node_generator "https://github.com/vikramaditya005/docurag/blob/main/docurag/generate/answer.py"
click node_verifier "https://github.com/vikramaditya005/docurag/blob/main/docurag/generate/verify.py"
click node_confidence "https://github.com/vikramaditya005/docurag/blob/main/docurag/generate/confidence.py"
click node_contracts "https://github.com/vikramaditya005/docurag/blob/main/docurag/schemas.py"
click node_agentflow "https://github.com/vikramaditya005/docurag/tree/main/docurag/agents"
click node_agentservers "https://github.com/vikramaditya005/docurag/tree/main/docurag/agents/mcp_servers"

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_webui,node_api,node_accounts,node_documents,node_user toneBlue
class node_ingestcoord,node_loaders,node_textloader,node_vision,node_chunks toneAmber
class node_embedder,node_store,node_dense,node_sparse,node_hybrid,node_reranker toneMint
class node_pipeline,node_generator,node_verifier,node_confidence,node_contracts toneRose
class node_agentflow,node_agentservers,node_gemini toneIndigo
```

## Components

### Web application

- [Web UI](https://github.com/vikramaditya005/docurag/blob/main/backend/static/js/app.js): `backend/static/js/app.js`
- [Web API](https://github.com/vikramaditya005/docurag/blob/main/backend/api/views.py): `backend/api/views.py`
- [Account forms](https://github.com/vikramaditya005/docurag/blob/main/backend/config/forms.py): `backend/config/forms.py`
- [Document records](https://github.com/vikramaditya005/docurag/blob/main/backend/api/models.py): `backend/api/models.py`

### Document ingestion

- [Ingestion coordinator](https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/coordinator.py): `docurag/ingest/coordinator.py`
- [Format loaders](https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/pdf_loader.py): `docurag/ingest/pdf_loader.py`
- [Text and tables](https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/text.py): `docurag/ingest/text.py`
- [Figure vision](https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/vision.py): `docurag/ingest/vision.py`
- [Semantic chunking](https://github.com/vikramaditya005/docurag/blob/main/docurag/ingest/chunker.py): `docurag/ingest/chunker.py`

### Search and indexing

- [Text embedder](https://github.com/vikramaditya005/docurag/blob/main/docurag/index/embedder.py): `docurag/index/embedder.py`
- [Chunk index](https://github.com/vikramaditya005/docurag/blob/main/docurag/index/store.py): `docurag/index/store.py`
- [Dense index](https://github.com/vikramaditya005/docurag/blob/main/docurag/index/vector_store.py): `docurag/index/vector_store.py`
- [BM25 index](https://github.com/vikramaditya005/docurag/blob/main/docurag/index/bm25_store.py): `docurag/index/bm25_store.py`
- [Hybrid retrieval](https://github.com/vikramaditya005/docurag/blob/main/docurag/retrieve/hybrid.py): `docurag/retrieve/hybrid.py`
- [Cross-encoder reranker](https://github.com/vikramaditya005/docurag/blob/main/docurag/retrieve/rerank.py): `docurag/retrieve/rerank.py`

### Answer workflow

- [Pipeline router](https://github.com/vikramaditya005/docurag/blob/main/docurag/pipeline.py): `docurag/pipeline.py`
- [Grounded generation](https://github.com/vikramaditya005/docurag/blob/main/docurag/generate/answer.py): `docurag/generate/answer.py`
- [Answer verification](https://github.com/vikramaditya005/docurag/blob/main/docurag/generate/verify.py): `docurag/generate/verify.py`
- [Confidence scoring](https://github.com/vikramaditya005/docurag/blob/main/docurag/generate/confidence.py): `docurag/generate/confidence.py`
- [Data contracts](https://github.com/vikramaditya005/docurag/blob/main/docurag/schemas.py): `docurag/schemas.py`

### Agent orchestration

- [Multi-agent route](https://github.com/vikramaditya005/docurag/tree/main/docurag/agents): `docurag/agents`
- [MCP tool servers](https://github.com/vikramaditya005/docurag/tree/main/docurag/agents/mcp_servers): `docurag/agents/mcp_servers`

### Other components

- **User / CLI**
- **Gemini service**

## Connections

- User / CLI → Web UI: uses (evidence: `README.md`)
- Web UI → Web API: requests
- User / CLI → Web API: uploads / asks (evidence: `README.md`)
- Web API → Document records: reads / writes (evidence: `backend/api/views.py`)
- Web API → Pipeline router: ingests / queries (evidence: `backend/api/views.py`)
- Pipeline router → Ingestion coordinator: ingests documents (evidence: `docurag/pipeline.py`)
- Ingestion coordinator → Format loaders: routes formats (evidence: `docurag/ingest/coordinator.py`)
- Ingestion coordinator → Text and tables: loads text (evidence: `docurag/ingest/coordinator.py`)
- Ingestion coordinator → Figure vision: describes figures (evidence: `docurag/ingest/coordinator.py`)
- Ingestion coordinator → Semantic chunking: chunks pages (evidence: `docurag/ingest/coordinator.py`)
- Ingestion coordinator → Chunk index: writes chunks (evidence: `docurag/ingest/coordinator.py`)
- Ingestion coordinator → Text embedder: embeds chunks (evidence: `docurag/ingest/coordinator.py`)
- Chunk index → Dense index: updates (evidence: `docurag/index/store.py`)
- Chunk index → BM25 index: updates (evidence: `docurag/index/store.py`)
- Pipeline router → Hybrid retrieval: retrieves evidence (evidence: `docurag/pipeline.py`)
- Pipeline router → Chunk index: uses index (evidence: `docurag/pipeline.py`)
- Pipeline router → Text embedder: embeds queries (evidence: `docurag/pipeline.py`)
- Hybrid retrieval → Cross-encoder reranker: reranks candidates (evidence: `docurag/retrieve/hybrid.py`)
- Pipeline router → Grounded generation: generates answer (evidence: `docurag/pipeline.py`)
- Pipeline router → Answer verification: verifies citations (evidence: `docurag/pipeline.py`)
- Pipeline router → Confidence scoring: scores confidence
- Pipeline router → Multi-agent route: routes optionally (evidence: `README.md`)
- Multi-agent route → MCP tool servers: uses tools
- Multi-agent route → Pipeline router: falls back (evidence: `README.md`)
- Grounded generation → Gemini service: generates with (evidence: `docurag/generate/answer.py`)
- Figure vision → Gemini service: transcribes with (evidence: `docurag/ingest/vision.py`)
