Skip to main content

Overlays

Overview

The Overlays module provides a custom streaming overlay editor where users can create, configure, and manage overlays with layered widgets. Each overlay has a unique key used for popout access in OBS browser sources. Overlays support configurable dimensions, background settings, and multiple layer types (alerts, chat, music, custom HTML/CSS). Layers are ordered by sort_order and can be individually toggled visible/hidden.

Architecture

Backend

  • GraphQL (apps/api/src/graphql/overlays.rs) -- Full CRUD for overlays and layers. Queries for listing/fetching overlays and their layers. Mutations for create, update, delete overlays and bulk-replace layers.
  • Database (apps/api/src/db/overlays.rs) -- PostgreSQL operations for overlays and overlay_layers tables. Includes generate_overlay_key() which creates a 12-character URL-safe random key.
  • Popout Access -- Overlays are accessed via /overlay/[key]?token=xxx using popout tokens for non-expiring OBS browser source access.

Frontend

  • Overlay editor UI in the Next.js web app.
  • Popout overlay renderer loads via the unique overlay key.
  • Layer configuration per layer type (alert config, chat style, music widget config, custom HTML/CSS/JS).

API

GraphQL Queries

QueryPermissionDescription
overlaysoverlays:readList all overlays for the account
overlay(id: UUID)overlays:readGet a single overlay by ID
overlayLayers(overlayId: UUID)overlays:readGet all layers for an overlay, ordered by sort_order

GraphQL Mutations

MutationPermissionDescription
createOverlay(input: CreateOverlayInput)overlays:createCreate a new overlay (defaults: 1920x1080, "transparent" background, "Main Overlay" name)
updateOverlay(input: UpdateOverlayInput)overlays:editUpdate overlay name, dimensions, or background
updateOverlayLayers(overlayId: UUID, layers: JSON)overlays:editBulk-replace all layers for an overlay. Each layer has: type, name, config (JSONB), visible, sort_order. Optionally include id to preserve identity.
deleteOverlay(id: UUID)overlays:deleteDelete an overlay and all its layers

REST Endpoints

All paths live under /v1/overlays. Bodies are snake_case and mirror the GraphQL inputs.

MethodPathPermissionDescription
GET/v1/overlaysoverlays:readList overlays for the account
POST/v1/overlaysoverlays:createCreate an overlay
GET/v1/overlays/{id}overlays:readGet an overlay with its layers
PATCH/v1/overlays/{id}overlays:editUpdate name, dimensions, background, or layers
DELETE/v1/overlays/{id}overlays:deleteDelete an overlay and its layers

Input Types

CreateOverlayInput:

FieldTypeDefaultDescription
nameString?"Main Overlay"Overlay name
widthi32?1920Canvas width in pixels
heighti32?1080Canvas height in pixels
backgroundString?"transparent"Background color/value

UpdateOverlayInput:

FieldTypeDescription
idUUIDOverlay ID (required)
nameString?New name
widthi32?New width
heighti32?New height
backgroundString?New background

Permissions

PermissionDescription
overlays:readView overlay configuration and layers
overlays:createCreate new overlays
overlays:editEdit overlay settings and layers
overlays:deleteDelete overlays

Database

TableDatabaseDescription
overlaysPostgreSQLid, account_id, name, key (unique 12-char URL-safe string), width, height, background, created_at, updated_at
overlay_layersPostgreSQLid, overlay_id (FK), type (layer type string), name, config (JSONB), visible (bool), sort_order (int), created_at, updated_at

Overlay Key Generation

The generate_overlay_key() function creates a 12-character random string using characters A-Z, a-z, 0-9, -, _. This key is used in the popout URL: /overlay/[key]?token=xxx.

Data Flow

  1. User creates an overlay via the editor. A unique key is generated.
  2. User adds layers (alert, chat, music, custom) and configures each one.
  3. Layers are saved via updateOverlayLayers mutation (bulk replace).
  4. The overlay is accessed in OBS via its popout URL with a popout token.
  5. The popout page loads the overlay and all its layers, connecting to WebSocket for real-time updates.

Key Files

PathDescription
apps/api/src/graphql/overlays.rsGraphQL queries and mutations
apps/api/src/db/overlays.rsDatabase operations and key generation