just-chat
real-time chat rooms that heat up, idle, and sleep
- 16 + 13 typed socket events
- restart-safe room lifecycle
- decaying heat score
- 15-table SQLite
A real-time multi-room chat platform built on a typed Socket.IO protocol: 16 client-to-server events and 13 server broadcasts share one strongly typed contract, with Zod-validated payloads on both sides. Identity is pinned at the WebSocket handshake from HMAC-SHA256-signed cookies, verified with a timing-safe comparison and never trusted from the client. That backs a dual guest/registered model where guests are first-class but RAM-only.
Rooms have a lifecycle. A single restart-safe sweeper drives live/idle/sleeping/cleaned states from persisted activity timestamps, with no per-room timers. A deterministic, exponentially decaying heat engine scores each room and streams incremental directory and heat deltas to subscribers.
Messages persist to a 15-table SQLite schema (WAL, foreign keys, hand-rolled transactional migrations with a version-tracked runner). A per-room in-memory ring buffer serves instant scrollback and stays coherent through edits and soft-deletes.
It runs as one Fastify + Socket.IO service with a WebSocket-aware helmet CSP, credentialed CORS, rate limiting, and structured logging. Vitest covers the pure heat and lifecycle engines plus the HTTP, schema, and socket flows.