Headless CMS
Define typed CMS collections and singletons in code, then bind request-scoped services to trusted context and Storage.
@puzzle-ui/cms is the framework-neutral schema, validation, querying, and
editorial lifecycle layer for Puzzle. Define the schema in code with
defineCMS, collection, and fields; the schema is the source of truth.
Content types are not registered or mutated at runtime.
The package owns collections and singletons, typed field definitions,
relationships, access policies, lifecycle hooks, drafts, revisions,
localization, and publishing. It uses @puzzle-ui/storage for metadata and
accepts asset-ID strings for media values. It does not provide a database,
identity provider, HTTP router, admin UI, scheduler implementation, or media
object storage.
Code-first collections
import { collection, defineCMS, fields } from "@puzzle-ui/cms";
export const cmsConfig = defineCMS({
collections: {
articles: collection({
name: "Article",
description: "Editorial articles.",
version: 1,
drafts: true,
timestamps: true,
localization: {
locales: ["en-US", "fr-FR"],
defaultLocale: "en-US",
},
fields: {
title: fields.text({ label: "Title", required: true, localized: true }),
slug: fields.slug({ label: "Slug", from: "title", required: true, localized: true }),
summary: fields.textarea({ label: "Summary", localized: true }),
featured: fields.boolean({ label: "Featured", defaultValue: false }),
},
}),
settings: collection.singleton({
name: "Site settings",
fields: {
siteName: fields.text({ label: "Site name", required: true }),
},
}),
},
});drafts and timestamps are opt-in. localization is configured with the
supported locale list and optional default locale. Collection keys (articles,
settings) are stable API keys; changing a key or making a breaking field
change requires a versioned migration. See Collections and
fields for the complete field catalog and migration rules.
Request-scoped service
Create the service after resolving trusted identity and tenant context on the
server. createCms binds context once; collection methods do not accept
tenant or actor IDs from the caller.
import { createCms } from "@puzzle-ui/cms";
import type {
CmsAccessPolicy,
CmsRequestContext,
} from "@puzzle-ui/cms";
import type { StorageAdapter } from "@puzzle-ui/storage";
export const createRequestCms = (
config: typeof cmsConfig,
storage: StorageAdapter,
context: CmsRequestContext,
accessPolicy: CmsAccessPolicy,
) =>
createCms({
config,
storage,
context,
accessPolicy,
});context must come from the trusted server session, and accessPolicy must
authorize the requested tenant, actor, action, and resource. When an
application intentionally omits request context for local single-tenant use,
the default scope is restricted to tenant "default" with actor null.
Access is never inferred from an entry or asset ID.
Guide
- Getting started
- CMS concepts
- Build a blog
- Collections and fields
- Entries, queries, and relationships
- Access policies
- Lifecycle hooks
- Drafts and revisions
- Localization and multilingual content
- Scheduling
- Previewing drafts
- Schema migrations
- Multi-tenant setup
- Custom Storage adapters
- Media, change events, and webhooks
- Next.js integration
- TanStack Start integration
- API reference
CMS authoring Pieces provide presentation components only; they do not fetch, authorize, or persist content.
Availability
@puzzle-ui/cms@0.18.0 is published to npm, but the code-first API documented
here is a newer rewrite and is not yet released. Do not assume the published
tarball contains these APIs. In this repository, add
"@puzzle-ui/cms": "workspace:*" to the consuming workspace and install from
the repository root to use the current code-first implementation.
The package root is its only public entry point. Use public exports from
@puzzle-ui/storage and @puzzle-ui/media; do not deep-import package source.