← Files Total CMSARCHIVED FILE

skills/totalcms/references/data-model.md

13.7 KB · Nov 15, 2026 · 06:58 UTC

↓ Download file

See the change to this file →

# Data model reference: collections, schemas, objects

> This is a summary. For exhaustive detail (every field type and option), read the
> on-disk docs that ship with the package at
> `vendor/totalcms/cms/resources/docs/{collections,schemas,fields}/` (or query the
> MCP server if connected).

Three concepts:
- **Schema** — the shape: which fields an object has and their types. JSON under
  `tcms-data` / managed via `schema:*`. The reserved schemas (blog, blogdown, image, gallery,
  builder-page, seo-site, automations, …) plus your own custom schemas.
- **Collection** — a named bucket of objects bound to a schema (e.g. `blog` uses the
  `blog` schema). Managed via `collection:*`. Carries its own settings: URL, sort,
  public operations, sitemap, SEO mapping, MCP exposure.
- **Object** — one record (one JSON file) in a collection.

## Inspect

```bash
vendor/bin/tcms schema:list --json
vendor/bin/tcms collection:list --json
vendor/bin/tcms collection:get blog --json
vendor/bin/tcms object:list blog --json
vendor/bin/tcms object:get blog my-post --json
```

## Create a schema

**Start from the reference schema.** Total CMS ships a reserved schema named
`totalcms` whose properties demonstrate every built-in field type with its
settings, and whose help text says what each field is for. Read it first and
copy property definitions from it instead of writing them from memory:

```bash
vendor/bin/tcms schema:get totalcms --json      # or MCP: get_schema { id: "totalcms" }
```

Then author your schema JSON and import it:

```bash
vendor/bin/tcms schema:import my-schema.json
```

If you edit a schema JSON file **in place** instead, nothing re-validates it —
run `vendor/bin/tcms schema:lint <id>` afterwards.

### Modelling rules

Match the field to the **shape of the value**. `text` is the last resort, not
the default. A date in a text field cannot be filtered by month; a number in
a text field sorts as a string; a yes/no in a text field is a typo waiting to
happen.

| The value is… | Use | Not |
|---|---|---|
| the identity / URL slug | `id` with `"settings": {"autogen": "${title}"}` | `text` |
| a headline, name, label | `text` | |
| a summary, excerpt, plain note | `textarea` | `text`, `styledtext` |
| a formatted body | `styledtext` | `textarea` |
| a body kept as Markdown source | `markdown` (source editor) or `styledmarkdown` (visual editor); render with `\|markdown` | `textarea`, `styledtext` |
| a date / a timestamp | `date` / `datetime` | `text` |
| yes or no (featured, draft, in stock) | `toggle` | `text`, `select` |
| one of a fixed list (status, size, layout) | `select` (`radio` for 2–5 shown at once) | `text` |
| several of a fixed list | `checklist` | `list` |
| tags / categories editors grow over time | `list` + `"settings": {"propertyOptions": true}` | `select` |
| a count, rating, sort order | `number` | `text` |
| a count that must be whole (page size, position) | `number` with `"type": "integer"` | `text` |
| money | `price` | `number` |
| an email / a URL / a phone | `email` / `url` / `phone` | `text` |
| one image / several / a file / a file library | `image` / `gallery` / `file` / `depot` | a path in `text` |
| a hosted video | `video` | `url` |
| a fixed group of related fields (address, hero) | `card` | flat `addressLine1`, `addressCity`… |
| repeating structured items (FAQs, team, line items) | `deck` (`deckTable` for short rows; image and file columns work there too) | a `list`, a `json` |
| an API key / token the site reuses | `secret` | `text`, `password` |
| a password to verify, never to read back | `password` | `secret` |
| an embed code, a Twig or HTML snippet, an automation handler | `code` with `"settings": {"mode": "twig"}` (or `html`, `css`, `javascript`, `php`) | `textarea`, `styledtext` |
| free-form structured data a template reads (`page.data.*`) | `json` | `textarea`, a `deck` with one item |
| an inline SVG (logo, icon) | `svg` | `image`, `code` |
| a time of day | `time` | `text` |
| a color | `color` | `text` |
| when it was created / last changed | `datetime` with `"settings": {"onCreate": true}` / `{"onUpdate": true}` (see below) | hand-set `date` |
| SEO metadata for a public page | a `card` with `"schemaref": ".../schemas/seo.json"` | separate `metaTitle` text fields |

