Configuration

The cms.config.ts file is the single entry point for all CMS configuration.

Everything is configured through a single cms.config.ts file. The engine loads this file at startup and uses it to build the database schema, register API routes, set up permissions, and configure the admin UI.

Config structure

          import { blocks, config, entity, localDisk, object, relation, role, select, slug, text } from "@cms/config";

export default config({
  // Locales for i18n (optional)
  i18n: {
    locales: [
      { label: "English", value: "en" },
      { label: "Portuguese", value: "pt" },
      { label: "French", value: "fr" },
    ],
    defaultLocale: "en",
  },

  // CORS origins for external frontends (optional)
  cors: {
    origins: ["https://example.com"],
  },

  // Where asset files live (required): localDisk() from @cms/config,
  // or s3({ bucket, region, ... }) from @cms/storage-s3
  storage: localDisk({ root: "./uploads" }),

  // Your content entities — add global: true for singleton entries
  entities: [posts, pages, authors, siteSettings],

  // Roles and permissions
  roles: [admin, editor, publicRole],
});
        

Built-in entities

CMS automatically registers four built-in entities that you don’t need to define:

_user

          // Auto-registered with these fields:
// - email (text, unique, required, must be a valid email)
// - name (text)
// - role (select of your config's roles, required)
// Plus automatic: id, createdAt, updatedAt, publishedAt
        

Authentication uses emailed login codes — no password column. The admin manages users on the usual entity screens, from Settings → Users.

Extending _user

To store your own data on users (a company, a phone number, a plan, an id in another system), extend the built-in with entity.extend and list it in entities:

          import { entity, relation, select, text } from "@cms/config";

const users = entity.extend("_user", {
  fields: [
    text("company"),
    text("phone"),
    select("plan", { options: ["free", "pro"], required: true, defaultValue: "free" }),
    relation("organization", { to: "organizations" }),
  ],
  hooks: {
    afterCreate: async (user, { system }) => {
      // e.g. create the customer in your billing system
    },
  },
  admin: {
    list: {
      columns: [{ label: "Email", sortKey: "email", render: ({ data }) => data.email }, "createdAt"],
    },
  },
});

export default config({ entities: [users, posts], roles, storage });
        
  • email, name, role and preferredLocale stay the engine’s: an extension adds fields after them and can’t redefine them. preferredLocale exists only when the config has more than one locale, but the name is taken either way.
  • A user is created before anyone fills in their profile (by signup, or an admin who only sets email and role), so an extension field is optional, or required with a defaultValue. The config refuses a required field without one.
  • Hooks are beforeCreate, afterCreate, beforeUpdate, afterUpdate, beforeDelete and afterDelete (users keep no versions). They run on every create, signup included. The sign-out of a deleted user still runs after them.
  • admin options replace the built-in ones key by key: users are titled by name (else email) and listed by email, name and role until you set summary or list.
  • Plugins can extend _user too, from their entities. Every extension is merged in config order: fields are added, hooks run one after another, and a field name or admin option two sources both set fails at load, naming them.

Run cms migration generate after changing the fields, as for any entity. To let customers fill in their own profile, see customer profiles.

_image, _video, _file

The three asset entities. All uploads go through POST /api/assets/upload and are routed to the correct entity by MIME type.

          // _image — fields: filename, mimeType, size, width, height, alt, url
// _video — fields: filename, mimeType, size, width, height, url
// _file  — fields: filename, mimeType, size, url
// All include automatic: id, createdAt, updatedAt
        

Reference them in your entity config with the typed field helpers:

          import { image, video, file } from "@cms/config";

image("featuredImage")
video("demoVideo")
file("attachment", { multiple: true })
        

See the Assets guide for the full upload API, image transforms, and querying reference.

Automatic fields

Every entity automatically gets:

  • id — UUID primary key
  • createdAt — timestamp, set on insert
  • updatedAt — timestamp, set on insert and update
  • publishedAt — when the document first went live (null while it’s a draft)
  • locale, translationGroup — on translatable entities only

Relation values carry _entity (the target entity’s name), not the document itself.

You never define these — they’re always present.

Admin UI configuration

The admin UI is configured through the admin key:

          import { BookOpenIcon, GearIcon } from "@phosphor-icons/react";
import { MyDashboard } from "./my-dashboard";

export default config({
  admin: {
    logo: "/logo.svg",
    title: "My CMS",
    sidebar: ({ group, item, divider, builtins }) => [
      builtins.DASHBOARD,
      group("Content", {
        collapsible: true,
        children: [
          item("posts", { label: "Posts", icon: BookOpenIcon }),
          item("authors", { label: "Authors" }),
        ],
      }),
      divider(),
      item("settings", { label: "Settings", icon: GearIcon }),
      divider(),
      builtins.ASSETS,
    ],
    dashboard: MyDashboard,
  },
  // ...
});
        

sidebar also receives the signed-in user as a second argument, to lay the sidebar out per user or role: ({ item }, { user }) => [...]. It’s layout only: access is set through role permissions, and non-admin roles get the result filtered by them. See Admin Extensibility → Sidebar.

See Admin Extensibility for the full guide.

Entity-level admin config

Each entity can carry its own admin options via the admin key on entity(...):

          import { entity, slug } from "@cms/config";
import { adminLivePreview } from "@cms/live-preview";

const page = entity("page", {
  admin: {
    preview: ({ data }) =>
      adminLivePreview({
        data,
        url: `http://localhost:3001/${data.slug}`,
      }),
  },
  fields: [slug("slug"), /* ... */],
});
        
  • preview — a function rendered alongside the form when the editor clicks Preview. The data parameter is fully typed to your entity’s fields. Use adminLivePreview for an iframe with real-time postMessage sync, or return any custom React.ReactNode.

See Live Preview for the full setup guide.

Field-level conditional UI

Individual fields can react to the rest of the form or the current user via admin.visible and admin.readOnly. Common uses: show a “publishedAt” date only when status === "published", hide an internal-notes field from non-editors, or make approvedBy read-only outside the admin role.

          date("publishedAt", {
  admin: { visible: ({ data }) => data.status === "published" },
}),
        

See Field visibility and access for the full pattern, including the difference between hiding in the UI and blocking at the API.

Previous

Installation

Next

Fields