Backend: - Notification model + Alembic migration - Notification service: CRUD, mark read, unread count, pending scheduled - WebSocket manager singleton for real-time push - WebSocket endpoint /ws/notifications with JWT auth via query param - APScheduler integration: periodic notification sender (every 60s), daily proactive health review job (8 AM) - AI tool: schedule_notification (immediate or scheduled) - Health review worker: analyzes user memory via Claude, creates ai_generated notifications with WebSocket push Frontend: - Notification API client + Zustand store - WebSocket hook with auto-reconnect (exponential backoff) - Notification bell in header with unread count badge + dropdown - Notifications page with type badges, mark read, mark all read - WebSocket initialized in AppLayout for app-wide real-time updates - Enabled notifications nav in sidebar - English + Russian translations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3.7 KiB
3.7 KiB
Phase 5: Notifications — Subplan
Goal
Deliver in-app real-time notifications via WebSocket, APScheduler for scheduled/recurring notifications, AI tool schedule_notification, daily proactive health review job, and frontend notification UI (bell in header, notification list page).
Prerequisites
- Phase 4 completed: memory service, AI tools, document processing
- APScheduler added to dependencies
Tasks
A. Backend Model & Migration (Tasks 1–3)
- A1. Create
backend/app/models/notification.py: Notification model (user_id, title, body, type, channel, status, scheduled_at, sent_at, read_at, metadata JSONB). - A2. Add
notificationsrelationship on User model. Updatemodels/__init__.py. - A3. Create migration
005_create_notifications.py.
B. Backend Schemas (Task 4)
- B4. Create
backend/app/schemas/notification.py: NotificationResponse, NotificationListResponse, UnreadCountResponse.
C. Backend Services (Tasks 5–7)
- C5. Create
backend/app/services/notification_service.py: create, list, unread count, mark read, mark all read, get pending scheduled, mark sent. - C6. Create
backend/app/services/ws_manager.py: ConnectionManager class (connect, disconnect, send_to_user). - C7. Create
backend/app/services/scheduler_service.py: AsyncIOScheduler wrapper (start, stop, schedule one-time, schedule recurring).
D. Backend API (Tasks 8–10)
- D8. Create
backend/app/api/v1/notifications.py: GET list, GET unread-count, PATCH /{id}/read, POST mark-all-read. - D9. Create
backend/app/api/v1/ws.py: WebSocket /ws/notifications with JWT auth via query param. - D10. Register routers. Wire scheduler in main.py lifespan. Add
apschedulerto pyproject.toml.
E. Backend AI Tool + Workers (Tasks 11–13)
- E11. Add
schedule_notificationtool to AI_TOOLS + handler in_execute_toolin ai_service.py. - E12. Create
backend/app/workers/notification_sender.py: periodic job (every 60s) sends pending scheduled notifications via WebSocket. - E13. Create
backend/app/workers/health_review.py: daily job queries user memories/docs, asks Claude for reminders, creates ai_generated notifications.
F. Frontend API & Store (Tasks 14–16)
- F14. Create
frontend/src/api/notifications.ts. - F15. Create
frontend/src/stores/notification-store.ts(Zustand). - F16. Create
frontend/src/hooks/use-notifications-ws.ts: WebSocket with auto-reconnect.
G. Frontend UI (Tasks 17–20)
- G17. Create
frontend/src/components/notifications/notification-bell.tsx: bell icon + unread badge + dropdown. - G18. Integrate bell into header.tsx. Init WebSocket in AppLayout.
- G19. Create
frontend/src/pages/notifications.tsx: full list with type filter, mark read. - G20. Update routes + enable sidebar notifications link.
H. i18n (Task 21)
- H21. Update en/ru translations with notification keys.
I. Tests (Tasks 22–23)
- I22. Create
backend/tests/test_notifications.py: CRUD, mark read, unread count, ownership isolation. - I23. Verify frontend builds cleanly.
Acceptance Criteria
- Notification CRUD API works with auth and ownership isolation
- WebSocket pushes notifications in real time
- AI
schedule_notificationtool creates scheduled/immediate notifications - APScheduler fires pending notifications at scheduled_at time
- Daily health review generates ai_generated notifications
- Frontend bell shows unread count, dropdown shows recent, updates in real time
- Notifications page with type filter and mark-as-read
- All UI text in English and Russian
- Backend tests pass, frontend builds clean
Status
COMPLETED