# biglanmao/lightrag architecture

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

- Interactive diagram: https://gitdiagram.com/biglanmao/lightrag
- Repository: https://github.com/biglanmao/lightrag
- Video tour (about a minute): https://gitdiagram.com/biglanmao/lightrag/video

## Overview

LightRAG is a knowledge-graph-enhanced retrieval-augmented generation system, exposed through an API and a web interface. Its main user workflow is to submit documents for parsing, chunking, and indexing, then query the resulting knowledge using retrieval and LLM generation; users can also inspect and manage documents and the graph. The repository supports multiple parser, chunker, LLM, and storage options. Some connections below are dashed because the relevant runtime call sites were not included in the excerpts; those links are architectural inferences, not verified calls.

Main entry points: [`lightrag/pipeline.py`](https://github.com/biglanmao/lightrag/blob/main/lightrag/pipeline.py) (Ingestion Pipeline), [`lightrag/api/lightrag_server.py`](https://github.com/biglanmao/lightrag/blob/main/lightrag/api/lightrag_server.py) (API Server), [`lightrag/lightrag.py`](https://github.com/biglanmao/lightrag/blob/main/lightrag/lightrag.py) (LightRAG Core), [`lightrag/parser/routing.py`](https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/routing.py) (Parser Routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Web UI"]
  node_api_server["API Server<br/>[lightrag_server.py]"]
  node_document_routes["Document Routes<br/>[document_routes.py]"]
  node_query_routes["Query Routes<br/>[query_routes.py]"]
  node_graph_routes["Graph Routes<br/>[graph_routes.py]"]
  node_webui["Web Interface"]
end

subgraph group_ingestion["Document Ingestion"]
  node_lightrag_core["LightRAG Core<br/>[lightrag.py]"]
  node_pipeline["Ingestion Pipeline<br/>[pipeline.py]"]
  node_parser_routing["Parser Routing<br/>[routing.py]"]
  node_parser_registry["Parser Registry<br/>[registry.py]"]
  node_chunker_registry["Chunker Registry<br/>[registry.py]"]
  node_recursive_chunker["Recursive Chunker"]
end

subgraph group_query["Retrieval and Generation"]
  node_query_engine["Query Operations<br/>[operate.py]"]
end

subgraph group_storage["Storage and Coordination"]
  node_storage_contracts["Storage Contracts<br/>[base.py]"]
  node_storage_factory["Storage Factory<br/>[factory.py]"]
  node_kv_storage[("Key-Value Storage<br/>[json_kv_impl.py]")]
  node_config_store[("Configuration Store<br/>[config_store.py]")]
  node_shared_coordination["Shared Coordination<br/>[shared_storage.py]"]
  node_pipeline_ingress["Pipeline Ingress"]
  node_namespace["Workspace Namespaces<br/>[namespace.py]"]
  node_metrics["Pipeline Metrics"]
end

subgraph group_integrations["Pluggable Engines"]
  node_llm_adapters["LLM Adapters<br/>[openai.py]"]
  node_docling["Docling Parser<br/>[client.py]"]
  node_mineru["MinerU Parser<br/>[client.py]"]
end

node_user(("User"))
node_external_llm{{"LLM Service"}}

node_user -->|"uses"| node_webui
node_user -->|"submits requests"| node_api_server
node_webui -.->|"calls API"| node_api_server
node_api_server -.->|"routes documents"| node_document_routes
node_api_server -.->|"routes queries"| node_query_routes
node_api_server -.->|"routes graph"| node_graph_routes
node_document_routes -->|"invokes document operations"| node_lightrag_core
node_query_routes -.->|"runs queries"| node_lightrag_core
node_graph_routes -.->|"reads graph"| node_lightrag_core
node_lightrag_core -->|"mixes in"| node_pipeline
node_pipeline -->|"selects parser"| node_parser_routing
node_parser_routing -->|"resolves parser"| node_parser_registry
node_parser_routing -.->|"dispatches parsing"| node_docling
node_parser_routing -.->|"dispatches parsing"| node_mineru
node_pipeline -->|"selects chunker"| node_chunker_registry
node_chunker_registry -->|"provides strategy"| node_recursive_chunker
node_pipeline -->|"uses operations"| node_query_engine
node_query_engine -.->|"requests generation"| node_llm_adapters
node_llm_adapters -.->|"calls model"| node_external_llm
node_lightrag_core -.->|"selects storage"| node_storage_factory
node_storage_factory -->|"implements contracts"| node_storage_contracts
node_storage_factory -->|"creates backend"| node_kv_storage
node_config_store -->|"uses namespaces"| node_namespace
node_config_store -->|"coordinates storage"| node_shared_coordination
node_shared_coordination -->|"provides ingress"| node_pipeline_ingress
node_shared_coordination -->|"aggregates metrics"| node_metrics
node_pipeline -->|"coordinates workers"| node_shared_coordination
node_pipeline -.->|"signals work"| node_pipeline_ingress

click node_api_server "https://github.com/biglanmao/lightrag/blob/main/lightrag/api/lightrag_server.py"
click node_document_routes "https://github.com/biglanmao/lightrag/blob/main/lightrag/api/routers/document_routes.py"
click node_query_routes "https://github.com/biglanmao/lightrag/blob/main/lightrag/api/routers/query_routes.py"
click node_graph_routes "https://github.com/biglanmao/lightrag/blob/main/lightrag/api/routers/graph_routes.py"
click node_webui "https://github.com/biglanmao/lightrag/blob/main/lightrag_webui/src/features/DocumentManager.tsx"
click node_lightrag_core "https://github.com/biglanmao/lightrag/blob/main/lightrag/lightrag.py"
click node_pipeline "https://github.com/biglanmao/lightrag/blob/main/lightrag/pipeline.py"
click node_parser_routing "https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/routing.py"
click node_parser_registry "https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/registry.py"
click node_chunker_registry "https://github.com/biglanmao/lightrag/blob/main/lightrag/chunker/registry.py"
click node_recursive_chunker "https://github.com/biglanmao/lightrag/blob/main/lightrag/chunker/recursive_character.py"
click node_query_engine "https://github.com/biglanmao/lightrag/blob/main/lightrag/operate.py"
click node_llm_adapters "https://github.com/biglanmao/lightrag/blob/main/lightrag/llm/openai.py"
click node_storage_contracts "https://github.com/biglanmao/lightrag/blob/main/lightrag/base.py"
click node_storage_factory "https://github.com/biglanmao/lightrag/blob/main/lightrag/kg/factory.py"
click node_kv_storage "https://github.com/biglanmao/lightrag/blob/main/lightrag/kg/json_kv_impl.py"
click node_config_store "https://github.com/biglanmao/lightrag/blob/main/lightrag/config_store.py"
click node_shared_coordination "https://github.com/biglanmao/lightrag/blob/main/lightrag/kg/shared_storage.py"
click node_pipeline_ingress "https://github.com/biglanmao/lightrag/blob/main/lightrag/kg/pipeline_ingress.py"
click node_namespace "https://github.com/biglanmao/lightrag/blob/main/lightrag/namespace.py"
click node_metrics "https://github.com/biglanmao/lightrag/blob/main/lightrag/pipeline_metrics.py"
click node_docling "https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/external/docling/client.py"
click node_mineru "https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/external/mineru/client.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_api_server,node_document_routes,node_query_routes,node_graph_routes,node_webui,node_user toneBlue
class node_lightrag_core,node_pipeline,node_parser_routing,node_parser_registry,node_chunker_registry,node_recursive_chunker toneAmber
class node_query_engine toneMint
class node_storage_contracts,node_storage_factory,node_kv_storage,node_config_store,node_shared_coordination,node_pipeline_ingress,node_namespace,node_metrics toneRose
class node_llm_adapters,node_docling,node_mineru,node_external_llm toneIndigo
```

## Components

### API and Web UI

- [API Server](https://github.com/biglanmao/lightrag/blob/main/lightrag/api/lightrag_server.py): `lightrag/api/lightrag_server.py`
- [Document Routes](https://github.com/biglanmao/lightrag/blob/main/lightrag/api/routers/document_routes.py): `lightrag/api/routers/document_routes.py`
- [Query Routes](https://github.com/biglanmao/lightrag/blob/main/lightrag/api/routers/query_routes.py): `lightrag/api/routers/query_routes.py`
- [Graph Routes](https://github.com/biglanmao/lightrag/blob/main/lightrag/api/routers/graph_routes.py): `lightrag/api/routers/graph_routes.py`
- [Web Interface](https://github.com/biglanmao/lightrag/blob/main/lightrag_webui/src/features/DocumentManager.tsx): `lightrag_webui/src/features/DocumentManager.tsx`

### Document Ingestion

- [LightRAG Core](https://github.com/biglanmao/lightrag/blob/main/lightrag/lightrag.py): `lightrag/lightrag.py`
- [Ingestion Pipeline](https://github.com/biglanmao/lightrag/blob/main/lightrag/pipeline.py): `lightrag/pipeline.py`
- [Parser Routing](https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/routing.py): `lightrag/parser/routing.py`
- [Parser Registry](https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/registry.py): `lightrag/parser/registry.py`
- [Chunker Registry](https://github.com/biglanmao/lightrag/blob/main/lightrag/chunker/registry.py): `lightrag/chunker/registry.py`
- [Recursive Chunker](https://github.com/biglanmao/lightrag/blob/main/lightrag/chunker/recursive_character.py): `lightrag/chunker/recursive_character.py`

### Retrieval and Generation

- [Query Operations](https://github.com/biglanmao/lightrag/blob/main/lightrag/operate.py): `lightrag/operate.py`

### Storage and Coordination

- [Storage Contracts](https://github.com/biglanmao/lightrag/blob/main/lightrag/base.py): `lightrag/base.py`
- [Storage Factory](https://github.com/biglanmao/lightrag/blob/main/lightrag/kg/factory.py): `lightrag/kg/factory.py`
- [Key-Value Storage](https://github.com/biglanmao/lightrag/blob/main/lightrag/kg/json_kv_impl.py): `lightrag/kg/json_kv_impl.py`
- [Configuration Store](https://github.com/biglanmao/lightrag/blob/main/lightrag/config_store.py): `lightrag/config_store.py`
- [Shared Coordination](https://github.com/biglanmao/lightrag/blob/main/lightrag/kg/shared_storage.py): `lightrag/kg/shared_storage.py`
- [Pipeline Ingress](https://github.com/biglanmao/lightrag/blob/main/lightrag/kg/pipeline_ingress.py): `lightrag/kg/pipeline_ingress.py`
- [Workspace Namespaces](https://github.com/biglanmao/lightrag/blob/main/lightrag/namespace.py): `lightrag/namespace.py`
- [Pipeline Metrics](https://github.com/biglanmao/lightrag/blob/main/lightrag/pipeline_metrics.py): `lightrag/pipeline_metrics.py`

### Pluggable Engines

- [LLM Adapters](https://github.com/biglanmao/lightrag/blob/main/lightrag/llm/openai.py): `lightrag/llm/openai.py`
- [Docling Parser](https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/external/docling/client.py): `lightrag/parser/external/docling/client.py`
- [MinerU Parser](https://github.com/biglanmao/lightrag/blob/main/lightrag/parser/external/mineru/client.py): `lightrag/parser/external/mineru/client.py`

### Other components

- **User**
- **LLM Service**

## Connections

- User → Web Interface: uses (evidence: `README.md`)
- User → API Server: submits requests (evidence: `README.md`)
- Web Interface → API Server: calls API
- API Server → Document Routes: routes documents
- API Server → Query Routes: routes queries
- API Server → Graph Routes: routes graph
- Document Routes → LightRAG Core: invokes document operations (evidence: `lightrag/api/routers/document_routes.py`)
- Query Routes → LightRAG Core: runs queries
- Graph Routes → LightRAG Core: reads graph
- LightRAG Core → Ingestion Pipeline: mixes in (evidence: `lightrag/pipeline.py`)
- Ingestion Pipeline → Parser Routing: selects parser (evidence: `lightrag/pipeline.py`)
- Parser Routing → Parser Registry: resolves parser (evidence: `lightrag/parser/routing.py`)
- Parser Routing → Docling Parser: dispatches parsing
- Parser Routing → MinerU Parser: dispatches parsing
- Ingestion Pipeline → Chunker Registry: selects chunker (evidence: `lightrag/pipeline.py`)
- Chunker Registry → Recursive Chunker: provides strategy (evidence: `lightrag/chunker/registry.py`)
- Ingestion Pipeline → Query Operations: uses operations (evidence: `lightrag/pipeline.py`)
- Query Operations → LLM Adapters: requests generation
- LLM Adapters → LLM Service: calls model
- LightRAG Core → Storage Factory: selects storage
- Storage Factory → Storage Contracts: implements contracts (evidence: `lightrag/kg/factory.py`)
- Storage Factory → Key-Value Storage: creates backend (evidence: `lightrag/kg/factory.py`)
- Configuration Store → Workspace Namespaces: uses namespaces (evidence: `lightrag/config_store.py`)
- Configuration Store → Shared Coordination: coordinates storage (evidence: `lightrag/config_store.py`)
- Shared Coordination → Pipeline Ingress: provides ingress (evidence: `lightrag/kg/shared_storage.py`)
- Shared Coordination → Pipeline Metrics: aggregates metrics (evidence: `lightrag/kg/shared_storage.py`)
- Ingestion Pipeline → Shared Coordination: coordinates workers (evidence: `lightrag/pipeline.py`)
- Ingestion Pipeline → Pipeline Ingress: signals work (evidence: `lightrag/pipeline.py`)
