How marchbeta2087/mengxi-llm-chat works
Mengxi Chat is a self-hosted LLM chat application: users sign in, manage keys and plugins, chat with upstream models, and search encrypted conversation history; administrators manage users, quotas, plugins, and audit records. The Vue SPA calls a FastAPI API, which coordinates services, persistence, Redis-backed controls, cryptography, plugin isolation, and upstream requests. The README documents these capabilities, but several implementing modules were not excerpted, so their internal call paths are omitted rather than inferred.
Main entry points: main.py FastAPI application · chat.py Chat orchestration · client.ts API client · __init__.py PostgreSQL data
Components 34
Web application
- SPA routes
src/frontend/src/router.ts - Session state
src/frontend/src/stores/auth.ts - Chat interface
src/frontend/src/views/ChatView.vue - Key management UI
src/frontend/src/views/KeysView.vue - Admin interface
src/frontend/src/views/AdminView.vue - Plugin interface
src/frontend/src/views/PluginsView.vue - Settings UI
src/frontend/src/views/SettingsView.vue - API client
src/frontend/src/api/client.ts
API and services
- FastAPI application
src/backend/app/main.py - Authentication routes
src/backend/app/api/auth.py - Chat and conversation routes
src/backend/app/api/chat.py - Key routes
src/backend/app/api/keys.py - Plugin and admin routes
src/backend/app/api/plugins.py - Admin and audit routes
src/backend/app/api/admin.py - Authentication service
src/backend/app/services/auth.py - Chat orchestration
src/backend/app/services/chat.py - Key pool scheduler
src/backend/app/services/scheduler.py - Rate limits and quotas
src/backend/app/services/ratelimit.py - Limit rules
src/backend/app/domain/ratelimit.py - Plugin policies
src/backend/app/services/plugins.py
Privacy and safety
- Encrypted conversations
src/backend/app/services/conversation.py - Key encryption manager
src/backend/app/services/key_manager.py - Encryption primitives
src/backend/app/core/crypto/cipher.py - Master key provider
src/backend/app/core/crypto/kek.py - Blind-index search
src/backend/app/domain/blind_index.py - SSRF validation
src/backend/app/core/ssrf.py
Runtime integrations
- Plugin sandbox
src/backend/app/infra/sandbox.py - LLM upstream client
src/backend/app/infra/upstream.py - Redis counters
src/backend/app/infra/redis_store.py - PostgreSQL data
src/backend/app/repositories/__init__.py - User and domain records
src/backend/app/models/user.py
Other components
- User or admin
- LLM provider
- Plugin process
Connections 42
- User or admin → SPA routes: uses
src/frontend/src/router.ts - SPA routes → Session state: checks session
src/frontend/src/router.ts - Session state → API client: requests auth
src/frontend/src/stores/auth.ts - User or admin → Chat interface: chats
src/frontend/src/views/ChatView.vue - Chat interface → API client: requests chat
src/frontend/src/views/ChatView.vue - User or admin → Key management UI: manages keys
src/frontend/src/views/KeysView.vue - Key management UI → API client: requests keys
src/frontend/src/views/KeysView.vue - User or admin → Plugin interface: manages plugins
- Plugin interface → API client: requests plugins
- User or admin → Admin interface: administers
- Admin interface → API client: requests admin
- User or admin → Settings UI: customizes
- API client → FastAPI application: calls API
- FastAPI application → Authentication routes: registers routes
src/backend/app/main.py - FastAPI application → Chat and conversation routes: registers routes
src/backend/app/main.py - FastAPI application → Key routes: registers routes
src/backend/app/main.py - FastAPI application → Plugin and admin routes: registers routes
src/backend/app/main.py - FastAPI application → Admin and audit routes: registers routes
src/backend/app/main.py - Authentication routes → Authentication service: authenticates
src/backend/app/api/auth.py - Authentication service → PostgreSQL data: uses repositories
src/backend/app/services/auth.py - Chat and conversation routes → Chat orchestration: dispatches chat
- Chat orchestration → Encrypted conversations: stores messages
- Chat orchestration → Key pool scheduler: selects key
- Chat orchestration → Rate limits and quotas: checks limits
- Chat orchestration → Plugin policies: applies plugins
- Chat orchestration → LLM upstream client: sends requests
- LLM upstream client → LLM provider: calls provider
- Encrypted conversations → Blind-index search: indexes search
- Encrypted conversations → Key encryption manager: gets conversation key
- Key encryption manager → Master key provider: wraps keys
src/backend/app/services/key_manager.py - Key encryption manager → Encryption primitives: encrypts secrets
src/backend/app/services/key_manager.py - Encrypted conversations → PostgreSQL data: persists conversations
- Key pool scheduler → PostgreSQL data: loads key pool
- Rate limits and quotas → Limit rules: uses rules
src/backend/app/api/deps.py - Rate limits and quotas → Redis counters: records counters
- Plugin policies → Plugin sandbox: runs plugins
- Plugin sandbox → Plugin process: isolates execution
- Plugin sandbox → SSRF validation: checks network access
src/backend/app/infra/sandbox.py - SSRF validation → LLM upstream client: validates targets
- Admin and audit routes → PostgreSQL data: reads admin records
- Key routes → PostgreSQL data: manages key records
- PostgreSQL data → User and domain records: stores records
src/backend/app/repositories/__init__.py