Omit `type` when the field implies it — the saver fills it in from `field`.

### Types: let the field decide, or use a property reference

Every property has a `field` (the editor) and a `type` (the stored shape).
Get the type one of three ways, in order of preference:

1. **Omit it.** On save the type is filled from the field: `text`/`textarea`/
   `select`/`styledtext`/`markdown`/`styledmarkdown` → `string`, `checkbox`/`toggle` → `boolean`,
   `number`/`price`/`range` → `number`, `checklist`/`multiselect` → `array`,
   and every other field → the type of the same name (`code` → `code`,
   `json` → `json`, `url` → `url`, `list` → `list`, `image` → `image` …).
2. **Use a property reference** when you want the shipped validation:
   `"$ref": "https://www.totalcms.co/schemas/properties/<type>.json"` with
   `<type>` one of `card code color date deck depot email file gallery image
   json list localizedtext password phone slug svg time url video`. A ref
   gives you the pattern for a URL, the format check for an email, and the
   "empty is allowed" branch, and it resolves to the right type name.
3. **Name the type** only when the field's default is wrong for the value:
   `"type": "integer"` on a `number` field is the common case. The recognised
   names are `array boolean card code color date deck depot email file gallery
   image integer json list localizedtext number password phone slug string svg
   time url video`.

Do not hand-write `"type": "string"` on a `code`, `url`, `email`, `json` or
`svg` field. It validates, but it is not what the saver would have chosen, the
schema editor's type dropdown falls out of step, and the schema page draws a
second (mismatched) type icon beside the field icon — that second icon is the
tell that a field/type pair is off.

**Timestamps are schema properties, not automatic.** A record gets `created`
and `updated` only if the schema declares them (`datetime` fields with
`onCreate` / `onUpdate` in `settings`, as the `builder-page` schema does).
Without them a record seeded by JumpStart or the CLI has no dates at all — no
sitemap `lastmod`, no `datePublished` / `dateModified` in the Article JSON-LD.
Put `updated` in the `index` so the sitemap can read it.

**Cards and decks need a full `formgrid` row** (`seo seo`, `address address`);
a half cell collapses the card's own grid. **Deck item keys** are letters,
digits and underscores — no hyphens — because items are read in Twig with dot
notation (`faqs.q1`, not `faqs['q-1']`). The admin converts as you type; it
only bites in data you write by hand (JumpStart, the API, imports).

**"Category" means five different things.** Ask which before modelling it:

| Meaning | It is |
|---|---|
| blog-style categories/tags, several per object, editor-extensible | `list` + `propertyOptions: true` (how the built-in `blog` schema does it) |
| a dropdown with fixed choices, one per object | `select` with static `options` |
| several fixed choices per object | `checklist` with static `options` |
| grouping collections in the admin sidebar | the collection's `category` setting |
| grouping schemas in the schema editor | the schema's top-level `category` (`Internal` is reserved — never use it) |

