Skip to content
Widget Library

Architecture

The layers of the Widget Library and the systems around it.

This page shows the layers of the library, where each one lives, and how a setting made in the panel becomes a widget on a page.


Layer What it is Where it lives
Contract The runtime interface, the config schema, the event protocol and the conformance scenarios src/contract/, scenarios/, fixtures/
Renderers One implementation of each widget per platform src/recommendation/ for the web; the mobile SDKs for the others
Runtime The connection to events, the basket and the page @segmentify/integration on the web; the platform SDK on mobile

The contract is the only layer shared by every platform. It is language-neutral on purpose: Swift and Kotlin cannot run TypeScript, so what they share with the web is the schema and the scenarios, not code.


A widget never imports @segmentify/integration. It receives a WidgetRuntime and calls only that.

panel settings ──► server ──► event response
│
@segmentify/integration
│ builds the runtime
│ loads the widget (lazy chunk)
▼
renderRecommendation(config, runtime, document)
│
runtime.sendInteraction / addToBasket / ...

This has three effects:

  • Tests need no integration. A recording runtime stands in for it.
  • Mobile uses the same shape. The Swift and Kotlin SDKs implement the same interface.
  • The dependency points one way. Integration depends on the library, never the reverse. A lint rule enforces it.

System Role for widgets Status
dashboard (the panel) Offers settings for a widget instead of a code editor Planned
sauron (panel backend) Validates the settings before they are saved Planned
gandalf (engine) Sends the config in the event response as structured data Planned
@segmentify/integration Builds the runtime, loads the widget, places it on the page Planned
widget-library The contract, the scenarios and the web widgets In progress

Today these systems still carry HTML, CSS and JavaScript for each campaign. The config-based path is added next to that one, so an old campaign and a new one can run on the same page.


The catalog in the panel lists about 200 campaign ideas. They are not 200 different widgets. Each entry is a preset: one widget plus a set of settings. The library therefore needs a small number of widgets, and the catalog needs one config per entry.