Architecture
Laravel Page Builder follows a five-layer architecture. Dependencies flow downward only. Never import from a higher layer.
The Five Layers
1. Schema
Immutable value objects that define the structure of sections, blocks, and settings.
SectionSchema— Defines a section type with its settings and allowed blocksBlockSchema— Defines a block type with its settingsSettingSchema— Defines a single setting with type, label, and default value
php
use PageBuilder\Schema\SectionSchema;
$schema = new SectionSchema([
'name' => 'Hero',
'settings' => [
[
'id' => 'title',
'type' => 'text',
'label' => 'Title',
'default' => 'Welcome'
],
],
]);2. Registry
Discovers and stores schemas from Blade @schema() directives.
SectionRegistry— Discovers section Blade files and extracts schemasBlockRegistry— Discovers block Blade files and extracts schemasSchemaExtractor— Parses@schemadirectives from Blade files
php
use PageBuilder\Facades\Section;
use PageBuilder\Facades\Block;
// Register additional paths
Section::add(resource_path('views/custom-sections'));
Block::add(resource_path('views/custom-blocks'));3. Components
Runtime Section/Block instances hydrated from page JSON.
Section— Runtime section object with settings, blocks, and editor attributesBlock— Runtime block object with settings, blocks, and editor attributesSettings— Settings value object with magic property access
blade
{{-- In a section Blade file --}}
<section {!! $section->editorAttributes() !!}>
<h1>{{ $section->settings->title }}</h1>
@blocks($section)
</section>4. Rendering
Blade rendering engine that transforms JSON into HTML.
Renderer— Core rendering engine: hydrates JSON into objects, renders via BladeEditorAttributes— Generatesdata-editor-*attributes for sections/blocksBladeDirectives— Registers@blocks,@sections,@schema,@editor
php
use PageBuilder\Facades\Page;
// Render a page
$html = Page::render('home');
// Render with extra meta
$html = Page::render('home', ['title' => 'My Home Page']);5. Services
High-level services for page management and theme configuration.
PageRenderer— Loads page JSON, renders all enabled sections in orderPageStorage— Reads/writes page JSON files to disk, handles layout splittingPageRegistry— Cached page manifest for fast lookupsSettingsStore— Core JSON persistence service forsettings.jsonThemeSettings— Global theme settings persistence and type-safe accessLayoutSettings— Shared layout configuration persistence and DTO access
php
use PageBuilder\Facades\Page;
use PageBuilder\Facades\Theme;
// Get page data
$page = Page::find('home');
// Get theme settings
$settings = Theme::settings();Data Flow
Page Rendering Flow
- Resolution —
Page::render($slug)resolves page data viaPageService, fetching stored JSON fromPageStorageor template definitions fromTemplateStorage. - Hydration —
Rendererhydrates the page JSON into runtimeSectionandBlockinstances, populating default setting values from registered schemas. - Execution —
PageRendereriterates through active sections in order, executing section Blade templates and expanding nested@blocksdirectives. - Output — Section HTML is compiled into the active master layout for delivery.
Editor Flow
- Shell Load — Editor interface (React SPA) initializes and loads page metadata.
- Data Fetch — Frontend fetches registered schemas and current page JSON via API.
- Live Preview — Visual edits update component state and render live within an iframe preview shell.
- Persistence — Saving updates passes JSON to
PageStoragefor file/database persistence.
Key Classes
| Class | Layer | Responsibility |
|---|---|---|
SectionSchema | Schema | Immutable section type definition |
BlockSchema | Schema | Immutable block type definition |
SettingSchema | Schema | Immutable setting definition |
SectionRegistry | Registry | Discovers and stores section schemas |
BlockRegistry | Registry | Discovers and stores block schemas |
Section | Components | Runtime section instance |
Block | Components | Runtime block instance |
Settings | Components | Settings value object |
Renderer | Rendering | Core rendering engine |
PageRenderer | Services | Full page rendering |
PageStorage | Services | JSON file read/write + layout split |
ThemeSettings | Services | Theme settings persistence |
LayoutSettings | Services | Shared layout config persistence |
Facades
php
use PageBuilder\Facades\Section;
use PageBuilder\Facades\Block;
use PageBuilder\Facades\Page;
use PageBuilder\Facades\Theme;Facades provide a static interface to the underlying services.