Skip to content

WhiteLotus AI — System Flow Diagram

Document type: Technical architecture reference
Organization: Whitelotus Corporation
Document owner: Product and Engineering
Status: Architecture reference; implementation details require source verification

This document describes the logical architecture and principal processing flows of WhiteLotus AI. It serves as a common reference for understanding the frontend, API gateway, application services, AI orchestration, integrations, retrieval pipeline, and supporting infrastructure.

The diagrams illustrate architectural relationships and intended processing paths. They must not be interpreted as proof of specific runtime calls, deployment topology, persistence behavior, or active configuration without verification against the current source code and deployment manifests.

At a glance

Architecture area Primary responsibility
User interface User interaction and request submission
API gateway Application entry point and gateway-level controls
Chat and orchestration Request processing, intent handling, and tool coordination
Integrations Controlled access to connected business applications
Retrieval-augmented generation (RAG) Document indexing, retrieval, and context preparation
Data and messaging Persistence, caching, and asynchronous processing where configured
Model runtime Language-model inference where configured

How to read this document

Solid arrows represent primary logical flows in the relevant diagram. Dashed arrows identify optional, configuration-dependent, or conceptual relationships. Neither arrow style independently verifies the current implementation.

1. High-Level System Architecture

The following diagram shows the principal components of WhiteLotus AI and their logical relationships.

Diagram A — System Entry and Application Services

This is the starting point of the architecture. It shows the user's request entering through the frontend and gateway, then reaching the relevant application services.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 55,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#64748b"
  }
}}%%

flowchart TB
    User(["User"])
    Browser["Web Browser"]
    Frontend["Next.js\n Frontend<br/>Port : 3000"]
    Gateway["REST API\n Gateway<br/>FastAPI\n Port : 8000"]

    subgraph Services["Application Services"]
        direction TB
        Chat["Chat\n Service<br/>Port : 8001"]
        Session["Session\n Service<br/>Port : 8002"]
        RAG["RAG\n Service<br/>Port : 8004"]
        UserSvc["User\n Service<br/>Port : 8005"]
        Integrations["Integrations\n Service<br/>Port : 8006"]
    end

    User --> Browser
    Browser --> Frontend
    Frontend --> Gateway

    Gateway --> Session
    Gateway --> UserSvc
    Gateway --> Chat
    Gateway --> RAG
    Gateway --> Integrations

    Integrations ==>|Authorized tool\n calls<br/>Diagram D| ToolEntry(["Connected\n Platforms"])
    Chat ==>|Continues\n in\n Diagram B| AIEntry(["AI Processing"])
    RAG -.->|Data access| DataEntry(["Data\n and\n Infrastructure<br/>Diagram C"])
    Chat -.->|Context retrieval| RAG

    %% Pastel fills with colored outlines.
    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 continuation fill:#E0F7FA,stroke:#0891B2,stroke-width:1.5px,stroke-dasharray:5 5,color:#164E63

    class User,Browser,Frontend,Gateway frontend
    class Chat,Session,RAG,UserSvc,Integrations application
    class AIEntry,DataEntry,ToolEntry continuation

    %% Transparent container preserves the active theme background.
    style Services fill:transparent,stroke:#7C3AED,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain visible in dark and light modes.
    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

Diagram B — AI Request-Processing Pipeline

This diagram expands the AI Processing continuation from Diagram A. The pipeline is arranged vertically so that the labels remain readable.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 45,
    "rankSpacing": 50,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#64748b"
  }
}}%%

flowchart TB
    Start(["From\n Diagram A<br/>Chat Service\n Port : 8001"])

    subgraph Pipeline["LangGraph AI Processing"]
        direction TB
        Graph["LangGraph\n Orchestration"]
        Safety["Safety\n and\n Context"]
        Intent["Intent\n Classification"]
        Auth["Authorization"]
        Dispatch["Tool Dispatch"]
        Model["LLM\n Processing"]
        Format["Response\n Formatting"]

        Graph --> Safety
        Safety --> Intent
        Intent --> Auth
        Auth --> Dispatch
        Dispatch --> Model
        Model --> Format
    end

    ToolCall(["Authorized\n Tool Call<br/>Continue to\n Diagram D"])
    DataCall(["Context\n Retrieval<br/>Continue to\n Diagram C"])
    Response(["Formatted\n Response<br/>Return to\n Chat Service"])

    Start --> Graph
    Dispatch -.-> ToolCall
    Safety -.-> DataCall
    Format --> Response

    %% Pastel fills with category-specific colored outlines.
    classDef entry fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
    classDef pipeline fill:#E0F7FA,stroke:#0891B2,stroke-width:1.5px,color:#164E63
    classDef continuation fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,stroke-dasharray:5 5,color:#7C3E00

    class Start entry
    class Graph,Safety,Intent,Auth,Dispatch,Model,Format pipeline
    class ToolCall,DataCall,Response continuation

    %% Transparent container preserves the active theme background.
    style Pipeline fill:transparent,stroke:#0891B2,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain visible in dark and light themes.
    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

