DeveloperLayout System Architecture

Layout System Architecture

SBAI-84 Phase 3 — Unified Layout System: Component Blocks, Configurable Tabs & Layout-Driven View Pages

The Layout Designer is a full page composer that drives entity edit and view pages from JSON layout definitions. Layouts are stored at _Templates/Layouts/{entity_type}.json and define field sections, component blocks, tabs, and view configuration.

Overview

Layouts determine how entity edit and view pages are rendered. Instead of hardcoded page layouts, each entity type has a JSON layout definition that controls:

  • Field sections — Groups of form fields with ordering, visibility, and collapse defaults
  • Component block sections — Reusable UI widgets (asset browser, timeline, chat, etc.)
  • Tab configuration — Which tabs appear on entity edit pages and in what order
  • View configuration — Whether the entity view page is layout-driven (view_config.layout_driven === true) or falls back to the type’s bespoke page / default view

Layout File Location

Layouts are stored as JSON files:

_Templates/Layouts/{entity_type}.json

For example: _Templates/Layouts/Character.json, _Templates/Layouts/Location.json

Key Schema Types

EntityLayout

// Abridged. Canonical schema and manipulation logic live in the core SDK
// (`@biloxistudios/studiobrain-sdk`, `src/layouts/`).
interface EntityLayout {
  entity_type: string;
  version: string;
  sections: LayoutSection[];
  tabs?: LayoutTab[];
  view_config?: LayoutViewConfig;
  editor_component?: string;   // custom editor block id (component-block-registry)
  viewer_component?: string;   // custom view block id
  markdown_skeleton?: string;  // initial markdown_body for new entities
}

LayoutSection

interface LayoutSection {
  id: string;
  title: string | null;
  columns?: number;
  collapsed_default?: boolean;
  fields?: LayoutField[];   // { key, label?, ui_component?, column_span?, ... }
  component?: string;
  component_config?: Record<string, unknown>;
  component_source?: 'builtin' | string;
}

LayoutTab

interface LayoutTab {
  id: string;
  label?: string;
  icon?: string;
  source?: 'builtin' | 'plugin' | 'template';
  plugin_id?: string;
  content?: LayoutTabContent; // section_group | component_block | plugin_panel
}

Component Block Registry

10 built-in blocks registered in frontend/src/lib/component-block-registry.ts in the core repo (plus plugin:{pluginId}:{panelId} blocks contributed by plugins):

Block IDCategoryDescription
entity-assetsmediaAsset browser with upload, primary image selection
entity-timelinedisplayTimeline event panel with auto-populate
production-statusworkflowProduction pipeline status editor
markdown-contentdisplayRendered markdown body content
primary-imagemediaHero/primary image with placeholder fallback
entity-chatinteractionAI chat panel for conversational editing
entity-relationshipsdisplayAuto-discovers and renders relationship fields
entity-workflow-triggerworkflowWorkflow trigger buttons
ai-generation-hubworkflowUnified AI media generation panel (image, audio, video)
static-contentdisplayStatic text, markdown notes, headers, or separators

File Map

Frontend paths are relative to frontend/ in the core repo (studiobrain-core); the cloud and desktop apps consume them via @biloxistudios/studiobrain-core-frontend.

AreaPathPurpose
Typessrc/types/layout.tsLayout TypeScript interfaces (mirror the SDK types)
Registrysrc/lib/component-block-registry.tsBuilt-in block definitions
Tab Hooksrc/hooks/useLayoutTabs.tsResolves tabs from layout with fallback to the 6 default tabs
Layout Hooksrc/hooks/useEntityLayout.tsLoads the layout for an entity type via GET /api/layouts/{type}
Auto layoutsrc/lib/auto-layout.tsGenerates a default layout from the template schema
Renderersrc/components/ComponentBlockRenderer.tsxGeneric block renderer
Viewsrc/components/LayoutDrivenEntityView.tsxLayout-driven entity view page
Designersrc/components/LayoutDesigner/Layout designer UI components
Backend (self-host)crates/sb-server/src/services/layout_service.rs (core)Layout validation and CRUD

Widget Resolution

When the system determines which widget to use for a field, it follows this precedence chain:

  1. Custom layout (saved via Layout Designer) — highest priority
  2. field_config (template frontmatter) — template author’s declaration
  3. Pattern inference — field names ending in _color → color-picker, etc.
  4. Type inference — schema type → default widget (string → text, boolean → checkbox)

Field Widget Registry

All available widgets are registered in src/lib/field-widget-registry.ts, a thin wrapper over the SDK widget registry (packages/sdk/src/templates/widget-registry.ts). The registry provides:

  • getAllWidgets() — all builtins + plugin widgets
  • getWidgetsByCategory() — grouped by category for the Layout Designer dropdown
  • getWidgetById() — lookup by widget ID

The Layout Designer’s field configuration panel reads from this registry to populate the widget type dropdown, organized by category: text, number, selection, date, color, entity, array, media, document, and plugin.

field_config Integration

When auto-layout.ts generates a default layout, it reads schema.field_config and merges widget configuration into each field’s layout definition. This means template authors can control widget rendering without using the Layout Designer at all.

The merge order:

  1. Layout field config (user-set in Layout Designer)
  2. field_config from template (template author defaults)
  3. Schema-inferred values (automatic fallback)