Introducing a new way to review your PRs.

Read the announcement

frappe / builder

Craft beautiful websites effortlessly with an intuitive visual builder and publish them instantly

View on GitHub

20 documents · Updated Nov 23, 2026

docs / server-api-and-events

Server API and events

The server API and event layer is the contract between the Builder editor, the Frappe site, and external services. It lets the editor read and change Builder documents, render previews and pages, manage assets, import templates, run AI-assisted page work, query analytics, and react to document or scheduled events.

API boundary

Builder uses two related API paths. Standard Frappe document resources handle normal reads and writes for Builder DocTypes. Whitelisted methods add actions that need server-side rules, rendering, file work, external service calls, AI jobs, or coordination across documents. The frontend calls both through frappe-ui resources, so the server remains the source of truth for saved page state.

The main API groups are:

API groupPurposeMain consumers
Builder Page document methodsSave drafts, publish or unpublish pages, create or restore snapshots, load page data, and check component versionsPage editor and version history
Builder Component actionsSave component content, load component data, replace or sync component use across pagesComponent editor and page canvas
Asset and font methodsUpload, import, and optimize site-owned images and fontsAsset controls and paste/import flows
Template methodsRead the remote template catalog and create editable pages from single-page or grouped template bundlesTemplate gallery
AI methodsStart assisted page work, manage chat sessions, confirm sensitive actions, and configure model providersAI chat and provider settings
Analytics methodsReturn page views, top pages, referrers, and click-through dataPage and site analytics
Site and access methodsRead site state, users, invitations, apps, and page foldersDashboard and settings
Editor support methodsSupply script autocomplete data, duplicate pages, copy or reorder scripts, evaluate component data, and report onboarding dataCode editor, page tools, component editor, and onboarding

The frontend uses list resources for collections such as pages, components, tokens, fonts, folders, and redirects. It uses document resources when it needs a full editable record. This split keeps list views small while allowing the editor to load the complete page or component only when needed. See frontend/…/webPage.ts and frontend/…/pageStore.ts.

References: builder/api.py• L33-65 builder/api.py• L333-493 builder/api.py• L524-701 builder/api.py• L718-902 builder/…/api.py• L52-141 builder/…/api.py• L349-707 frontend/…/webPage.ts• L1-48 frontend/…/pageStore.ts• L118-141

Page lifecycle API

The page lifecycle separates working content from live content. The editor saves its block tree as a draft, while publishing moves that draft into the live page and records a publish snapshot before the change takes effect. Preview requests render the draft without making it public.

When the editor processes a page, the API follows this relationship:

flowchart LR
    E[Builder editor] -->|save draft| P[Builder Page]
    P -->|preview request| R[Server renderer]
    R --> H[Preview HTML]
    P -->|publish| S[Builder Snapshot]
    P --> L[Published page]
    P -->|unpublish| U[Unavailable public route]

The page document also owns page data and client-script links. A page-data request evaluates the page's data source for the current route variables. A publish request preserves the content needed for rollback, then queues preview-image generation after the database change. Snapshot restore writes back to the draft, which lets an engineer review the result before publishing it.

The server renderer is also the website route handler. It checks page access, selects draft blocks for preview, and selects live blocks for normal requests. The page route can be static or dynamic. Dynamic routes disable normal page caching because their output depends on request data. See builder/…/builder_page.py and frontend/…/PagePreview.vue.

References: builder/api.py• L38-65 builder/…/builder_page.py• L64-104 builder/…/builder_page.py• L146-250 builder/…/builder_page.py• L346-431 frontend/…/pageStore.ts• L189-271 frontend/…/PagePreview.vue• L222-231

Component coordination

Components let several pages share a block design while keeping page instances in the page data. The server exposes the component record and its data result separately. A page render resolves the component used by a block, passes its properties to the component data script, and then renders the resulting block tree.

Saving a component does not silently rewrite every page. The editor offers an explicit sync action. That action finds pages that refer to the component, updates both their draft and live trees, and clears the affected route caches. This preserves local page state until the user chooses to apply the shared change.

