/

Developer Guide

Socket Service Architecture

Bounded context: real-time transport (generic) · Stack: Node.js / Socket.IO · Code-level walkthrough: Socket Service

The socket-service is the bridge between the broker and the browser. It carries per-building telemetry and alerts to connected clients over WebSockets. It is classified as a generic subdomain (see Telemetry Distribution: pure transport, with no domain model and no database.


Architectural Style

Deliberately the simplest service in the system: no persistence and no domain model. Everything the service does splits cleanly into two kinds of code, and index.ts says so in its own header comment: “Composition root (imperative shell): build dependencies, wire the pure handlers to them, and start listening. No logic lives here — that’s in core/ and handlers/, which is why this file is excluded from coverage.”

graph LR
    subgraph "Imperative Shell"
        IDX["index.ts\ncomposition root"]
        AUTH["auth.ts\nauthenticateClaimsHeader"]
        CONN["handlers/connection.ts"]
        TEL["handlers/telemetry.ts"]
        NOTIF["handlers/notification.ts"]
    end
    subgraph "Functional Core — core/relay.ts"
        REL["roomForBuilding · roomForDomain\nbuildingIdFromChannel"]
    end
    BR1[(broker: notifications)] --> IDX
    BR2[(broker: telemetry:filtered:*)] --> IDX
    IDX -->|"io.use() — handshake middleware"| AUTH
    IDX -->|"io.on('connection')"| CONN
    IDX --> TEL
    IDX --> NOTIF
    TEL --> REL
    NOTIF --> REL
    CONN --> REL
    TEL -->|room-scoped| CL[Connected clients]
    NOTIF -->|room-scoped / broadcast| CL

Key Architectural Decisions


Integration

For the channel-to-event mapping, the client subscription protocol, and scaling notes, see the Socket Service internals page.