Diagram C — Data and Infrastructure

This diagram expands the data and infrastructure continuation. It separates the storage, cache, messaging, and model components from the main request flow.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 55,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#64748b"
  }
}}%%

flowchart TB
    DataEntry(["From\n Diagrams\n A and B<br/>Application\n and\n AI Services"])

    subgraph Infrastructure["Data and Infrastructure"]
        direction TB
        PostgreSQL[("PostgreSQL<br/>+<br/>pgvector")]
        Redis[("Redis Cache\n and\n Rate Limiting")]
        RabbitMQ[("RabbitMQ<br/>Message\n Broker")]
        Nvidia["Qwen\n ver: 3.5\n 9-B Model\n Server"]
    end

    RAGAccess["RAG<br/>Service<br/>Port: 8004"]
    SessionAccess["Session<br/>Service<br/>Port: 8002"]
    UserAccess["User<br/>Service<br/>Port: 8005"]
    IntegrationAccess["Integrations\n Service<br/>Port : 8006"]
    ChatAccess["Chat<br/>AI Processing<br/>Port: 8001"]

    DataEntry --> RAGAccess
    DataEntry --> SessionAccess
    DataEntry --> UserAccess
    DataEntry --> IntegrationAccess
    DataEntry --> ChatAccess

    RAGAccess --> PostgreSQL
    RAGAccess --> Redis
    SessionAccess --> PostgreSQL
    UserAccess --> PostgreSQL
    IntegrationAccess --> PostgreSQL

    ChatAccess -.->|Model inference| Nvidia
    ChatAccess -.->|Messaging,\n if configured| RabbitMQ

    %% Pastel fills with category-specific colored outlines.
    classDef entry fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
    classDef application fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A
    classDef infrastructure fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B

    class DataEntry entry
    class RAGAccess,SessionAccess,UserAccess,IntegrationAccess,ChatAccess application
    class PostgreSQL,Redis,RabbitMQ,Nvidia infrastructure

    %% Transparent container preserves the active theme background.
    style Infrastructure fill:transparent,stroke:#059669,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain visible in both themes.
    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

Diagram D — Read-Only Integrations

This diagram expands the authorized tool-call continuation from Diagrams A and B. It groups the six external platforms separately, keeping their labels large and avoiding crossing lines.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#64748b"
  }
}}%%

flowchart TB
    Entry(["From\n  Diagrams\n A and B<br/>Authorized\n Tool Call"])

    IntegrationService["Integrations\n Service<br/>FastAPI\n Port : 8006"]

    subgraph Platforms["Connected Platforms — Read Only"]
        direction TB
        Jira["Jira"]
        Slack["Slack"]
        Drive["Google\n Drive"]
        Gmail["Google\n Gmail"]
        Calendar["Google\n Calendar"]
        Teams["Microsoft\n Teams"]
    end

    Result(["Integration\n Results\n Return to\n AI Processing"])

    Entry --> IntegrationService

    IntegrationService --> Jira
    IntegrationService --> Slack
    IntegrationService --> Drive
    IntegrationService --> Gmail
    IntegrationService --> Calendar
    IntegrationService --> Teams

    Jira --> Result
    Slack --> Result
    Drive --> Result
    Gmail --> Result
    Calendar --> Result
    Teams --> Result

    %% Pastel fills with category-specific colored outlines.
    classDef entry fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
    classDef application fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A
    classDef provider fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
    classDef continuation fill:#E0F7FA,stroke:#0891B2,stroke-width:1.5px,stroke-dasharray:5 5,color:#164E63

    class Entry continuation
    class IntegrationService application
    class Gmail,Calendar,Drive,Jira,Slack,Teams provider
    class Result continuation

    %% Transparent container preserves the active theme background.
    style Platforms fill:transparent,stroke:#D97706,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain visible in both themes.
    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

Architecture interpretation

  • Frontend: Provides the user-facing workspace and initiates application requests.
  • REST API gateway: Provides the API entry point and applies configured request controls, authentication, authorization, validation, and routing.
  • Application services: Separate chat, session, retrieval, user, integration, and notification responsibilities.
  • AI orchestration: Coordinates safety checks, context preparation, intent handling, authorization, tool dispatch, model processing, and response formatting.
  • Integrations: Connect to third-party systems through approved operations and provider permissions.
  • Supporting infrastructure: Supplies database, caching, messaging, and model-serving capabilities where configured.

Architecture versus implementation

The diagram intentionally includes some optional relationships. Confirm that each dependency is active before using this diagram as an operational troubleshooting reference.

2. User Request Lifecycle

The request lifecycle describes how a message can move from the frontend to the application services and back to the user.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#9CA3AF"
  }
}}%%

