# WebSocket Chat - Feature Specification ## Overview Add WebSocket support to the chat-api service. `GET /ws` upgrades to a WebSocket connection. Incoming messages are published to a Redis Pub/Sub channel. A Redis subscriber broadcasts received messages to all connected WebSocket clients. ## Requirements ### Functional Requirements 1. **WebSocket Endpoint**: `GET /api/chat-api/ws` upgrades HTTP connections to WebSocket 2. **Message Publishing**: Incoming WebSocket messages are published to Redis Pub/Sub channels 3. **Message Broadcasting**: A Redis subscriber receives messages and broadcasts them to all connected WebSocket clients 4. **Room Support**: Optional room-based messaging via `GET /api/chat-api/ws/{room}` or `?room=` query parameter ### Non-Functional Requirements 1. Uses existing `pkg/realtime` package (Hub, WSClient, RedisBroadcaster) 2. Follows existing chat-api handler and routing patterns 3. Redis connection configured via `REDIS_URL` environment variable 4. Graceful shutdown of hub and Redis broadcaster on SIGTERM ## Acceptance Criteria - [ ] `GET /api/chat-api/ws` upgrades to WebSocket - [ ] Messages sent by a client are published to Redis - [ ] Messages from Redis are broadcast to all connected clients - [ ] Hub and Redis broadcaster shut down gracefully - [ ] Configuration via `REDIS_URL` environment variable - [ ] OpenAPI spec updated with WebSocket endpoint documentation