Skip to content
STACK IT FAST

Dify.ai

Curated OSSAI-agentLLM App Builder20+ people

Audited from github.com/langgenius/dify

Dify is an open-source LLM application platform combining a visual workflow builder, RAG pipelines, and AI agents with model management and observability, deployable self-hosted via Docker or on Dify Cloud.

Language
TypeScript
Database
PostgreSQL
Hosting
Nginx
Running for
2 years 1 month
Team
20+ people

Why this architecture

Agent execution and vector retrieval are split into separate, independently scalable services (a Go sandbox runtime, a FastAPI agent orchestrator, and pluggable vector-store providers) so untrusted tool code and swappable retrieval backends stay out of the core Flask API process.

Tech stack by layer

9 technologies · audited Sep 17, 2026
Frontend & UI
  • Next.jsServes the Studio console and end-user app UI; scripts and web/next.config.ts drive the standard build.
  • VitePowers an experimental "vinext" dev/build path (dev:vinext, build:vinext scripts) alongside the Next.js build.
  • Jotai + TanStack FormShared atom-based state and form bindings, packaged as an in-repo workspace library for the web app.
  • dify-ui (@base-ui/react + Tailwind)Dify's own component package (buttons, dialogs, comboboxes) built on @base-ui/react, shared by web and packages/dify-ui.
Backend & APIs
  • FlaskRuns the console/service REST API; app.py and app_factory.py bootstrap the WSGI app served by Gunicorn.
  • CeleryExecutes background jobs (workflow runs, document indexing) via a dedicated entrypoint and scheduler.
  • Gunicorn + geventProduction WSGI server using gevent workers and gevent-websocket for the Flask API process.
  • dify-agent (FastAPI + pydantic-ai)Standalone Python service that runs autonomous agents, separate from the main Flask API process.
  • dify-agent-runtime (Go)Sandboxed shell/file execution backend for agents, using landlock-lsm for OS-level isolation.
Data & Persistence
  • PostgreSQLPrimary relational store, accessed via psycopg2-binary from the Flask API and Celery workers.
  • RedisCelery broker/result backend and general cache, via redis[hiredis].
  • Pluggable vector storesRAG retrieval backends are workspace packages under api/providers/vdb, with pgvector, Elasticsearch, and TiDB deployable via Docker.(inferred)
Infrastructure & Deploy
  • Docker ComposeSelf-hosted stack is assembled from docker/docker-compose.yaml plus per-service env files.
  • NginxReverse proxy in front of the web and api containers for self-hosted deployments.
  • SSRF proxyDedicated proxy container that outbound tool/plugin HTTP calls are routed through to contain SSRF risk.
Tooling, Testing & Ops
  • pydantic-aiAgent orchestration framework used by the dify-agent service for tool calling and multi-step reasoning.
  • e2bOptional cloud sandbox provider for agent code execution, alongside the local Go landlock sandbox.

Dify.ai architecture diagram

Open SVG
Dify.ai architecture diagramStudio console → Reverse proxy (HTTPS); Apps & SDKs → Reverse proxy (API); Reverse proxy → API (/api); API → PostgreSQL (psycopg2); API → Redis (enqueue); Redis → Celery workers (tasks); Celery workers → Vector store (index docs); API → dify-agent (run agent); dify-agent → Agent runtime (sandbox exec); API → SSRF proxy (tool HTTP)CLIENTSSERVICESWORKERS & JOBSDATA & STORAGEEXTERNALStudio consoleNext.js · dify-uiApps & SDKsREST · Node/PHP SDKsReverse proxyNginxAPIFlask · Gunicorndify-agentFastAPI · pydantic-aiCelery workersworkflows · indexingAgent runtimeGo · landlockPostgreSQLRedisbroker · cacheVector storepgvector / ES / TiDBSSRF proxyoutbound HTTP/apirun agentHTTPSAPItasksindex docssandbox execpsycopg2enqueuetool HTTP
How the main components of Dify.ai connect, drawn from the audited repository.
Diagram as text
  • Studio console (Next.js · dify-ui) → Reverse proxy (Nginx): HTTPS
  • Apps & SDKs (REST · Node/PHP SDKs) → Reverse proxy (Nginx): API
  • Reverse proxy (Nginx) → API (Flask · Gunicorn): /api
  • API (Flask · Gunicorn) → PostgreSQL: psycopg2
  • API (Flask · Gunicorn) → Redis (broker · cache): enqueue
  • Redis (broker · cache) → Celery workers (workflows · indexing): tasks
  • Celery workers (workflows · indexing) → Vector store (pgvector / ES / TiDB): index docs
  • API (Flask · Gunicorn) → dify-agent (FastAPI · pydantic-ai): run agent
  • dify-agent (FastAPI · pydantic-ai) → Agent runtime (Go · landlock): sandbox exec
  • API (Flask · Gunicorn) → SSRF proxy (outbound HTTP): tool HTTP

