Overview
Open WebUI is a full-stack application built with a modern, scalable architecture. The system consists of a SvelteKit frontend and a FastAPI backend, designed to provide a responsive AI chat interface with extensive customization capabilities.Technology Stack
Frontend
- Framework: SvelteKit 5.x
- Build Tool: Vite 5.x
- Language: TypeScript 5.x
- Styling: Tailwind CSS 4.x
- State Management: Svelte stores
- Real-time Communication: Socket.IO Client
- Code Editor: CodeMirror 6
- Rich Text: TipTap (ProseMirror)
Backend
- Framework: FastAPI 0.128.x
- Server: Uvicorn with workers support
- Language: Python 3.11-3.12
- Database ORM: SQLAlchemy 2.x + Peewee 3.x
- Migrations: Alembic + Peewee-migrate
- Authentication: PyJWT, python-jose
- Real-time: Python-SocketIO 5.x
- Task Scheduling: APScheduler 3.x
Architecture Layers
1. Presentation Layer (Frontend)
- User interface rendering
- Client-side state management
- Real-time chat updates via WebSockets
- File uploads and document handling
- Code execution with Pyodide (browser-based Python)
2. Application Layer (Backend)
Core Backend Components
Located inbackend/open_webui/:
Main Application (main.py):
- FastAPI app initialization
- Middleware configuration (CORS, compression, sessions)
- WebSocket integration
- Startup/shutdown lifecycle management
routers/):
auths.py- Authentication and authorizationchats.py- Chat managementmodels.py- Model configurationusers.py- User managementfiles.py- File handlingretrieval.py- RAG (Retrieval-Augmented Generation)pipelines.py- Pipeline integrationtools.py- Tool/function callingimages.py- Image generationaudio.py- Speech-to-text and text-to-speech
models/):
- Database models using Peewee ORM
- User, Chat, Model, Function, File entities
socket/):
- WebSocket connection handling
- Real-time message streaming
- Collaborative features
3. Data Layer
- SQLite (default) or PostgreSQL
- Stores users, chats, models, configurations
- Encrypted SQLite option available
- Redis (optional) for session management
- Required for horizontal scaling
- WebSocket state synchronization
- ChromaDB (default)
- Alternatives: Qdrant, Milvus, PGVector, Elasticsearch, OpenSearch, Pinecone
- Document embeddings and similarity search
4. Integration Layer
- Ollama integration (local models)
- OpenAI API compatibility (OpenAI, Anthropic, etc.)
- Custom model endpoints
- Plugin framework for custom logic
- Python-based middleware
- Rate limiting, monitoring, filtering
- Repository: open-webui/pipelines
- Native Python function calling
- MCP (Model Context Protocol) support
- Code editor with built-in support
Key Features Implementation
Authentication & Authorization
- JWT-based authentication
- Role-Based Access Control (RBAC)
- OAuth2/OIDC support (LDAP, SSO)
- SCIM 2.0 provisioning
- API key management
backend/open_webui/routers/auths.py, utils/auth.py
Real-Time Communication
- Socket.IO for WebSocket connections
- Streaming chat completions
- Collaborative editing with Y.js
- Redis pub/sub for multi-instance deployments
backend/open_webui/socket/main.py
RAG (Retrieval-Augmented Generation)
- Document ingestion and chunking
- Embedding generation (local or API)
- Vector similarity search
- Hybrid search with BM25
- Reranking support
- Multiple content extractors (Tika, Docling, Azure Document Intelligence)
backend/open_webui/routers/retrieval.py, backend/open_webui/retrieval/
Code Execution
- Browser-based: Pyodide (Python in WebAssembly)
- Server-based: Jupyter integration
- Sandboxed execution environment
- Support for multiple languages via CodeMirror
@pyscript/core, backend config in main.py
Image Generation & Editing
- OpenAI DALL-E integration
- Google Gemini support
- Local: ComfyUI, AUTOMATIC1111
- Prompt-based editing workflows
backend/open_webui/routers/images.py
Audio Processing
Speech-to-Text:- Local: Faster Whisper
- API: OpenAI, Azure, Deepgram, Mistral
- OpenAI TTS
- Azure Speech Services
- ElevenLabs
- Transformers (local)
- Web Speech API
backend/open_webui/routers/audio.py
Scalability & Production
Horizontal Scaling
- Redis-backed sessions for stateless workers
- Multi-worker support (Uvicorn workers)
- Load balancer compatible
- WebSocket sticky sessions support
Observability
- OpenTelemetry integration
- Traces, metrics, and logs
- Audit logging middleware
- Custom monitoring hooks
ENABLE_OTEL=true
Storage Options
File Storage:- Local filesystem (default)
- S3-compatible storage
- Google Cloud Storage
- Azure Blob Storage
- SQLite with encryption
- PostgreSQL for production
- Connection pooling
Configuration Management
Configuration is managed through:- Environment Variables - Primary configuration method
- AppConfig (
config.py) - Runtime configuration state - Database - User-modifiable settings stored in DB
- Redis - Distributed configuration for multi-instance
backend/open_webui/config.py, backend/open_webui/env.py
Security Architecture
- Security headers middleware
- CORS configuration
- Content Security Policy
- API key restrictions
- Input validation with Pydantic
- SQL injection prevention (parameterized queries)
- XSS protection (DOMPurify on frontend)
backend/open_webui/utils/security_headers.py
Request Flow Example
Chat Message Flow
Development Workflow
- Frontend changes: Edit Svelte components, hot-reload updates automatically
- Backend changes: Modify Python files, restart server (or use
--reload) - Database changes: Update models, migrations run on startup
- API changes: Update routers, OpenAPI docs auto-generated at
/docs
API Documentation
When running in development mode (ENV=dev):
- Swagger UI:
http://localhost:8080/docs - OpenAPI JSON:
http://localhost:8080/openapi.json
Next Steps
- Set up your Local Development Environment
- Review Contributing Guidelines
- Explore Plugin Development