Skip to content
Skillpedia
APIs & servers (backend)8.1k · #12598

webiny-api-cms-content-models

What it does

This skill guides your AI when creating or changing CMS content models in a Webiny project through code. It is for developers who want their data structures defined in version-controlled code.

When to use it

  • ✓When you want to create a content model such as products or blog posts in code.
  • ✓When fields need validation or references to other models.
  • ✓When you need to choose the right admin display for a field type.

Skill link

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/content-models/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/content-models/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Create a content model for products in code with name, price and a reference to a category model.”

5 new skills a week. 1 minute to read.

How it works

The skill shows a model class that uses a fluent builder to declare fields, layouts, title fields and API names. The model is registered in the project's configuration file.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Creating Content Models via Code

TL;DR

Content models are created using the ModelFactory pattern. You define a class implementing ModelFactory.Interface, use the fluent ModelFactory.Builder API to declare fields, validators, layout, and API names, then export with ModelFactory.createImplementation(). Register in webiny.config.tsx as <Api.Extension>.

The ModelFactory Pattern

Every code-based content model follows the same structure:

import { ModelFactory } from "webiny/api/cms/model";

class MyModelImpl implements ModelFactory.Interface {
  async execute(builder: ModelFactory.Builder) {
    return [
      builder
        .public({ modelId: "myModel", name: "My Model", group: "ungrouped" })
        .description("Description of the model")
        .fields(fields => ({
          // field definitions here
        }))
        .layout([/* row definitions */])
        .titleFieldId("fieldId")
        .singularApiName("MyModel")
        .pluralApiName("MyModels")
    ];
  }
}

export default ModelFactory.createImplementation({
  implementation: MyModelImpl,
  dependencies: []
});

Register in webiny.config.tsx:

<Api.Extension src={"/extensions/MyModel.ts"} />

YOU MUST include the full file path with the .ts extension in the src prop. For example, use src={"/extensions/MyModel.ts"}, NOT src={"/extensions/MyModel"}. Omitting the file extension will cause a build failure.

YOU MUST use export default for the createImplementation() call when the file is targeted directly by an Extension src prop. Using a named export (export const MyModel = ...) will cause a build failure. Named exports are only valid inside files registered via createFeature.

Model Configuration Methods

Method Purpose
.public({ modelId, name, group }) Creates a public model (accessible via Read API). modelId is the internal DB identifier. group organizes it in the Admin sidebar.
.description("...") Model description shown in Admin UI
.fields(fields => ({ ... })) Define all fields using the fluent field builder
.layout([["field1", "field2"], ["field3"]]) Arrange fields in rows in the Admin editor. Each inner array is one row.
.titleFieldId("name") Which field to use as the entry's display title
.descriptionFieldId("message") Which field to use as the entry's description
.singularApiName("Product") Singular name for GraphQL queries (e.g., getProduct)
.pluralApiName("Products") Plural name for GraphQL queries (e.g., listProducts)
.singleEntry() Makes the model a singleton (only one entry can exist). Automatically adds
FAQ

How is the model registered?

As an API extension in the webiny configuration file, using the full file path with the .ts extension.

Can fields be nested?

Yes. The skill covers nested layouts inside object and dynamic zone fields.

Does it cover choosing field display types?

Yes. It explains which admin display to use for each field type.

Details

Original description by the author

Creating Headless CMS content models via code using the ModelFactory pattern. Use this skill when the developer wants to create, modify, or understand content model definitions, define fields and validators, set up reference fields between models, configure field layouts (including nested layouts inside object or dynamicZone fields), pick the correct Admin UI renderer for a field type (textInput/textInputs, lexicalEditor/lexicalEditors, file/files, objectAccordionSingle/objectAccordionMultiple, etc.), or work with the ModelFactory builder API. Also covers field types (text, longText, number, b

repo: webiny/webiny-js

Popularity

GitHub stars
8.1k
Ranking position
#12598
License
—
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills