Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,212 of 9,212 pages
About the help in other languages
All help pages

Headless overview: architecture, data flow and choosing an approach

What this is. The big picture of Exponential as a headless CMS: which parts of the kernel answer a program, how a request travels through them, how changes travel back out, and how to choose between plain HTTP, the…

Download as PDF

Address: https://doc.exponential.earth/learninminutes/exphelp/viewer/headless/overview.md

On this page

Headless overview: architecture, data flow and choosing an approach

What this is. The big picture of Exponential as a headless CMS: which parts of the kernel answer a program, how a request travels through them, how changes travel back out, and how to choose between plain HTTP, the TypeScript SDK, persisted queries, webhooks and subscriptions.

When to use it. Before you design a front end, an app or an integration; when you explain the system to a new team member; when you decide where a cache or a CDN belongs.

Quick example. The front page and its first three children, anonymously:

EXP=https://www.example.com
curl -s "$EXP/api/graphql" -H 'Content-Type: application/json' \
  -d '{"query":"{ node(urlAlias: \"\") { name url children(limit: 3) { totalCount nodes { name urlAlias } } } }"}'
{"data":{"node":{"name":"Fit & Healthy","url":"https://alpha.se7enx.com/","children":{"totalCount":16,
 "nodes":[{"name":"Fitness","urlAlias":"fitness"},{"name":"Healthy eating","urlAlias":"healthy-eating"},
 {"name":"Recipes","urlAlias":"recipes"}]}}},"extensions":{"requestId":"9ec7706373d6dfc4","schemaHash":"19deb36636de"}}

Contents

  1. What "headless" means here
  2. The parts
  3. The life of a request
  4. The life of a change
  5. Who may read and change what
  6. Choosing an approach
  7. Rendering strategies
  8. The TypeScript SDK
  9. What the API does not do
  10. Limits at a glance
  11. Planning for the long term

What "headless" means here

Exponential renders its own pages with templates, and it can also hand its content to programs that render it themselves: a React or Vue front end, a mobile app, a static site generator, a search indexer, a shop, an AI agent. "Headless" means the second way. Both can run at the same time on the same installation: the editors keep the administration, the templates keep serving the classic site, and the API serves the new clients. Nothing about the content model changes for the API: content classes, translations, locations, sections, object states, roles and workflows are exactly those of the administration.

The kernel offers three programmatic interfaces. This section is about the first:

InterfaceAddressUse it for
GraphQL API/api/graphql (per siteaccess)everything new: reading content with exactly the fields a page needs, writing it with policy checks, real-time events
REST API v1/v2/api/ezp/v1/..., /api/ezp/v2/...existing integrations built on it; see REST API v1 and v2
Templates and ezjscore callsthe site's pagesclassic server-rendered pages