Key architectural decisions

6 decisions
  1. 01

    Agent execution is split into two services outside the main API

    dify-agent (Python, FastAPI + pydantic-ai, dify-agent/pyproject.toml) orchestrates agent reasoning, while dify-agent-runtime (Go, dify-agent-runtime/go.mod) runs shell and file operations inside a landlock-lsm sandbox. Neither runs inside the Flask api process that serves normal console/app requests.

  2. 02

    The web console can build with Next.js or an experimental Vite path

    web/package.json defines both the standard "build"/"dev" scripts (next build, next dev) and "build:vinext"/"dev:vinext" scripts that go through web/vite.config.ts, so the same app/ directory can be served by either toolchain during the transition.

  3. 03

    Vector store backends are pluggable provider packages, not a hard dependency

    api/pyproject.toml declares a uv workspace over providers/vdb/*, and docker/ ships separate compose fragments for pgvector, Elasticsearch, TiDB, and Couchbase, so operators choose a retrieval backend at deploy time rather than the API hard-coding one vector database client.

  4. 04

    Outbound tool calls go through a dedicated SSRF proxy container

    docker/ssrf_proxy is a separate service in the compose stack that HTTP requests originating from tools, plugins, and code-execution nodes are routed through, keeping arbitrary user-configured URLs from reaching internal services directly.

  5. 05

    The CLI is a separate TypeScript package compiled to native binaries

    cli/package.json builds @langgenius/difyctl with vite-plus and ships per-platform bun targets (linux-x64, darwin-arm64, windows-x64, etc.) rather than requiring a Node/Python runtime on the operator machine.

  6. 06

    API-consumer SDKs live in the monorepo but ship independently

    sdks/nodejs-client (dify-client, published to npm) and sdks/php-client are versioned and published separately from the main app/api images, giving external integrators a stable client without depending on the app release cadence.

How Dify.ai is built

How Dify is structured

The repository is a pnpm workspace (pnpm-workspace.yaml: web, e2e, sdks/nodejs-client, packages/*, cli) laid over a set of independently versioned services. web/ is the Next.js console and app UI; api/ is the Flask REST API and Celery worker codebase, managed with uv (api/pyproject.toml, api/uv.lock); dify-agent/ and dify-agent-runtime/ are separate Python and Go services for running AI agents; cli/ builds the difyctl command-line tool; and sdks/ holds the published Node.js and PHP client libraries. docker/ contains the self-hosting Compose stack, and .github/workflows runs over 30 CI jobs covering web, API, CLI, and agent-runtime tests.

Frontend

web/ is a Next.js app (web/next.config.ts) with an app-router directory (web/app) and its own i18n system (web/i18n, web/i18n-config). The same package also defines dev:vinext/build:vinext scripts that build through web/vite.config.ts, an alternate Vite-based path that coexists with the standard Next.js build. Shared UI comes from packages/dify-ui, an internal component library on top of @base-ui/react with Tailwind-based lint rules (lint:tailwind in the root package.json), and shared state/form logic is factored into the workspace package packages/jotai-tanstack-form (Jotai atoms plus TanStack Form). Icons are generated into the app from packages/iconify-collections. Browser tests run through web/vitest.browser.setup.ts and Storybook (web/.storybook).

Backend & APIs

api/app.py and api/app_factory.py construct the Flask application; api/controllers, api/services, and api/core hold the route handlers, business logic, and LLM/workflow engine respectively. api/pyproject.toml pins Flask, Flask-RESTX, Flask-Login, and Flask-Migrate (with api/migrations), and the production image runs it under Gunicorn with gevent workers (api/gunicorn.conf.py, gevent-websocket). Asynchronous work — workflow execution, document ingestion, scheduled jobs — goes through Celery, started via api/celery_entrypoint.py and configured for a Redis broker. Two more Python/Go services extend the backend rather than living inside it: dify-agent is a FastAPI app (pydantic-ai-slim, jwcrypto, optional e2b cloud sandboxes) that runs agent reasoning loops, and dify-agent-runtime is a Go binary (dify-agent-runtime/go.mod) built around landlock-lsm that executes shell commands and file operations for agents inside an OS-level sandbox.

Data & persistence

PostgreSQL is the primary datastore, reached from the API and workers via psycopg2-binary (api/pyproject.toml). Redis (redis[hiredis]) backs the Celery broker/result store and general caching. Retrieval-augmented generation does not hard-code a single vector database: api/pyproject.toml declares a uv workspace over providers/vdb/*, and the docker/ directory ships separate service definitions for pgvector, elasticsearch, tidb, iris, and couchbase-server, so operators pick a vector backend when they deploy rather than the API committing to one.

Build, test & deploy

The JS side is linted with a combination of ESLint, oxlint (via the in-house vite-plus/vp CLI), Knip for unused exports, and tsslint; unit tests run on Vitest and end-to-end flows on Playwright plus Cucumber (e2e/cucumber.config.ts, @cucumber/cucumber), including a dedicated accessibility suite using @axe-core/playwright (accessibility-e2e.yml). Python code is checked with ruff, pyrefly, and pytest (api/pytest.ini, api/conftest.py). CI (.github/workflows) includes main-ci.yml, db-migration-test.yml, vdb-tests-full.yml for the pluggable vector backends, and separate cli-* and dify-agent-tests.yml jobs, plus docker-build.yml/build-push.yml that publish images per service.

Self-hosting notes

docker/docker-compose.yaml is the documented self-hosting entry point: cd docker && cp .env.example .env && docker compose up -d, after which setup completes at http://localhost/install. The README states minimum requirements of 2 CPU cores and 4 GiB RAM. docker/nginx fronts the web and api containers, docker/certbot handles TLS, and docker/ssrf_proxy is a dedicated proxy that outbound calls from tools, plugins, and code-execution nodes are routed through so arbitrary user-supplied URLs cannot reach internal services directly. Each backend image (api/Dockerfile, web/Dockerfile, dify-agent/Dockerfile, dify-agent-runtime/docker/Dockerfile) is a separate multi-stage build.

What to copy (and what not to)

Pulling agent tool execution out of the request-serving API process, into a language chosen for the job (Go with landlock-lsm for OS-level sandboxing, not Python), is a pattern worth copying for anything that runs user- or LLM-generated commands. Routing tool-originated HTTP through a separate SSRF proxy container is a cheap, composable way to add that isolation without rewriting application code. The pluggable-vector-store workspace (providers/vdb/*) is good for a project shipping to many self-hosters with different infrastructure, but it adds real abstraction overhead — a single-backend project targeting one deployment environment would not need it. The dual Next.js/Vite build path is a migration artifact rather than a pattern to replicate; it exists because the team is mid-transition, not because running two build tools long-term is desirable.

Sources & repo audit

Audited
Sep 17, 2026
Commit
ad9a5be
License
NOASSERTION

Independent analysis of repository at github.com/langgenius/dify. Spotted an inaccuracy? Use the claim form to request a correction.

Show this stack on your README or website
Tech stack of Dify.ai
[![Tech stack of Dify.ai on STACK IT FAST](https://stackitfast.com/badge/dify.svg)](https://stackitfast.com/project/dify)

Paste it into your README. It shows your current stack and links to this page.

Use this stack

Scaffold it with your agent

Paste this prompt into Claude Code, Cursor, Windsurf or AGY to start a project with Dify.ai's architecture.

  1. 1Copy the promptThe full markdown spec, with every layer and decision.
  2. 2Open your AI toolClaude Code, Cursor, Windsurf or Copilot, in a new repo.
  3. 3Paste and scaffoldUse it as the first instruction; review before you ship.
use-this-stack.md · 61 lines · 8.3 KB
# MISSION: Scaffold "Dify.ai" Production Architecture
You are an expert Senior Staff Software Architect and Full-Stack Engineer. Your mission is to scaffold and implement a production-grade, highly reliable, and modular codebase following the proven architecture of **Dify.ai**.
---
## 1. PROJECT SPECIFICATIONS & BENCHMARK
- **Reference Architecture**: Dify.ai
- **What It Does**: Dify is an open-source LLM application platform combining a visual workflow builder, RAG pipelines, and AI agents with model management and observability, deployable self-hosted via Docker or on Dify Cloud.
- **Domain & Category**: LLM App Builder
- **Production Scale**: 20+ people
- **Development Mode**: AI-AGENT
- **Architectural Rationale**: Agent execution and vector retrieval are split into separate, independently scalable services (a Go sandbox runtime, a FastAPI agent orchestrator, and pluggable vector-store providers) so untrusted tool code and swappable retrieval backends stay out of the core Flask API process.
- **Live Website Reference**: https://dify.ai
- **Source Repository**: https://github.com/langgenius/dify
---
## 2. PRODUCTION TECH STACK
- **Full Stack Array**: Next.js, TypeScript, Python, Flask, Celery, Redis, PostgreSQL, Go, Docker
- **Primary Language(s)**: TypeScript, Python, JavaScript
- **License of the reference repo**: NOASSERTION
- **Frontend**: Next.js — Serves the Studio console and end-user app UI; scripts and web/next.config.ts drive the standard build.; Vite — Powers an experimental "vinext" dev/build path (dev:vinext, build:vinext scripts) alongside the Next.js build.; Jotai + TanStack Form — Shared atom-based state and form bindings, packaged as an in-repo workspace library for the web app.; dify-ui (@base-ui/react + Tailwind) — Dify's own component package (buttons, dialogs, comboboxes) built on @base-ui/react, shared by web and packages/dify-ui.
- **Backend & APIs**: Flask — Runs the console/service REST API; app.py and app_factory.py bootstrap the WSGI app served by Gunicorn.; Celery — Executes background jobs (workflow runs, document indexing) via a dedicated entrypoint and scheduler.; Gunicorn + gevent — Production WSGI server using gevent workers and gevent-websocket for the Flask API process.; dify-agent (FastAPI + pydantic-ai) — Standalone Python service that runs autonomous agents, separate from the main Flask API process.; dify-agent-runtime (Go) — Sandboxed shell/file execution backend for agents, using landlock-lsm for OS-level isolation.
- **Data & persistence**: PostgreSQL — Primary relational store, accessed via psycopg2-binary from the Flask API and Celery workers.; Redis — Celery broker/result backend and general cache, via redis[hiredis].; Pluggable vector stores — RAG retrieval backends are workspace packages under api/providers/vdb, with pgvector, Elasticsearch, and TiDB deployable via Docker.
- **Infrastructure & deploy**: Docker Compose — Self-hosted stack is assembled from docker/docker-compose.yaml plus per-service env files.; Nginx — Reverse proxy in front of the web and api containers for self-hosted deployments.; SSRF proxy — Dedicated proxy container that outbound tool/plugin HTTP calls are routed through to contain SSRF risk.
- **Tooling, testing & ops**: pydantic-ai — Agent orchestration framework used by the dify-agent service for tool calling and multi-step reasoning.; e2b — Optional cloud sandbox provider for agent code execution, alongside the local Go landlock sandbox.
---
## 3. KEY ARCHITECTURAL DECISIONS (audited from https://github.com/langgenius/dify @ ad9a5be)
1. **Agent execution is split into two services outside the main API**: dify-agent (Python, FastAPI + pydantic-ai, dify-agent/pyproject.toml) orchestrates agent reasoning, while dify-agent-runtime (Go, dify-agent-runtime/go.mod) runs shell and file operations inside a landlock-lsm sandbox. Neither runs inside the Flask api process that serves normal console/app requests.
2. **The web console can build with Next.js or an experimental Vite path**: web/package.json defines both the standard "build"/"dev" scripts (next build, next dev) and "build:vinext"/"dev:vinext" scripts that go through web/vite.config.ts, so the same app/ directory can be served by either toolchain during the transition.
3. **Vector store backends are pluggable provider packages, not a hard dependency**: api/pyproject.toml declares a uv workspace over providers/vdb/*, and docker/ ships separate compose fragments for pgvector, Elasticsearch, TiDB, and Couchbase, so operators choose a retrieval backend at deploy time rather than the API hard-coding one vector database client.
4. **Outbound tool calls go through a dedicated SSRF proxy container**: docker/ssrf_proxy is a separate service in the compose stack that HTTP requests originating from tools, plugins, and code-execution nodes are routed through, keeping arbitrary user-configured URLs from reaching internal services directly.
5. **The CLI is a separate TypeScript package compiled to native binaries**: cli/package.json builds @langgenius/difyctl with vite-plus and ships per-platform bun targets (linux-x64, darwin-arm64, windows-x64, etc.) rather than requiring a Node/Python runtime on the operator machine.
6. **API-consumer SDKs live in the monorepo but ship independently**: sdks/nodejs-client (dify-client, published to npm) and sdks/php-client are versioned and published separately from the main app/api images, giving external integrators a stable client without depending on the app release cadence.
---
## 4. NON-NEGOTIABLE ARCHITECTURAL GUARDRAILS
1. **Monorepo & Modular Separation**:
   - Structure as a Turborepo monorepo with strict package boundaries:
     - `apps/web`: Application UI, routing, layouts, and server endpoints.
     - `packages/ui`: Shared design tokens, CSS variables, and Radix UI primitive components.
     - `packages/db`: Database schemas, client singleton, declarative migrations, and seed scripts.
     - `packages/config`: Shared TypeScript, ESLint, and build configurations.
2. **Strict Type Safety & Zero `any` Policy**:
   - Enable `strict: true`, `noImplicitAny: true`, and `strictNullChecks: true`.
   - Validate ALL external inputs, API request bodies, and query parameters with **Zod** schemas before execution.
3. **Frontend & Rendering Guidelines**:
   - Utilize Next.js 15 App Router: default to React Server Components (RSC) for data fetching. Handle mutations through Server Actions with Zod validation. Keep 'use client' directives restricted strictly to interactive leaf components.
4. **Design System & Aesthetics**:
   - Keep every color, radius, shadow and font in a single token file (CSS variables) and consume tokens everywhere; never hardcode hex values in components.
   - Prefer crisp 1px borders and one subtle shadow scale over blurry default shadows. Pair one sans-serif for body/headings with one monospace for tags, badges, metrics, and code.
5. **Data Layer & Reliability**:
   - Write declarative schema definitions with foreign keys, composite indexes on queried filters, and automated timestamp triggers.
   - Use connection pooling and prepared statements for serverless database execution.
---
## 5. STEP-BY-STEP SCAFFOLDING ROADMAP
- **Phase 1: Workspace & Root Config**: Initialize package manager, monorepo configuration (`turbo.json`, `tsconfig.base.json`, `package.json`).
- **Phase 2: Database Schema & Client**: Set up the data layer (PostgreSQL, Redis, Pluggable vector stores): client, connection pool, models, and migration scripts.
- **Phase 3: Design Tokens & UI Primitives**: Build accessible `Button`, `Input`, `Card`, `Badge`, and layout wrappers inside `packages/ui`.
- **Phase 4: Core Application Routes & Handlers**: Implement primary authentication, user session handling, and application routes.
- **Phase 5: Quality Assurance & Build Verification**: Run `tsc --noEmit`, ESLint, Prettier, and smoke test suites to ensure zero compilation or runtime errors.
---
## 6. EXECUTION INSTRUCTIONS
1. Review all specifications, architectural guardrails, and stack choices above.
2. Present the full monorepo directory tree structure.
3. Systematically generate the complete, production-ready codebase according to the 5-phase roadmap above — starting with the root workspace setup, followed by the database schema, UI design system package, and full-stack application routes until the repository is fully scaffolded and ready to run.
Scaffolded something with this prompt?
Would you pick this stack for a llm app builder project?

Frequently asked about Dify.ai

What is Dify built with?

The Studio console is a Next.js/TypeScript app in web/, the core API is a Python Flask app in api/ backed by PostgreSQL and Redis, background work runs through Celery, and AI agents execute in two dedicated services: a FastAPI/pydantic-ai orchestrator (dify-agent) and a Go sandbox runtime (dify-agent-runtime).

Does Dify need a backend?

Yes. Dify is the backend: the api/ Flask service, Celery workers, PostgreSQL, Redis, and a vector store are all required to run workflows, RAG pipelines, and agents; the web/ Next.js app is a client of that API rather than a standalone frontend.

Can I self-host Dify?

Yes, via Docker Compose. The README states minimum requirements of 2 CPU cores and 4 GiB RAM, and docker/docker-compose.yaml plus docker/.env.example bring up the web, api, worker, Postgres, Redis, Nginx, and SSRF proxy containers together.

How does Dify run AI agents safely?

Agent tool calls are isolated from the main API: dify-agent-runtime (Go) executes shell and file operations inside a landlock-lsm sandbox, and dify-agent (Python) can alternatively delegate execution to e2b cloud sandboxes, while all outbound HTTP from tools passes through a separate SSRF proxy container.

What does the Dify architecture look like?

A Next.js console (web/) in front of a Flask REST API with Celery workers (api/), separate Python and Go services for running agents (dify-agent, dify-agent-runtime), and PostgreSQL, Redis and a pluggable vector store, all wired together by the Docker Compose stack in docker/.

One email a month: new deep dives and stack trends

New source-audited architectures, head-to-head comparisons and the monthly stack report. No spam, unsubscribe anytime.

use-this-stack.md