flowchart TD
    Start(["User submits\n a message"])
    Frontend["Frontend\n validates\n and\n submits\n request"]
    Gateway["API gateway\n processes\n request"]
    Identity{"Authenticated\n and\n Authorized?"}
    Reject["Return an\n appropriate\n error"]
    Chat["Chat service\n receives\n request"]
    Context["Prepare\n conversation\n context"]
    Safety["Apply\n safety checks"]
    Intent["Determine\n user intent"]
    Route{"Tool\n or\n retrieval\n required?"}
    Model["Generate\n a\n model response"]
    Permission["Validate\n server-side\n permissions"]
    Allowed{"Operation\n permitted?"}
    Execute["Execute\n authorized\n operation"]
    Result["Validate\n and\n normalize\n result"]
    Combine["Prepare\n final response"]
    Stream["Return\n or\n stream\n response"]
    End(["Request\n completed"])

    Start --> Frontend
    Frontend --> Gateway
    Gateway --> Identity

    Identity -- No --> Reject
    Reject --> End

    Identity -- Yes --> Chat
    Chat --> Context
    Context --> Safety
    Safety --> Intent
    Intent --> Route

    Route -- No --> Model
    Route -- Yes --> Permission
    Permission --> Allowed

    Allowed -- No --> Combine
    Allowed -- Yes --> Execute
    Execute --> Result
    Result --> Combine

    Model --> Combine
    Combine --> Stream
    Stream --> End

    %% Pastel fills with category-specific colored outlines.

    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 processing fill:#E0F7FA,stroke:#0891B2,stroke-width:1.5px,color:#164E63
    classDef decision fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
    classDef success fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
    classDef error fill:#FCE8E6,stroke:#DC2626,stroke-width:1.5px,color:#7F1D1D

    class Start,End frontend
    class Frontend,Gateway,Chat application
    class Context,Safety,Intent,Model,Combine processing
    class Identity,Route,Permission,Allowed decision
    class Execute,Result,Stream success
    class Reject error

    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

Request lifecycle responsibilities

Stage Responsibility
Request submission Receive the user's message and applicable conversation metadata.
Gateway processing Apply configured authentication, authorization, validation, and request controls.
Context preparation Gather permitted conversation context.
Safety checks Apply relevant input and output safety policies.
Intent handling Determine the requested operation and processing path.
Authorization Validate the user, connection, resource, and requested operation.
Tool execution Execute an authorized operation using validated inputs.
Result handling Validate and normalize tool output.
Response generation Produce a response based on the request and available evidence.
Response delivery Return the result using the configured HTTP or streaming mechanism.

Conditional processing

Not every request needs an integration call or document retrieval. The exact branches, validation order, and response-delivery mechanism must be verified against the current application code.

3. AI Orchestration and LangGraph

WhiteLotus AI uses a graph-based orchestration approach to coordinate request processing and tool execution.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#9CA3AF"
  }
}}%%

flowchart TD
    Input(["Incoming\n Chat Request"])

    subgraph Orchestration["LangGraph AI Orchestration"]
        direction TB

        Safety["Safety Node"]
        Context["Context Node"]
        Intent["Intent\n Classification\n Node"]
        Auth["Authorization\n Node"]
        Dispatch["Tool Dispatch\n Node"]
        LLM["LLM\n Processing\n Node"]
        Format["Response\n Formatting \n Node"]

        Safety --> Context
        Context --> Intent
        Intent --> Auth
        Auth --> Dispatch
        Dispatch --> LLM
        LLM --> Format
    end

    Output(["Formatted \n Response"])

    Input --> Safety
    Format --> Output

    %% Pastel fills with category-specific colored outlines.

    classDef endpoint fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
    classDef orchestration fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A
    classDef processing fill:#E0F7FA,stroke:#0891B2,stroke-width:1.5px,color:#164E63
    classDef authorization fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
    classDef response fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B

    class Input endpoint
    class Safety,Context,Intent,LLM,Format processing
    class Auth,Dispatch authorization
    class Output response

    %% Transparent container preserves the active theme background.

    style Orchestration fill:transparent,stroke:#7C3AED,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain legible across themes.

    linkStyle default stroke:#9CA3AF,stroke-width:1.3px 

Logical node responsibilities

Node Responsibility
safety Apply relevant safety checks.
context Prepare permitted conversation and request context.
intent Classify the request and identify the required processing path.
auth Enforce server-side authorization before protected operations.
tool_dispatch Select and invoke an eligible registered tool.
llm Perform model-based processing when required.
format Normalize and format the result for delivery.

The diagram is a simplified logical sequence. It does not specify the exact internal graph edges, conditional branches, retries, or state schema.

