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}.jsonFor 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 ID | Category | Description |
|---|---|---|
entity-assets | media | Asset browser with upload, primary image selection |
entity-timeline | display | Timeline event panel with auto-populate |
production-status | workflow | Production pipeline status editor |
markdown-content | display | Rendered markdown body content |
primary-image | media | Hero/primary image with placeholder fallback |
entity-chat | interaction | AI chat panel for conversational editing |
entity-relationships | display | Auto-discovers and renders relationship fields |
entity-workflow-trigger | workflow | Workflow trigger buttons |
ai-generation-hub | workflow | Unified AI media generation panel (image, audio, video) |
static-content | display | Static 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.
| Area | Path | Purpose |
|---|---|---|
| Types | src/types/layout.ts | Layout TypeScript interfaces (mirror the SDK types) |
| Registry | src/lib/component-block-registry.ts | Built-in block definitions |
| Tab Hook | src/hooks/useLayoutTabs.ts | Resolves tabs from layout with fallback to the 6 default tabs |
| Layout Hook | src/hooks/useEntityLayout.ts | Loads the layout for an entity type via GET /api/layouts/{type} |
| Auto layout | src/lib/auto-layout.ts | Generates a default layout from the template schema |
| Renderer | src/components/ComponentBlockRenderer.tsx | Generic block renderer |
| View | src/components/LayoutDrivenEntityView.tsx | Layout-driven entity view page |
| Designer | src/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:
- Custom layout (saved via Layout Designer) — highest priority
field_config(template frontmatter) — template author’s declaration- Pattern inference — field names ending in
_color→color-picker, etc. - 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 widgetsgetWidgetsByCategory()— grouped by category for the Layout Designer dropdowngetWidgetById()— 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:
- Layout field config (user-set in Layout Designer)
field_configfrom template (template author defaults)- Schema-inferred values (automatic fallback)
Related
- Component Blocks Reference — Complete catalog of built-in UI blocks
- Plugin Iframe Protocol — Plugin block integration details