Skip to main content

Template system

A template is what a white-label sportsbook looks like. The system is built around one split, enforced by tooling:

A template is an arrangement, not an implementation. It declares which blocks appear, in what order, what a tenant may edit, and what the theme looks like. Everything that actually renders — the odds table, the bet slip, the navigation — lives in one shared kit.

A block fixed in the kit is fixed everywhere at once; a block copied into a template would be fixed once and stay broken in every other template. So templates contain no rendering code beyond their layout arrangement.

The kit​

@sportsbook/template-kit owns every block, the theme tokens, the data port and the template contract. Two rules hold it together, and both are enforced by its ESLint config, not by convention:

  1. Plain React, no framework imports. The same template renders inside the widget's Shadow DOM on a casino's page and server-side in the Next.js white-label site. A next/* import would break the first; browser globals would break the second.
  2. No data client in blocks. Blocks receive live data through an injected data port (SportsbookDataPort). A block that queried the GraphQL client directly would render empty on the server — injection is what makes one template work in both hosts.

Anatomy of a template​

templates/
<template-id>/
template.config.ts the declaration: id, name, version + the four below
fields.ts the editable fields the layout reads its props from
default-content.ts what it renders before anyone edits anything
tokens.ts what it overrides in the theme
zones.ts the named slots it opens
layout.tsx the arrangement itself (the only React file)
configs.ts hand-maintained: every config, nothing that renders
registry.generated.ts generated and committed: configs + lazy layout imports

Key properties of the contract:

  • Configs are pure data. Everything in template.config.ts survives JSON.stringify — the back-office reads it to list the templates the platform ships, and both rendering hosts read it to render one. Validation runs at module load, so an invalid declaration fails the build, not a tenant's page.
  • fields.ts is the single source. The content type and the content resolver are both derived from one descriptor — a renamed field is a compile error, not a silently empty page.
  • Colors are theme tokens, not fields. One place to change a color, one precedence rule.
  • version is a schema version. Content carries the version it was written under, so a rendering host stays pinned to the schema its content matches. Adding an optional field is not a bump; renaming or removing one is.
  • Default content must render as-is. A template ships finished: what default-content.ts declares is what a white label serves, so it is validated at module load like the rest of the config.

Creating a template​

pnpm create-template casino-x --title "Casino X"

The scaffolder writes the six files and regenerates the registry. One step is deliberately manual — registering the config in templates/configs.ts — and the command prints it. That file is hand-maintained because it imports each config directly, which keeps React out of the back-office's import graph: the admin is a Node process that needs every schema and must never load a layout.

Then:

pnpm run build --filter=@sportsbook/templates # regenerates the registry, lints, compiles
pnpm run test --filter=@sportsbook/template-kit # the render suite mounts every template on a fake data port

A template has no test suite of its own on purpose: its build runs the registry generator, the documentation lint gate and the compiler, and the kit's render suite exercises it against injected data. The full contract for authors ships with the source (.claude/rules/templates.md) — written to be followed by a human or handed verbatim to a coding agent.

How it reaches players​

  1. The back-office points a white label at a template — that choice is the whole of what it stores.
  2. The widget renders the template client-side inside its Shadow DOM, with live odds flowing through the data port.
  3. The site renders the same template server-side on the operator's own domain, from the same declaration.

One declaration, two hosts, zero duplicated rendering code.