# amp2byte/dify architecture

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

- Interactive diagram: https://gitdiagram.com/amp2byte/dify
- Repository: https://github.com/amp2byte/dify

## Overview

Dify is an open-source LLM application development platform. Its main creator workflow is to configure an app or visual workflow, connect models and tools, and run it for end users; RAG adds document ingestion and retrieval, while agents support tool-driven tasks. The map also includes model/provider management, persistence, and operational logging. The README documents product capabilities, but most implementation files were not sampled, so several subsystem boundaries are shown without speculative internal call chains.

Main entry points: [`api/core/app/apps`](https://github.com/amp2byte/dify/tree/main/api/core/app/apps) (App runners), [`api/services/rag_pipeline/rag_pipeline.py`](https://github.com/amp2byte/dify/blob/main/api/services/rag_pipeline/rag_pipeline.py) (RAG pipeline), [`api/core/agent`](https://github.com/amp2byte/dify/tree/main/api/core/agent) (Autonomous agent), [`api/controllers/console/datasets`](https://github.com/amp2byte/dify/tree/main/api/controllers/console/datasets) (Knowledge management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_creation["App creation"]
  node_console["Creator interface"]
  node_workflow["Visual workflows"]
  node_prompt["Prompt IDE"]
  node_app_config["App configuration<br/>[model.py]"]
end

subgraph group_runtime["Application runtime"]
  node_entrypoints["Run interfaces"]
  node_app_runtime["App runners"]
  node_invoke_context["Invocation context"]
  node_models["Model providers<br/>[model_providers.py]"]
  node_tool_engine["Tool engine<br/>[tool_engine.py]"]
  node_response["App response<br/>[app.py]"]
end

subgraph group_knowledge["RAG and knowledge"]
  node_knowledge_ui["Knowledge management"]
  node_rag_pipeline["RAG pipeline<br/>[rag_pipeline.py]"]
  node_ingestion["Document ingestion"]
  node_retrieval["Retrieval service"]
  node_datasets[("Dataset records<br/>[dataset.py]")]
end

subgraph group_platform["Platform services"]
  node_database["Database extension<br/>[ext_database.py]"]
  node_engine["Database engine<br/>[engine.py]"]
  node_storage["File storage<br/>[ext_storage.py]"]
  node_account[("Account records<br/>[account.py]")]
  node_auth["Login and identity<br/>[login.py]"]
  node_external_api["External API helpers<br/>[external_api.py]"]
  node_observability["Run observability"]
end

subgraph group_agent["Agent execution"]
  node_agent["Autonomous agent"]
  node_shell_config["Shell configuration<br/>[configs.py]"]
  node_sandbox["Sandbox runtime"]
end

node_creator(("App creator"))
node_user(("End user"))

node_creator -->|"configures apps"| node_console
node_console -->|"builds workflows"| node_workflow
node_creator -->|"crafts prompts"| node_prompt
node_prompt -->|"configures apps"| node_app_config
node_app_config -.->|"configures runs"| node_app_runtime
node_user -->|"runs apps"| node_entrypoints
node_entrypoints -.->|"invokes apps"| node_app_runtime
node_app_runtime -.->|"uses context"| node_invoke_context
node_app_runtime -->|"calls models"| node_models
node_app_runtime -->|"uses tools"| node_tool_engine
node_app_runtime -.->|"returns results"| node_response
node_knowledge_ui -->|"configures ingestion"| node_rag_pipeline
node_rag_pipeline -.->|"ingests documents"| node_ingestion
node_ingestion -.->|"stores documents"| node_datasets
node_rag_pipeline -->|"retrieves context"| node_retrieval
node_retrieval -.->|"searches datasets"| node_datasets
node_database -->|"initializes"| node_engine
node_knowledge_ui -.->|"stores files"| node_storage
node_auth -.->|"uses identity"| node_account
node_app_runtime -.->|"records runs"| node_observability
node_app_runtime -->|"runs agent"| node_agent
node_agent -.->|"uses shell settings"| node_shell_config
node_shell_config -.->|"configures shell"| node_sandbox
node_agent -->|"connects tools"| node_tool_engine

click node_console "https://github.com/amp2byte/dify/tree/main/api/controllers/console/app"
click node_workflow "https://github.com/amp2byte/dify/tree/main/api/core/app/apps/workflow"
click node_prompt "https://github.com/amp2byte/dify/tree/main/api/core/app/app_config"
click node_app_config "https://github.com/amp2byte/dify/blob/main/api/models/model.py"
click node_entrypoints "https://github.com/amp2byte/dify/tree/main/api/controllers/service_api/app"
click node_app_runtime "https://github.com/amp2byte/dify/tree/main/api/core/app/apps"
click node_invoke_context "https://github.com/amp2byte/dify/blob/main/api/core/app/entities/app_invoke_entities.py"
click node_models "https://github.com/amp2byte/dify/blob/main/api/controllers/console/workspace/model_providers.py"
click node_tool_engine "https://github.com/amp2byte/dify/blob/main/api/core/tools/tool_engine.py"
click node_response "https://github.com/amp2byte/dify/blob/main/api/controllers/service_api/app/app.py"
click node_knowledge_ui "https://github.com/amp2byte/dify/tree/main/api/controllers/console/datasets"
click node_rag_pipeline "https://github.com/amp2byte/dify/blob/main/api/services/rag_pipeline/rag_pipeline.py"
click node_ingestion "https://github.com/amp2byte/dify/blob/main/api/tasks/rag_pipeline/rag_pipeline_run_task.py"
click node_retrieval "https://github.com/amp2byte/dify/blob/main/api/core/rag/datasource/retrieval_service.py"
click node_datasets "https://github.com/amp2byte/dify/blob/main/api/models/dataset.py"
click node_database "https://github.com/amp2byte/dify/blob/main/api/extensions/ext_database.py"
click node_engine "https://github.com/amp2byte/dify/blob/main/api/models/engine.py"
click node_storage "https://github.com/amp2byte/dify/blob/main/api/extensions/ext_storage.py"
click node_account "https://github.com/amp2byte/dify/blob/main/api/models/account.py"
click node_auth "https://github.com/amp2byte/dify/blob/main/api/libs/login.py"
click node_external_api "https://github.com/amp2byte/dify/blob/main/api/libs/external_api.py"
click node_observability "https://github.com/amp2byte/dify/blob/main/api/repositories/workflow_app_log_query_repository.py"
click node_agent "https://github.com/amp2byte/dify/tree/main/api/core/agent"
click node_shell_config "https://github.com/amp2byte/dify/blob/main/dify-agent/src/dify_agent/layers/shell/configs.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,node_app_config,node_user toneBlue
class node_entrypoints,node_app_runtime,node_invoke_context,node_models,node_tool_engine,node_response toneAmber
class node_knowledge_ui,node_rag_pipeline,node_ingestion,node_retrieval,node_datasets toneMint
class node_database,node_engine,node_storage,node_account,node_auth,node_external_api,node_observability toneRose
class node_agent,node_shell_config,node_sandbox,node_creator toneIndigo
```

## Components

### App creation

- [Creator interface](https://github.com/amp2byte/dify/tree/main/api/controllers/console/app): `api/controllers/console/app`
- [Visual workflows](https://github.com/amp2byte/dify/tree/main/api/core/app/apps/workflow): `api/core/app/apps/workflow`
- [Prompt IDE](https://github.com/amp2byte/dify/tree/main/api/core/app/app_config): `api/core/app/app_config`
- [App configuration](https://github.com/amp2byte/dify/blob/main/api/models/model.py): `api/models/model.py`

### Application runtime

- [Run interfaces](https://github.com/amp2byte/dify/tree/main/api/controllers/service_api/app): `api/controllers/service_api/app`
- [App runners](https://github.com/amp2byte/dify/tree/main/api/core/app/apps): `api/core/app/apps`
- [Invocation context](https://github.com/amp2byte/dify/blob/main/api/core/app/entities/app_invoke_entities.py): `api/core/app/entities/app_invoke_entities.py`
- [Model providers](https://github.com/amp2byte/dify/blob/main/api/controllers/console/workspace/model_providers.py): `api/controllers/console/workspace/model_providers.py`
- [Tool engine](https://github.com/amp2byte/dify/blob/main/api/core/tools/tool_engine.py): `api/core/tools/tool_engine.py`
- [App response](https://github.com/amp2byte/dify/blob/main/api/controllers/service_api/app/app.py): `api/controllers/service_api/app/app.py`

### RAG and knowledge

- [Knowledge management](https://github.com/amp2byte/dify/tree/main/api/controllers/console/datasets): `api/controllers/console/datasets`
- [RAG pipeline](https://github.com/amp2byte/dify/blob/main/api/services/rag_pipeline/rag_pipeline.py): `api/services/rag_pipeline/rag_pipeline.py`
- [Document ingestion](https://github.com/amp2byte/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/amp2byte/dify/blob/main/api/core/rag/datasource/retrieval_service.py): `api/core/rag/datasource/retrieval_service.py`
- [Dataset records](https://github.com/amp2byte/dify/blob/main/api/models/dataset.py): `api/models/dataset.py`

### Platform services

- [Database extension](https://github.com/amp2byte/dify/blob/main/api/extensions/ext_database.py): `api/extensions/ext_database.py`
- [Database engine](https://github.com/amp2byte/dify/blob/main/api/models/engine.py): `api/models/engine.py`
- [File storage](https://github.com/amp2byte/dify/blob/main/api/extensions/ext_storage.py): `api/extensions/ext_storage.py`
- [Account records](https://github.com/amp2byte/dify/blob/main/api/models/account.py): `api/models/account.py`
- [Login and identity](https://github.com/amp2byte/dify/blob/main/api/libs/login.py): `api/libs/login.py`
- [External API helpers](https://github.com/amp2byte/dify/blob/main/api/libs/external_api.py): `api/libs/external_api.py`
- [Run observability](https://github.com/amp2byte/dify/blob/main/api/repositories/workflow_app_log_query_repository.py): `api/repositories/workflow_app_log_query_repository.py`

### Agent execution

- [Autonomous agent](https://github.com/amp2byte/dify/tree/main/api/core/agent): `api/core/agent`
- [Shell configuration](https://github.com/amp2byte/dify/blob/main/dify-agent/src/dify_agent/layers/shell/configs.py): `dify-agent/src/dify_agent/layers/shell/configs.py`
- **Sandbox runtime**

### Other components

- **App creator**
- **End user**

## Connections

- App creator → Creator interface: configures apps (evidence: `README.md`)
- Creator interface → Visual workflows: builds workflows (evidence: `README.md`)
- App creator → Prompt IDE: crafts prompts (evidence: `README.md`)
- Prompt IDE → App configuration: configures apps (evidence: `README.md`)
- App configuration → App runners: configures runs (evidence: `api/core/app/apps/pipeline/pipeline_generator.py`)
- End user → Run interfaces: runs apps (evidence: `README.md`)
- Run interfaces → App runners: invokes apps
- App runners → Invocation context: uses context (evidence: `api/core/app/apps/pipeline/pipeline_queue_manager.py`)
- App runners → Model providers: calls models (evidence: `README.md`)
- App runners → Tool engine: uses tools (evidence: `README.md`)
- App runners → App response: returns results
- Knowledge management → RAG pipeline: configures ingestion (evidence: `README.md`)
- RAG pipeline → Document ingestion: ingests documents
- Document ingestion → Dataset records: stores documents (evidence: `api/tasks/rag_pipeline/rag_pipeline_run_task.py`)
- RAG pipeline → Retrieval service: retrieves context (evidence: `README.md`)
- Retrieval service → Dataset records: searches datasets (evidence: `api/core/rag/datasource/retrieval_service.py`)
- Database extension → Database engine: initializes (evidence: `api/extensions/ext_database.py`)
- Knowledge management → File storage: stores files
- Login and identity → Account records: uses identity
- App runners → Run observability: records runs
- App runners → Autonomous agent: runs agent (evidence: `README.md`)
- Autonomous agent → Shell configuration: uses shell settings
- Shell configuration → Sandbox runtime: configures shell
- Autonomous agent → Tool engine: connects tools (evidence: `README.md`)
