# langgenius/dify architecture

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

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

## Overview

Dify is an LLM application development platform: users configure workflows, prompts, models, and knowledge sources, then run deployed applications or RAG pipelines. Its backend includes application-definition and invocation components, retrieval, and persistence; the README also identifies agent capabilities and observability. The map combines documented product capabilities with relationships shown in sampled source or the source index; unsampled subsystems are represented only where the README or tree supports them.

Main entry points: [`api/core/app/apps/workflow/generate_task_pipeline.py`](https://github.com/langgenius/dify/blob/main/api/core/app/apps/workflow/generate_task_pipeline.py) (Workflow Runner), [`api/tasks/rag_pipeline/rag_pipeline_run_task.py`](https://github.com/langgenius/dify/blob/main/api/tasks/rag_pipeline/rag_pipeline_run_task.py) (RAG Pipeline Task), [`api/controllers/console/app`](https://github.com/langgenius/dify/tree/main/api/controllers/console/app) (Console API), [`api/models/workflow.py`](https://github.com/langgenius/dify/blob/main/api/models/workflow.py) (Workflow Definition)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["App Authoring"]
  node_console["Console API"]
  node_workflow["Workflow Definition<br/>[workflow.py]"]
  node_prompt["Prompt IDE<br/>[manager.py]"]
end

subgraph group_runtime["Execution Runtime"]
  node_appdef["App Definition Query"]
  node_invoke["Invocation Context"]
  node_workflowrun["Workflow Runner"]
  node_queue["Run Event Queue"]
  node_agent["Agent Runtime<br/>[client.py]"]
end

subgraph group_knowledge["Knowledge and RAG"]
  node_ragui["RAG Pipeline"]
  node_ragrun["RAG Pipeline Task"]
  node_retrieval["Retrieval Service"]
end

subgraph group_platform["Platform Services"]
  node_models["Model Providers<br/>[model_providers.py]"]
  node_storage["File Storage<br/>[ext_storage.py]"]
  node_observability["Observability<br/>[otel_config.py]"]
end

subgraph group_state["Persistence"]
  node_apprepo["Definition Repository"]
  node_dataset[("Dataset Models<br/>[dataset.py]")]
  node_db[("Database Extension<br/>[ext_database.py]")]
end

node_user(("App Builder"))

node_user -->|"configures apps"| node_console
node_console -->|"edits workflows"| node_workflow
node_user -->|"crafts prompts"| node_prompt
node_user -->|"selects models"| node_models
node_workflow -->|"defines runs"| node_workflowrun
node_appdef -->|"queries definitions"| node_apprepo
node_user -->|"builds RAG"| node_ragui
node_ragrun -.->|"uses retrieval"| node_retrieval
node_ragrun -.->|"reads dataset"| node_dataset
node_ragrun -->|"builds pipeline"| node_workflowrun
node_workflowrun -.->|"publishes events"| node_queue
node_workflowrun -.->|"uses context"| node_invoke
node_user -.->|"inspects runs"| node_observability
node_storage -.->|"persists metadata"| node_db

click node_console "https://github.com/langgenius/dify/tree/main/api/controllers/console/app"
click node_workflow "https://github.com/langgenius/dify/blob/main/api/models/workflow.py"
click node_prompt "https://github.com/langgenius/dify/blob/main/api/core/app/app_config/easy_ui_based_app/prompt_template/manager.py"
click node_models "https://github.com/langgenius/dify/blob/main/api/controllers/console/workspace/model_providers.py"
click node_appdef "https://github.com/langgenius/dify/blob/main/api/services/app_definition_query_service.py"
click node_apprepo "https://github.com/langgenius/dify/blob/main/api/repositories/app_definition_query_repository.py"
click node_invoke "https://github.com/langgenius/dify/blob/main/api/core/app/entities/app_invoke_entities.py"
click node_workflowrun "https://github.com/langgenius/dify/blob/main/api/core/app/apps/workflow/generate_task_pipeline.py"
click node_queue "https://github.com/langgenius/dify/blob/main/api/core/app/apps/pipeline/pipeline_queue_manager.py"
click node_agent "https://github.com/langgenius/dify/blob/main/api/clients/agent_backend/client.py"
click node_ragui "https://github.com/langgenius/dify/blob/main/api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py"
click node_ragrun "https://github.com/langgenius/dify/blob/main/api/tasks/rag_pipeline/rag_pipeline_run_task.py"
click node_retrieval "https://github.com/langgenius/dify/blob/main/api/core/rag/datasource/retrieval_service.py"
click node_dataset "https://github.com/langgenius/dify/blob/main/api/models/dataset.py"
click node_storage "https://github.com/langgenius/dify/blob/main/api/extensions/ext_storage.py"
click node_db "https://github.com/langgenius/dify/blob/main/api/extensions/ext_database.py"
click node_observability "https://github.com/langgenius/dify/blob/main/api/configs/observability/otel/otel_config.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_console,node_workflow,node_prompt toneBlue
class node_appdef,node_invoke,node_workflowrun,node_queue,node_agent toneAmber
class node_ragui,node_ragrun,node_retrieval toneMint
class node_models,node_storage,node_observability toneRose
class node_apprepo,node_dataset,node_db,node_user toneIndigo
```

## Components

### App Authoring

- [Console API](https://github.com/langgenius/dify/tree/main/api/controllers/console/app): `api/controllers/console/app`
- [Workflow Definition](https://github.com/langgenius/dify/blob/main/api/models/workflow.py): `api/models/workflow.py`
- [Prompt IDE](https://github.com/langgenius/dify/blob/main/api/core/app/app_config/easy_ui_based_app/prompt_template/manager.py): `api/core/app/app_config/easy_ui_based_app/prompt_template/manager.py`

### Execution Runtime

- [App Definition Query](https://github.com/langgenius/dify/blob/main/api/services/app_definition_query_service.py): `api/services/app_definition_query_service.py`
- [Invocation Context](https://github.com/langgenius/dify/blob/main/api/core/app/entities/app_invoke_entities.py): `api/core/app/entities/app_invoke_entities.py`
- [Workflow Runner](https://github.com/langgenius/dify/blob/main/api/core/app/apps/workflow/generate_task_pipeline.py): `api/core/app/apps/workflow/generate_task_pipeline.py`
- [Run Event Queue](https://github.com/langgenius/dify/blob/main/api/core/app/apps/pipeline/pipeline_queue_manager.py): `api/core/app/apps/pipeline/pipeline_queue_manager.py`
- [Agent Runtime](https://github.com/langgenius/dify/blob/main/api/clients/agent_backend/client.py): `api/clients/agent_backend/client.py`

### Knowledge and RAG

- [RAG Pipeline](https://github.com/langgenius/dify/blob/main/api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py): `api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py`
- [RAG Pipeline Task](https://github.com/langgenius/dify/blob/main/api/tasks/rag_pipeline/rag_pipeline_run_task.py): `api/tasks/rag_pipeline/rag_pipeline_run_task.py`
- [Retrieval Service](https://github.com/langgenius/dify/blob/main/api/core/rag/datasource/retrieval_service.py): `api/core/rag/datasource/retrieval_service.py`

### Platform Services

- [Model Providers](https://github.com/langgenius/dify/blob/main/api/controllers/console/workspace/model_providers.py): `api/controllers/console/workspace/model_providers.py`
- [File Storage](https://github.com/langgenius/dify/blob/main/api/extensions/ext_storage.py): `api/extensions/ext_storage.py`
- [Observability](https://github.com/langgenius/dify/blob/main/api/configs/observability/otel/otel_config.py): `api/configs/observability/otel/otel_config.py`

### Persistence

- [Definition Repository](https://github.com/langgenius/dify/blob/main/api/repositories/app_definition_query_repository.py): `api/repositories/app_definition_query_repository.py`
- [Dataset Models](https://github.com/langgenius/dify/blob/main/api/models/dataset.py): `api/models/dataset.py`
- [Database Extension](https://github.com/langgenius/dify/blob/main/api/extensions/ext_database.py): `api/extensions/ext_database.py`

### Other components

- **App Builder**

## Connections

- App Builder → Console API: configures apps (evidence: `README.md`)
- Console API → Workflow Definition: edits workflows (evidence: `README.md`)
- App Builder → Prompt IDE: crafts prompts (evidence: `README.md`)
- App Builder → Model Providers: selects models (evidence: `README.md`)
- Workflow Definition → Workflow Runner: defines runs (evidence: `README.md`)
- App Definition Query → Definition Repository: queries definitions (evidence: `api/services/app_definition_query_service.py`)
- App Builder → RAG Pipeline: builds RAG (evidence: `README.md`)
- RAG Pipeline Task → Retrieval Service: uses retrieval
- RAG Pipeline Task → Dataset Models: reads dataset (evidence: `api/tasks/rag_pipeline/rag_pipeline_run_task.py`)
- RAG Pipeline Task → Workflow Runner: builds pipeline (evidence: `api/tasks/rag_pipeline/rag_pipeline_run_task.py`)
- Workflow Runner → Run Event Queue: publishes events
- Workflow Runner → Invocation Context: uses context
- App Builder → Observability: inspects runs
- File Storage → Database Extension: persists metadata