**Know what `relationalOptions` can do before designing around it.** It fills
a select from one collection or one Data View. Each option's value is one
property of an object (default `id`), and its label is one or more properties
or a `format` template. It cannot merge two collections, prefix a value
(`site:<id>`), or filter by the object being edited ("only this member's
items"). When the options need any of that, do not build a Data View to fake
it. Keep the field a `text` or plain `select` in the schema, and have the
front-end form pass `options` it built in Twig for that user. The admin can
edit the raw value.

### Ordering: sort by what the data already says

Do not reach for a `sort` or `order` number field first. It is the lazy
answer. Every new object needs a number, and inserting one in the middle
renumbers the rest. Two editors pick the same number, and the number means
nothing to anyone reading the record. Work through these in order and stop at
the first that fits:

1. **Look at how the list is used, then at the properties already there.**
   A blog reads newest first (`date`), a directory alphabetically (`name`,
   with `natural: true` so "Item 2" comes before "Item 10"), a price list by
   `price`, an events list by start date. Most lists already carry the
   property they should be ordered by.
2. **Rank the values of an existing property.** When the order follows a
   field with a fixed set of values (a team by `position`, a menu by
   `course`), the collection's `manualSort` setting lists those values in
   order and the `manualSort` filter applies it. Its `remainder` rule sorts
   anything not in the list. Editors never type a number.
3. **Chain sorts before adding anything.** `sortCollection` takes several
   keys, so "featured first, then newest, then by title" is one call, not a
   new field. The same rules are the `sort` option of `cms.collection.query()`.
4. **Only then add a property, and make its name say why the item moves.**
   - A `featured` toggle lifts a few items to the top.
   - A small `weight` select (1 to 3, default 2) lets an editor lead with one
     item or sink one without numbering the rest. An unset weight reads as
     the default.
   - Name the property for its intent (`featured`, `pinned`, `weight`), never
     `sort`.
   - If the order is meant to be fair, `shuffle` the list, then apply the
     weight with a stable sort so the shuffle holds within each weight.

A free position number is right only when the order is truly arbitrary and
editorial, with no property behind it and few enough items to keep in your
head (the steps of a process, say). Even then, ask whether those items belong
in one object's `deck` rather than in a collection of their own.

**Public pages need the SEO card.** Any schema whose objects render as pages
should carry `seo` (a `card` referencing the reserved `seo` schema), a
full-width `formgrid` row (`seo seo`), **and** `seo` in the `index` array —
without the index entry, noindex is ignored by the sitemaps. The collection
also needs its **URL** set, or objects get no canonical, no `og:url` and no
Article JSON-LD. Details: `docs/site-builder/seo.md`.

### Descriptions are read by agents, not just editors

Five slots feed the MCP tool catalog that other AI agents see: the schema
`description`, each property's `help` (or `mcp.description` when it should
differ from the editor-facing hint), the collection's `mcp` card
(`access`, `description`, `resource`) and each saved-query tool's
`description`. Generic text there produces generic content later.

Write each as a brief to a writer who cannot see the site: what the value is
for, its shape, what good looks like, constraints the field type does not
imply. Not "The title" but "Headline shown in listings and as the page
title. Sentence case, under 70 characters, no trailing period." Not
"Categories" but "Editorial sections this post belongs to, usually one. Pick
from the existing values; add a new one only for a genuinely new topic."
Examples for every slot: `docs/mcp/agent-editing.md`, section "Writing for agents".

Do not confuse these with a collection's general **Description** (admin
dashboard), the SEO mapping's **Description Template** (which composes the
meta description from the object's properties), or a Site Builder page's `description` (its
meta description). None of those reach an agent.

### Definition of done for schema work

```bash
vendor/bin/tcms schema:lint <id> --strict
```

Zero errors and zero warnings — every property has help text and the schema
has a description — **before** reporting the schema as finished. Do this on
the first pass; do not leave descriptions for a follow-up.

## Create / import content

Always through the CLI (or the API/MCP) — never by writing files into
`tcms-data/`. The CLI validates, fills derived fields and timestamps, updates
the index and fires events; a hand-written file does none of that.

One object — `object:create` (file path, or `-` for stdin):

```bash
echo '{"id":"hello","title":"Hello","body":"..."}' | vendor/bin/tcms object:create blog -
```

Change part of an existing object — `object:patch` merges only the fields you send:

```bash
echo '{"featured":true}' | vendor/bin/tcms object:patch blog hello -
```

Many objects — **`collection:import`** from JSON/CSV (JSON is an array of
objects conforming to the collection's schema):

```bash
vendor/bin/tcms collection:import blog posts.json
```

```json
[ { "id": "hello", "title": "Hello", "body": "..." } ]
```

Full-site bulk seeding — **`jumpstart:import`**. The **admin UI** works for
all of it, of course.

## Export / query

```bash
vendor/bin/tcms collection:query blog --json        # filters + pagination
vendor/bin/tcms collection:export blog --json        # JSON | CSV | ZIP
vendor/bin/tcms object:export blog hello             # single object (+assets as ZIP)
```

## Storage format

A collection stores objects as JSON by default. Set its `format` to
`markdown` (or run `vendor/bin/tcms collection:convert <id> --to=markdown`) to
store each object as a `.md` file with YAML frontmatter and the `content`
property as the body — the right shape for docs sites and markdown blogs.
Details: `docs/collections/storage-format.md`.

## Repair

If an index or file metadata gets out of sync:

```bash
vendor/bin/tcms repair:index blog
vendor/bin/tcms repair:files
```

Exhaustive reference: `vendor/totalcms/cms/resources/docs/{collections,schemas,fields}/`.

SHA-256: 992c81b8d95edab5a9afccfc56076fe1eecbaed7fa06584339b001bf2d64aea9