# hudasharings/ragflow architecture

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

- Interactive diagram: https://gitdiagram.com/hudasharings/ragflow
- Repository: https://github.com/hudasharings/ragflow

## Overview

1. **Repository shape**
   - This is a full-stack RAG/agent platform, not a single service.
   - The main boundaries are: **web UI**, **Python backend/API**, **document intelligence and retrieval pipeline**, **agent orchestration**, **sandboxed code execution**, and **deployment/integration tooling**.

2. **User-facing web application**
   - `web/` is a React + TypeScript + Vite frontend.
   - It contains the primary product surfaces: chats, datasets/knowledge bases, documents, files, agents, memories, search, user settings, and admin views.
   - The frontend is mostly a stateful console for configuring pipelines and viewing results/logs rather than just a chat UI.

3. **API and application layer**
   - `api/` is the main backend entry point, with `api/ragflow_server.py` wiring the server.
   - `api/apps/` is organized by domain: chat, documents, files, knowledge bases, connectors, LLM settings, users, tenants, memory, search, plugins, MCP, evaluation, and system config.
   - This layer acts as the HTTP boundary and translates UI/API requests into service calls and async tasks.

4. **Domain services and persistence**
   - `api/db/services/` and `api/db/joint_services/` implement the business logic behind those API modules.
   - `api/db/db_models.py` defines the persistent model boundary; the codebase clearly separates route handlers from data/service logic.
   - The backend uses a relational database for metadata and workflow state, while external stores handle documents and indexes.

5. **Core RAG engine**
   - `rag/` is the runtime inference and retrieval core.
   - It contains pipeline primitives for parsing, splitting, tokenizing, hierarchical merging, advanced RAG, app-specific flows, and LLM wrappers.
   - `rag/prompts/` and `rag/nlp/` show that generation is tightly coupled with prompt templates, query rewriting, ranking, and language-aware retrieval logic.

6. **Document understanding pipeline**
   - `deepdoc/` is the document intelligence subsystem.
   - It includes parsers for PDF, DOCX, PPT, Excel, HTML, Markdown, JSON, text, OCR, layout recognition, and table structure recognition.
   - This is the ingestion front door for unstructured content; its output feeds chunking, metadata extraction, and retrieval index construction.

7. **External data source connectors**
   - `common/data_source/` implements many connectors to third-party systems such as Google Drive, Confluence, GitHub, GitLab, Jira, Slack, Teams, Notion, Dropbox, Box, SharePoint, Gmail, IMAP, WebDAV, Airtable, Asana, Discord, and others.
   - These connectors are a separate ingestion path from local file upload.
   - Their role is to pull remote content into the same document parsing/indexing pipeline used for uploaded files.

8. **Storage and indexing backends**
   - `rag/utils/`, `common/doc_store/`, and `api/db/` show the main persistence boundaries.
   - The platform supports Elasticsearch or Infinity for document/vector retrieval, MinIO/S3-like object storage for file blobs, Redis for caching/coordination, and MySQL for application state.
   - The README and docker assets confirm that these are first-class runtime dependencies, not optional extras.

9. **Agent orchestration and tool execution**
   - `agent/` defines the workflow/agent canvas and reusable components such as loop, switch, iteration, retrieval, message, variable assignment/aggregation, and LLM nodes.
   - `agent/tools/` provides tool adapters for web search, SQL execution, crawling, code execution, academic search, finance/data sources, email, and retrieval.
   - `agent/templates/` and the canvas UI in `web/src/pages/agent/` indicate that agents are built as editable graphs and serialized as DSL/JSON workflows.

10. **Sandboxed code execution**
   - `sandbox/` is a separate execution subsystem for running user/code-tool workloads safely.
   - It has its own executor manager service, container runtime configuration, seccomp profile, and base images.
   - This is a hard security boundary: code execution is intentionally isolated from the main backend.

11. **Admin and operations plane**
   - `admin/server/` and `admin/client/` form a dedicated admin service and CLI, separate from the main product API.
   - It handles user/role/service management and operational tasks.
   - This is distinct from end-user RAG flows and should be drawn as an internal ops plane.