Component versions protect a page instance from unexpected changes. The editor asks the server for a current version when it pins a component. Later it can ask which pins are out of date and re-pin a selected instance. A missing stored version falls back to the live component, so a page can still render when old history has been removed.

References: builder/api.py• L715-720 builder/api.py• L774-885 builder/…/builder_component.py• L40-111 builder/…/builder_component.py• L126-194 builder/…/builder_component.py• L211-257 builder/…/builder_page.py• L433-447 frontend/…/componentStore.ts• L94-141 frontend/…/componentStore.ts• L222-309

Asset and script services

Builder turns external or uploaded resources into site-owned assets so published pages do not depend on a source site that may change or reject cross-site requests. Asset upload is limited to users who can write page content. Remote asset and font imports use the same write boundary and return a map that lets the editor replace source URLs in the current block tree.

The server can keep formats that should not pass through image conversion, while other imported images can become smaller WebP files. Imported fonts become site-owned user fonts. This gives the editor stable resources that can appear in the font picker and in published pages.

The server also creates public files for page scripts, page styles, and global Builder settings. A script or style change updates its public file and its cache-busting URL. Page rendering then adds global settings resources and page-linked resources to the response. This connects a saved document change to the files that website visitors load.

External fetches accept only HTTP or HTTPS URLs and reject URLs that resolve to private or internal network addresses. Image imports cap the number and size of requests, while font imports cap the number and size of font files. These limits protect an editor action from becoming an open request path into the site network.

References: builder/api.py• L62-339 builder/api.py• L409-452 builder/…/builder_client_script.py• L33-111 builder/…/builder_settings.py• L37-75 builder/…/builder_page.py• L556-588 frontend/…/helpers.ts• L348-369 frontend/…/importRemoteAssets.ts• L22-58

Template import API

The template API connects a Builder site to a central Builder Hub. It lets an authorized user view a cached catalog, fetch page bundles, and turn those bundles into editable local resources. The server performs the Hub request, so the browser does not need a cross-origin request path.

An imported bundle can contain shared components, variables, fonts, client scripts, and page blocks. A single-page import creates one local page. A template-group import creates a project folder and gives its pages a shared route prefix so links between those pages remain valid.

The Hub address comes from site configuration and falls back to the default Builder Hub. Catalog and bundle failures are logged and reported as an empty catalog or a clear import error. This prevents a temporary Hub problem from corrupting local page data.

References: builder/api.py• L493-609 builder/api.py• L612-701

AI API

The AI API gives the editor one server entry point for assisted page work. It accepts a user turn with page context, stores the chat session, validates the selected model, and queues the work so a long model response does not hold the web request open. The response confirms acceptance while progress returns through the realtime channel.

AI sessions keep messages and page links so a conversation can continue across pages. The API also supports session loading, session lists, steering notes, cancellation, replay of active output, and restoration of the conversation before a selected turn. These actions keep the chat state and the editor state aligned after reloads or interrupted work.

Some AI actions need a clear user decision before they change site settings or pages. The API stores the proposed action, checks ownership and permissions when the user confirms it, applies or skips it, and can resume the conversation afterward. Provider and model methods let an authorized user connect a provider, test or store its key, discover models, check credits, and enable models without exposing stored keys to the editor.

This flow connects the page API to external model gateways without making the model the authority for saved content. The server remains responsible for permission checks and accepted page changes.

References: builder/…/api.py• L52-141 builder/…/api.py• L144-337 builder/…/api.py• L349-551 builder/…/api.py• L577-707

Frappe hooks

Frappe hooks connect Builder behavior to the site runtime. They make a Builder Page a website-generated record, route Builder paths into the editor and page renderer, schedule analytics work, and expose the Builder app entry point only to users with Builder access.

The hooks define these runtime links:

HookSystem effect
Website generatorPublished Builder Pages participate in Frappe website page generation
Route and renderer hooksBuilder routes resolve to the Builder page renderer and support dynamic routes
Jinja methods and filtersPage templates can use Builder data and safe output helpers
User invitation hooksBuilder invitations create telemetry events when sent and accepted
Document event hookA new Builder user invitation is observed after insert
Scheduled tasksWeb-page views and Builder click events move into the analytics store on a schedule
Install and migration hooksTemplates, tokens, block templates, and standard pages are brought into sync
Desk app and API discovery hooksThe Builder entry point uses the site-specific editor route and API clients can discover method source

These hooks are the runtime bridge for the broader Builder domain. Page storage and rendering are described in Builder server domain. The public page result and its route behavior are described in Website rendering and publishing.

References: builder/hooks.py• L45-75 builder/hooks.py• L98-134 builder/hooks.py• L196-220 builder/user_invitation.py• L6-13 builder/install.py• L12-30

Event and job flows

Builder uses events for work that should happen after a document change or outside the request that initiated it. The main event paths connect document changes to cache clearing, preview images, analytics storage, telemetry, AI progress, and live editor refreshes.

When a page or related resource changes, the system coordinates the work in this order:

sequenceDiagram
    participant UI as Builder editor
    participant F as Frappe API
    participant D as Builder document
    participant Q as Queue or scheduler
    participant W as Website or analytics store

    UI->>F: Save, publish, or change a resource
    F->>D: Validate and store the document
    D->>Q: Queue preview, cache, analytics, or AI work
    Q->>W: Update public output, analytics data, or editor state
    F-->>UI: Return saved state or accepted job

Component updates queue cache clearing for published pages that use the component. Publishing queues preview-image creation after commit. The ten-minute scheduler copies web-page views and Builder click rows into a site-local analytics store. Analytics reads use that store so dashboard queries do not compete with the main document tables during normal use.

AI turns use the same split between the request and the worker. The API returns an accepted response after it queues the turn, while the worker sends progress over Redis-backed realtime events. An editor that reloads during a build can ask for the active stream state and continue to show the live result.

The editor also uses Frappe's socket channel for document subscriptions and named event messages. This channel is the coordination path for open documents and live updates. It is separate from the HTTP API: HTTP changes data, while the socket path tells interested editor views about activity or keeps their subscriptions current. See frontend/…/realtimeHandler.ts.

References: builder/…/builder_page.py• L207-250 builder/…/builder_page.py• L346-371 builder/…/builder_component.py• L40-76 builder/…/api.py• L119-141 builder/…/api.py• L699-707 builder/hooks.py• L118-134 builder/builder_analytics.py• L181-195 builder/builder_analytics.py• L383-395 frontend/…/realtimeHandler.ts• L14-77

Analytics API

The analytics API turns two event streams into dashboard data. Frappe's web-page view records provide page visits. Builder Page Click records provide tracked clicks from published Builder pages. Both streams use the page path so the API can compare views with clicks for a page or element.

The frontend sends a date range, time interval, and optional route filter. The server returns totals, time buckets, referrer domains, top pages, or click-through rates. Page analytics requires a date range. If the analytics store is not ready or a query fails, the API returns an empty result shape instead of breaking the dashboard.

Analytics access is protected by the same page-read boundary as other Builder reporting. Click capture allows guests because it runs on published pages. It uses the request referrer to identify the site path, ignores non-site and reserved paths, caps stored click text, and writes the click record without delaying the visitor response.

References: builder/api.py• L722-812 builder/builder_analytics.py• L258-380 builder/builder_analytics.py• L398-470 frontend/…/useAnalytics.ts• L324-413

External domain API

Custom-domain actions are a small proxy from Builder to the Frappe Cloud domain service. They let an authorized site manager inspect the server address, verify DNS, add or remove a domain, set the primary host, and control redirects without exposing the external service credentials to the frontend.

Every domain method checks for the System Manager role before it calls the external service. The frontend verifies DNS before it asks to add a domain, then refreshes the domain list after each change. This keeps the UI aligned with the external service while leaving the server responsible for permission and error translation.

References: builder/domain.py• L7-86 frontend/…/domains.ts• L19-100

Use these pages to place the API and event layer in the rest of the system:

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep whitelisted method names and document method names aligned with the frappe-ui resource calls. A renamed method can fail only when a user opens a less common editor action.
  • Keep page publish, preview, and route-cache behavior aligned. A change to which field is live must also preserve the correct public route and preview result.
  • Keep component version fields and snapshot restore data compatible. A version check that no longer matches stored pins can silently render the live component instead of the page version.
  • Keep imported template bundle fields aligned with the local Builder DocTypes. A bundle can fail after download if a renamed resource field is not normalized at the import boundary.
  • Keep grouped-template route prefixes aligned with imported folder names. A change to either side can break relative links between pages in one imported group.
  • Keep AI session ownership, pending-action status, and page permission checks aligned. A change to one boundary can expose another user's chat or apply a proposed change without the intended confirmation.
  • Keep AI queue payloads and realtime event names aligned with the editor's session and active-build reads. A mismatch can leave a valid background job invisible or make a finished run appear active.
  • Keep analytics path and uniqueness fields consistent between Web Page View and Builder Page Click. The CTR join depends on the shared path.
  • Keep scheduled ingestion names in builder/hooks.py aligned with the analytics functions. A hook mismatch leaves dashboards empty without changing the page editor.
  • Keep public script URL generation aligned with page rendering. A document can save correctly while visitors still receive an old script if the public file link is not refreshed.
  • Keep external domain method names aligned with the Frappe Cloud domain service. The Builder proxy does not define the domain state itself.

Important failure modes

TriggerConsequenceGuard
A page is published without a valid draft or route stateThe live page can keep old content or become unreachablePublish snapshots the draft and the page document clears route caches when live route fields change
A component changes but its pages are not syncedExisting page instances keep their earlier component structureSync is an explicit action that updates matching draft and live blocks and clears affected caches
A remote asset or font resolves to a private addressA server-side fetch could reach an internal serviceThe URL guard rejects private, loopback, link-local, reserved, and multicast addresses
A template Hub request fails or returns an incomplete bundleThe template picker can be empty or the selected page cannot be createdCatalog failures return an empty list, while page creation rejects a bundle without a page
An imported template group has a route conflictPages can overlap existing routes or relative links can point to the wrong pageGroup import chooses an unused folder and route prefix before creating the pages
An AI request queues without a valid model or keyThe editor receives no usable generation result after accepting the turnThe API validates the model and resolves its key before it queues the worker
A pending AI action is confirmed by the wrong user or at the wrong stateA protected change can be applied outside its intended chat flowThe API checks session ownership, pending status, and the relevant write permission before applying it
Analytics ingestion has not run or the analytics store is lockedReports show no data or return an empty resultScheduled ingestion rebuilds or appends data, while reads use read-only connections and retry lock conflicts
A client script document changes without its public file updateThe saved script differs from the file loaded by the websiteDocument update hooks regenerate the public file and its versioned URL
DNS is not ready when a domain is addedThe external domain service rejects the add requestThe frontend checks DNS first and reports the verification result before the add call

Key files

FileWhy to read it
builder/api.pyMain Builder API boundary for previews, assets, templates, access data, folders, components, editor support, and analytics
builder/…/api.pyAI chat, background job acceptance, pending-action confirmation, session control, provider setup, and active-build state
builder/…/builder_page.pyPage document lifecycle, public rendering contract, snapshots, publishing, and route cache effects
builder/…/builder_component.pyComponent data, page references, cache work, and explicit page synchronization
builder/…/builder_client_script.pyLink between saved script documents and public files loaded by pages
builder/builder_analytics.pyEvent ingestion and the read model used by analytics requests
builder/hooks.pyFrappe runtime hooks, website routing, scheduled tasks, invitation events, and API discovery
builder/domain.pyServer-side proxy for Frappe Cloud custom-domain actions
frontend/…/pageStore.tsFrontend calls that drive page save, publish, snapshot, restore, and page-data flows
frontend/…/componentStore.tsFrontend calls that load, save, sync, and version component instances
frontend/…/useAnalytics.tsRequest parameters and response use for page and site analytics
frontend/…/realtimeHandler.tsSocket subscriptions and named event messages used by the editor