The chatserver module provides a fully self-hostable, real-time chat backend written in Go. It integrates WebSocket-based messaging, JWT authentication via Keycloak, PostgreSQL for persistence, and Valkey (Redis-compatible) for caching and rate limiting. The system is modular and designed to be observable, scalable, and easy to deploy behind a reverse proxy.
caddyfile.dev and caddyfile.prod are included in the project
Server identity and rate limiting config are initialized from PostgreSQL
JWT keys are loaded dynamically from Keycloak’s JWKS endpoint
In development, you must trust Caddy's local CA for HTTPS to work properly on localhost
📝 TODO
Graceful shutdown support
Flush user session durations and close WebSocket connections cleanly on shutdown.
Ping/pong keepalive and idle timeout
Detect and clean up stale client connections automatically.
Retry failed whispers
Implement a retry queue for private messages if the target client is momentarily disconnected.
Split whisper/broadcast queues
Process Broadcast() and Whisper() flows in separate background goroutines to isolate errors and improve throughput.
Expose Prometheus metrics
Provide system health stats like connected clients, message rates, and cache timings at a /metrics endpoint for Prometheus to scrape.
Improve dashboard load UX
Introduce loading states and staged delivery to avoid UI stalls.