Collections
Collections are the content types of SHADE. Core has none built in; modules add their own: the website module's pages, navigation, footer and posts, the shop's products, or a client's own module's events or vacancies (Writing a client module). One definition in code drives everything:
| From the definition | Where |
|---|---|
TypeScript types (EntryData<typeof collection>) | shade/features/entries/shared/infer.ts |
| Validation (Zod, per mode: draft / publish / patch) | buildEntrySchema |
| Database tables, versions, child and join tables | generator → shade/features/entries/server/collections.generated.sql.ts → migration |
Permissions collections.<slug>.<verb> | registered at API startup, typed via ActionRegistry |
Admin API /api/collections/:slug and content API /api/v1/content/collections/:slug | apps/admin |
| Admin list and edit screens, sidebar group | shade/features/entries/admin |
SDK client shade.collection('…') | shade/sdk |
| MCP access (opt-in, drafts only) | shade/features/ai/server/mcp/collection-tools.ts |
Collections compile to real SQL tables rather than a generic table with a JSON blob per row, so the data has real columns, indexes, foreign keys and join tables, like a dedicated application.
Defining a collection
Built-in collections live in shade/features/entries/shared/builtin/. A module lists its collections in its
manifest (collections: [...], slugs prefixed <plugin>-) and declares their actions next to them (see
modules/commerce/shared/collections.ts). A definition looks like this:
import { defineCollection } from '@shadestack/core/collections'
export const teamMembers = defineCollection({
slug: 'team-members',
labels: { singular: 'Team member', plural: 'Team members' },
titleField: 'name',
slugField: 'slug',
fields: [
{ kind: 'text', name: 'name', label: 'Name', required: true, index: true },
{ kind: 'slug', name: 'slug', label: 'Slug', required: true, unique: true, from: 'name' },
{ kind: 'email', name: 'email', label: 'Email', unique: true },
{ kind: 'image', name: 'photo', label: 'Photo' },
{ kind: 'select', name: 'seniority', label: 'Seniority', options: [
{ label: 'Junior', value: 'junior' }, { label: 'Medior', value: 'medior' }, { label: 'Senior', value: 'senior' }
] },
{ kind: 'relation', name: 'department', label: 'Department', to: 'departments' },
{ kind: 'relation', name: 'skills', label: 'Skills', to: 'skills', many: true },
{ kind: 'repeater', name: 'links', label: 'Links', fields: [
{ kind: 'text', name: 'label', label: 'Label', required: true },
{ kind: 'url', name: 'url', label: 'URL', required: true }
] },
{ kind: 'richtext', name: 'bio', label: 'Bio' }
],
admin: { group: 'Company', icon: 'i-lucide-users', listColumns: ['name', 'seniority', 'status', 'updatedAt'] },
publicApi: {},
access: { editor: ['read', 'create', 'update', 'publish', 'delete'] }
})
Every link to an entry in the admin (the AI changes, the dashboard, a file's uses) opens the collection's form. A
collection a module edits on a screen of its own names it in admin.editorRoute, an admin path in which :id stands
for the entry's id (editorRoute: '/website/theme' for a singleton), and those links lead there instead. On the AI
changes screen a singleton has no title of its own, so its row carries the collection's name.
Then:
pnpm db:collections # regenerate shade/features/entries/server/collections.generated.sql.ts (built-in collections)
pnpm db:generate # drizzle-kit writes the SQL migration — review it in the PR
pnpm db:migrate
Until 0.1.0 no instance is live, so there is no data to protect: renaming a table, a column, an enum value or a name
stored in rows is done in place, in the schema, and db:generate writes the migration (when it asks whether a column
was renamed or dropped and added, either answer is fine). No alias, no kept old name and no test on data. From 0.1.0
on, a rename is written by hand (drizzle-kit generate --custom) and tested on a database holding rows under the old
names. Core's shade/kernel/db/migrations/README.md ("Adding one") says how.
A module's collections get their tables in the module, with the same generator: shade-module collections writes
server/collections.generated.sql.ts and the module's own pnpm db:generate its migration
(see Writing a module). Core's migration history and
each module's were squashed into one baseline on 17 November 2026, and are squashed again just before 0.1.0. A
database migrated by an earlier history is refused at start with a message to reset it: drop it and make it again
(docker compose down -v, or drop the database), as no client runs SHADE yet.
What it becomes in the database
team_members
id uuid primary key
name text -- + index
slug text unique
email text unique
photo_id uuid references media(id) on delete restrict
seniority text check (seniority in ('junior', 'medior', 'senior'))
department_id uuid references departments(id) on delete restrict
bio jsonb -- rich text is a document
status entry_status not null default 'draft'
latest_version_id, published_version_id uuid references team_members_versions(id)
published_at, created_at, updated_at, created_by, updated_by
team_members_skills -- many relation → join table
parent_id uuid references team_members(id) on delete cascade
skills_id uuid references skills(id) on delete restrict
position integer
team_members_links -- repeater → child table
id uuid primary key
parent_id uuid references team_members(id) on delete cascade -- named team_members_links_parent_fk
position integer
label text
url text
team_members_versions -- immutable snapshots, same typed columns
id, parent_id, version_note, version_author_id, version_created_at,
name, slug, email, photo_id, seniority, department_id, bio
team_members_versions_skills, team_members_versions_links -- mirrored child tables
Mapping rules
| Field | Storage |
|---|---|
| text, textarea, email, url, slug | text (+ index / unique) |
| emails | jsonb not null default '[]' |
| number | integer, or numeric with decimals |
| money | integer: whole cents (1250 is € 12,50); min and max in cents |
| toggle | boolean not null default false |
| date | date, or timestamptz with time: true |
| select | text + check constraint |
| image, file | <name>_id → media |
| relation | <name>_id → target table |
| relation (many) | join table <table>_<name> with position |
| link | <name>_kind, <name>_collection, <name>_entry_id (no foreign key), <name>_url, <name>_anchor, <name>_new_tab |
| group | prefixed columns <group>_<field> |
| repeater | child table <table>_<name> with parent_id, position (nested repeaters nest tables) |
| richtext | jsonb (a document) |
| tree | jsonb (a validated node tree) |
| json | jsonb, nullable (the value its module's check gave back) |
JSON is used only for documents (rich text, page trees and a module's own documents in json fields), all validated before they are saved. Everything you filter, sort, relate or report on is a real column.
Drafts and history
- The main table is the working copy; every save also writes an immutable snapshot to
<slug>_versions. published_version_idpoints at the live snapshot; the content API only ever reads published snapshots.drafts: falseturns this off (saves are live, no versions table) — for data that is not published content.
Integrity
- References from main and child tables use
on delete restrict: you cannot delete media, a page or an entry that is still used. The services report a readable CONFLICT first; the database is the backstop. - References from versions tables use
on delete set null: history never blocks a delete. - Singletons have
id integer primary key default 1 check (id = 1). - A published entry always has its published version:
<slug>_published_version,status <> 'published' or published_version_id is not null, on every main table with drafts. indexesadds composite indexes, andwheremakes one partial, over the rows whose fields hold the given values. One default header and one default footer, for instance:indexes: [{ fields: ['kind'], unique: true, where: { default: true } }](<slug>_kind_when_default_unique). A save check can still give the readable answer first; the index holds the rule when two saves run at once.- The content API reads the published versions, so the versions table gets the same indexes as plain ones (versions
share a slug), its translations
(locale, column)for them, and the main table a unique index onpublished_version_id(<slug>_published_version_unique): one entry by its slug stays an index lookup however often it is saved.
Changing a collection
| Change | Migration |
|---|---|
| Add a field | add column (nullable) — safe |
| Rename a field | drizzle-kit asks "rename or drop+create?" — answer rename to keep data |
| Remove a field | drop column — visible in review; data is gone |
| Change a field's kind | usually drop + add; write a manual data migration if values must be kept |
Add unique | fails if existing rows have duplicates — clean them first |
Built-in collections
Core has none: every collection comes from a module. The forms module keeps its forms in forms-forms
(Forms).
The website module adds these (each with its locales and versions tables):
| Collection | Tables | Edited in |
|---|---|---|
website-pages | website_pages | the visual editor |
website-navigation (singleton) | website_navigation, website_navigation_items, website_navigation_items_children | the entry editor with a live layout preview |
website-footer (singleton) | website_footer, website_footer_columns, website_footer_columns_links, website_footer_social | the entry editor with a live layout preview |
website-posts | website_posts | the collection screens; each post gets a page from its item template |
website-parts | website_parts | Header and footer: the site's headers and footers as trees, one default of each, others picked per page |
A collection with itemPages: true (and a slug field and publicApi) gets a page per published item, built from
the page marked as its template in the page settings: /<item path>/<slug>.
The pages service is a typed facade over the generic collection service, so the page editor, MCP tools and
public API keep their dedicated shapes. Navigation and footer are edited as plain entries; getPublishedLayout
(the website module's server/layout.ts) reads them in their public shape.
Using entries on the site
A frontend gets its collections' types from the instance with shade-types, a command of @shadestack/client. It
reads the instance's OpenAPI document with a read token and writes the published data of each collection with a
public API the token may read:
npx shade-types --url https://admin.example.org --token "$SHADE_TOKEN" --out src/shade-types.ts
The address and token may come from SHADE_API_URL and SHADE_TOKEN instead of --url and --token. Without
--out the types are printed. Write the file again when the collections change. Give the types to the client, and
collection(slug) knows each collection's data:
import { createShadeClient } from '@shadestack/client'
import type { ShadeCollections } from './shade-types'
const shade = createShadeClient<ShadeCollections>({ baseUrl: process.env.SHADE_API_URL!, token: process.env.SHADE_TOKEN! })
const members = await shade.collection('team-members').all({ sort: 'name' })
// members[0].data.name: string
The framework packages take the same types. shadeFromEnv<ShadeCollections>() in @shadestack/next,
@shadestack/nuxt and @shadestack/sveltekit, and createSiteClient<ShadeCollections>() from
@shadestack/client/render, give a site client whose collection(slug) knows each collection's data and which still
finds pages. @shadestack/astro has no read client of its own: import createShadeClient or createSiteClient from
@shadestack/client or @shadestack/client/render.
Only the fields the public API shows are in the types. A relation is the related entry's id, or with depth the entry
itself ({ id, collection, data }), and null when that entry is not published. A json field's value is unknown.
Code that has the collection's definition, such as a module's own site part, can type the data with it instead:
import type { EntryData } from '@shadestack/core/collections'
import type { teamMembers } from '@shadestack/config/collections'
const members = await shade.collection<EntryData<typeof teamMembers>>('team-members').all({
where: { seniority: { eq: 'senior' } },
sort: 'name'
})
Field types
Each field kind is one folder, shade/fields/<kind>/:
| File | What it holds |
|---|---|
shared.ts | The descriptor type (TextField), its Zod schema, its columns (plan), model checks, flags (scalar, title, slugSource), structure (nested, joins), the empty value and the list cell. Browser-safe. |
server.ts | Row mapping (toColumns, fromColumns), the filterable column, references and referrers. |
admin/ | The editor component (FieldText.vue), named by component in shared.ts. |
The entries feature (features/entries) looks a field's type up (fieldType(field), serverFieldType(field)) instead of
switching over kinds; it only knows the three structures a type can have: its own columns, nested fields in the
same table (group) or a child table (repeater), and a join table (many relation). Adding a field type: a folder
with those parts, its kind in FIELD_KINDS, and one line in fields/shared.ts and fields/server/index.ts.
Languages
Every entry exists in all of the site's languages. The default language is stored in the entry's
own columns; each table with translatable fields has a <table>_locales table for the other languages, generated
with the rest (pnpm db:collections).
- A field is translatable when its type says so (text, textarea, rich text, slugs) or it sets
translatable: true;translatable: falsekeeps it shared. - A field's part in search is
search: 'A' | 'B' | 'C' | 'D' | false(weights, best first;falseleaves it out, and on a group or repeater everything inside). Without it the title countsA, text and slugsB, textarea and rich textC, the rest not at all (Search). GET /api/collections/<slug>/<id>?locale=enreturns the entry in English;meta.missinglists the text that is not translated and shows the default language (paths are written likeitems.2.label). Which translations are out of date is the editorial module's, with its own routes and the entry list's column. The content API says nothing about it: it serves published text.PUT …withlocale: 'en'saves the English text:dataholds translatable fields only, repeater items with theirid(a tree keeps every language in its texts). Structure is edited in the default language.- Repeater items carry an
idin entry data. Send it back when saving: the item is updated in place and keeps its translations; items without anidare new. - A translated unique field (a slug) is unique per language.