Notification
Internals of the Notification domain. For the public API, see Notification API.
Notifications are part of the ticketing lane; chat is a native /api/v1 feature
added later to the same Go package (domain/notifications). Checked against CoreAPI staging on 2026-11-16.
How notifications are created¶
graph LR
I["Identity"] -->|CreateNotification| N["NotificationService"]
C["Commerce"] -->|CreateNotification| N
CA["Catalogue (ticket group, rail menu, banner)"] -->|CreateNotification| N
A["Advertising, Analytics"] -->|CreateNotification| N
N --> DB[("johorzoo.notification")]
Admin["Admin frontend"] -->|/api/:workspaceId/notifications| DB
Other domains call the Go service; there is no HTTP route to create one. This is the "Internal API" section of the old page:
CreateNotification(performedBy, authorityLevel, notificationType, title, message, date, workspaceID string) error
workspaceIDstamps the row; the organization is resolved from the workspace (ResolveOrganizationForWorkspace). Callers passSPATIO_TICKETING_WORKSPACE_IDor the ticket group's workspace.- Two helpers wrap it with
date = now(YYYY-MM-DD HH:MM:SS): one with performerSYSTEM, one with a given performer. typeis free text. Values in use:Order,Customer/customer,Ticket Group,Rail Menu,Banner,Password reset,Admin Account Profile.authorityLevelis the actor's role orsystem/customer; casing is not consistent (CUSTOMER,customer,Customerall occur).- List:
is_deleted = false AND workspace_id = ?, searchILIKEon title, message, type and performed_by, newest first,limitclamped to 10–100. Update, mark-all-read and delete-all are workspace-scoped; "delete" is a soft delete (is_deleted). - Auth:
ProtectedRS256+RequireWorkspacePermission(workspace:notifications:manage)on/api/:workspaceId. The group/api/:workspaceIdis broad; register new/api/<word>/…ticketing routes with this in mind.
Chat¶
- Wired by
notificationsroutes.SetupChatfromroutes_platform.go(needsOrgServiceto list org users). Routes inroutes/chat_routes.go, all behindProtectedRS256; the caller isauthClaims.UserIDand the organization isauthClaims.Org.OrgID. No named permission. - A direct chat is unique per organization by
direct_key(the two user IDs sorted and joined). Group chats have no key and a name; membership changes need the caller to be a participant, and fail withErrNotGroupChaton direct chats. - Message IDs are UUIDv7, so the
beforecursor doubles as chronological order.ListMessagesclampslimitto 1–100 (else 50). - Websocket (
GET /chat/ws): one connection per user session;Hub(chat_hub.go) keeps connections by user ID and fans a message out to every participant's connections. Browsers can't set headers on a websocket handshake, soProtectedRS256falls back to theaccess_tokencookie. Inbound frame{type:"message", chatId, body}; outbound{type:"message"|"error"}. The hub is in-process: with more than one CoreAPI replica, a message is pushed only to sockets on the replica that received it. REST sends and websocket sends use the sameSendMessage.
Data model¶
erDiagram
Notification {
uint notification_id
string organization_id
string workspace_id
string performed_by
string authority_level
string type
string title
text message
string date
bool is_read
bool is_deleted
}
Chat {
uuid id
string organization_id
string type
string direct_key
string name
timestamptz last_message_at
}
ChatParticipant {
uuid chat_id
string user_id
timestamptz last_read_at
}
ChatMessage {
uuid id
uuid chat_id
string sender_id
text body
}
Chat ||--o{ ChatParticipant : has
Chat ||--o{ ChatMessage : contains
johorzoo.notification; chats, chat_participants and chat_messages in public.
Known issues¶
- The old page described
GET /api/notificationsandPUT /api/notificationwith no workspace and an{ success, data }answer; both were wrong since 2026-09-14 (workspace-scoped, ticketing format). last_read_atonchat_participantsis stored but no route reads or sets it: there is no unread count yet.- The
authority_levelandtypevalues are not an enum; the admin UI filters on them as strings. - Chat websocket scales to one replica only (see above).
Change history¶
- 2026-09-14: notifications scoped to
:workspaceId; search and pagination in the workspace. - 2026-09-01: group chat and websocket.
- 2026-08-19: mark all read, delete all.
- 2026-08-17: direct chat.
- 2026-06-23: first notification documentation.