How lobehub/lobe-chat works
Main Components
a) Frontend Layer:
• Next.js Application (src/app)
• Authentication Routes (/auth)
• Main Application Routes (/chat, /settings, etc.)
• Modal System (@modal)
• Mobile & Desktop Layouts
• Internationalization System (locales/)
b) Core Services Layer:
• Agent Runtime System (src/libs/agent-runtime)
• Plugin System (src/libs/plugin)
• Database Layer
• Client Database (IndexedDB/LocalStorage)
• Server Database (PostgreSQL)
• Authentication Services
• Next-Auth
• Clerk Integration
c) Backend Layer:
• API Routes (src/app/api)
• TRPC Endpoints (src/app/trpc)
• WebAPI Services (src/app/webapi)
d) External Services Integration:
• Multiple LLM Providers (OpenAI, Anthropic, etc.)
• Storage Services (S3)
• Authentication Providers
• Plugin Gateway
Data Flow Relationships
• User Interface → Core Services → Backend Services → External APIs
• Plugin System ↔ Core Services ↔ LLM Providers
• Authentication Flow → User Sessions → Protected Resources
• File Upload → Storage Services → Knowledge Base
Key Architectural Patterns
• Feature-based Module Organization
• Service Layer Pattern
• Repository Pattern for Data Access
• Plugin Architecture
• Event-driven State Management
a) Visual Elements:
• Clear boundaries between systems
• Database symbols
b) Labels and Annotations:
• Component names
• API endpoints
• Data flow descriptions
• Integration points
• Authentication flows