12. **SDKs, integrations, and external surfaces**
   - `sdk/python/` exposes a client SDK for automation and external applications.
   - `mcp/` provides MCP client/server support, and `plugin/` plus `intergrations/` add embedding points for chat platforms, browser extensions, and Firecrawl.
   - These are outbound/integration boundaries, letting third-party systems consume or extend RAGFlow without using the web UI.

13. **Primary runtime data flow**
   - The main flow is: user configures a knowledge base or agent in the web app → API persists metadata and launches processing → document/content ingestion parses source material → chunks and embeddings are stored/indexed → retrieval and reranking are performed at query time → LLM response is generated with citations and references returned to the UI.
   - Agent flows add another layer: graph-defined tool calls, branching, loops, and optional sandboxed code execution happen before or during retrieval/generation.

14. **Deployment model**
   - The repo is designed for containerized deployment.
   - `docker/` and `helm/` define the production topology: web-facing reverse proxy, backend service, database, object storage, search engine, Redis, and sandbox executor.
   - `Dockerfile*`, GitHub workflows, and the source-launch instructions show that local dev and production share the same service boundaries, just different packaging.

15. **What to draw in an architecture diagram**
   - Draw the frontend, main API/backend, admin service, sandbox, and external stores as separate boxes.
   - Show two ingestion paths into the backend: uploaded files and external connectors.
   - Show the backend fanning out to document parsing, RAG indexing, agent orchestration, and admin/state services.
   - Show Elasticsearch/Infinity, MySQL, MinIO/S3, Redis, and LLM providers as external dependencies of the backend and pipeline layers.

