This document describes the overall system architecture of Langflow, a low-code platform for building AI agents and workflows. It covers the three-tier architecture consisting of the build/deploy layer, backend services, and frontend application, and explains how these layers interact to enable visual flow building and execution.
For specific implementation details about individual subsystems, see:
Langflow follows a monorepo architecture with three main packages that form distinct architectural layers:
Key architectural characteristics:
| Layer | Technology | Purpose |
|---|---|---|
| Build & Deploy | uv, npm, Docker | Dependency management, compilation, containerization |
| Backend Services | FastAPI, SQLModel, LFX | REST API, execution engine, component system |
| Frontend Application | React, ReactFlow, Zustand | Visual flow editor, state management, user interface |
Sources: pyproject.toml1-390 src/backend/base/pyproject.toml1-255 src/frontend/package.json1-173
The monorepo is organized as a uv workspace with three core packages:
Package roles:
langflow (root): Main package that users install via pip install langflow. Contains minimal dependencies and includes the compiled frontend.
langflow-base[complete]~=0.8.0langflow-base: Core backend functionality including FastAPI application, services, and component system.
lfx~=0.3.0, fastapi>=0.115.2, langchain~=0.3.27lfx: Low-level execution engine, component base classes, and graph processing.
The workspace configuration is defined in pyproject.toml80-86:
Sources: pyproject.toml1-390 src/backend/base/pyproject.toml1-255
The backend is a FastAPI application that serves both the API and the compiled frontend:
Application initialization sequence (see src/backend/base/langflow/main.py34-135):
create_app() assembles the FastAPI applicationsetup_services() initializes all core services via ServiceManager/api/v1/*/ and serve the React applicationKey code entities:
create_app() - src/backend/base/langflow/main.py138-273setup_services() - src/backend/base/langflow/main.py276-349Sources: src/backend/base/langflow/main.py1-800
The backend uses a service-oriented architecture with centralized service management:
Service lifecycle:
ServiceManagerDatabaseService depends on SettingsService)Sources: src/backend/base/langflow/services/ src/backend/base/langflow/main.py276-349
The frontend is a single-page React application built with Vite:
Component hierarchy:
App.tsx provides routing and global contextsPageComponent manages the ReactFlow canvasGenericNode represents individual flow componentsSources: src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx1-750 src/frontend/src/CustomNodes/GenericNode/index.tsx1-686
Langflow uses Zustand for centralized state management:
Key store responsibilities:
| Store | File | Primary Responsibility |
|---|---|---|
flowStore | src/frontend/src/stores/flowStore.ts1-1000 | Manages active flow nodes, edges, and execution state |
flowsManagerStore | stores/flowsManagerStore.ts | Manages collection of flows, undo/redo, current flow selection |
typesStore | stores/typesStore.ts | Caches component definitions from backend API |
alertStore | stores/alertStore.ts | Displays notifications and error messages |
messagesStore | stores/messagesStore.ts | Manages chat messages and sessions |
globalVariablesStore | stores/globalVariablesStore/ | Environment variables and global settings |
State synchronization flow:
onNodesChange)autoSaveFlow in src/frontend/src/stores/flowStore.ts86)Sources: src/frontend/src/stores/flowStore.ts1-1000 src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx1-750
The visual flow editor is built on ReactFlow (@xyflow/react):
Handle ID format (see src/frontend/src/utils/reactflowUtils.ts323-450):
Handles use escaped JSON strings as IDs to encode type information:
{"type":"str","fieldName":"input_value","id":"node_id","inputTypes":["Message","str"]}{"id":"node_id","name":"output","output_types":["Message"],"dataType":"ChatOutput"}Connection validation (see isValidConnection() at src/frontend/src/utils/reactflowUtils.ts323-450):
output_types and inputTypesSources: src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx86-750 src/frontend/src/CustomNodes/GenericNode/index.tsx1-686 src/frontend/src/utils/reactflowUtils.ts1-2000
The component system is based on a JSON registry that catalogs all available components:
Key registry files:
component_index.json - Complete component catalog with metadatastable_hash_history.json - Tracks component code changes for version detectionComponent metadata structure (see types in src/frontend/src/types/api/index.ts33-89):
Sources: src/frontend/src/types/api/index.ts1-300
From user interaction to component execution:
Key execution functions:
| Function | Location | Purpose |
|---|---|---|
buildFlowVerticesWithFallback() | src/frontend/src/utils/buildUtils.ts | Initiates build with SSE or polling fallback |
Graph.from_flow_data() | Backend graph engine | Converts flow JSON to executable DAG |
instantiate_class() | Backend component loader | Creates component instances from definitions |
Vertex.build() | Backend vertex executor | Executes component with inputs |
Event streaming (see src/frontend/src/utils/buildUtils.ts1-800):
/api/v1/build/{flow_id}/streambuildStatus in flowStore/api/v1/build/{flow_id}/eventsSources: src/frontend/src/utils/buildUtils.ts1-800 src/frontend/src/stores/flowStore.ts1-1000
Data transformation stages:
User Interaction → ReactFlow State
GenericNodeGenericNode calls store actions to update nodes arrayReactFlow State → Backend Format
flowStore serializes nodes/edges to flow JSONreactflowUtils.ts transform ReactFlow objects/api/v1/flows/{id} or /api/v1/build/{id}/flowBackend Processing
Graph class converts JSON to executable DAGVertex instances execute components in topological orderBackend Results → Frontend Display
buildStatus map in flowStoreGenericNode components display status indicatorsSources: src/frontend/src/CustomNodes/GenericNode/index.tsx1-686 src/frontend/src/utils/reactflowUtils.ts1-2000 src/frontend/src/utils/buildUtils.ts1-800
The project uses uv for Python dependency management and npm for frontend builds:
Key development workflows:
| Command | Purpose | Details |
|---|---|---|
make init | First-time setup | Installs all dependencies (backend + frontend) |
make run_cli | Run Langflow | Builds frontend, then starts backend server |
make backend | Backend only | Starts FastAPI without rebuilding frontend |
make frontend | Frontend only | Starts Vite dev server on port 3000 |
make format | Format code | Runs Ruff (Python) and Biome (TypeScript) |
Hot-reload component development (see Makefile290-298):
Sources: Makefile1-600
Build commands (see Makefile407-466):
Docker images (multiple variants available):
langflowai/langflow:latest - Full applicationlangflowai/langflow-backend:latest - Backend onlylangflowai/langflow-frontend:latest - Frontend onlySources: Makefile407-466
| Layer | Core Technologies | Key Libraries |
|---|---|---|
| Backend | Python 3.10-3.13, FastAPI, SQLModel | langchain, pydantic, alembic, uvicorn |
| Frontend | React 19, TypeScript, Vite | @xyflow/react, zustand, axios, tailwindcss |
| Execution | LFX engine, Python async | langchain-core, networkx, diskcache |
| Build | uv, npm, Docker | hatch, vite, Biome, Ruff |
| Database | SQLite (default), PostgreSQL | sqlalchemy, asyncio, alembic |
| Testing | pytest, Playwright | pytest-asyncio, jest, pytest-xdist |
Browser compatibility:
Python compatibility:
Sources: pyproject.toml1-390 src/backend/base/pyproject.toml1-255 src/frontend/package.json1-173
Refresh this wiki
This wiki was recently refreshed. Please wait 3 days to refresh again.