# arafa1974/dify architecture

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

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

## Overview

Dify is an LLM application development platform: users configure apps and workflows, connect models and knowledge sources, then run them through chat, API, or workflow interfaces. Its major product areas include workflow and agent execution, prompt/model configuration, RAG ingestion and retrieval, and operational integrations. The graph combines README-documented capabilities with relationships visible in sampled source and the source index; unsampled implementation details are represented only where the tree supports a subsystem path.

Main entry points: [`api/core/app/apps/advanced_chat/generate_task_pipeline.py`](https://github.com/arafa1974/dify/blob/main/api/core/app/apps/advanced_chat/generate_task_pipeline.py) (Chat and agent runtime), [`api/controllers/console/app`](https://github.com/arafa1974/dify/tree/main/api/controllers/console/app) (App builder), [`api/core/app/apps/workflow/generate_task_pipeline.py`](https://github.com/arafa1974/dify/blob/main/api/core/app/apps/workflow/generate_task_pipeline.py) (Workflow runtime), [`api/tasks/rag_pipeline/rag_pipeline_run_task.py`](https://github.com/arafa1974/dify/blob/main/api/tasks/rag_pipeline/rag_pipeline_run_task.py) (RAG pipeline tasks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["App authoring"]
  node_builder["App builder"]
  node_workflow_authoring["Workflow authoring<br/>[workflow.py]"]
  node_prompt_models["Prompt and models"]
end

subgraph group_runtime["App runtime"]
  node_chat_runtime["Chat and agent runtime"]
  node_workflow_runtime["Workflow runtime"]
  node_run_context["Invocation context"]
  node_run_events["Run event queue"]
end

subgraph group_knowledge["Knowledge and RAG"]
  node_knowledge_authoring["Knowledge management"]
  node_rag_pipeline["RAG pipeline<br/>[rag_pipeline.py]"]
  node_rag_run["RAG pipeline tasks"]
  node_retrieval["Knowledge retrieval"]
  node_dataset_store[("Dataset records<br/>[dataset.py]")]
end

subgraph group_platform["Platform services"]
  node_app_definitions["App definitions"]
  node_definition_store[("Definition repository")]
  node_model_providers["Model providers<br/>[model_providers.py]"]
  node_file_storage[("File storage<br/>[ext_storage.py]")]
  node_observability["Observability<br/>[otel_config.py]"]
end

node_user(("App creator or user"))
node_model_service{{"Model inference service"}}

node_user -->|"configures apps"| node_builder
node_builder -->|"edits workflows"| node_workflow_authoring
node_builder -->|"configures prompts"| node_prompt_models
node_workflow_authoring -.->|"publishes definitions"| node_app_definitions
node_app_definitions -->|"queries definitions"| node_definition_store
node_user -->|"runs app"| node_chat_runtime
node_user -->|"runs workflow"| node_workflow_runtime
node_chat_runtime -->|"uses context"| node_run_context
node_workflow_runtime -->|"uses context"| node_run_context
node_workflow_runtime -->|"publishes events"| node_run_events
node_prompt_models -.->|"selects models"| node_model_providers
node_chat_runtime -.->|"requests inference"| node_model_service
node_user -->|"manages sources"| node_knowledge_authoring
node_knowledge_authoring -.->|"configures ingestion"| node_rag_pipeline
node_rag_pipeline -->|"schedules runs"| node_rag_run
node_rag_run -.->|"uses retrieval"| node_retrieval
node_retrieval -->|"reads datasets"| node_dataset_store
node_rag_run -.->|"uses file storage"| node_file_storage
node_chat_runtime -.->|"retrieves knowledge"| node_retrieval
node_user -.->|"views operations"| node_observability

click node_builder "https://github.com/arafa1974/dify/tree/main/api/controllers/console/app"
click node_workflow_authoring "https://github.com/arafa1974/dify/blob/main/api/controllers/console/app/workflow.py"
click node_prompt_models "https://github.com/arafa1974/dify/tree/main/api/core/app/app_config"
click node_app_definitions "https://github.com/arafa1974/dify/blob/main/api/services/app_definition_query_service.py"
click node_definition_store "https://github.com/arafa1974/dify/blob/main/api/repositories/app_definition_query_repository.py"
click node_chat_runtime "https://github.com/arafa1974/dify/blob/main/api/core/app/apps/advanced_chat/generate_task_pipeline.py"
click node_workflow_runtime "https://github.com/arafa1974/dify/blob/main/api/core/app/apps/workflow/generate_task_pipeline.py"
click node_run_context "https://github.com/arafa1974/dify/blob/main/api/core/app/entities/app_invoke_entities.py"
click node_run_events "https://github.com/arafa1974/dify/blob/main/api/core/app/apps/pipeline/pipeline_queue_manager.py"
click node_model_providers "https://github.com/arafa1974/dify/blob/main/api/controllers/console/workspace/model_providers.py"
click node_knowledge_authoring "https://github.com/arafa1974/dify/tree/main/api/controllers/console/datasets"
click node_rag_pipeline "https://github.com/arafa1974/dify/blob/main/api/services/rag_pipeline/rag_pipeline.py"
click node_rag_run "https://github.com/arafa1974/dify/blob/main/api/tasks/rag_pipeline/rag_pipeline_run_task.py"
click node_retrieval "https://github.com/arafa1974/dify/blob/main/api/core/rag/datasource/retrieval_service.py"
click node_dataset_store "https://github.com/arafa1974/dify/blob/main/api/models/dataset.py"
click node_file_storage "https://github.com/arafa1974/dify/blob/main/api/extensions/ext_storage.py"
click node_observability "https://github.com/arafa1974/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_builder,node_workflow_authoring,node_prompt_models,node_user toneBlue
class node_chat_runtime,node_workflow_runtime,node_run_context,node_run_events toneAmber
class node_knowledge_authoring,node_rag_pipeline,node_rag_run,node_retrieval,node_dataset_store toneMint
class node_app_definitions,node_definition_store,node_model_providers,node_file_storage,node_observability toneRose
class node_model_service toneIndigo
```

## Components

### App authoring

- [App builder](https://github.com/arafa1974/dify/tree/main/api/controllers/console/app): `api/controllers/console/app`
- [Workflow authoring](https://github.com/arafa1974/dify/blob/main/api/controllers/console/app/workflow.py): `api/controllers/console/app/workflow.py`
- [Prompt and models](https://github.com/arafa1974/dify/tree/main/api/core/app/app_config): `api/core/app/app_config`

### App runtime

- [Chat and agent runtime](https://github.com/arafa1974/dify/blob/main/api/core/app/apps/advanced_chat/generate_task_pipeline.py): `api/core/app/apps/advanced_chat/generate_task_pipeline.py`
- [Workflow runtime](https://github.com/arafa1974/dify/blob/main/api/core/app/apps/workflow/generate_task_pipeline.py): `api/core/app/apps/workflow/generate_task_pipeline.py`
- [Invocation context](https://github.com/arafa1974/dify/blob/main/api/core/app/entities/app_invoke_entities.py): `api/core/app/entities/app_invoke_entities.py`
- [Run event queue](https://github.com/arafa1974/dify/blob/main/api/core/app/apps/pipeline/pipeline_queue_manager.py): `api/core/app/apps/pipeline/pipeline_queue_manager.py`

### Knowledge and RAG

- [Knowledge management](https://github.com/arafa1974/dify/tree/main/api/controllers/console/datasets): `api/controllers/console/datasets`
- [RAG pipeline](https://github.com/arafa1974/dify/blob/main/api/services/rag_pipeline/rag_pipeline.py): `api/services/rag_pipeline/rag_pipeline.py`
- [RAG pipeline tasks](https://github.com/arafa1974/dify/blob/main/api/tasks/rag_pipeline/rag_pipeline_run_task.py): `api/tasks/rag_pipeline/rag_pipeline_run_task.py`
- [Knowledge retrieval](https://github.com/arafa1974/dify/blob/main/api/core/rag/datasource/retrieval_service.py): `api/core/rag/datasource/retrieval_service.py`
- [Dataset records](https://github.com/arafa1974/dify/blob/main/api/models/dataset.py): `api/models/dataset.py`

### Platform services

- [App definitions](https://github.com/arafa1974/dify/blob/main/api/services/app_definition_query_service.py): `api/services/app_definition_query_service.py`
- [Definition repository](https://github.com/arafa1974/dify/blob/main/api/repositories/app_definition_query_repository.py): `api/repositories/app_definition_query_repository.py`
- [Model providers](https://github.com/arafa1974/dify/blob/main/api/controllers/console/workspace/model_providers.py): `api/controllers/console/workspace/model_providers.py`
- [File storage](https://github.com/arafa1974/dify/blob/main/api/extensions/ext_storage.py): `api/extensions/ext_storage.py`
- [Observability](https://github.com/arafa1974/dify/blob/main/api/configs/observability/otel/otel_config.py): `api/configs/observability/otel/otel_config.py`

### Other components

- **App creator or user**
- **Model inference service**

## Connections

- App creator or user → App builder: configures apps (evidence: `README.md`)
- App builder → Workflow authoring: edits workflows (evidence: `README.md`)
- App builder → Prompt and models: configures prompts (evidence: `README.md`)
- Workflow authoring → App definitions: publishes definitions
- App definitions → Definition repository: queries definitions (evidence: `api/repositories/app_definition_query_repository.py`)
- App creator or user → Chat and agent runtime: runs app (evidence: `README.md`)
- App creator or user → Workflow runtime: runs workflow (evidence: `README.md`)
- Chat and agent runtime → Invocation context: uses context (evidence: `api/core/app/entities/app_invoke_entities.py`)
- Workflow runtime → Invocation context: uses context (evidence: `api/core/app/entities/app_invoke_entities.py`)
- Workflow runtime → Run event queue: publishes events (evidence: `api/core/app/apps/pipeline/pipeline_queue_manager.py`)
- Prompt and models → Model providers: selects models
- Chat and agent runtime → Model inference service: requests inference
- App creator or user → Knowledge management: manages sources (evidence: `README.md`)
- Knowledge management → RAG pipeline: configures ingestion (evidence: `api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py`)
- RAG pipeline → RAG pipeline tasks: schedules runs (evidence: `api/tasks/rag_pipeline/rag_pipeline_run_task.py`)
- RAG pipeline tasks → Knowledge retrieval: uses retrieval
- Knowledge retrieval → Dataset records: reads datasets (evidence: `api/core/rag/datasource/retrieval_service.py`)
- RAG pipeline tasks → File storage: uses file storage
- Chat and agent runtime → Knowledge retrieval: retrieves knowledge
- App creator or user → Observability: views operations
