@thescaffold/chat-server
v0.2.0
Published
Transport-agnostic chat server for X Chat (chat.v1 protocol, send pipeline, room coordination)
Readme
@thescaffold/chat-server
The transport-agnostic chat server. Implements the chat.v1 protocol on the
server side: connection registry, per-room coordination, the send pipeline,
authorization, and rate limiting. Has no HTTP-framework dependency — works
behind a bare http.Server, Express, Fastify, or NestJS.
Composition
import { createServer } from 'node:http';
import { ChatServer } from '@thescaffold/chat-server';
import {
createMemoryStores,
InMemoryPresence,
InMemoryPubSub,
InMemoryStorage,
DevAuthAdapter,
createBuiltinContentRegistry,
} from '@thescaffold/chat-addons';
const { roomStore, messageStore, userStore } = createMemoryStores();
const chat = new ChatServer({
auth: new DevAuthAdapter(),
roomStore,
messageStore,
userStore,
presence: new InMemoryPresence(),
pubsub: new InMemoryPubSub(),
storage: new InMemoryStorage(),
contentRegistry: createBuiltinContentRegistry(),
});
const http = createServer((_req, res) => res.end('ok'));
await chat.attachWebSocket(http, { path: '/ws/chat' });
http.listen(3000);Pieces
ChatServer— top-level facadeWsTransport—wspackage adapter; lives behind theTransportinterfaceRoomCoordinator— pubsub fan-out + backpressure sheddingSendPipeline— auth → rate-limit → validate → moderate → persistConnectionRegistry— per-node sockets indexed by id / user / roomAuthorization— membership checksTokenBucketRateLimiter— per-(user, room) limiter
Observability sinks (Logger, MetricsSink) are interfaces with no-op
defaults; bind the pino/prom-client/OTEL implementations from @thescaffold/chat-addons
in production.
