/

Developer Guide

Chat Service Architecture

Bounded context: Knowledge & Assistance (shared with agent-service) · Stack: Node.js / Express · Code-level walkthrough: Chat Service

The chat-service owns conversations: it persists message history, enforces per-conversation limits, and forwards each question to agent-service for an answer. It holds no assistant logic itself — agent-service is stateless per request and never sees a conversation until chat-service sends it one.


Architectural Style

A layered architecture — Router → Controller → Service → Model — with one twist: the service layer has two members that do fundamentally different jobs. services/conversation.ts is ordinary persistence (Mongoose CRUD, scoped to the caller). services/agent.ts touches no model at all — it’s a plain HTTP client to agent-service’s /ask, forwarding the caller’s x-gateway-claims header verbatim rather than re-authenticating.

graph TD
    subgraph Router
        R[router.ts]
    end
    subgraph "Controller — controller/conversation.ts"
        C["createConversation · listConversations · getConversation\nrenameConversation · deleteConversation · sendMessage"]
    end
    subgraph "Service"
        CSV["services/conversation.ts\nCRUD, ownership checks, limits"]
        ASV["services/agent.ts\naskAgent — HTTP client only"]
    end
    subgraph Model
        M["models/conversation.ts"]
    end
    R --> C
    C --> CSV
    CSV -->|"sendMessage: forward question + trimmed history"| ASV
    CSV --> M
    M -.-> DB[(chat-db)]
    ASV -->|"POST /ask, x-gateway-claims forwarded"| AGENT[agent-service]

Key Architectural Decisions


Integration

For the conversation schema, the citation format, and the API, see the Chat Service internals page.