Orchestration security constraints

  • Do not treat model-generated text as proof of user authorization.
  • Do not rely on an LLM-generated confirmation field, such as entities["__confirmed"], as the sole confirmation or authorization control.
  • Validate the requested operation and its arguments on the server.
  • Use registered tools with explicit schemas and permission boundaries.
  • Handle failures without exposing credentials, tokens, internal secrets, or sensitive exception details.
  • Preserve the distinction between retrieved evidence, tool output, model-generated text, and verified application state.

Authorization must remain server-side

The model may help interpret a user's intent, but the application must independently enforce permissions and any required confirmation. A model-generated flag must never bypass a security-sensitive check.

4. Integration Architecture

The integrations service provides the application boundary between orchestration and connected business applications.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#9CA3AF"
  }
}}%%

flowchart TB
    Request(["User Request"])
    Intent["Intent\n and\n Operation\n Identification"]

    subgraph IntegrationFlow["Integration Architecture"]
        direction TB

        Policy["Server-Side\n Authorization"]
        Registry["Registered Tool\n Selection"]
        API["Integrations\n Service<br/>FastAPI : 8006"]
        Credentials["Authorized\n Connection\n Credentials"]
        Provider["External\n Provider\n API"]
        Normalize["Response\n Validation\n and\n Normalization"]

        Policy --> Registry
        Registry --> API
        API --> Credentials
        API --> Provider
        Provider --> Normalize
    end

    Result(["Result Returned\n to\n Orchestration"])

    Request --> Intent
    Intent --> Policy
    Normalize --> Result

    %% Pastel fills with category-specific colored outlines.

    classDef endpoint fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
    classDef orchestration fill:#E0F7FA,stroke:#0891B2,stroke-width:1.5px,color:#164E63
    classDef authorization fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
    classDef integration fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A
    classDef provider fill:#F1F5F9,stroke:#64748B,stroke-width:1.5px,color:#334155
    classDef response fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B

    class Request endpoint
    class Intent orchestration
    class Policy,Registry authorization
    class API,Credentials integration
    class Provider provider
    class Normalize,Result response

    %% Transparent container preserves the active theme background.

    style IntegrationFlow fill:transparent,stroke:#7C3AED,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain legible across themes.

    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

This diagram is conceptual. Confirm the actual credential retrieval, provider request, callback, and response-processing paths against the implementation.

4.1 Intended integration scope

The product's intended integration scope is read-only access to six business applications.

Integration Intended read operations Prohibited write operations
Jira Retrieve permitted issues and project information Create, update, transition, or delete issues
Slack Retrieve permitted messages and channel information Send messages, modify content, or change workspace resources
Google Drive Search and retrieve permitted files and metadata Create, modify, move, or delete files
Google Gmail Search and read email information Send, draft, delete, or modify messages
Google Calendar Retrieve calendar information Create, update, or delete events
Microsoft Teams Retrieve permitted team, channel, and message information Send messages or modify teams, channels, or other resources

Read-only is a requirement, not an assumed guarantee

This table defines intended product behavior. It does not establish that existing routes, registered tools, OAuth scopes, provider permissions, or authorization checks already enforce the restriction.

The implementation must be audited and tested before read-only enforcement is described as complete.

4.2 Read-only enforcement requirements

  1. Maintain an explicit allowlist of permitted read operations for each integration.
  2. Reject write-capable operations on the server, even if requested by the model.
  3. Request only the OAuth scopes required for approved functionality.
  4. Validate user identity, connection ownership, resource access, and operation permissions.
  5. Treat email bodies, documents, issues, and messages as untrusted input.
  6. Prevent instructions in external content from overriding system policies or authorization decisions.
  7. Avoid logging access tokens, refresh tokens, client secrets, or sensitive provider content.
  8. Test that prohibited operations are rejected at the application boundary.

Where available, provider-side read-only permissions should complement application-level enforcement.

5. Retrieval-Augmented Generation (RAG)

RAG enables the application to retrieve relevant document content and use it as context when generating an answer.

The following diagram represents a logical ingestion and retrieval pipeline. Confirm the active implementation before relying on the individual stages as deployed behavior.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#9CA3AF"
  }
}}%%

flowchart TB
    subgraph Ingestion["Document Ingestion Pipeline"]
        direction TB

        Upload["Document\n Upload\n or\n Ingestion"]
        Validate["Validate\n File\n and\n Metadata"]
        Extract["Extract\n Supported\n Text"]
        Chunk["Split Text\n into\n Chunks"]
        Embed["Generate\n Document\n Embeddings"]
        Store[("Store\n Chunks,\n Vectors,<br/>and\n Metadata")]

        Upload --> Validate
        Validate --> Extract
        Extract --> Chunk
        Chunk --> Embed
        Embed --> Store
    end

    subgraph Retrieval["Query and Retrieval Pipeline"]
        direction TB

        Question["User Question"]
        Query["Prepare\n Retrieval Query"]
        QueryEmbed["Generate\n Query\n Embedding"]
        Search["Search\n Permitted\n Document\n Chunks"]
        Filter["Apply\n Access\n and\n Relevance\n Filters"]
        Context["Prepare\n Selected\n Context"]

        Question --> Query
        Query --> QueryEmbed
        QueryEmbed --> Search
        Search --> Filter
        Filter --> Context
    end

    Store -.->|"Indexed chunks\n and\n vectors"| Search

    Context --> Generate["Generate\n Answer\n Using\n Retrieved\n Context"]
    Generate --> Response(["Return\n Grounded\n Response"])

    %% Pastel fills with category-specific colored outlines.

    classDef ingestion fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
    classDef retrieval fill:#E0F7FA,stroke:#0891B2,stroke-width:1.5px,color:#164E63
    classDef storage fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
    classDef security fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
    classDef response fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A

    class Upload,Validate,Extract,Chunk,Embed ingestion
    class Question,Query,QueryEmbed,Search retrieval
    class Store storage
    class Filter,Context security
    class Generate,Response response

    %% Transparent containers preserve the active theme background.

    style Ingestion fill:transparent,stroke:#2563EB,stroke-width:1.5px,color:inherit
    style Retrieval fill:transparent,stroke:#0891B2,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain legible across themes.

    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

RAG responsibilities

Stage Responsibility
Ingestion Accept supported documents through an authorized path.
Validation Validate file type, size, metadata, and access permissions.
Text extraction Extract usable text from supported document formats.
Chunking Divide extracted content into retrieval-sized segments.
Embedding Convert text into vectors using the configured embedding model.
Storage Persist chunks, vectors, and associated metadata.
Retrieval Find relevant chunks for the user's query.
Access filtering Ensure retrieved content is accessible to the requesting user.
Context preparation Supply selected evidence to answer generation.
Response generation Answer from available evidence and communicate limitations when evidence is insufficient.

RAG security requirements

  • Apply document-level access controls during retrieval, not only during upload.
  • Validate files and protect ingestion workers against malicious content.
  • Treat retrieved text as untrusted data rather than executable instructions.
  • Avoid exposing complete documents when only a limited excerpt is required.
  • Distinguish source-supported facts from model-generated interpretation.
  • Handle missing, irrelevant, or low-confidence retrieval results without inventing evidence.

Keep configuration documentation synchronized

Record the embedding model, vector dimensions, chunking parameters, similarity thresholds, retrieval limits, and database schema from the active settings and source code. Update this page when those settings change.

6. Service and Port Reference

The following table records the service ports used in this architecture reference. Verify each value against the active service configuration and deployment manifests.

Component Documented port Primary responsibility
Next.js frontend 3000 User interface
REST API gateway 8000 API entry point
Chat service 8001 Conversation processing and orchestration
Session service 8002 Session-related operations
RAG service 8004 Document retrieval and related processing
User service 8005 User-related operations
Integrations service 8006 Third-party integration operations
PostgreSQL host mapping 5433 Database access through the documented host port
Redis 6379 Caching and rate-limiting support, where configured

RabbitMQ is also part of the documented supporting infrastructure. Its effective ports, exchanges, queues, consumers, and message routing must be verified against the active configuration.

Host ports and container ports

A host-mapped port may differ from the port used for communication between containers. Confirm the effective address and port from the deployment configuration rather than assuming that the host mapping is used internally.

6.1 Configuration verification

Verify:

  • Service startup commands and listening ports.
  • Gateway routing targets and internal service URLs.
  • Authentication and authorization middleware.
  • Health checks, timeouts, and request limits.

Verify:

  • PostgreSQL connection settings and migrations.
  • pgvector extension, schema, and indexes.
  • Redis usage, cache keys, TTLs, and rate-limit configuration.
  • RabbitMQ exchanges, queues, consumers, acknowledgements, and retry policies.

Verify:

  • Configured model provider and model identifier.
  • Model endpoint and connectivity.
  • Context limits, generation settings, and timeout behavior.
  • Runtime memory requirements and failure handling.

7. Data and Messaging Flow

This diagram summarizes logical relationships between the main request-processing components and supporting infrastructure.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#9CA3AF"
  }
}}%%

flowchart LR
    Frontend["Frontend<br/>Next.js :3000"]
    Gateway["API Gateway<br/>FastAPI :8000"]

    subgraph Application["Application Services"]
        direction TB
        Chat["Chat Service<br/>:8001"]
        Session["Session\n Service<br/>:8002"]
        RAG["RAG Service<br/>:8004"]
        Integrations["Integrations\n Service<br/>:8006"]
    end

    subgraph Infrastructure["Data and Messaging"]
        direction TB
        DB[("PostgreSQL\n +\n pgvector")]
        Cache[("Redis")]
        Broker[("RabbitMQ")]
    end

    subgraph External["External Systems"]
        direction TB
        Providers["External\n Provider\n APIs"]
        Model["Configured\n Model\n Runtime"]
    end

    Frontend -->|"HTTP requests"| Gateway
    Gateway --> Chat
    Gateway --> Session

    Chat -.->|"Retrieval requests"| RAG
    RAG -.->|"Document\n and\n vector access"| DB
    Session -.->|"Persistence,\n if configured"| DB

    Chat -.->|"Inference,\n if configured"| Model
    Chat -.->|"Cache operations,\n if configured"| Cache

    Integrations -.->|"Provider requests"| Providers
    Chat -.->|"Messaging,\n if configured"| Broker
    Broker -.->|"Configured consumers"| Chat

    %% Pastel fills with category-specific colored outlines.

    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 data fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
    classDef messaging fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
    classDef external fill:#F1F5F9,stroke:#64748B,stroke-width:1.5px,color:#334155

    class Frontend,Gateway frontend
    class Chat,Session,RAG,Integrations application
    class DB,Cache data
    class Broker messaging
    class Providers,Model external

    %% Transparent containers preserve the active theme background.

    style Application fill:transparent,stroke:#7C3AED,stroke-width:1.5px,color:inherit
    style Infrastructure fill:transparent,stroke:#059669,stroke-width:1.5px,color:inherit
    style External fill:transparent,stroke:#64748B,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain legible across themes.

    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

Data-flow principles

  • Route requests through the designated application boundaries.
  • Apply authentication and authorization before exposing protected resources.
  • Keep provider credentials in approved server-side storage.
  • Validate data received from external providers before using it downstream.
  • Minimize sensitive content retained in logs and caches.
  • Apply retention and deletion rules to stored conversation and document data.
  • Document asynchronous processing only after confirming that it is used by the relevant operation.

Dashed arrows indicate conceptual or configuration-dependent relationships; they do not establish that the depicted interaction is enabled.

8. Security Boundaries

Security depends on keeping untrusted inputs separate from trusted application decisions and protected resources.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#9CA3AF"
  }
}}%%

flowchart TB
    subgraph Untrusted["Untrusted Inputs"]
        direction TB
        Browser["User Browser"]
        UserInput["User Input"]
        ExternalContent["External\n Documents\n and\n Messages"]
    end

    subgraph Application["Application Trust Boundary"]
        direction TB
        Gateway["API Gateway<br/>FastAPI :8000"]
        Identity["Identity\n and\n Access\n Controls"]
        Policy["Server-Side\n Policy\n Enforcement"]
        Orchestration["AI\n Orchestration"]
        Registry["Authorized\n Tool\n Registry"]
    end

    subgraph Protected["Protected Resources"]
        direction TB
        Secrets["Credentials\n and\n Tokens"]
        Data[("Database\n and\n Document\n Store")]
        Integrations["Integrations\n Service<br/>FastAPI :8006"]
        Providers["External\n Provider\n APIs"]
    end

    Browser --> UserInput
    UserInput --> Gateway
    Gateway --> Identity
    Identity --> Policy
    Policy --> Orchestration
    Orchestration --> Registry
    Registry --> Integrations
    Integrations --> Providers
    Integrations -.->|"Authorized\n credential\n access"| Secrets
    Orchestration -.->|"Authorized\n data access"| Data

    ExternalContent -.->|"Untrusted content;\n validate before use"| Orchestration

    %% Pastel fills with security-zone-specific outlines.

    classDef untrusted fill:#FCE8E6,stroke:#DC2626,stroke-width:1.5px,color:#7F1D1D
    classDef application fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A
    classDef protected fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
    classDef external fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00

    class Browser,UserInput,ExternalContent untrusted
    class Gateway,Identity,Policy,Orchestration,Registry application
    class Secrets,Data,Integrations protected
    class Providers external

    %% Transparent containers preserve the active theme background.

    style Untrusted fill:transparent,stroke:#DC2626,stroke-width:1.5px,color:inherit
    style Application fill:transparent,stroke:#7C3AED,stroke-width:1.5px,color:inherit
    style Protected fill:transparent,stroke:#059669,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain legible across themes.

    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

The trust boundaries shown here are logical. Confirm the actual network isolation, secret storage, database permissions, and enforcement points in the deployed environment.

8.1 Authentication and authorization

  • Verify authentication tokens using the configured signature-verification method and trusted signing configuration.
  • Do not accept unverified token claims as proof of identity.
  • Enforce authorization on the server for protected operations and resources.
  • Do not rely on frontend controls as the only access restriction.
  • Validate connection ownership and resource-level permissions before executing integration operations.

8.2 Integration credentials

  • Protect OAuth client secrets, access tokens, and refresh tokens.
  • Validate OAuth callbacks and state parameters.
  • Avoid logging tokens or including them in user-facing errors.
  • Restrict credentials to the minimum required scopes.
  • Handle expired or revoked credentials through explicit, safe failure paths.

8.3 AI and tool security

  • Treat user input and third-party content as untrusted.
  • Enforce operation permissions independently of the model's decision.
  • Do not allow model-generated confirmation flags to bypass server-side controls.
  • Validate tool arguments against explicit schemas and resource-level permissions.
  • Apply suitable limits to tool calls, retries, and retrieved content.

8.4 Data protection

  • Enforce access controls on documents, conversations, and integration data.
  • Apply retention policies and secure deletion where required.
  • Avoid exposing secrets or sensitive internal information in logs, traces, errors, or generated responses.
  • Restrict access to operational diagnostics and stored application data.

Security requirements require implementation evidence

Listing a security control in this document does not establish that it is implemented. Confirm each control through code review, configuration review, and appropriate automated tests.

9. Error Handling and Recovery

The following diagram describes a generic bounded-retry pattern for operations where retrying is safe.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#9CA3AF"
  }
}}%%

flowchart TD
    Start(["Request\n or\n tool operation"])
    Execute["Execute\n operation"]
    Success{"Operation\n successful?"}
    Validate["Validate result"]
    Retryable{"Failure\nis \n retryable?"}
    Limit{"Retry limit\n reached?"}
    Retry["Retry\n with bounded\n backoff"]
    Error["Return a safe,\n actionable\n error"]
    Log["Record\n sanitized\n diagnostics"]
    Response["Continue\n response\n processing"]
    End(["Complete"])

    Start --> Execute
    Execute --> Success

    Success -- Yes --> Validate
    Validate --> Response

    Success -- No --> Retryable
    Retryable -- No --> Error
    Retryable -- Yes --> Limit

    Limit -- Yes --> Error
    Limit -- No --> Retry
    Retry --> Execute

    Error --> Log
    Log --> End
    Response --> End

    %% Pastel fills with category-specific colored outlines.

    classDef process fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
    classDef decision fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
    classDef success fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
    classDef failure fill:#FCE8E6,stroke:#DC2626,stroke-width:1.5px,color:#7F1D1D
    classDef recovery fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A

    class Start,Execute,Response,End process
    class Success,Retryable,Limit decision
    class Validate success
    class Error,Log failure
    class Retry recovery

    %% Neutral connectors remain legible across themes.

    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

Error-handling requirements

  • Apply bounded retries only to operations that are safe to retry.
  • Use backoff and suitable timeouts for transient failures.
  • Do not automatically retry non-idempotent operations without an appropriate safety mechanism.
  • Handle expired credentials and provider rate limits explicitly.
  • Return errors that help users understand the next action without revealing secrets or internal implementation details.
  • Record enough sanitized diagnostic information to support troubleshooting.
  • Ensure failed integrations do not silently produce fabricated success results.
  • Verify that streaming responses terminate cleanly and communicate errors consistently.

10. Deployment and Runtime View

The following diagram presents a logical deployment view, not a complete production topology.

%%{init: {
  "flowchart": {
    "htmlLabels": true,
    "nodeSpacing": 50,
    "rankSpacing": 65,
    "useMaxWidth": true
  },
  "themeVariables": {
    "fontSize": "18px",
    "lineColor": "#9CA3AF"
  }
}}%%

flowchart TB
    Client["User Browser"]

    subgraph ApplicationRuntime["Application Runtime"]
        direction TB
        Frontend["Next.js\n Frontend<br/>:3000"]
        Gateway["REST API\n Gateway<br/>FastAPI :8000"]
        Session["Session\n Service<br/>FastAPI :8002"]
        UserService["User\n Service<br/>FastAPI :8005"]
        Integrations["Integrations\n Service<br/>FastAPI :8006"]
        Chat["Chat\n Service<br/>FastAPI :8001"]
        RAG["RAG\n Service<br/>FastAPI :8004"]
    end

    subgraph SupportingRuntime["Supporting Runtime"]
        direction TB
        Redis[("Redis<br/>:6379")]
        DB[("PostgreSQL\n +\n pgvector")]
        MQ[("RabbitMQ")]
        Model["Qwen-3.5: 9B\n Model Server"]
    end

    Client --> Frontend
    Frontend --> Gateway

    Gateway --> Chat
    Gateway --> Session
    Gateway --> RAG
    Gateway --> UserService
    Gateway --> Integrations

    Gateway -.->|"Cache,\n if configured"| Redis
    Chat -.->|"Database access,\n if configured"| DB
    Chat -.->|"Messaging,\n if configured"| MQ
    Chat -.->|"Inference,\n if configured"| Model
    RAG -->|"Document\n and\n vector access"| DB

    %% Pastel fills with category-specific colored outlines.

    classDef client fill:#F1F5F9,stroke:#64748B,stroke-width:1.5px,color:#334155
    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 data fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
    classDef messaging fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
    classDef model fill:#FCE7F3,stroke:#DB2777,stroke-width:1.5px,color:#831843

    class Client client
    class Frontend frontend
    class Gateway,Chat,Session,RAG,UserService,Integrations application
    class DB,Redis data
    class MQ messaging
    class Model model

    %% Transparent containers preserve the active theme background.

    style ApplicationRuntime fill:transparent,stroke:#7C3AED,stroke-width:1.5px,color:inherit
    style SupportingRuntime fill:transparent,stroke:#059669,stroke-width:1.5px,color:inherit

    %% Neutral connectors remain legible across themes.

    linkStyle default stroke:#9CA3AF,stroke-width:1.3px

