Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

03 — User Journey (WS / Realtime Module)

Journeys across the connection lifecycle, not screens — the realtime layer's only native moments are connect, event, and reconnect. Source-grounded: handshake (ws.gateway.ts:35-57), fan-out (ws-bridge.service.ts:16-22), rooms (ws.gateway.ts:50,63-74).


J1 — Login to connected (all personas)

StepActorSystem (source)
1User signs in; REST returns access tokenAuth module (token subject/tenant/roles payload)
2Client opens socket to /ws with tokennamespace: '/ws' (ws.gateway.ts:20-23); token via handshake.auth.token or handshake.query.token (ws.gateway.ts:37-39)
3Server verifies token against JWT_ACCESS_SECRETws.gateway.ts:42-44
4Server joins socket to tenant:{tenantId} roomws.gateway.ts:50
5Client shows connected indicator; subscribes to extra rooms if neededsubscribe event (ws.gateway.ts:63-68)
6Server begins delivering tenant eventsbridge active (ws-bridge.service.ts:23)

Failure paths: missing token → UnauthorizedExceptionclient.disconnect() (ws.gateway.ts:40,54-56). Invalid/expired token → same disconnect. The client must re-drive this journey after any reconnect.

J2 — Live dashboard update (Org Admin)

  1. Admin has dashboard open on a fee page.
  2. Cashier marks payment complete → payments.* domain event emitted (EventBus.emit, events/event-bus.service.ts:11).
  3. WsBridge.onAny catches it (ws-bridge.service.ts:16) → broadcastToTenant (ws.gateway.ts:76) → all admin sockets in tenant:{id}.
  4. Client receives envelope {eventType, occurredAt, payload} (ws-bridge.service.ts:17-21).
  5. Dashboard tile animates the new total without a page reload.

J3 — Notification receipt (Teacher / Student / Parent)

  1. User is on any module screen.
  2. Announcement published → notification.created event (dot-namespace convention, API_STANDARDS.md:642-658).
  3. Toast slides in (m-fast, 00-shared/08), bell badge increments.
  4. User taps → navigates to the detail; list shows the item (reconciled with REST).

J4 — Network flap (all personas)

  1. WiFi drops. Socket.io client detects ping timeout (server-side heartbeat defaults).
  2. Client enters reconnecting state; UI shows offline banner (component in 07).
  3. Backoff retries re-establish the connection (client-side; see 15).
  4. On reconnect: handshake runs again — token must still be valid (see 14_QA_Checklist.md "auth on reconnect"). If the access token expired, the client refreshes via REST and reopens the socket.
  5. Missed events are not replayed (fire-and-forget bridge). Client refetches affected lists via REST for eventual consistency — mandatory reconciliation rule (10 §6).

J5 — Message delivery (planned)

  1. Teacher sends message → Communication module (planned), delivered via this WsModule (docs/IMPLEMENTATION_PLAN.md:119).
  2. Recipient sockets receive the message event; thread list updates live.
  3. Until Communication lands, this journey is a contract placeholder, not a feature.

J6 — Realtime admin debug (proposed)

  1. IT admin opens Realtime Debug view (proposed)05 §5.
  2. Sees connection health, live event stream, room membership for own tenant.
  3. Uses it to verify fan-out after a deployment.

Journey rules

  • Every reconnect restarts at step 2 of J1 — there is no session resumption in source.
  • No journey requires the user to act on the connection itself; failure UX is banner-level (see 06 §1) and non-blocking.