Builder content documents
Builder content documents are the saved authoring model for a site built with Frappe Builder. A Builder Page owns the page tree and its publishing state. Other documents supply reusable components, starter blocks, scripts, design values, fonts, folders, site defaults, recoverable versions, AI configuration and authoring history, and editor plugins around that page. This page is part of the builder server domain; see server API and events for the interfaces that act on these records.
Content document model
The content model separates page-specific work from reusable site resources. A page stores its block tree and links to the resources that give the tree behavior and visual meaning.
The main relationships are:
| Document | Role | Relationship |
|---|---|---|
Builder Page | Page content and delivery settings | Links to a project folder and page client-script rows. Its block data can refer to components, tokens, and fonts. It also separates draft, live, and staging delivery states. |
Builder Component | Reusable block tree with optional data behavior | A component can belong to a page and page blocks can extend it. |
Block Template | Starter block for the editor | Supplies a block tree for insertion. It is not a live page dependency. |
Builder Project Folder | Page grouping | A page may link to one folder. Standard folders are protected outside developer mode. |
Builder Settings | Site-wide defaults | A single document controls global scripts, styles, favicon, home page, language, and editor safeguards. |
Builder Client Script | Reusable page script or style asset | A page uses it through Builder Page Client Script child rows. |
Builder Token | Named design value | Blocks use the token name as a CSS variable. Color tokens can have a dark value. |
User Font | Uploaded font resource | A block can name the font family. The page resolves that name to the uploaded font file. |
Builder Snapshot | Saved JSON state | Stores selected fields for a page or component. It is also the record used for component versions. |
Builder AI Session | Authoring conversation and page associations | Links a conversation to a primary page and user. Builder AI Session Page child rows record other pages used by or changed through the conversation. |
Builder AI Message | Durable conversation turn | Stores one user or assistant turn with its type, task context, status, and structured metadata. |
Builder AI Provider | AI connection and model namespace | Defines an enabled provider and its connection source. Models link to it through the provider name and route prefix. |
Builder AI Model | AI model choice | Identifies a model under a provider and records whether it is enabled and which inputs it supports. Sessions keep the selected model identifier for their authoring work. |
Builder Plugin | Installed editor extension | Records the installed plugin package, source, release identity, enabled state, and install state. The plugin runs in the editor with the current editor user's access. |
Builder Plugin State | Per-user plugin state | Stores JSON state for one user and one plugin installation. It is separate from the shared plugin installation record. |
The browser-facing types in frontend/…/doctypes.ts mirror these document contracts. They help the editor treat child rows and linked documents as one content model rather than as unrelated records. AI session messages, page associations, and plugin state follow the same persisted-record model, while the page and its blocks remain the source of site content. References: frontend/…/doctypes.ts• L17-194, builder/…/builder_ai_session.json• L19-79, builder/…/builder_ai_session_page.json• L7-25, builder/…/builder_ai_message.json• L20-71, builder/…/builder_ai_provider.json• L22-84, builder/…/builder_ai_model.json• L23-95, builder/…/builder_plugin.json• L22-125, builder/…/builder_plugin_state.json• L12-40
Page content
Builder Page is the content boundary for one route. It names the page, maps it to a route, stores page metadata and access rules, and holds the block tree that becomes the page body. A page can be live, staged at its route, or kept offline (builder/…/builder_page.json• L49-263).
The page has two content states:
draft_blocksholds the working tree that can be reviewed in preview.blocksholds the live or staged tree used at the served route after promotion.
The page accepts block data from editor actions and external write paths in structured form. On insert and update, the page normalizes list data into compact JSON and ensures that the live block field has an empty-tree value when no content exists. This keeps the saved document contract stable for paste, AI, and API writes (builder/…/builder_page.py• L175-187). The update path is covered by the page test that saves a list-shaped block tree after insert (builder/…/test_builder_page.py• L169-184).
Page block data can also bind content to page data, component data, or passed properties. When several bindings target the same block value, the current dynamic value takes priority, the older dataKey value is the next fallback, and the saved block value is the final fallback. Image blocks preserve usable absolute and inline URL forms while encoding only characters that a URL cannot carry directly (builder/…/builder_page.py• L1002-1051, builder/…/builder_page.py• L1054-1064).
The page also stores a page data script for request data and optional head and body HTML. Dynamic routes can pass route values into that page data. The page-specific language and metadata can override site defaults. Authenticated access and indexing controls affect how the route is exposed.
When a page is published, its draft content becomes live content. A publish snapshot records the content before that change. A page can also promote its draft to a staging route, which is served but excluded from search indexing and the sitemap. A live page moves to staging through a separate action that keeps its live content at the route and leaves unpublished edits in the draft. When live and staging pages share a route, live content has precedence. A page cannot use the direct staging-publish action while it is live (builder/…/builder_page.py• L404-455). References: builder/…/builder_page.json• L67-263, builder/…/builder_page.py• L175-203, builder/…/builder_page.py• L404-455, builder/…/builder_page.py• L1818-1857, builder/…/test_builder_page.py• L169-219, builder/…/test_builder_page.py• L355-386, builder/…/test_builder_page.py• L472-494
Reusable visual content
Components
Builder Component is a reusable block tree with a stable component ID and an optional data script. A page block that extends a component keeps the page-level changes around that shared structure, so one component can support many page instances while each instance can receive props and component data (builder/…/builder_component.json• L17-51).
Component use is a relationship inside page block JSON rather than a child table. The component record can point back to its owning page through for_web_page, while usage across pages is found by inspecting live and draft block trees. A normal component save creates or reuses a version and queues cache clearing, but it does not itself rewrite every page instance. The explicit component sync operation finds pages that use the component, updates both draft and live instances, and repins them to the latest version. Bulk imports skip cache clearing and version capture because related components may not exist yet. A later real edit can create the version safely (builder/…/builder_component.py• L40-99).
Component versions are stored as Builder Snapshot records. A page instance can keep a componentVersion pin so later component edits do not silently change captured page content. An explicit sync can move instances to the latest version, while a missing version falls back to the current component. Each version captures the component block and data script needed for rendering. References: builder/…/builder_component.json• L24-51, builder/…/builder_component.py• L40-111, builder/…/test_builder_component.py• L48-69, builder/…/component_versions.py• L4-18, builder/…/component_versions.py• L90-200
Block templates
Block Template is a catalog of ready-to-insert block trees. It gives the editor a named block, a preview, a category, preview dimensions, and a sort position. In contrast with a component, a template is a starting point that becomes page content when inserted. The page does not need to keep a live link to the template (builder/…/block_template.json• L17-64).
The editor reads the template catalog in sort order and uses the preview fields to present the available choices. Template categories group common structure, text, forms, media, and advanced content without changing the page model. References: builder/…/block_template.json• L17-72, frontend/…/builderBlockTemplate.ts• L3-11
Site authoring resources
Project folders
Builder Project Folder gives pages a simple grouping label. Its main distinction is whether the folder is standard content shipped by an app or a user-managed folder. A page links to the folder through project_folder; the folder does not own page content (builder/…/builder_page.json• L224-229).
Standard folders are part of managed site content. Normal users cannot edit or delete them outside developer mode, which protects app-provided page organization during normal authoring. References: builder/…/builder_project_folder.json• L12-24, builder/…/builder_project_folder.py• L21-41
Builder settings
Builder Settings is the single site-wide document. It supplies defaults and shared behavior for every Builder page, including the home page, favicon, language, global JavaScript and CSS, head and body HTML, image conversion, color-mode behavior, and editor safety controls (builder/…/builder_settings.json• L27-139).
Page values take priority where the page has its own setting. For example, a page language or favicon can override the site value, while the site home page and global assets affect the whole site. Changes to site-wide scripts, styles, HTML, or color-mode behavior clear cached pages because every page uses those values. The document also tracks optional AI and onboarding state, but those values are site settings rather than page content. References: builder/…/builder_settings.json• L59-139, builder/…/builder_settings.py• L37-45, builder/…/builder_page.py• L520-588, frontend/…/builderSettings.ts• L4-8
Design tokens
Builder Token stores a named design value that blocks can reuse. Tokens support color, dimension, and font values. A color token may define a separate dark value, which lets the same page content adapt to a different color mode (builder/…/builder_token.json• L14-55).
The token name becomes the stable CSS variable name used by page styles. This makes a token a shared design contract: changing its value can change every page that refers to it. Standard tokens can be exported with app content, while site token data is cached for page delivery and its rendered token routes are cleared when a token changes. See site configuration and design tokens for the wider styling model. References: builder/…/builder_token.json• L14-64, builder/…/builder_token.py• L17-32, builder/…/builder_token.py• L84-126
User fonts
User Font connects a human-readable font name to an uploaded font file. Blocks refer to the font by family name, so the page can collect the fonts used by its block tree and load the matching files at render time (builder/…/user_font.json• L12-23).
Font records are separate from tokens because a font needs a file resource, while a font token is only a named design value. The page can therefore use an uploaded font directly or use a token that resolves to a font family. References: builder/…/user_font.py• L9-12, builder/…/user_font.py• L24-44, builder/…/builder_page.py• L482-495, builder/…/builder_page.py• L754-760
Script documents
Builder Client Script is a reusable JavaScript or CSS asset. Its required script type tells the system how to publish and load the asset. A generated public URL is kept with the document so pages can load the saved asset rather than embed the source in every page (builder/…/builder_client_script.json• L13-32). Saving the asset refreshes its served file and clears the cache of pages that link to it, so an edit reaches those pages without changing each page record (builder/…/builder_client_script.py• L40-50, builder/…/builder_client_script.py• L85-104).
Builder Page Client Script is a child row, not a standalone authoring resource. It stores one link from a page to a Builder Client Script. The page can list several rows, and each linked asset is loaded with the page according to its type. A component can also have block-level client behavior in its saved block tree; that behavior is distinct from the page-level script links. References: builder/…/builder_page_client_script.json• L11-27, builder/…/builder_client_script.json• L35-44, builder/…/builder_page.py• L656-669
Snapshots and saved versions
Builder Snapshot is a generic saved-state record. It identifies the source document with reference_doctype and reference_name, labels the kind of saved state with snapshot_type, and stores selected field values as JSON (builder/…/builder_snapshot.json• L15-51). A snapshot captures only the fields named by its caller and avoids storing a new copy when the latest snapshot of that type has the same data. This lets different consumers keep their own version policy without making the snapshot record specific to pages or components (builder/…/builder_snapshot.py• L28-75).
The snapshot model serves two related needs:
- Page publish and manual snapshots preserve page content for review or restore.
- Component version snapshots preserve the component fields needed by a pinned page instance.
Restoring page content is non-destructive: the saved tree is put into the draft state for review, and publishing remains a separate action. AI snapshots can also restore page script links and the saved source of linked client scripts. Publish snapshots are pruned by policy, while manual checkpoints and other snapshot types are kept separate. References: builder/…/builder_snapshot.py• L78-144, builder/…/builder_page.py• L446-524
Authoring and delivery flow
The authoring flow turns saved page data into a reviewable draft and then into live or staged route content. Shared resources join the flow at the point where the page uses them.
The diagram shows the high-level path from editor data to a published or staged page.
flowchart LR
A[Editor] --> B[Builder Page draft_blocks]
B --> C{Referenced resources}
C --> D[Builder Component]
C --> E[Builder Token]
C --> F[User Font]
B --> G[Builder Page Client Script]
G --> H[Builder Client Script]
B --> I[Preview]
B --> J[Publish]
B --> S[Publish to staging]
J --> K[Builder Snapshot]
J --> L[Builder Page blocks]
L --> M[Published route]
S --> N[Staging route]
N --> O[No index and no sitemap entry]
P[Builder Settings] --> I
P --> M
P --> N
The editor first changes the page draft. Preview combines that draft with component data, token values, fonts, page scripts, and site settings. AI authoring can add durable session messages and page associations while it prepares or applies page changes, but those records do not become the page tree by themselves. Publish records the content and moves it to the live page state. Staging serves promoted content at the route without making it a searchable public page. Moving a live page to staging keeps its served live content while its unpublished edits remain in the draft. When route names overlap, route selection keeps the live page ahead of the staging page. The live route then uses the page together with the same shared resources. See website rendering and publishing for the delivery path and content import, export, and setup for managed content movement. References: builder/…/builder_page.py• L404-466, builder/…/builder_page.py• L542-669, builder/…/builder_page.py• L1818-1857, builder/…/session.py• L180-234, builder/…/test_builder_page.py• L181-219
Related persisted records
Some Builder records sit beside the core authoring model rather than defining page content. Builder Page Click stores read-only click observations with a path, element, text, uniqueness flag, and visitor ID. It supports page analytics and should not be treated as a page block or a page dependency (builder/…/builder_page_click.json• L13-44).
AI authoring records
AI authoring uses provider and model records for shared connection and capability choices. A Builder AI Provider names an enabled model namespace and its connection source. A Builder AI Model belongs to that provider and records the model identifier, enabled state, context window, and image-input support. A session keeps the selected model identifier for its authoring work. References: builder/…/builder_ai_provider.json• L22-84, builder/…/builder_ai_model.json• L23-95, builder/…/builder_ai_session.json• L49-70
Builder AI Session and Builder AI Message preserve the conversation that supports page authoring. A session has a primary page and user, while Builder AI Session Page child rows link the same conversation to other pages that it used or changed. Each message stores a role, content, message type, task or block context, status, and JSON metadata. The AI layer reads these rows to rebuild chat history and selected context such as plans or attached images. The page and its blocks remain the source of saved site content. Deleting a session removes its messages, so this supporting history does not block cleanup of the session. Page cleanup must also account for the session's primary page and its related page associations. See builder access and analytics for access and usage records. References: builder/…/builder_ai_session.json• L19-79, builder/…/builder_ai_session.py• L27-38, builder/…/builder_ai_session_page.json• L7-25, builder/…/builder_ai_session_page.py• L7-20, builder/…/builder_ai_message.json• L20-71, builder/…/session.py• L180-234, builder/…/builder_page.py• L358-375, builder/…/test_builder_ai_message.py• L8-24
Plugin installations
Builder Plugin is the site record for an editor extension. It identifies the package and source, records the installed version and checksum, controls whether the editor runs it, and keeps install progress or failure state. The checksum also distinguishes release assets, so a new package release can use a new entry URL without replacing an older release that an open editor may still need (builder/…/builder_plugin.json• L22-125, builder/…/builder_plugin.py• L28-92).
Builder Plugin State stores the mutable JSON state of one plugin for one user. The installation record is shared by the site, while the state record keeps each editor user's plugin data separate. The pair of installation and user is unique, and deleting an installation removes its state and files. See plugin extensibility for the editor-facing extension model. References: builder/…/builder_plugin_state.json• L12-40, builder/…/builder_plugin_state.py• L24-35, builder/…/builder_plugin.py• L73-76, builder/…/builder_plugin.py• L162-170
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to
Builder Pageblock fields must preserve both the draft-to-live contract and snapshot restore behavior. - Changes to page write paths must preserve block-tree normalization so list input and empty content remain valid persisted JSON.
- Changes to dynamic binding fields must preserve the precedence from current dynamic values to legacy
dataKeyto saved block content. - Changes to image source handling must preserve absolute URL syntax, inline data payloads, and the light/dark source relationship.
- Changes to staging or route selection must keep live content, staged content, search indexing, and sitemap behavior distinct. Live pages must remain ahead of staging pages on shared routes.
- Changes to component references must keep component IDs, version pins, and usage scans aligned across live and draft block trees.
- Changes to component save behavior must preserve the distinction between real edits and bulk imports so version capture, cache clearing, and explicit page sync happen at the correct time.
- Changes to token names or values must preserve the CSS variable contract and the rendered token asset used by pages and previews.
- Changes to client-script links must keep the child-row link, script type, generated public URL, and page asset loading in agreement.
- Changes to page or component standard content must keep app export and cleanup behavior aligned with references from other standard pages.
- Changes to folder or settings defaults must account for the difference between managed standard data and site-local data.
- Changes to site-wide settings or token values must preserve cache invalidation for pages and rendered asset routes.
- Changes to AI providers or models must keep provider namespaces, model identifiers, enabled state, and input capabilities aligned with session model selection.
- Changes to AI session fields or page associations must preserve the primary-page relationship, the additional-page child rows, context reconstruction, and cleanup of owned messages.
- Changes to plugin installation records must keep release identity, entry URLs, enabled state, and install state aligned with the files on disk.
- Changes to plugin state must preserve the one-row-per-installation-and-user contract and must not accept the owner from a client request.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A page saves a block tree without keeping draft, live, and staging handling distinct. | Preview, route delivery, search visibility, or restore can use the wrong version of page content. | Keep draft writes, publish snapshots, live promotion, and staging promotion as separate content actions. |
| A page write path stores a raw list or an unset live block field. | The document can violate the saved JSON contract and later reads can fail or behave differently. | Normalize block lists before save and use an empty block tree for missing live content. |
A dynamic binding is applied twice or the legacy dataKey fallback is dropped. | Dynamic content can leak template text or skip a valid fallback. | Group bindings by target and keep current dynamic values ahead of dataKey and static content. |
| An image URL is encoded as an opaque string. | Absolute image URLs or inline data images can stop loading or lose their payload. | Preserve URL-safe syntax and encode only characters that need encoding. |
| A component reference lacks a usable version pin or its pinned snapshot is pruned. | A page instance can render current component content instead of the content it captured. | Capture the full component state on component use or edit, and treat missing pins as an explicit fallback. |
| A component save is expected to update every existing page instance without an explicit sync. | Existing draft and live instances can keep their old component structure or version. | Use the component sync operation as a separate propagation step and preserve its repinning behavior. |
| A bulk import triggers component sync or version creation before all related records exist. | Imported pages can receive partial component content or fail during import. | Defer cross-page sync and version work during bulk import. |
| A token name changes while blocks still use the old CSS variable. | Pages keep the old value or lose the intended style. | Treat token names as shared style keys and update dependent block data when renaming them. |
| A client script link points to a missing or wrong-type script record. | Page behavior or styles do not load as intended. | Keep the child link, script type, generated public URL, and page asset loading in agreement. |
| A standard folder, page, component, or token is edited outside its managed mode. | App-provided content can drift from its exported source. | Protect standard records outside developer mode and use the standard export path for managed changes. |
| A page or component is deleted without its snapshots or dependent exported assets being handled. | Old versions or files remain available without a valid source. | Delete page snapshots and clean unreferenced standard dependencies during the delete path. |
| AI message metadata is stored as invalid JSON or message status is separated from the returned message shape. | Plans, attachments, or turn state can disappear when chat history is read back. | Keep metadata JSON valid and preserve the database status field when messages are converted to chat data. |
| A page association is recorded only in the session's primary page or only in its child rows. | A conversation can disappear from a page's history or page cleanup can leave a stale association. | Keep the primary-page field and Builder AI Session Page rows synchronized with the pages used by the session. |
| An AI session is deleted without clearing the records it owns. | Link checks can block deletion or leave authoring history without its session. | Delete session-owned messages as part of the session delete path. |
| An AI turn uses image input with a model that does not support vision. | The whole turn can fail even when the provider connection is valid. | Keep model capability data accurate and select a model that supports the input used by the session. |
| A provider route prefix or model identifier changes without updating model selection. | A session can point to a model route that cannot be resolved. | Treat provider namespaces and model identifiers as one selection contract. |
| A plugin is marked ready while its release entry or checksum-named files are missing. | The editor cannot load the extension or can load a stale release. | Keep install state, checksum, and release assets consistent before enabling the plugin. |
| Two plugin state rows exist for one installation and user. | Reads can return an arbitrary state and user changes can be lost. | Enforce the unique installation-and-user relationship. |
Key files
| File | Why to read it |
|---|---|
| builder/…/builder_page.json | Defines the page fields and the page-to-folder and page-to-script relationships. |
| builder/…/builder_page.py | Shows the page lifecycle from block normalization and draft content through preview, publish, staging, restore, dynamic binding, image URL handling, and shared-resource loading. |
| builder/…/test_builder_page.py | Shows the page contracts for list-shaped block writes, dynamic binding fallbacks, image URLs, live and staging delivery, sitemap behavior, and component version behavior. |
| builder/…/builder_component.json | Defines reusable component content, identity, page ownership, and data behavior. |
| builder/…/builder_component.py | Explains component version capture, explicit page sync, import handling, cache clearing, and page reference discovery. |
| builder/…/test_builder_component.py | Shows that sync updates both page states and that repeated component saves remain available without document-lock errors. |
| builder/…/component_versions.py | Defines how component state is captured and pinned for page instances. |
| builder/…/block_template.json | Defines the starter block catalog used by the editor. |
| builder/…/builder_settings.json | Defines site-wide defaults and editor controls. |
| builder/…/builder_settings.py | Shows site-wide asset updates and cache invalidation. |
| builder/…/builder_token.py | Shows how saved design values become shared CSS variables and invalidate their rendered routes. |
| builder/…/builder_client_script.py | Shows how reusable scripts become public assets and invalidate referencing page caches. |
| builder/…/builder_page_client_script.json | Defines the page-to-script child link. |
| builder/…/builder_snapshot.py | Defines saved state, version lookup, restore, deduplication, and retention behavior. |
| builder/…/user_font.py | Shows how page font references resolve to uploaded font records. |
| builder/…/builder_ai_provider.json and builder/…/builder_ai_model.json | Define shared AI connection records and the model choices used by authoring sessions. |
| builder/…/builder_ai_session.json and builder/…/builder_ai_session.py | Define the primary page, related-page associations, authoring conversation, and message cleanup boundary. |
| builder/…/builder_ai_session_page.json and builder/…/builder_ai_session_page.py | Define the child relationship that records additional pages used by a session. |
| builder/…/builder_ai_message.json and builder/…/test_builder_ai_message.py | Define the durable message contract and protect JSON metadata that can contain markup. |
| builder/…/builder_plugin.json and builder/…/builder_plugin.py | Define installed editor extensions, release identity, load URLs, and cleanup boundaries. |
| builder/…/builder_plugin_state.json and builder/…/builder_plugin_state.py | Define per-user plugin state and its uniqueness contract. |
| builder/…/session.py | Shows how persisted AI messages become chat history and context for page authoring. |
| frontend/…/doctypes.ts | Gives the editor-facing view of the persisted document contracts and child rows. |