## Phase 1: WebSocket Infrastructure ### 1.1 Connection Manager - [ ] 1.1.1 建立 backend/app/core/websocket.py - [ ] 1.1.2 實作 ConnectionManager class - [ ] 1.1.3 實作 connect/disconnect/send_to_user 方法 - [ ] 1.1.4 加入心跳偵測機制 ### 1.2 WebSocket Endpoint - [ ] 1.2.1 新增 WS /ws/notifications endpoint - [ ] 1.2.2 實作 WebSocket token 驗證 - [ ] 1.2.3 連線時查詢並推送未讀通知 - [ ] 1.2.4 處理 WebSocket 異常與斷線 ### 1.3 Testing - Phase 1 - [ ] 1.3.1 WebSocket 連線測試 - [ ] 1.3.2 未讀通知補送測試 - [ ] 1.3.3 斷線處理測試 ## Phase 2: Redis Pub/Sub Integration ### 2.1 Redis Pub/Sub Service - [ ] 2.1.1 建立 backend/app/core/redis_pubsub.py - [ ] 2.1.2 實作 publish_notification 函數 - [ ] 2.1.3 實作 subscribe_user_channel 函數 - [ ] 2.1.4 訊息 JSON 序列化處理 ### 2.2 Cross-Process Broadcasting - [ ] 2.2.1 WebSocket endpoint 訂閱 user channel - [ ] 2.2.2 收到 Redis 訊息時推送給連線 - [ ] 2.2.3 處理訂閱錯誤與重連 ### 2.3 Testing - Phase 2 - [ ] 2.3.1 Redis Pub/Sub 單元測試 - [ ] 2.3.2 跨 process 通知測試(手動驗證) ## Phase 3: Service Integration ### 3.1 NotificationService 整合 - [ ] 3.1.1 create_notification 後呼叫 publish_notification - [ ] 3.1.2 確保所有通知類型都即時推播 - [ ] 3.1.3 處理 Redis 連線失敗 gracefully ### 3.2 Frontend WebSocket Client - [ ] 3.2.1 建立 frontend/src/services/websocket.ts - [ ] 3.2.2 實作 WebSocket 連線與重連邏輯 - [ ] 3.2.3 訊息處理與分發 ### 3.3 NotificationContext 整合 - [ ] 3.3.1 修改 NotificationContext 使用 WebSocket - [ ] 3.3.2 收到通知時更新未讀數量 - [ ] 3.3.3 收到 unread_sync 時同步狀態 ### 3.4 Testing - Phase 3 - [ ] 3.4.1 完整即時通知流程測試 - [ ] 3.4.2 前端 WebSocket 整合測試