sp3-test-1770368381/.sdlc/features/websocket-chat/spec.md
rdev-worker 0e39598aa6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
build: /implement-feature websocket-chat --requirements 'GET /ws upgrades to...
2026-02-06 09:09:52 +00:00

31 lines
1.4 KiB
Markdown

# 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