Skip to Content
FeaturesModels

Models

A model defines the structure and behavior of your content in Foir. Every piece of data — pages, blog posts, bookings, product records, configurations — is stored as a record that belongs to a model.

Overview

A model is a schema definition that controls what data your records can hold and how they behave. Each model has:

  • Key — A unique identifier used in APIs and configuration (e.g., page, blog-post, booking)
  • Name — A display name shown in the console
  • Fields — The schema that defines the shape of each record (see Field Types)
  • Config — Capability flags that control versioning, publishing, variants, and more

Model Capabilities

Every model has a config object that enables or disables features:

CapabilityDescriptionDefault
versioningTrack change history; each update creates a new versionOff
publishingDraft/publish workflow; records are not live until explicitly publishedOff
variantsMultiple content versions for different audiences (device, segment, market)Off
embeddingsMaintain vector embeddings of this model’s prose so its records can be found by meaning (see AI & Search)Off

Record ownership is configured separately from these capability flags, via the model’s top-level access field (ownerPlane: user | project | organization) — see Defining Models → Model Access.

These capabilities are mix-and-match, and the relationship between them is derived rather than enforced. A model is effectively versioned when it declares versioning or publishing or variants — any one of the three is enough, and nothing refuses a model that declares publishing without versioning. The console turns the prerequisites on for you, which is why the chain reads as a rule; the platform does not check it on write.

There is one guard, and it runs in the other direction. A config edit that would turn effective versioning off — dropping the last of the three from a model that had one — is refused with FAILED_PRECONDITION, unless the model holds no records. Existing records store their content in version rows that the un-versioned read path never consults, so allowing it would mutate a stale inline blob and serve it back: silent content loss rather than a mode change. Turning it on migrates in the same transaction; turning it off has no defined migration, so it is refused until one exists.

Whether a model is record-bearing or embedded (inline) is not a capability flag. It is the model’s kind, chosen when you create the model. You can change it later only while nothing depends on it: a record-bearing model becomes embedded only while it has no records, and an embedded model becomes record-bearing only while no other model embeds it. Record-bearing models are automatically available on the public API as standalone types; inline models are usable as a field type inside other models rather than queried on their own (see Inline Schemas). There is no separate “public API” flag.

Hierarchy

A model’s records form a tree when one of its reference fields declares the hierarchy relationship kind. That field is the tree edge, and declaring it is the whole of it — there is no capability flag beside it.

You name the field, choose what it points at, and place it wherever it reads best:

{ key: 'page', name: 'Page', config: { versioning: true, publishing: true }, fields: [ // ...your fields { key: 'parent', type: 'reference', label: 'Parent', config: { multiple: false, referenceTypes: ['page'], placement: 'settings', relationship: { kind: 'hierarchy' }, }, }, ], }

A model with a tree edge reserves ancestors and path, because the platform serves both beside its fields. A model without one reserves nothing — path on a model of shipments is a shipping path and nothing takes it away.

Three rules the platform enforces on the edge:

  • One per model. It is the edge ancestors and path walk, and a second leaves both undefined.
  • Single-valued. A record has one parent; a list of them is a graph, not a tree.
  • Not on an embedded model, which bears no records to parent.

referenceTypes on the edge is yours. A parent need not share its child’s model — a collection and a product can both sit under a page — because the walk follows each ancestor’s own tree edge, not the model it started from. Name only the models that really are parents: two or more targets make parent a GraphQL union, and every caller then has to project it through inline fragments.

placement: 'settings' above is not specific to hierarchy — it is available on any field, and puts it on the record editor’s Settings tab instead of the content form. It suits the tree edge because where a record sits is a setting rather than something the record says, but that is a choice you make, not one the platform makes for you.

Two virtual fields come with it, computed on every read and never stored — so a re-parent is correct on the next request with no backfill, no webhook and no sync job:

query { page(naturalKey: "japan-26") { path # "/lookbook/japan-26" ancestors { _naturalKey } # [{ _naturalKey: "lookbook" }] } }

The same read through the data client — both fields are part of the complete-by-default selection, so nothing asks for them:

const page = await foir.page.findUnique({ naturalKey: 'japan-26' }); page.path; // "/lookbook/japan-26" page.ancestors.map((a) => a._naturalKey); // ["lookbook"]
  • ancestors is flat and root-first, and carries identity only (_id, _naturalKey, _modelKey). Identity-only is deliberate: a child’s public URL already exposes its ancestors’ slugs, so the walk never widens what a caller can see. For an ancestor’s content, follow parent like any other reference.
  • path is the raw key join — every ancestor’s natural key root-first, then the record’s own. Locale prefixing stays yours: it belongs to your routing, not to the data.

Filtering by parent is an ordinary where-input, which is how you read one level of children:

query { pages(where: { parent: { id: { eq: "rec_lookbook" } } }) { edges { node { _naturalKey } } } }
const children = await foir.page.findMany({ where: { parent: { id: { eq: 'rec_lookbook' } } }, });

Walk semantics, all of them deliberate:

SituationWhat you get
No parentancestors: [], path is / followed by the record’s own key
A cycleThe walk stops at the repeat and still returns — a data bug must not 500 a page
An ancestor you cannot see, or that no longer existsIdentity still projects; path is null, because a partial join composes the wrong URL

The edge itself is unconstrained — any record may be a parent. Your modelling bounds the tree, not the platform.

Use Case Categories

Simple Data (no capabilities) — For application data that needs direct read/write without overhead. Records are updated in place with no drafts, versions, or publishing step. Examples: form submissions, bookings, app configuration, feature flags, counters.

Published Content (versioning + publishing) — For content that needs a review workflow. Each edit creates a new version, and content stays in draft until explicitly published. Examples: blog posts, announcements, documentation, policies.

Personalized Content (versioning + publishing + variants) — For content that changes based on audience. Variants target different devices, markets, or user segments, and each variant has its own version history. Examples: landing pages, navigation menus, promotional banners, product descriptions.

Reusable Components (inline kind) — For models used as field types inside other models. When a model is created with the inline kind, its key becomes available as a field type. Examples: hero banners, CTAs, testimonials, product cards.

Quick Reference

Use CaseVersioningPublishingVariants
Blog postsYesYesNo
Landing pagesYesYesYes
Navigation menusYesYesYes
Form submissionsNoNoNo
App configurationNoNoNo
Event bookingsNoNoNo
Hero banners (inline)NoNoNo

In the console

  1. Go to Content > Models
  2. Click Create Model
  3. Fill in:
    • Name: e.g., “Blog Post”
    • Key: auto-generated from the name (e.g., blog-post), or set manually
  4. Choose the model’s kind: record-bearing or embedded (inline). You can change it later only while nothing depends on it.
  5. Configure capabilities (versioning, publishing, variants)
  6. Add fields to the schema
  7. Click Save

Model schemas track changes with version history. When you edit a model’s fields, a new schema version is created, and you can restore a previous schema version if needed.

Via the CLI

List all models

foir models list

Get a model by key

foir models get blog-post

Create a model

foir models create --data '{ "key": "blog-post", "name": "Blog Post", "fields": [ { "key": "title", "label": "Title", "type": "text", "required": true }, { "key": "slug", "label": "Slug", "type": "text", "required": true }, { "key": "body", "label": "Body", "type": "prose" } ], "config": { "pluralName": "Blog Posts", "versioning": true, "publishing": true } }'

foir models create takes a single model definition via --data/-d (inline JSON) or --file/-f (a JSON file). For bulk or declarative model management — defining your models in code and syncing them all at once — use foir push instead (see Config System).

Update a model

The model is identified by its key (positional argument); pass the changed fields with --data:

foir models update blog-post --data '{ "name": "Blog Post", "fields": [...] }'

Delete a model

foir models delete blog-post

List schema versions

foir models versions blog-post

Via the API

Who may read a model’s definition

On the platform API, listing models, reading one and reading the project’s whole schema (ListModels, GetModel, GetProjectSchema) take models:read. Reading or writing a model’s records does not include it.

The data API is separate. Its models query takes schemas:read, and its introspection shows a credential the types and fields that credential may query. Neither is the platform’s read of a definition, so a key that reads records and holds no models:read still introspects what it may read.

List models

The public API exposes a single models query that returns the project’s models as a plain list. It takes an optional category filter and requires the schemas:read scope.

No SDK equivalent — models describes the shape of your project, which is what the data client’s manifest (GET /v1/manifest) already is; a second source of the same fact would disagree with the manifest the moment one is cached and the other is not. Your models themselves are the data client’s whole subject — each record-bearing model gets its own typed operations. See Choosing an API Style.

query { models(category: "content") { key name description pluralName pluralKey category capabilities { isVersioned isPublishable hasVariants } fields { key label type required } } }

There is no id field, no raw config JSON, and no pagination/search/filter arguments — capabilities are surfaced through the capabilities object:

FieldMeaning
isVersionedThe model tracks version history
isPublishableThe model has a draft/publish workflow
hasVariantsThe model supports content variants

The models query lists every model in the project, inline models included. The difference is in the typed query layer: only record-bearing models get their own typed root queries; inline models have no standalone records, so they surface only as field types embedded in other models.

Config System

Models can also be defined in code using defineModel in your foir.config.ts file. This is useful for version-controlling your model schemas alongside your application code.

See Model Configuration for the full reference.

Best Practices

  • Choose the minimal set of capabilities each model needs. Simpler models are faster and easier to work with. Remember the dependency chain: publishing implies versioning, and variants implies both.
  • Use clear, descriptive keys. The key is permanent and used throughout your APIs and configuration.
  • Enable inline for models meant to be embedded as field types rather than queried as standalone records.
  • Use foir push to sync model definitions declaratively from your codebase, rather than creating them one at a time.
  • Track schema changes with meaningful descriptions so you can review and roll back if needed.
Last updated on