Catalogue
title: Catalogue internals description: How the Catalogue domain is built: data model, playout scheduler, approval flow, creation flows, known gaps and change history. audience: internal type: explanation owner: platform-team last_reviewed: 2026-11-17
Internals of the Catalogue domain. For the public API, see Catalogue API and Catalogue ticketing API.
Architecture¶
graph LR
CMS["CMS frontend"]
CustomerApp["Customer app"]
CoreAPI["CoreAPI"]
CMSDB["CMS tables\n(playlists, media_channels,\nlayout_templates, time_blocks)"]
TicketingDB["Ticketing tables\n(ticket_group, banner, rail_menu, tag)"]
CMS -->|/api/v1/playlists\n/api/v1/media-channels| CoreAPI
CMS -->|/api/ticketGroups\n/api/railMenus\n/api/banners| CoreAPI
CustomerApp -->|/api/ticketGroups\n/api/railMenus/customer| CoreAPI
CoreAPI --> CMSDB
CoreAPI --> TicketingDB
The two sides share one Go domain package but register separate route groups: the flat CMS package under /api/v1, and the ticketing subpackage under /api.
Data model¶
erDiagram
Playlist {
string id
string organizationId
string workspaceId
string name
int version
int totalDuration
string status
int mediaCount
string thumbnailUrl
string canvasTemplateId
string aspectRatio
bool multiZone
int actualZoneCount
string readyState
}
PlaylistVersion {
string id
string playlistId
int version
string status
string readyState
string createdBy
string action
string note
string publishedBy
string publishedAt
}
PlaylistCanvasTemplate {
string id
string organizationId
string name
string orientation
string aspectRatio
bool multiZone
int zoneCount
bool isSystem
}
PlaylistItem {
string id
string playlistId
string versionId
string mediaId
string itemType
int sortOrder
int durationSeconds
int zoneIndex
}
MediaChannel {
string id
string organizationId
string name
string orientation
string deliveryMode
string approvalStatus
string status
}
LayoutTemplate {
string id
string name
string orientation
bool isSystem
}
LayoutZone {
string id
string templateId
string name
float widthPercent
float heightPercent
}
TimeBlock {
string id
string channelId
string playlistId
string blockType
string startDate
string endDate
string startTime
string endTime
string recurrence
string[] recurrenceDays
int priority
string color
}
TimeBlockZoneAssignment {
string timeBlockId
string zoneId
string playlistId
}
ChannelFallbackConfig {
string channelId
string standbySlate
string adSlate
string blackoutSlate
string defaultPlaylistId
}
TicketGroup {
uint ticketGroupId
string groupNameBm
string groupNameEn
string groupNameCn
string groupType
bool isActive
string activeStartDate
string activeEndDate
}
TicketVariant {
uint ticketVariantId
uint ticketGroupId
string nameEn
float unitPrice
}
Tag {
uint tagId
string tagName
string tagDesc
}
Banner {
uint bannerId
int placement
bool isActive
string activeStartDate
string activeEndDate
}
RailMenu {
uint railMenuId
string nameEn
int placement
bool isActive
}
Playlist ||--o{ PlaylistItem : "contains"
Playlist ||--o{ PlaylistVersion : "has versions (live/draft/historical)"
PlaylistVersion ||--o{ PlaylistItem : "scopes items via versionId"
PlaylistCanvasTemplate ||--o{ Playlist : "shapes zones for"
MediaChannel ||--o{ TimeBlock : "scheduled by"
TimeBlock ||--o{ TimeBlockZoneAssignment : "drives multiple zones"
LayoutTemplate ||--o{ LayoutZone : "has zones"
TicketGroup ||--o{ TicketVariant : "has variants"
TicketGroup }o--o{ Tag : "tagged with"
RailMenu }o--o{ TicketGroup : "contains (type: ticket)"
Rail Menu items are a discriminated union
A RailMenu's content array isn't purely TicketGroup rows — each entry is { type: "ticket" | "advertisement", placement, detail }, sorted by placement across both types. Advertisement entries come from the advertising domain (read-only here; no CRUD route exists under /railMenus for them). See the ticketing API page for the public shape.
Access control gaps¶
The CMS routes run through a header-scope guard (log-only by default; enforce mode refuses requests whose token and X-Organization-ID / X-Workspace-ID disagree). The ws:playlist:publish permission constant exists but no handler in this domain enforces it; TellyboardAdmin checks it client-side before deciding whether to broadcast directly or route through Approvals (see Provisioning internals).
Ticketing integration config (now replaced by org-owned payment and POS profiles, see Integration profiles) had two gaps while it existed: workspace permission did not check that the ticket group belongs to the workspace, and a profile assignment checked only the foreign key, not that the profile belongs to the same organization. Payment and POS profiles are org-owned, can be narrowed to a workspace, and an inactive profile is rejected at credential-resolve time.
Ticketing notes¶
All ticketing responses are wrapped in a standard envelope (`{ success, message, data }` / `{ success: false, message }` from `pkg/models`), unlike the bare-JSON CMS endpoints above. Nearly every mutating handler also fires an audit notification (`notificationService.CreateNotification(admin, role, category, title, message, timestamp)`) as a side effect — not user-visible in the response, but worth knowing if notification volume looks unexpected.
Rail menu content is ticket groups and advertisements, merged
A rail menu's content array is a discriminated union, sorted by placement across both types: { type: "ticket", placement, detail: TicketGroupDTO } or { type: "advertisement", placement, detail: AdvertisingTicketDTO }. Advertisement entries are read from the advertising domain (RailMenuAdvertisingTicketRepository) — there is no create/update/delete route for ads under /railMenus; they're managed in the advertising domain and only surfaced here on read. AdvertisingTicketDTO fields: advertisementId, advertisementType (brandImage|coupon|editorial|typographic), advertiser, color, title{Bm,En,Cn}, header{Bm,En,Cn}, desc{Bm,En,Cn}, actionButton, redirectUrl, imageUrl, isActive. The customer endpoint filters ads by isActive and the active-date window (server's Malaysia-timezone "now"); the admin endpoint does not filter.
Time block scheduling¶
Time blocks define what playlist plays on a channel during a given window.
sequenceDiagram
participant Admin
participant CoreAPI
participant DB
Admin->>CoreAPI: POST /media-channels/:id/time-blocks
Note over Admin,CoreAPI: { name, blockType, startDate, endDate,\n startTime, endTime, recurrence,\n recurrenceDays, priority, playlistId }
CoreAPI->>DB: INSERT time_blocks
CoreAPI-->>Admin: 201 { id }
A default block (priority 0) is synthesised from the channel's zone assignment if no scheduled block covers a window (id: "default-"+zoneID, recurrence: "daily", color: "#9ca3af").
Background playout scheduler¶
A recurring goroutine (StartChannelScheduler, started once at boot, re-run every 15s) decides what each channel should actually be showing right now and pushes it to devices — this is what makes scheduled time blocks take effect without any per-request trigger.
flowchart LR
Tick["Every 15s"] --> Resolve["Resolve active time blocks\nper channel (date/time/recurrence)"]
Resolve --> Rank["Rank by type\n(override/event=10, scheduled=5, default=1),\nthen priority, then recency"]
Rank --> Changed{"Winning block\nchanged or 5min elapsed?"}
Changed -->|no| Skip["Skip — already dispatched"]
Changed -->|yes| Dispatch["Dispatch to online devices\nin the channel's assigned spaces"]
Dispatch --> MQTT["Has playlistId?\nMQTT PLAY (retained, QoS 1)"]
Dispatch --> HTTP["No playlistId (zone-driven)?\nInternal HTTP POST /devices/:id/play"]
- "Online" =
last_seen_atwithin the last 5 minutes. - Per-channel in-memory state (
activeStates) avoids redundant re-dispatch; an override block ending with nothing to replace it resumes the channel's default/fallback block. ResyncDeviceOnReconnect(deviceId)(called from the provisioning domain's heartbeat/reconnect path) re-sends just the current active state to a single device that just came back online, without waiting for the next tick.
This is orthogonal to the Provisioning domain's Broadcast feature
The scheduler drives scheduled content per channel/time-block. Broadcast to Space in the Provisioning domain is a separate, ad-hoc "push this now, ignore the schedule" mechanism used for one-off/always-on assignments.
Approval flow (media channels)¶
stateDiagram-v2
[*] --> draft
draft --> pending_review: submit
pending_review --> approved: admin approves
pending_review --> rejected: admin rejects
rejected --> draft: edit & resubmit
approved --> active: go live
approvalStatus transitions via PATCH on the channel's approvalStatus field in PUT /media-channels/:id.
Key creation flows¶
Create a Playlist and Add Media¶
POST /api/v1/playlists
Header: X-Organization-ID: <org-uuid>
Body: { "name": "Morning Show" }
→ Returns: { "playlistId": "uuid" }
POST /api/v1/playlists/:playlistId/media
Body: [
{ "mediaId": "...", "position": 0, "duration": 30, "name": "...", "mediaType": "video" },
{ "mediaId": "...", "position": 1, "duration": 15, ... }
]
→ Clears existing items, inserts new ones, recalculates totalDuration + version
Media sync is replace-all
POST /playlists/:id/media deletes all existing items before inserting. Always send the full ordered list.
Thumbnail is derived, not stored on create
There's no separate thumbnail endpoint. GET /playlists computes thumbnailUrl per playlist from its live version's first item (by sort_order): the item's own thumbnailUrl if set, else the item's media URL if it's an image. GET /playlists/:id does not populate this field — only the list endpoint does.
Start, Edit, and Publish a Playlist Draft¶
POST /api/v1/playlists/:playlistId/draft
→ Copies every item from the live version into a new draft version
→ Returns: { "message": "Draft started", "version": 3 }
POST /api/v1/playlists/:playlistId/media?target=draft
Body: [ { "mediaId": "...", "position": 0, "duration": 30, ... } ]
→ Replaces the draft's items only — live is untouched
→ Returns: { "success": true, "count": 1 }
PATCH /api/v1/playlists/:playlistId/ready
→ Sets the draft's readyState to "ready"
→ Returns: { "message": "Draft version marked ready" }
POST /api/v1/playlists/:playlistId/publish-draft
→ Current live version becomes historical; draft becomes the new live
→ Returns: { "message": "Draft published", "version": 3 }
Not visible anywhere until published
A draft's items never reach a device — the scheduler and /media?target=live (the default) only ever read the live version. Publishing is the only thing that promotes draft content to what's actually broadcast.
Roll Back or Restore a Playlist Version¶
# Restore an old version directly to live (skips the draft stage)
POST /api/v1/playlists/:playlistId/rollback
Body: { "version": 2 }
→ Archives current live to historical, restores v2 as the new live
→ Returns: { "message": "Rolled back", "version": 2 }
# Restore an old version's content into the current draft instead
POST /api/v1/playlists/:playlistId/draft/rollback
Body: { "version": "v002" }
→ Reuses (or creates) the draft, copies v002's items into it
→ live is untouched
→ Returns: { "message": "Restored content from v002 into current draft (v004)", "version": 4 }
Create a Media Channel with a Base Playlist¶
POST /api/v1/media-channels
Headers: X-Organization-ID, X-User-ID
Body: {
"name": "Lobby Channel",
"orientation": "landscape",
"deliveryMode": "pre-cached",
"basePlaylistId": "playlist-uuid", ← optional: auto-creates zone assignment
"layoutTemplateId": "template-uuid" ← optional
}
→ If basePlaylistId provided: auto-creates channel_zone_assignment
(uses first zone of layoutTemplate, or falls back to channelId as zoneId)
→ Returns: { "id": "channel-uuid" }
Assign Channel to a Space (Push to Devices)¶
POST /api/v1/media-channels/:channelId/spaces
Headers: X-User-ID
Body: { "spaceId": "location-uuid" }
→ Inserts channel_space_assignments (ON CONFLICT DO NOTHING)
→ Queries playlist items from channel's zone assignment
→ For each device in the space: publishes MQTT to
topic: "tellyboard/devices/{deviceId}/play"
payload: { id, playlistName, items: [...] }
→ Also dispatches an internal HTTP POST to each device's
{INTERNAL_API_URL}/api/v1/devices/:deviceId/play (in addition to MQTT)
→ Returns: { message, devices, sentCount, playlistId }
Schedule a Time Block¶
POST /api/v1/media-channels/:channelId/time-blocks
Headers: X-User-ID
Body: {
"name": "Lunch Promo",
"blockType": "scheduled",
"playlistId": "playlist-uuid",
"startDate": "2026-06-01",
"endDate": "2026-08-31",
"startTime": "11:30",
"endTime": "13:30",
"recurrence": "weekly",
"recurrenceDays": ["mon","tue","wed","thu","fri"],
"priority": 20,
"color": "#f59e0b"
}
→ Returns: { "id": "block-uuid" }
Priority
Higher priority wins when blocks overlap. Default blocks (from zone assignments) always have priority: 0.
Multi-zone alternative: zone_assignments
Instead of (or in addition to) a top-level playlistId, the body can carry zone_assignments: [{ zone_id, playlist_id, items }] to drive several zones from one time block. If a zone's items array is supplied inline, the handler auto-creates a playlist for that zone on the fly and assigns it — see Create a Media Channel with a Base Playlist above.
Change history¶
| Date | Author | Change |
|---|---|---|
| 2026-09-20 | Claude | Full audit against current staging: added IsActive enforcement + unique (org, slug) index note (ebaa1c5) to the payment/POS profile sections; confirmed the DELETE integration-config endpoint and TLS-verification fix (b19a7a3) are correctly documented |
| 2026-09-18 | Claude | Updated for the org-profile redesign (3072320) — payment/POS credentials moved from TicketGroupIntegrationConfig to shared payment_profiles/pos_profiles |
| 2026-08-07 | — | Documented Playlist Draft/Version/Publish/Rollback workflow, Playlist Canvas Templates, GET /me, multi-zone Time Blocks (zone_assignments), the background Playout Scheduler, and the Rail Menu ticket-group/advertisement merge |
| 2026-06-23 | Nucha | Initial catalogue domain documentation |
| 2026-06-17 | — | Added description, architecture, data model, creation flows |
| 2026-06-16 | Pin | Created the openapi |