WhiteLotusAI — System Design¶
Document type: System Design Specification
Product stage: Beta
Status: Source-inspected baseline; runtime verification pending
Audience: Software Engineers, QA Engineers, DevOps, Security Reviewers, and Technical Stakeholders
Organization: Whitelotus Corporation
1. Purpose and Scope¶
This document defines the system-level design of WhiteLotusAI, including its application components, service boundaries, communication mechanisms, supporting infrastructure, deployment considerations, and outstanding architectural questions.
It establishes a common technical reference for implementation, testing, maintenance, and future architectural decisions.
The specification is based on the source-code and configuration observations documented in the current engineering baseline. It distinguishes configured behavior from runtime-verified behavior and identifies areas that require further investigation.
Verification status
A configured endpoint, declared dependency, or application startup sequence does not independently prove that an end-to-end workflow operates correctly. Runtime connectivity, interface contracts, security controls, and failure recovery must be validated through reproducible tests.
1.1 Scope¶
This document covers:
- Logical system architecture and component responsibilities.
- HTTP and RabbitMQ communication patterns.
- Application services and message-processing workers.
- Database, caching, and message-broker dependencies.
- Deployment and runtime considerations.
- Known design risks, verification requirements, and maintenance principles.
Detailed API contracts, database schemas, integration-specific behavior, and deployment procedures belong in their respective documentation pages.
2. System Design Overview¶
WhiteLotusAI follows a multi-service architecture combining a Next.js frontend, a FastAPI API gateway, dedicated application services, message-driven workers, and supporting infrastructure.
The system uses synchronous HTTP communication for web-facing and service API operations, alongside RabbitMQ messaging for selected inter-service requests and background processing.
2.1 Architectural characteristics¶
| Design area | Implementation baseline | Architectural purpose |
|---|---|---|
| User interface | Next.js with TypeScript | Provides the browser-based application |
| API gateway | FastAPI | Centralizes API routing, gateway behavior, rate limiting, and proxying |
| Chat application | FastAPI | Hosts chat-related APIs and agent functionality |
| Integrations application | FastAPI | Exposes integration, webhook, MCP, and OAuth-related functionality |
| Message processing | RabbitMQ | Supports worker consumption and request/reply operations |
| Relational and vector infrastructure | PostgreSQL with pgvector support | Provides configured database infrastructure; actual persistence paths require verification |
| Caching and rate limiting | Redis | Supports gateway rate limiting and potentially other explicitly configured cache operations |
| Container orchestration | Docker Compose | Defines local and production-oriented service configurations |
| Edge and TLS configuration | Nginx and Certbot | Supports reverse-proxy and certificate-management deployment configuration |
2.2 High-level design principles¶
| Principle | Description |
|---|---|
| Explicit service boundaries | Each component has a defined responsibility and an identifiable communication interface. |
| Multiple communication patterns | HTTP and RabbitMQ are used for different interaction patterns according to the operation and destination. |
| Security by design | Authentication, authorization, credential management, OAuth security, and network restrictions must be addressed explicitly. |
| Evidence-based verification | Architectural claims must be supported by source-code inspection, configuration evidence, or reproducible tests, as appropriate. |
These principles guide implementation decisions, architectural reviews, testing, and documentation maintenance. They do not imply that every requirement has already been implemented or verified.
3. Logical System Architecture¶
The following diagram represents the observed logical relationships between the main application components and supporting infrastructure. It deliberately distinguishes configured HTTP proxy relationships from verified service interfaces.
3.1 Architecture diagram¶
flowchart TB
Browser["User's Browser"]
Frontend["Next.js Frontend"]
Gateway["REST API Gateway<br/>FastAPI :8000"]
subgraph HTTPServices["HTTP Application Services"]
Chat["Chat Service<br/>FastAPI :8001"]
Integrations["Integrations Service<br/>FastAPI :8006"]
end
subgraph Messaging["RabbitMQ Message Processing"]
Broker["RabbitMQ Broker"]
subgraph Workers["Message-Consuming Workers"]
UserWorker["User Worker"]
SessionWorker["Session Worker"]
RAGWorker["RAG Worker"]
end
end
subgraph Infrastructure["Supporting Infrastructure"]
Redis[("Redis<br/>Rate-Limiting Support")]
Database[("PostgreSQL + pgvector")]
end
Browser --> Frontend
Frontend -->|"HTTP API requests"| Gateway
Gateway -.->|"Configured HTTP proxy;<br/>runtime reachability to verify"| Chat
Gateway -.->|"Configured HTTP proxy;<br/>runtime reachability to verify"| Integrations
Gateway <-->|"Request/reply operations"| Broker
Chat <-->|"Message-based operations"| Broker
Integrations <-->|"Selected message-based operations"| Broker
Broker <-->|"User operations"| UserWorker
Broker <-->|"Session operations"| SessionWorker
Broker <-->|"Retrieval and document operations"| RAGWorker
Gateway -->|"Rate limiting"| Redis
RAGWorker -.->|"Vector-store dependency;<br/>exact persistence path to verify"| Database
%% Pastel fills with colored outlines for the reference design.
classDef frontend fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
classDef application fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A
classDef messaging fill:#FFF2CC,stroke:#D97706,stroke-width:2px,color:#7C3E00
classDef worker fill:#F1F5F9,stroke:#64748B,stroke-width:1.5px,color:#334155
classDef infrastructure fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
class Browser,Frontend frontend
class Gateway,Chat,Integrations application
class Broker messaging
class UserWorker,SessionWorker,RAGWorker worker
class Redis,Database infrastructure
%% Transparent containers preserve the active theme background.
style HTTPServices fill:transparent,stroke:#7C3AED,stroke-width:1.5px,color:inherit
style Messaging fill:transparent,stroke:#D97706,stroke-width:1.5px,color:inherit
style Workers fill:transparent,stroke:#64748B,stroke-width:1px,color:inherit
style Infrastructure fill:transparent,stroke:#059669,stroke-width:1.5px,color:inherit
%% Neutral connectors remain visible in dark and light themes.
linkStyle default stroke:#9CA3AF,stroke-width:1.3px
Diagram conventions
- Solid arrows represent principal configured or inspected relationships.
- Dashed arrows identify relationships whose runtime interface or persistence path remains unverified.
- Bidirectional arrows indicate interaction in both directions, not a guarantee of reliable delivery or successful execution.
- Colored borders distinguish component categories. Node fills and text are intentionally left to the active Mermaid theme to improve dark- and light-mode compatibility.
3.2 Architecture interpretation¶
- The browser loads the Next.js frontend.
- The frontend sends API requests to the configured gateway base URL.
- The FastAPI gateway handles explicit API routes and then applies its configured proxy behavior for applicable unmatched requests.
- The gateway, Chat service, and Integrations service participate in selected RabbitMQ workflows.
- User, Session, and RAG workers process messages through the shared listener and handler infrastructure.
- Redis supports the gateway's configured rate-limiting functionality.
- PostgreSQL with pgvector is configured as database infrastructure, while the precise schema and persistence relationships remain subject to verification.
The diagram describes the logical design baseline. It is not a network topology, deployment guarantee, or end-to-end execution trace.
4. Component Responsibilities¶
4.1 Component inventory¶
| Component | Primary responsibility | Observed communication | Verification requirement |
|---|---|---|---|
| Frontend | Browser-based user experience | HTTP to the configured API base URL | Validate endpoint configuration and authentication flow |
| REST API gateway | Routing, rate limiting, proxying, and selected backend operations | HTTP and RabbitMQ | Validate explicit routes, proxy behavior, and message contracts |
| Chat service | Chat APIs and agent functionality | HTTP and RabbitMQ | Validate routes, plugin initialization, and listener behavior |
| Integrations service | Integration APIs, webhooks, MCP, and OAuth-related operations | HTTP and selected RabbitMQ operations | Validate routes, authorization, and downstream dependencies |
| User worker | User-related message handling | RabbitMQ consumer and replies | Verify handler registration and any separate HTTP interface |
| Session worker | Session-related message handling | RabbitMQ consumer and replies | Verify supported methods and request/reply contracts |
| RAG worker | Document ingestion, retrieval, and document-management operations | RabbitMQ and vector-store initialization | Verify persistence, retrieval, and message contracts |
| PostgreSQL with pgvector | Relational and vector-capable database infrastructure | Database connections, as configured | Verify models, migrations, and actual consumers |
| Redis | Rate limiting and configured supporting operations | Redis client connections | Verify connection settings, key usage, and failure behavior |
| RabbitMQ | Message transport and request/reply | Exchanges, queues, routing keys, and correlation identifiers | Verify routing, acknowledgements, retries, and recovery behavior |
4.2 REST API gateway¶
The REST API gateway is implemented using FastAPI and is configured on port 8000.
Its inspected responsibilities include:
- Exposing application API routers.
- Applying the configured CORS policy.
- Initializing Redis-backed rate limiting.
- Dispatching requests through explicit route handlers.
- Forwarding applicable unmatched requests through a proxy router.
- Initiating RabbitMQ request/reply operations for supported backend methods.
- Configuring API documentation availability according to the execution environment.
The gateway configuration references Chat, Session, RAG, User, and Integrations upstream URLs.
Upstream interface constraint
An upstream URL in configuration is not proof that the target process exposes a compatible HTTP interface. The gateway's proxy mappings must be reconciled with the actual application entry points before those paths are described as supported interfaces.
4.3 Chat service¶
The Chat service is a FastAPI application configured on port 8001, with the route prefix /api/chat-svc.
The inspected startup sequence includes:
- Registering plugins.
- Performing plugin health checks.
- Starting a health-check loop.
- Warming the agent.
- Starting a RabbitMQ listener for chat messages.
- Loading configured service URLs and messaging settings for selected operations.
The service therefore participates in HTTP and message-based workflows.
CORS security review
The inspected Chat service CORS configuration allows all origins, methods, and headers while also allowing credentials. This is a security-review finding, not a production security recommendation.
The permitted origins and credential policy should be restricted to the application's documented requirements.
4.4 Integrations service¶
The Integrations service is a FastAPI application configured on port 8006.
Its inspected application includes integration and webhook routers under /api/integrations-svc, alongside MCP and OAuth-related routers.
Observed responsibilities include:
- Exposing integration-related APIs.
- Handling webhook routes.
- Providing MCP-related functionality.
- Supporting OAuth-related operations.
- Calling Chat HTTP endpoints for tool-schema discovery and tool dispatch.
- Participating in selected message-driven workflows.
The service's HTTP contracts, integration-specific authorization, OAuth lifecycle, and message-based dependencies should be documented in their respective reference pages.
4.5 User worker¶
The User entry point imports user handler modules and starts the shared RabbitMQ listener. It also checks encryption-key configuration before listening.
The inspected entry point establishes a message-driven worker. It does not establish that this entry point creates a FastAPI application or mounts the User OAuth token APIRouter.
The existence and availability of any separate User HTTP interface must be verified independently.
4.6 Session worker¶
The Session entry point imports session handlers and starts the shared RabbitMQ listener.
The inspected implementation establishes a message-consumer entry point, but does not establish that the worker exposes an HTTP API.
Session operations should be documented using the actual registered message methods and payload contracts rather than inferred from the gateway's configured upstream URLs.
4.7 RAG worker¶
The RAG entry point imports its handler modules and initializes supporting components before starting its listener.
The inspected startup sequence is:
- Load the embedding model.
- Initialize the vector-store pool.
- Start the RabbitMQ listener.
- Close the search cache and vector-store pool during shutdown.
The configured responsibilities include document ingestion, retrieval, and document-management operations through message handlers.
The exact vector-store implementation, database schema, embedding configuration, and runtime persistence guarantees require further inspection.
5. Inter-Service Communication¶
WhiteLotusAI uses HTTP and RabbitMQ for distinct interaction patterns. The communication contract must be understood in terms of the initiating component, destination, transport, payload, and expected response.
5.1 HTTP request/response¶
HTTP is used for frontend-to-gateway requests and for APIs exposed by FastAPI applications.
The Integrations service also calls Chat endpoints for MCP tool-schema discovery and tool dispatch.
The gateway defines HTTP proxy mappings for multiple services. However, the inspected User, Session, and RAG entry points are message consumers, which creates an interface-alignment question for corresponding proxy paths.
HTTP verification checklist¶
- Confirm each configured upstream URL resolves to the intended process.
- Confirm the destination exposes the expected HTTP routes and methods.
- Verify authentication and authorization at each applicable boundary.
- Verify request and response schemas.
- Verify timeout behavior and upstream error propagation.
- Verify proxy routing does not unintentionally bypass security controls.
5.2 RabbitMQ request/reply¶
The shared messaging implementation provides a message-based request/reply mechanism.
sequenceDiagram
autonumber
participant C as Requesting Component
participant Q as RabbitMQ Broker
participant W as Worker
participant H as Registered Handler
rect rgb(219, 234, 254)
Note over C,Q: 1. REQUEST DISPATCH
C->>C: Prepare request and correlation ID
C->>Q: Publish request with routing key
Q->>W: Deliver message to worker
end
rect rgb(243, 232, 255)
Note over W,H: 2. HANDLER EXECUTION
W->>H: Dispatch through process_data
H-->>W: Return handler result
end
rect rgb(209, 250, 229)
Note over W,Q: 3. RESPONSE DELIVERY
W->>Q: Publish reply when applicable
Q-->>C: Deliver correlated reply
end
Note over C,H: Verify timeout, retry, acknowledgement, and failure behavior
The sequence illustrates the observed design pattern, not a guarantee that every request follows the complete sequence successfully.
The observed flow is:
- The caller creates or obtains a reply destination.
- The caller publishes a request to the configured exchange.
- A routing key identifies the destination queue.
- The request includes a correlation identifier.
- The worker dispatches the request through
BaseHandler.process_data. - The worker sends the result to the request's reply destination when applicable.
- The caller correlates the reply with the original request.
The listener uses robust RabbitMQ connections and includes connection retry logic.
Delivery guarantees
Connection retries do not independently establish guaranteed delivery, exactly-once execution, or complete recovery from broker outages and worker failures.
Delivery semantics depend on queue durability, message persistence, acknowledgement behavior, retry policy, idempotency, timeout handling, and recovery implementation. These must be verified from code and tests.
5.3 Handler registration¶
The inspected worker entry points import their handler modules before invoking the shared listen(...) function.
This import-based registration pattern makes handler availability dependent on module imports and successful handler registration.
The following contracts require verification before publishing a complete messaging API reference:
- Registered method names and destination queues.
- Request and response payload schemas.
- Unknown-method handling.
- Handler exceptions and error serialization.
- Message acknowledgements and retry behavior.
- Correlation identifiers and reply timeouts.
5.4 Communication pattern comparison¶
Best suited to: Direct API requests and responses.
- Uses HTTP routes and request/response payloads.
- Supports browser-facing and service-facing APIs.
- Requires explicit route, authorization, timeout, and error-handling validation.
Best suited to: Message-driven worker operations and request/reply interactions.
- Uses exchanges, queues, routing keys, and message payloads.
- Supports communication between callers and worker processes.
- Requires explicit delivery, acknowledgement, retry, and correlation policies.
Neither transport should be considered reliable solely because its client library or connection configuration supports retries.
6. Supporting Infrastructure¶
6.1 Infrastructure inventory¶
| Dependency | Configured technology | Primary role | Outstanding verification |
|---|---|---|---|
| Relational database | pgvector/pgvector:pg16 |
Relational and vector-capable storage | Models, migrations, schemas, indexes, and service access |
| Cache and rate limiting | Redis 7 | Gateway rate limiting and configured supporting operations | Key design, expiration, failure behavior, and other usage |
| Message broker | RabbitMQ 3.13 management image | Inter-service messaging | Exchanges, queues, bindings, acknowledgements, and recovery |
| Application containers | Docker Compose | Local and production-oriented orchestration | Environment parity, dependency readiness, and startup order |
| Reverse proxy | Nginx | Reverse-proxy configuration | Route forwarding, headers, TLS, and access restrictions |
| Certificate management | Certbot | Certificate issuance or renewal configuration | Challenge configuration, renewal, and certificate installation |
Versions and image references above describe the inspected configuration baseline. They should be reconciled with the active deployment manifests before a release.
6.2 PostgreSQL and pgvector¶
The Docker Compose configuration uses pgvector/pgvector:pg16.
This establishes the configured database image but does not establish the complete database design or which application services access specific tables.
The database architecture reference should be based on verified:
- ORM models and table definitions.
- Migration history and current schema.
- Primary and foreign key relationships.
- Vector dimensions and index configuration.
- Transaction boundaries and persistence ownership.
- Database connection settings for each service.
6.3 Redis¶
The Docker Compose configuration uses Redis 7. The REST API initializes a Redis-backed rate limiter during application startup.
Other Redis responsibilities should be documented only after inspecting the relevant clients, call sites, key prefixes, expiration policies, and failure handling.
6.4 RabbitMQ¶
The configured RabbitMQ deployment uses the rabbitmq:3.13-management image.
The inspected application components use exchanges and queues for message consumption and request/reply operations.
A dedicated messaging reference should identify:
| Contract element | Required documentation |
|---|---|
| Exchange | Name, type, and declaration location |
| Queue | Name, durability, and consumer |
| Binding | Routing key and destination |
| Request | Method name and payload schema |
| Reply | Response schema and correlation behavior |
| Failure handling | Acknowledgements, retries, timeouts, and dead-letter behavior where configured |
Do not infer queue durability, delivery guarantees, or dead-letter configuration from the presence of RabbitMQ alone.
7. Deployment and Runtime Considerations¶
The repository contains Docker Compose configurations for local and production-oriented deployment. The inspected configuration includes application services, PostgreSQL, Redis, RabbitMQ, a frontend container in the production-oriented setup, Nginx, and a Certbot renewal container.
The presence of deployment configuration is not equivalent to verified production readiness.
7.1 Deployment validation¶
| Area | Validation requirement | Expected evidence |
|---|---|---|
| Startup and readiness | Confirm dependencies are ready before dependent operations begin | Reproducible startup and readiness tests |
| Network connectivity | Validate service-to-service DNS, ports, and routing | Connectivity tests and deployment logs |
| Database | Validate initialization and migration execution | Migration results and schema inspection |
| Messaging | Validate broker readiness and worker recovery | Request/reply and failure-injection tests |
| Configuration | Validate required variables and environment-specific values | Configuration validation and deployment checks |
| OAuth | Validate credentials, redirect URIs, callback handling, and token persistence | Integration tests with controlled credentials |
| Reverse proxy | Validate routing and upstream behavior | HTTP integration tests |
| TLS | Validate certificate issuance, installation, and renewal | Certificate and renewal checks |
| Security | Validate authentication, authorization, CORS, and secret handling | Security tests and configuration review |
| Observability | Validate useful health signals and diagnostic logs | Monitoring and operational tests |
7.2 Configuration and secrets¶
Credentials, encryption keys, OAuth tokens, and internal service secrets must be managed outside committed source files.
Configuration should be validated at startup, with missing or invalid required values producing explicit failures rather than silent degradation.
For related configuration details, see Configuration.
8. Known Design Risks and Open Questions¶
The following register captures outstanding issues in the source-inspected baseline. These are investigation items, not assertions that every affected workflow is broken.
| ID | Area | Observation | Required action |
|---|---|---|---|
| SD-01 | User HTTP interface | The inspected User entry point runs a RabbitMQ listener; OAuth handlers define an APIRouter. |
Identify whether an application mounts and serves the router. |
| SD-02 | Session HTTP interface | The inspected Session entry point runs a RabbitMQ listener. | Establish whether configured Session proxy paths are intended and reachable. |
| SD-03 | RAG HTTP interface | The inspected RAG entry point runs a RabbitMQ listener. | Establish whether configured RAG proxy paths are intended and reachable. |
| SD-04 | OAuth token persistence | The Gmail client sends an HTTP request to the User service. | Verify endpoint availability and the intended transport. |
| SD-05 | Handler registry | Worker handlers are registered through imports. | Validate supported methods, payloads, and unknown-method behavior. |
| SD-06 | Database design | PostgreSQL with pgvector is configured. | Verify models, migrations, schemas, and actual persistence paths. |
| SD-07 | CORS | Chat permits all origins while allowing credentials. | Review allowed origins and production security requirements. |
| SD-08 | Production TLS | Nginx and Certbot are configured. | Verify certificate issuance, TLS configuration, and renewal. |
| SD-09 | Readiness checks | Container health checks inspect Python process presence. | Determine whether checks accurately reflect service readiness. |
Risk management
Track each item through the documentation audit and the project's issue-management process. Close an item only when the relevant implementation evidence or reproducible test supports the resolution.
9. Design Principles for Beta Development¶
The following principles should guide architectural changes and documentation maintenance.
- Explicit interfaces: Every service must have identifiable supported HTTP routes, message methods, or both.
- Traceable communication: Document the caller, destination, transport, payload, and expected response for each important interaction.
- Verified contracts: Derive API schemas and messaging contracts from implementation and tests.
- Secure configuration: Keep credentials, encryption keys, and OAuth tokens outside committed source files.
- Observable operation: Health checks should reflect meaningful service readiness rather than process existence alone.
- Defined failure handling: Test timeouts, retries, broker outages, partial failures, and recovery.
- Incremental documentation: Update affected reference pages when implementation changes.
- Evidence-based status: Mark a component or workflow as verified only when sufficient evidence supports the claim.
9.1 Verification maturity¶
Use the following distinctions when reviewing architecture statements.
| Classification | Meaning |
|---|---|
| Source-inspected | Relevant source code or configuration has been examined. |
| Configuration-confirmed | A setting or dependency is explicitly declared in configuration. |
| Test-verified | A reproducible test demonstrates the stated behavior within its scope. |
| Runtime-verified | The behavior has been observed in the relevant running environment. |
| Production-validated | Operational, security, resilience, and deployment requirements have been assessed against production criteria. |
These classifications are not interchangeable. In particular, configuration confirmation does not establish runtime or production behavior.
10. Review and Maintenance¶
Review this document whenever service responsibilities, communication mechanisms, deployment dependencies, security boundaries, or persistence architecture change.
Before promoting this baseline to a production-ready system-design specification:
- Resolve or formally accept the outstanding interface questions.
- Validate the principal frontend-to-backend workflows.
- Verify message contracts and failure-handling behavior.
- Reconcile database documentation with the actual schema and persistence code.
- Review production network boundaries, CORS, secrets, and TLS configuration.
- Ensure architectural diagrams remain consistent with the implementation.
Document changes should be reviewed alongside relevant code changes so that architectural claims remain traceable to the implementation.
Related documentation¶
Explore WhiteLotusAI's high-level architecture, core components, service boundaries, and system relationships.
Explore architectureUnderstand how requests, messages, and information move between application services and external integrations.
Explore data flowReview database structures, data models, migration practices, and persistence mechanisms.
Explore database designExamine container definitions, service configuration, environment dependencies, and deployment procedures.
Review Docker deploymentUnderstand environment variables, application settings, configuration requirements, and environment-specific values.
Review configurationTrack documentation quality, source-verification status, evidence gaps, and outstanding review findings.
Review audit findingsDocument status: Initial source-inspected system-design baseline. Runtime verification and resolution of the outstanding design questions remain pending.