Deployment considerations

  • Keep internal services and data stores off public interfaces unless external access is explicitly required.
  • Configure environment variables and secrets through approved deployment mechanisms.
  • Separate local development configuration from production configuration.
  • Configure health checks, timeouts, restart behavior, and resource limits.
  • Verify container networking and port mappings.
  • Monitor service availability, request latency, model latency, and integration failures.
  • Confirm that persistent data volumes and backups are configured for the actual deployment.
  • Validate the deployment against supported runtime and dependency versions.

11. Component Responsibilities

Component Responsibility Verification focus
Frontend User interaction and request submission Authentication handling, session behavior, errors, and streaming
REST API gateway API entry point and gateway controls Token verification, authorization, validation, CORS, rate limiting, and routing
Chat service Conversation processing and orchestration Graph execution, state handling, streaming, and failure recovery
Session service Session-related operations Ownership checks, persistence, and lifecycle behavior
RAG service Document retrieval Access filtering, relevance filtering, and source traceability
User service User-related operations Identity consistency, authorization, and data validation
Integrations service Provider connections and tool operations OAuth handling, credential protection, scopes, and read-only enforcement
PostgreSQL / pgvector Relational and vector storage Schema, migrations, ownership, indexes, and backups
Redis Configured caching and rate limiting TTLs, key isolation, failure behavior, and sensitive-data handling
RabbitMQ Configured asynchronous messaging Queue topology, acknowledgements, retries, dead-letter behavior, and consumers
Model runtime Local inference, where enabled Model configuration, memory use, latency, and availability

12. Architecture Constraints and Verification Gates

The following requirements should be treated as engineering constraints during implementation and release reviews.

Access control

  • Authentication is verified server-side.
  • Authorization is enforced for each protected operation.
  • Integration connections and retrieved resources are scoped to the appropriate user or authorized tenant.
  • Model output is never the sole authority for a security-sensitive decision.

Read-only integrations

  • Gmail, Google Calendar, Google Drive, Jira, Slack, and Microsoft Teams use explicit read-operation allowlists.
  • Write-capable routes and tools are disabled, rejected, or otherwise prevented from running in the read-only configuration.
  • OAuth scopes and provider permissions are reviewed alongside application-level checks.
  • Automated tests prove that prohibited operations are rejected, not merely absent from the user interface.

RAG access isolation

  • Retrieval respects the requesting user's access rights.
  • Retrieved content is treated as untrusted input.
  • Missing or insufficient evidence is handled transparently.
  • Source attribution and document metadata are preserved where required.

Operational reliability

  • Timeouts, retries, and error handling are bounded.
  • Logs exclude credentials and sensitive data.
  • Service health and integration failures are observable.
  • Deployment configuration is reproducible and reviewed.

Release gate

Treat these checklists as verification criteria, not as evidence that a control has passed. Mark an item complete only after reviewing the relevant implementation, configuration, or test results.

13. Maintenance Checklist

Update this document when a verified change affects:

  • Service responsibilities, ports, or deployment boundaries.
  • API gateway routing or authentication behavior.
  • LangGraph nodes, transitions, state, or tool-dispatch logic.
  • Integration providers, OAuth scopes, registered tools, or read-only enforcement.
  • Document ingestion, embedding configuration, retrieval, or vector storage.
  • Database schemas, Redis behavior, RabbitMQ topology, or model serving.
  • Security boundaries, error handling, monitoring, or deployment configuration.

Before publishing an architecture change:

  1. Compare the proposed diagrams with the current source code.
  2. Verify service ports and dependencies against active configuration.
  3. Distinguish implemented behavior from proposed or planned behavior.
  4. Update the relevant architecture, security, integration, or deployment page.
  5. Build the documentation site and resolve warnings or errors.
  6. Review the rendered diagrams and internal links.
System Architecture

Review architectural decisions, component responsibilities, service boundaries, and technical design principles.

Explore system design
Architecture Overview

Understand the high-level system structure, application services, infrastructure components, and their relationships.

View architecture overview
Deployment & Infrastructure

Explore deployment configurations, infrastructure dependencies, containerization, and environment-specific considerations.

Explore deployment guidance
Product Requirements

Reference functional requirements, acceptance criteria, product constraints, and expected system behaviour.

Review requirements

Maintenance principle: architectural documentation is trustworthy only when it remains consistent with the implementation.