Main entry points: [`api/apps`](https://github.com/hudasharings/ragflow/tree/main/api/apps) (Domain Apps), [`rag/flow`](https://github.com/hudasharings/ragflow/tree/main/rag/flow) (RAG Core), [`api/ragflow_server.py`](https://github.com/hudasharings/ragflow/blob/main/api/ragflow_server.py) (API Server), [`api/db/services`](https://github.com/hudasharings/ragflow/tree/main/api/db/services) (Services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web UI"]
  node_web_home["Product UI<br/>React/Vite console"]
  node_web_agent["Agent Canvas<br/>workflow editor"]
  node_web_dataset["Datasets<br/>knowledge console"]
  node_web_chat["Chats<br/>conversation UI"]
  node_web_search["Search UI<br/>retrieval UI"]
  node_web_admin["Admin UI<br/>ops console"]
end

subgraph group_api["Backend API"]
  node_api_server["API Server<br/>FastAPI entrypoint<br/>[ragflow_server.py]"]
  node_api_apps["Domain Apps<br/>HTTP modules"]
  node_api_services["Services<br/>business logic"]
  node_api_models[("DB Models<br/>persistence models<br/>[db_models.py]")]
end

subgraph group_rag["RAG Engine"]
  node_deepdoc["DeepDoc<br/>document intelligence"]
  node_rag_core["RAG Core<br/>retrieval pipeline"]
  node_rag_models["LLM Wrappers<br/>model adapters"]
  node_rag_prompts["Prompts<br/>prompt templates"]
  node_rag_nlp["NLP<br/>query logic"]
end

subgraph group_agent["Agent Runtime"]
  node_agent_canvas["Agent DSL<br/>workflow engine<br/>[canvas.py]"]
  node_agent_components["Components<br/>node library"]
  node_agent_tools["Tools<br/>tool adapters"]
end

subgraph group_ops["Ops & Integrations"]
  node_sandbox_exec["Sandbox Exec<br/>isolated runtime"]
  node_admin_service["Admin Service<br/>ops backend"]
  node_sdk_client["Python SDK<br/>client SDK"]
  node_mcp_plugin["MCP & Plugins<br/>integration layer"]
  node_connectors["Data Connectors<br/>source ingestion"]
end

node_storage[("Storage Backends<br/>external deps")]

node_web_home -->|"API requests"| node_api_server
node_web_agent -->|"save/run graphs"| node_api_apps
node_web_dataset -->|"manage KBs"| node_api_apps
node_web_chat -->|"chat sessions"| node_api_apps
node_web_search -->|"search queries"| node_api_apps
node_web_admin -->|"admin ops"| node_admin_service
node_api_server -->|"routes to domains"| node_api_apps
node_api_apps -->|"business logic"| node_api_services
node_api_services -->|"persist state"| node_api_models
node_api_apps -->|"ingest files"| node_deepdoc
node_api_apps -->|"sync sources"| node_connectors
node_deepdoc -->|"parsed content"| node_rag_core
node_rag_core -->|"embed/rerank/llm"| node_rag_models
node_rag_core -->|"prompting"| node_rag_prompts
node_rag_core -->|"query rewrite"| node_rag_nlp
node_agent_canvas -->|"compose nodes"| node_agent_components
node_agent_canvas -->|"invoke tools"| node_agent_tools
node_agent_tools -->|"code tools"| node_sandbox_exec
node_agent_components -->|"retrieval steps"| node_rag_core
node_api_apps -->|"workflow API"| node_agent_canvas
node_api_apps -->|"ops endpoints"| node_admin_service
node_sdk_client -->|"programmatic access"| node_api_server
node_mcp_plugin -->|"integration surface"| node_api_server
node_rag_core -->|"indexes/blobs"| node_storage
node_api_services -->|"app state"| node_storage
node_connectors -->|"raw assets"| node_storage
node_admin_service -->|"admin data"| node_storage

click node_web_home "https://github.com/hudasharings/ragflow/tree/main/web/src/pages"
click node_web_agent "https://github.com/hudasharings/ragflow/tree/main/web/src/pages/agent"
click node_web_dataset "https://github.com/hudasharings/ragflow/tree/main/web/src/pages/dataset"
click node_web_chat "https://github.com/hudasharings/ragflow/tree/main/web/src/pages/next-chats"
click node_web_search "https://github.com/hudasharings/ragflow/tree/main/web/src/pages/next-search"
click node_web_admin "https://github.com/hudasharings/ragflow/tree/main/web/src/pages/admin"
click node_api_server "https://github.com/hudasharings/ragflow/blob/main/api/ragflow_server.py"
click node_api_apps "https://github.com/hudasharings/ragflow/tree/main/api/apps"
click node_api_services "https://github.com/hudasharings/ragflow/tree/main/api/db/services"
click node_api_models "https://github.com/hudasharings/ragflow/blob/main/api/db/db_models.py"
click node_deepdoc "https://github.com/hudasharings/ragflow/tree/main/deepdoc"
click node_rag_core "https://github.com/hudasharings/ragflow/tree/main/rag/flow"
click node_rag_models "https://github.com/hudasharings/ragflow/tree/main/rag/llm"
click node_rag_prompts "https://github.com/hudasharings/ragflow/tree/main/rag/prompts"
click node_rag_nlp "https://github.com/hudasharings/ragflow/tree/main/rag/nlp"
click node_agent_canvas "https://github.com/hudasharings/ragflow/blob/main/agent/canvas.py"
click node_agent_components "https://github.com/hudasharings/ragflow/tree/main/agent/component"
click node_agent_tools "https://github.com/hudasharings/ragflow/tree/main/agent/tools"
click node_sandbox_exec "https://github.com/hudasharings/ragflow/tree/main/sandbox/executor_manager"
click node_admin_service "https://github.com/hudasharings/ragflow/tree/main/admin/server"
click node_sdk_client "https://github.com/hudasharings/ragflow/tree/main/sdk/python/ragflow_sdk"
click node_mcp_plugin "https://github.com/hudasharings/ragflow/tree/main/mcp"
click node_connectors "https://github.com/hudasharings/ragflow/tree/main/common/data_source"

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_home,node_web_agent,node_web_dataset,node_web_chat,node_web_search,node_web_admin toneBlue
class node_api_server,node_api_apps,node_api_services,node_api_models toneAmber
class node_deepdoc,node_rag_core,node_rag_models,node_rag_prompts,node_rag_nlp toneMint
class node_agent_canvas,node_agent_components,node_agent_tools toneRose
class node_sandbox_exec,node_admin_service,node_sdk_client,node_mcp_plugin,node_connectors toneIndigo
class node_storage toneNeutral
```

## Components

### Web UI

React console for chat, datasets, agents, search, memory, files, and admin views.

- [Product UI](https://github.com/hudasharings/ragflow/tree/main/web/src/pages): React/Vite console · Main end-user application surfaces and navigation. · `web/src/pages`
- [Agent Canvas](https://github.com/hudasharings/ragflow/tree/main/web/src/pages/agent): workflow editor · Editable graph canvas, forms, run sheets, logs, and shared agent views. · `web/src/pages/agent`
- [Datasets](https://github.com/hudasharings/ragflow/tree/main/web/src/pages/dataset): knowledge console · Knowledge base management, documents, chunking, parsing, and testing screens. · `web/src/pages/dataset`
- [Chats](https://github.com/hudasharings/ragflow/tree/main/web/src/pages/next-chats): conversation UI · Chat experiences, sessions, assistants, and next-generation chat views. · `web/src/pages/next-chats`
- [Search UI](https://github.com/hudasharings/ragflow/tree/main/web/src/pages/next-search): retrieval UI · Search, retrieval documents, previews, and embedded search experiences. · `web/src/pages/next-search`
- [Admin UI](https://github.com/hudasharings/ragflow/tree/main/web/src/pages/admin): ops console · Dedicated admin views for users, roles, monitoring, services, and whitelists. · `web/src/pages/admin`

### Backend API

Python HTTP layer, domain apps, and persistence services.

- [API Server](https://github.com/hudasharings/ragflow/blob/main/api/ragflow_server.py): FastAPI entrypoint · Backend application startup and routing boundary. · `api/ragflow_server.py`
- [Domain Apps](https://github.com/hudasharings/ragflow/tree/main/api/apps): HTTP modules · Domain-oriented API modules for chat, documents, files, KBs, connectors, LLMs, search, memory, and system config. · `api/apps`
- [Services](https://github.com/hudasharings/ragflow/tree/main/api/db/services): business logic · Service layer implementing domain behavior and task coordination. · `api/db/services`
- [DB Models](https://github.com/hudasharings/ragflow/blob/main/api/db/db_models.py): persistence models · Relational data model boundary for application state and workflow metadata. · `api/db/db_models.py`

### RAG Engine

Retrieval, parsing, chunking, prompting, and model wrappers.

- [DeepDoc](https://github.com/hudasharings/ragflow/tree/main/deepdoc): document intelligence · Document parsing, OCR, layout, and table understanding. · `deepdoc`
- [RAG Core](https://github.com/hudasharings/ragflow/tree/main/rag/flow): retrieval pipeline · Core runtime for parsing, splitting, tokenizing, hierarchical merging, and app-specific RAG flows. · `rag/flow`
- [LLM Wrappers](https://github.com/hudasharings/ragflow/tree/main/rag/llm): model adapters · Chat, embedding, rerank, OCR, sequence-to-text, and TTS model interfaces. · `rag/llm`
- [Prompts](https://github.com/hudasharings/ragflow/tree/main/rag/prompts): prompt templates · Prompt and template library used across retrieval, generation, summarization, and citation flows. · `rag/prompts`
- [NLP](https://github.com/hudasharings/ragflow/tree/main/rag/nlp): query logic · Query rewriting, tokenization, synonym handling, search logic, and term weighting. · `rag/nlp`

### Agent Runtime

Graph-based workflows, tools, and execution orchestration.

- [Agent DSL](https://github.com/hudasharings/ragflow/blob/main/agent/canvas.py): workflow engine · Graph/canvas runtime that serializes agent workflows and pipeline definitions. · `agent/canvas.py`
- [Components](https://github.com/hudasharings/ragflow/tree/main/agent/component): node library · Reusable workflow nodes such as loop, switch, iteration, retrieval, message, variables, and LLM. · `agent/component`
- [Tools](https://github.com/hudasharings/ragflow/tree/main/agent/tools): tool adapters · Adapters for web search, SQL, crawling, code execution, academic and finance sources. · `agent/tools`

### Ops & Integrations

Admin service, SDKs, MCP, plugins, deployment, and sandboxing.

- [Sandbox Exec](https://github.com/hudasharings/ragflow/tree/main/sandbox/executor_manager): isolated runtime · Containerized and seccomp-restricted code execution service. · `sandbox/executor_manager`
- [Admin Service](https://github.com/hudasharings/ragflow/tree/main/admin/server): ops backend · Separate admin server and CLI for user, role, and service management. · `admin/server`
- [Python SDK](https://github.com/hudasharings/ragflow/tree/main/sdk/python/ragflow_sdk): client SDK · Programmatic client for chat, dataset, document, agent, memory, and session operations. · `sdk/python/ragflow_sdk`
- [MCP & Plugins](https://github.com/hudasharings/ragflow/tree/main/mcp): integration layer · MCP client/server support plus plugin and embedding extension points. · `mcp`
- [Data Connectors](https://github.com/hudasharings/ragflow/tree/main/common/data_source): source ingestion · Third-party source connectors for drive, docs, code, tickets, chat, email, and web sources. · `common/data_source`

### Other components

- **Storage Backends**: external deps · Document/vector stores, object storage, cache, and database backends.

## Connections

- Product UI → API Server: API requests · UI calls backend endpoints for all product flows.
- Agent Canvas → Domain Apps: save/run graphs · Canvas and run sheets persist and execute agent workflows.
- Datasets → Domain Apps: manage KBs · Dataset screens manage documents, parsing, chunking, and retrieval setup.
- Chats → Domain Apps: chat sessions · Chat UI drives conversations, assistants, and message history.
- Search UI → Domain Apps: search queries · Search views request retrieval and document previews.
- Admin UI → Admin Service: admin ops · Admin UI uses the separate administration backend.
- API Server → Domain Apps: routes to domains · Server entrypoint wires HTTP modules by domain.
- Domain Apps → Services: business logic · Request handlers delegate to domain services.
- Services → DB Models: persist state · Services read and write application metadata and workflow state.
- Domain Apps → DeepDoc: ingest files · Document and file flows trigger parsing and document understanding.
- Domain Apps → Data Connectors: sync sources · Connector flows pull remote content into the ingestion pipeline.
- DeepDoc → RAG Core: parsed content · Document intelligence output feeds chunking and retrieval preparation.
- RAG Core → LLM Wrappers: embed/rerank/llm · Core RAG runtime depends on model wrappers for generation and ranking.
- RAG Core → Prompts: prompting · Retrieval and generation use shared prompt templates.
- RAG Core → NLP: query rewrite · Core retrieval uses NLP helpers for query analysis and search logic.
- Agent DSL → Components: compose nodes · Canvas workflows are built from reusable component nodes.
- Agent DSL → Tools: invoke tools · Agent graphs call external tools and connectors during execution.
- Tools → Sandbox Exec: code tools · Untrusted code execution is delegated to the sandbox subsystem.
- Components → RAG Core: retrieval steps · Agent workflows can embed retrieval and generation subflows.
- Domain Apps → Agent DSL: workflow API · Backend exposes agent creation, save, run, and log endpoints.
- Domain Apps → Admin Service: ops endpoints · Administrative functionality is separated from end-user flows.
- Python SDK → API Server: programmatic access · SDK speaks to the main backend API.
- MCP & Plugins → API Server: integration surface · MCP and plugins extend or consume backend capabilities.
- RAG Core → Storage Backends: indexes/blobs · Retrieval depends on vector/document stores and object storage.
- Services → Storage Backends: app state · Backend services use relational and cache storage for persistent state.
- Data Connectors → Storage Backends: raw assets · Ingested content is staged in object and document stores.
- Admin Service → Storage Backends: admin data · Admin service manages operational metadata and user/role state.
