Summary
Add real-time bidirectional communication to the backend using github.com/gorilla/websocket, enabling the web and mobile clients to receive live updates without polling.
Scope
Backend (Go)
Web (Next.js)
- Add a
useWebSocket hook in lib/ that opens the connection, handles reconnection with exponential backoff, and exposes incoming messages
- Attach the Firebase ID token on connect for authentication
- Typed message envelope:
{ type: string; payload: unknown } — discriminated union for known event types
Mobile (Android / Jetpack Compose)
- Add OkHttp WebSocket client (already available transitively via Retrofit/OkHttp)
- Manage the connection in a
WebSocketManager singleton or scoped to a ViewModel
- Reconnect on network change; pass Firebase token on handshake
Acceptance criteria
Dependencies
Summary
Add real-time bidirectional communication to the backend using
github.com/gorilla/websocket, enabling the web and mobile clients to receive live updates without polling.Scope
Backend (Go)
github.com/gorilla/websocketdependencyWebSocketHubininternal/infrastructure/ws/that manages connected clients, broadcasts messages, and handles disconnectionsGET /wsupgrade endpoint inroutes.go— authenticated via Firebase token query param orUpgradeheader (ties into feat: add Firebase Authentication across all app layers #15)server.goas a long-lived goroutine alongside the HTTP serverWeb (Next.js)
useWebSockethook inlib/that opens the connection, handles reconnection with exponential backoff, and exposes incoming messages{ type: string; payload: unknown }— discriminated union for known event typesMobile (Android / Jetpack Compose)
WebSocketManagersingleton or scoped to a ViewModelAcceptance criteria
GET /wsupgrades to a WebSocket connection and rejects unauthenticated requests with 401useWebSockethook receives and surfaces live messages in a componentbackend/docs/websocket.mdandweb/docs/websocket.mdDependencies