The framework-agnostic engine behind TanStack CMS: schema-as-code, the content store and review queue, revisions, scheduling, i18n, media, auth guards, and the agent operation registry.
pnpm add @tanstack/cms-coreMost apps also install @tanstack/cms-ui-react (admin + public
routes) and @tanstack/cms-api (server functions, HTTP, MCP).
// src/cms.config.ts
import { defineCms } from '@tanstack/cms-core'
export const cms = defineCms({
collections: [
{
name: 'post',
label: 'Posts',
titleField: 'title',
imageField: 'cover',
bodyField: 'body',
fields: [
{ name: 'title', label: 'Title', type: 'text', required: true },
{ name: 'slug', label: 'Slug', type: 'text' },
{ name: 'cover', label: 'Cover', type: 'image' },
{ name: 'body', label: 'Body', type: 'markdown' },
],
},
],
blockTypes: [],
})defineCms is isomorphic: import the config from your router entry so the
model is registered on both client and server.
| Import | Runs on | Contents |
|---|---|---|
@tanstack/cms-core |
client + server | defineCms, schema helpers, opSchemas, auth types, theme |
@tanstack/cms-core/server |
server | store (getAs, listAs, commitDocument, stageWrite, approve, …), media library, runOp, auth guards, CmsError |
@tanstack/cms-core/storage |
config | StorageAdapter contract, query/frontmatter utilities (the Postgres engine ships in @tanstack/cms-store-postgres) |
@tanstack/cms-core/storage/conformance |
tests | runStorageConformance() for custom storage adapters |
@tanstack/cms-core/media |
config | MediaAdapter contract, createLocalMedia(), image sniffing |
@tanstack/cms-core/media/conformance |
tests | runMediaConformance() for custom media adapters |
The storage engine is Postgres. In development the default is embedded
Postgres (PGlite) — the same adapter and migration ladder as a server,
compiled to WebAssembly and run in-process, so no database server is needed
(tanstack-cms init scaffolds it). For production, point at a Postgres server.
Set the engine globally with defineCms({ storage }) or per collection with
defineCollection({ storage }):
import { createPostgresStorage } from '@tanstack/cms-store-postgres'
import { createPgliteStorage } from '@tanstack/cms-store-postgres/pglite'
// Development (embedded, no server):
defineCms({ /* … */, storage: createPgliteStorage({ dataDir: '.data/pglite' }) })
// Production (Postgres server):
defineCms({ /* … */, storage: createPostgresStorage({ connectionString: process.env.DATABASE_URL }) })Adapters only persist records. Validation, hooks, revisions, the review
queue, and scheduling all live in core, so every backend behaves the same.
That guarantee is checked by runStorageConformance().
Uploads are sniffed from their bytes, size-limited (uploads.maxBytes,
default 10 MiB), and SVGs are sanitized. Metadata (filename, dimensions, alt)
is stored in the database, and bytes go to the media adapter, which defaults
to <dataDir>/uploads:
import { s3Media } from '@tanstack/cms-media-s3'
defineCms({ /* … */, media: s3Media({ bucket: 'cms', endpoint: process.env.R2_ENDPOINT }) })Documents store /api/media/<id>, so switching adapters never rewrites
content. With the optional sharp package installed, /api/media/<id>?w=640&format=webp
resizes and re-encodes images on the fly.
MIT