The parts

                       ┌───────────────────────────── Exponential installation ─────────────────────────────┐
 browser / app /       │                                                                                    │
 server / build ──────►│ request shield ─► index_rest.php ─► early answer (response cache) ──► 200/304       │
   ▲                   │  (exp_request_     │   (anonymous GET, or a key/token whose rights are remembered)  │
   │                   │   shield)          ▼                                                                │
   │                   │              REST kernel: siteaccess (host, path, X-Siteaccess), CORS, auth         │
   │                   │              (API key, OAuth token, none) ─► rate limit ─► expGraphQLServer          │
   │                   │                                  │ schema per siteaccess (classes → types)          │
   │                   │                                  ▼                                                  │
   │                   │                  queries read through the user's policies ─► database, search       │
   │                   │                  mutations: policies, workflows, audit ─► publish ─┐                │
   │                   │                                                                    ▼                │
   │                   │  event journal (var/<site>/graphql/events/*.jsonl) ◄── every content change          │
   │                   │      │                         │                                                    │
   │ signed POST       │      ▼                         ▼                                                    │
   └───────────────────┤  webhooks (cron part or      subscriptions (/api/graphql/subscribe:                 │
     (webhook) / SSE   │  expqueue jobs)               SSE, WebSocket through Velocity)                       │
                       └────────────────────────────────────────────────────────────────────────────────────┘
PartCodeWhat it does
Request shieldextension exp_request_shielddecides every request before the kernel: methods, paths, budgets, browser checks. See CORS, rate limits and the request shield.
Early answerindex_rest.php, expGraphQLResponseCacheanswers a cached persisted query before the settings and the database are loaded. See Cache tags and invalidation.
REST kernelkernel/private/rest/picks the siteaccess, answers CORS preflights, signs the request in (expApiKeyRest, OAuth), routes /api/graphql to expGraphQLRestController.
Rate limiterexpGraphQLRateLimitercounts requests per key, user or address in var/cache/graphql/rate/.
Schema builderexpGraphQLSchemaBuilder, expGraphQLTypes, expGraphQLFieldMapper, expGraphQLNamingbuilds one schema per siteaccess from the content classes; its hash is the schema hash.
ServerexpGraphQLServerparses, checks the limits (depth, complexity, length), resolves persisted queries, runs the query, formats errors.
RepositoryexpGraphQLRepository, expGraphQLContent, expGraphQLLocation, expGraphQLBatchLoaderreads content through the kernel's fetch functions with the user's policies, batching what a level of the query asks for.
WriterexpGraphQLWriter, expGraphQLMutations, expGraphQLFieldInput, expGraphQLUploadthe mutations: the same operations, workflows and audit as the administration.
Event listener and journalexpGraphQLEventListener, expGraphQLEventsnotes every content change during a request and appends it to the journal at the end of the request.
WebhooksexpGraphQLWebhooks, cron part graphqlwebhooks, expGraphQLWebhookQueueHandlersends events to end points, signed, with retries.
SubscriptionsexpGraphQLSubscriptionsstreams events to clients that may read them.

The life of a request

  1. The shield looks at the method, the path and the client's budget. For /api/** the shipped rules answer a browser check as JSON (HTTP 429 with the header Request-Shield-Challenge), never as an HTML page.
  2. The early answer. For a GET (or a JSON POST) of a persisted query, index_rest.php looks into the response cache first. An anonymous request, or a request whose key or token was seen in the last CredentialCacheTtl seconds, is answered from there with X-GraphQL-Cache: HIT, before settings or database are touched. A client that sends If-None-Match with the ETag it has gets 304 Not Modified.
  3. The siteaccess is chosen as for every REST request: by host or path, or by the header X-Siteaccess when it names a siteaccess that exists (an unknown name is ignored and the host decides). The API answers only where graphql.ini [GraphQLSettings] Enabled=enabled and, when SiteAccessList[] is not empty, the siteaccess is listed; elsewhere 404 with extensions.code DISABLED.
  4. Sign-in. Authorization: Bearer expk_... is a personal API key; another Bearer token is an OAuth token; no header means the anonymous user. A key that is wrong, expired, revoked, limited to other siteaccesses, or whose owner is disabled answers 401 with {"error":"invalid_token"} before GraphQL runs. A key may never be sent in the query string or the body.
  5. The rate limit is counted before the schema is built: over the limit is 429 with RATE_LIMITED and Retry-After.
  6. The schema of the siteaccess is built from the content classes it shows (cached per siteaccess, keyed by its hash).
  7. The query is checked: at most MaxQueryLength bytes, MaxDepth levels, MaxComplexity points; introspection only where Introspection allows it; a mutation only by POST, signed in, with the right scope. Then it runs as the user: every object, location and field is read through that user's policies. What the user may not read is null or left out of a list, never an error.
  8. The answer is JSON with data, errors (if any) and extensions (requestId, schemaHash), and the headers X-GraphQL-Schema, X-Request-Id, ETag, X-Exponential-Cache-Tags (queries), the X-RateLimit-* headers and Cache-Control. An answer of a persisted query is stored in the response cache for the next request.

The status is 200 for every answer GraphQL produced, errors of the query included. 400 means the request could not be read (not JSON, a variables that is not an object), 401 a bad credential, 404 a switched-off API, 429 a rate limit or a subscription limit, 503 a missing library.

The life of a change

  1. An editor publishes in the administration, a migration runs, a script imports, or a client sends a mutation.
  2. Wherever content changes (publish, move, hide, reveal, trash, delete, a GraphQL mutation, a whole-cache clear), the kernel calls expGraphQLEventListener. It only notes the change.
  3. At the end of the request, after the database transaction, the notes become records and are appended to the journal var/<site>/graphql/events/events-<generation>.jsonl in one locked write. Nothing is sent from the request that made the change; a failure here is logged and never reaches the editor.
  4. The response cache is expired: every publish clears the view caches, and the GraphQL answers with them.
  5. The webhooks: the cron part graphqlwebhooks (in the frequent group) reads the journal from its cursor, puts one delivery per interested end point into the outbox (or the job queue), and sends them signed, with retries.
  6. The subscriptions: every open stream polls the journal (every SubscriptionPollInterval ms), and for each matching event checks the subscriber's rights at that moment, runs the subscription's selection and sends it.
  7. Your front end turns the event into cache tags (c<object>, l<node>, pl<parent>) and drops exactly the pages that showed that content. See Cache tags and invalidation.

The journal is written only while somebody listens: the API is on in some siteaccess, and subscriptions are enabled or a webhook is configured.

Who may read and change what

Every request runs as one user of the installation, and that user's roles and policies decide, exactly as in the web interface:

RequestRuns asReadsWrites
no Authorizationthe anonymous userwhat the role Anonymous allows in the siteaccessnothing (unless AnonymousMutations=enabled, or a schema extension opens a mutation to anonymous callers)
a personal API keythe key's ownerwithin the owner's policies, if the key has graphql:readwith graphql:write too, within the owner's policies
a public read keyits owner, who may only readwithin the owner's policiesnever
an OAuth tokenthe signed-in personwithin their policieswithin their policies
the session of the administration (playground, /graphql/query)the signed-in editorwithin their policieswith the form token (X-CSRF-Token)
the console (exp:graphql:query --as=<login>)that user, or anonymouswithin their policieswithin their policies

The schema settings decide what can be asked at all (ClassList[], ExcludedClassList[], HiddenFieldList[], HiddenDatatypeList[]); the policies decide what a given user gets. The user account classes (user, user_group) and the datatypes ezuser and ezpassword are excluded by default. Details: Authentication.

Choosing an approach

Start from what your project is, then pick the transport and the way you learn about changes.

Your projectFetch withLearn about changes byCache in
Server-rendered front end (Next.js, Nuxt, SvelteKit, Astro SSR, Remix)the SDK on the server with a read key, persisted queriesa webhook to a revalidation routethe framework's data cache, tagged with the cache tags; a CDN in front
Static site (Astro static, Eleventy, Gatsby, Hugo with a script)the SDK or fetch at build time, cursor pagination over everythinga webhook that starts a rebuildthe build output
Single-page app in the browseranonymous GET of persisted queries, or a public read keya subscription for live parts, otherwise a normal reloadthe browser cache with ETag/304
Mobile appthe SDK (@exponentialcms/expo) with an OAuth token per person, or anonymouspush from your own server that receives webhooksthe app's store
Search index, data warehouse, ERP syncthe SDK or fetch with a server keya webhook with Payload=query (the answer of a persisted query in the body)your target system
Editorial tools, importersa key with graphql:write, mutations(you are the source)none
Live dashboard, ticker, notificationsa subscriptionthe subscription itselfnone

Plain HTTP or the SDK? Every feature works with plain HTTP: GraphQL over HTTP is one POST with a JSON body. Use plain fetch or curl for scripts, other languages and one-off tools. Use the TypeScript SDK in JavaScript and TypeScript projects: it adds typed results, the stable error codes as error classes, retries that honor Retry-After, the cache tags parsed, persisted queries as GET, subscriptions with automatic resume, webhook verification and framework adapters.

Ad-hoc or persisted queries? Ad-hoc queries (the query text in each request) are the simplest and fine for servers and builds. Persisted queries (stored with exp:graphql:persist and called by name) are the fast path: they are the only answers the server caches, they can be served before the kernel starts, and with PersistedQueriesOnly=anonymous they lock anonymous clients to the queries you shipped. Use them for every public, high-traffic page.

Webhooks or subscriptions? Webhooks reach servers (your revalidation route, a build service, a search indexer); they are retried for hours and survive the receiver being down. Subscriptions reach clients that hold a connection open (a browser tab, a dashboard); they are best effort while connected, resume with Last-Event-ID across reconnects, and hold one PHP process (or Velocity worker) each.

One siteaccess or several? A siteaccess has its own languages, root node and settings. A multilingual or multisite front end either calls one siteaccess per language or site (X-Siteaccess), or one siteaccess and passes language: per query. See the cookbook recipes Multisite and Language switcher.

Rendering strategies

StrategyRequest patternInvalidationNotes
Server-side rendering per requestone or a few queries per page viewnone needed, or a short CDN TTLsimplest; the response cache and persisted queries keep it fast
Incremental static regeneration / data cachequeries cached by the framework, taggedwebhook → revalidateTag() for tagsForEvent(event)the most efficient for most sites
Full static buildcursor walk over the whole tree at build timewebhook → build hook (debounced)simplest hosting; rebuild time grows with the site
CDN-cached HTMLyour pages carry Cache-Tag/Surrogate-Key from the answers' tagswebhook → the CDN's purge-by-tag APIsee Cache tags and invalidation, "CDN purging"
Client-side renderingqueries from the browsernormal reloads, or subscriptionsneeds CORS; never ship a writing key

The TypeScript SDK

The SDK is a set of npm packages under @exponentialcms/, one repository each at https://github.com/se7enxweb/exponentialcms-<name>. All of them build on the client. Version 1.0.0 is prepared; until the packages are on npm, install from GitHub (npm install github:se7enxweb/exponentialcms-client).

PackageRepositoryWhat it adds
@exponentialcms/clientexponentialcms-clientthe dependency-free client: queries, mutations, persisted queries, uploads, subscriptions (SSE), keys and tokens, retries, errors, cache tags, webhook verification, preview handlers, CDN tag headers
@exponentialcms/queryexponentialcms-querya typed query builder: a node by id, remote id, path or URL alias, children, subtree, search
@exponentialcms/writeexponentialcms-writetyped mutations: create, update, translate, publish drafts, preview tokens, move, hide, reveal, locations, delete
@exponentialcms/codegenexponentialcms-codegenTypeScript types per content class from contentClasses
@exponentialcms/datatypesexponentialcms-datatypesthe types of field values and the string formats mutations write
@exponentialcms/richtextexponentialcms-richtextrich text (ezxmltext) as a tree; render to HTML, text or Markdown
@exponentialcms/nextexponentialcms-nextNext.js App Router: revalidation route, tags for cached functions, previews
@exponentialcms/nuxtexponentialcms-nuxtNuxt: a query composable, a tag index for the Nitro cache, the webhook handler
@exponentialcms/sveltekitexponentialcms-sveltekitSvelteKit: queries in load functions with tags, the webhook route
@exponentialcms/astroexponentialcms-astroAstro: a content loader, the webhook end point
@exponentialcms/reactexponentialcms-reactReact: provider, query hooks, rich text and image components
@exponentialcms/react-routerexponentialcms-react-routerReact Router 7 and Remix loaders with tags, webhook and preview routes
@exponentialcms/vueexponentialcms-vueVue 3: plugin, query composable, rich text and images
@exponentialcms/angularexponentialcms-angularAngular: provider, TransferState queries, purge tags
@exponentialcms/solidexponentialcms-solidSolidJS and SolidStart
@exponentialcms/qwikexponentialcms-qwikQwik City
@exponentialcms/litexponentialcms-litLit controllers and templates
@exponentialcms/emberexponentialcms-emberEmber helpers and a tag-invalidated store
@exponentialcms/web-componentsexponentialcms-web-components<exp-node>, <exp-richtext>, <exp-image> without a framework
@exponentialcms/nodeexponentialcms-nodeExpress, Fastify, Hono: webhook route, previews, CDN tags
@exponentialcms/edgeexponentialcms-edgeCloudflare Workers, Vercel and Netlify edge, Deno Deploy
@exponentialcms/deno-freshexponentialcms-deno-freshFresh 2 (Deno)
@exponentialcms/gatsbyexponentialcms-gatsbya Gatsby 5 source plugin
@exponentialcms/eleventyexponentialcms-eleventyEleventy 3 data, filters and collections
@exponentialcms/docusaurusexponentialcms-docusaurusDocusaurus 3 plugin and Markdown exporter
@exponentialcms/vitepressexponentialcms-vitepressVitePress data loaders
@exponentialcms/expoexponentialcms-expoExpo and React Native
@exponentialcms/electronexponentialcms-electronElectron, the key kept in the main process
@exponentialcms/tauriexponentialcms-tauriTauri, the key in the OS keyring
@exponentialcms/ai-toolsexponentialcms-ai-toolstyped tools for AI agents on the client and Exponential Tron (MCP)

The kernel also ships starter projects: ./console exp:graphql:starter --kit=next|nuxt|astro|expo|html --to=<dir> --apply writes a project with queries generated from the schema of your siteaccess.

What the API does not do

Knowing the edges saves time:

  • No user administration. Users, user groups, roles and policies are not in the schema (the classes user and user_group are excluded, ezuser and ezpassword hidden). Manage them in the administration or with the console.
  • No class administration. Content classes are read (contentClasses), never changed through GraphQL. Change them in the administration or with migrations.
  • No rendering of pages. The API gives data. RichText.html is rendered rich text and url fields are site addresses, but whole pages come from your front end (or from the classic templates).
  • Dynamic collections of layouts are not run. LayoutBlock.items lists the items placed by hand; a dynamic collection's query runs only when the classic page renders.
  • No exactly-once delivery. Webhooks are at least once: de-duplicate by X-Exponential-Delivery.
  • No ordering guarantee across retries. Deliveries are sent oldest first, but a retried delivery can arrive after a later one. See Events, webhooks and subscriptions, "Ordering".
  • Search facets need Solr. With the kernel's own search engine SearchResult.facets is empty.
  • No caching of ad-hoc queries on the server. Only persisted queries are kept in the response cache.

Limits at a glance

Setting (graphql.ini [GraphQLSettings])DefaultEffect
MaxQueryLength100000 bytesa longer query: BAD_USER_INPUT
MaxDepth12deeper: DEPTH_LIMIT
MaxComplexity1000every field 1 point; a list field counts its limit/first times the fields below it: COMPLEXITY_LIMIT
MaxListLimit100a larger limit or first is lowered to it
DefaultListLimit25a list without limit/first
RateLimit / RateLimitAnonymous / RateLimitPublicKey600 / 120 / 3000 per RateLimitWindow (60 s)over it: 429 RATE_LIMITED
MaxUploadSize32Ma larger file is refused
MaxSubscriptions / PerUser / PerAddress200 / 5 / 10over it: 429 SUBSCRIPTION_LIMIT
SubscriptionMaxDuration280 sthe stream ends; the client resumes with Last-Event-ID
PreviewTokenTtl / MaxPreviewTokenTtl3600 / 86400 slifetime of preview tokens

Planning for the long term

A headless project lives for many years and outlives several front-end frameworks. Decisions that age well:

  • Address content by remote id or URL alias, not by node id, in anything stored outside the installation. Node ids differ between environments; remote ids travel with content packages and migrations.
  • Keep your queries in .graphql files in your repository and persist them on deploy (exp:graphql:persist queries/ --apply). They are then checked against the schema before they go live.
  • Watch the schema hash. Fail your build when X-GraphQL-Schema differs from the hash your types were generated for, and regenerate them (@exponentialcms/codegen).
  • Decide by extensions.code, never by message. Codes are a stable contract; messages are translated and may be reworded.
  • Treat webhook delivery as at least once and unordered. Make every receiver idempotent.
  • Give every client its own key with the smallest scope and an expiry, and rotate them on a schedule. See Authentication, "Rotating keys".
  • Read the compatibility policy before every upgrade.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x