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
- What "headless" means here
- The parts
- The life of a request
- The life of a change
- Who may read and change what
- Choosing an approach
- Rendering strategies
- The TypeScript SDK
- What the API does not do
- Limits at a glance
- 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:
| Interface | Address | Use 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 calls | the site's pages | classic 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) │
└────────────────────────────────────────────────────────────────────────────────────┘| Part | Code | What it does |
|---|---|---|
| Request shield | extension exp_request_shield | decides every request before the kernel: methods, paths, budgets, browser checks. See CORS, rate limits and the request shield. |
| Early answer | index_rest.php, expGraphQLResponseCache | answers a cached persisted query before the settings and the database are loaded. See Cache tags and invalidation. |
| REST kernel | kernel/private/rest/ | picks the siteaccess, answers CORS preflights, signs the request in (expApiKeyRest, OAuth), routes /api/graphql to expGraphQLRestController. |
| Rate limiter | expGraphQLRateLimiter | counts requests per key, user or address in var/cache/graphql/rate/. |
| Schema builder | expGraphQLSchemaBuilder, expGraphQLTypes, expGraphQLFieldMapper, expGraphQLNaming | builds one schema per siteaccess from the content classes; its hash is the schema hash. |
| Server | expGraphQLServer | parses, checks the limits (depth, complexity, length), resolves persisted queries, runs the query, formats errors. |
| Repository | expGraphQLRepository, expGraphQLContent, expGraphQLLocation, expGraphQLBatchLoader | reads content through the kernel's fetch functions with the user's policies, batching what a level of the query asks for. |
| Writer | expGraphQLWriter, expGraphQLMutations, expGraphQLFieldInput, expGraphQLUpload | the mutations: the same operations, workflows and audit as the administration. |
| Event listener and journal | expGraphQLEventListener, expGraphQLEvents | notes every content change during a request and appends it to the journal at the end of the request. |
| Webhooks | expGraphQLWebhooks, cron part graphqlwebhooks, expGraphQLWebhookQueueHandler | sends events to end points, signed, with retries. |
| Subscriptions | expGraphQLSubscriptions | streams events to clients that may read them. |
The life of a request
- 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 headerRequest-Shield-Challenge), never as an HTML page. - The early answer. For a
GET(or a JSONPOST) of a persisted query,index_rest.phplooks into the response cache first. An anonymous request, or a request whose key or token was seen in the lastCredentialCacheTtlseconds, is answered from there withX-GraphQL-Cache: HIT, before settings or database are touched. A client that sendsIf-None-Matchwith theETagit has gets304 Not Modified. - The siteaccess is chosen as for every REST request: by host or path, or by the header
X-Siteaccesswhen it names a siteaccess that exists (an unknown name is ignored and the host decides). The API answers only wheregraphql.ini [GraphQLSettings] Enabled=enabledand, whenSiteAccessList[]is not empty, the siteaccess is listed; elsewhere404withextensions.codeDISABLED. - Sign-in.
Authorization: Bearer expk_...is a personal API key; anotherBearertoken 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 answers401with{"error":"invalid_token"}before GraphQL runs. A key may never be sent in the query string or the body. - The rate limit is counted before the schema is built: over the limit is
429withRATE_LIMITEDandRetry-After. - The schema of the siteaccess is built from the content classes it shows (cached per siteaccess, keyed by its hash).
- The query is checked: at most
MaxQueryLengthbytes,MaxDepthlevels,MaxComplexitypoints; introspection only whereIntrospectionallows it; a mutation only byPOST, 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 isnullor left out of a list, never an error. - The answer is JSON with
data,errors(if any) andextensions(requestId,schemaHash), and the headersX-GraphQL-Schema,X-Request-Id,ETag,X-Exponential-Cache-Tags(queries), theX-RateLimit-*headers andCache-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
- An editor publishes in the administration, a migration runs, a script imports, or a client sends a mutation.
- 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. - 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>.jsonlin one locked write. Nothing is sent from the request that made the change; a failure here is logged and never reaches the editor. - The response cache is expired: every publish clears the view caches, and the GraphQL answers with them.
- The webhooks: the cron part
graphqlwebhooks(in thefrequentgroup) 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. - The subscriptions: every open stream polls the journal (every
SubscriptionPollIntervalms), and for each matching event checks the subscriber's rights at that moment, runs the subscription's selection and sends it. - 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:
| Request | Runs as | Reads | Writes |
|---|---|---|---|
no Authorization | the anonymous user | what the role Anonymous allows in the siteaccess | nothing (unless AnonymousMutations=enabled, or a schema extension opens a mutation to anonymous callers) |
| a personal API key | the key's owner | within the owner's policies, if the key has graphql:read | with graphql:write too, within the owner's policies |
| a public read key | its owner, who may only read | within the owner's policies | never |
| an OAuth token | the signed-in person | within their policies | within their policies |
the session of the administration (playground, /graphql/query) | the signed-in editor | within their policies | with the form token (X-CSRF-Token) |
the console (exp:graphql:query --as=<login>) | that user, or anonymous | within their policies | within 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 project | Fetch with | Learn about changes by | Cache in |
|---|---|---|---|
| Server-rendered front end (Next.js, Nuxt, SvelteKit, Astro SSR, Remix) | the SDK on the server with a read key, persisted queries | a webhook to a revalidation route | the 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 everything | a webhook that starts a rebuild | the build output |
| Single-page app in the browser | anonymous GET of persisted queries, or a public read key | a subscription for live parts, otherwise a normal reload | the browser cache with ETag/304 |
| Mobile app | the SDK (@exponentialcms/expo) with an OAuth token per person, or anonymous | push from your own server that receives webhooks | the app's store |
| Search index, data warehouse, ERP sync | the SDK or fetch with a server key | a webhook with Payload=query (the answer of a persisted query in the body) | your target system |
| Editorial tools, importers | a key with graphql:write, mutations | (you are the source) | none |
| Live dashboard, ticker, notifications | a subscription | the subscription itself | none |
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
| Strategy | Request pattern | Invalidation | Notes |
|---|---|---|---|
| Server-side rendering per request | one or a few queries per page view | none needed, or a short CDN TTL | simplest; the response cache and persisted queries keep it fast |
| Incremental static regeneration / data cache | queries cached by the framework, tagged | webhook → revalidateTag() for tagsForEvent(event) | the most efficient for most sites |
| Full static build | cursor walk over the whole tree at build time | webhook → build hook (debounced) | simplest hosting; rebuild time grows with the site |
| CDN-cached HTML | your pages carry Cache-Tag/Surrogate-Key from the answers' tags | webhook → the CDN's purge-by-tag API | see Cache tags and invalidation, "CDN purging" |
| Client-side rendering | queries from the browser | normal reloads, or subscriptions | needs 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).
| Package | Repository | What it adds |
|---|---|---|
@exponentialcms/client | exponentialcms-client | the 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/query | exponentialcms-query | a typed query builder: a node by id, remote id, path or URL alias, children, subtree, search |
@exponentialcms/write | exponentialcms-write | typed mutations: create, update, translate, publish drafts, preview tokens, move, hide, reveal, locations, delete |
@exponentialcms/codegen | exponentialcms-codegen | TypeScript types per content class from contentClasses |
@exponentialcms/datatypes | exponentialcms-datatypes | the types of field values and the string formats mutations write |
@exponentialcms/richtext | exponentialcms-richtext | rich text (ezxmltext) as a tree; render to HTML, text or Markdown |
@exponentialcms/next | exponentialcms-next | Next.js App Router: revalidation route, tags for cached functions, previews |
@exponentialcms/nuxt | exponentialcms-nuxt | Nuxt: a query composable, a tag index for the Nitro cache, the webhook handler |
@exponentialcms/sveltekit | exponentialcms-sveltekit | SvelteKit: queries in load functions with tags, the webhook route |
@exponentialcms/astro | exponentialcms-astro | Astro: a content loader, the webhook end point |
@exponentialcms/react | exponentialcms-react | React: provider, query hooks, rich text and image components |
@exponentialcms/react-router | exponentialcms-react-router | React Router 7 and Remix loaders with tags, webhook and preview routes |
@exponentialcms/vue | exponentialcms-vue | Vue 3: plugin, query composable, rich text and images |
@exponentialcms/angular | exponentialcms-angular | Angular: provider, TransferState queries, purge tags |
@exponentialcms/solid | exponentialcms-solid | SolidJS and SolidStart |
@exponentialcms/qwik | exponentialcms-qwik | Qwik City |
@exponentialcms/lit | exponentialcms-lit | Lit controllers and templates |
@exponentialcms/ember | exponentialcms-ember | Ember helpers and a tag-invalidated store |
@exponentialcms/web-components | exponentialcms-web-components | <exp-node>, <exp-richtext>, <exp-image> without a framework |
@exponentialcms/node | exponentialcms-node | Express, Fastify, Hono: webhook route, previews, CDN tags |
@exponentialcms/edge | exponentialcms-edge | Cloudflare Workers, Vercel and Netlify edge, Deno Deploy |
@exponentialcms/deno-fresh | exponentialcms-deno-fresh | Fresh 2 (Deno) |
@exponentialcms/gatsby | exponentialcms-gatsby | a Gatsby 5 source plugin |
@exponentialcms/eleventy | exponentialcms-eleventy | Eleventy 3 data, filters and collections |
@exponentialcms/docusaurus | exponentialcms-docusaurus | Docusaurus 3 plugin and Markdown exporter |
@exponentialcms/vitepress | exponentialcms-vitepress | VitePress data loaders |
@exponentialcms/expo | exponentialcms-expo | Expo and React Native |
@exponentialcms/electron | exponentialcms-electron | Electron, the key kept in the main process |
@exponentialcms/tauri | exponentialcms-tauri | Tauri, the key in the OS keyring |
@exponentialcms/ai-tools | exponentialcms-ai-tools | typed 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
useranduser_groupare excluded,ezuserandezpasswordhidden). 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.htmlis rendered rich text andurlfields are site addresses, but whole pages come from your front end (or from the classic templates). - Dynamic collections of layouts are not run.
LayoutBlock.itemslists 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.facetsis 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]) | Default | Effect |
|---|---|---|
MaxQueryLength | 100000 bytes | a longer query: BAD_USER_INPUT |
MaxDepth | 12 | deeper: DEPTH_LIMIT |
MaxComplexity | 1000 | every field 1 point; a list field counts its limit/first times the fields below it: COMPLEXITY_LIMIT |
MaxListLimit | 100 | a larger limit or first is lowered to it |
DefaultListLimit | 25 | a list without limit/first |
RateLimit / RateLimitAnonymous / RateLimitPublicKey | 600 / 120 / 3000 per RateLimitWindow (60 s) | over it: 429 RATE_LIMITED |
MaxUploadSize | 32M | a larger file is refused |
MaxSubscriptions / PerUser / PerAddress | 200 / 5 / 10 | over it: 429 SUBSCRIPTION_LIMIT |
SubscriptionMaxDuration | 280 s | the stream ends; the client resumes with Last-Event-ID |
PreviewTokenTtl / MaxPreviewTokenTtl | 3600 / 86400 s | lifetime 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
.graphqlfiles 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-Schemadiffers from the hash your types were generated for, and regenerate them (@exponentialcms/codegen). - Decide by
extensions.code, never bymessage. 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.