Collections

Define content types with TypeScript schemas and field validation. Collections are the foundation of your content model in CatCMS. [object Object]

Overview

Collections define your content types using TypeScript schemas. Each collection automatically gets:

  • Type-safe database schema
  • Automatic API endpoints
  • Admin UI for content management
  • Field validation and constraints
  • Version control through git

Two Types of Collections

Config-Managed Collections:

  • Defined in TypeScript files (src/collections/*.collection.ts)
  • Version controlled with your codebase
  • Automatically synced on app startup
  • Locked from editing in the admin UI (marked with β€œConfig” badge)
  • Type-safe with IDE autocomplete

UI-Created Collections:

  • Created and edited through the admin interface
  • Stored directly in the database
  • Not version controlled
  • Fully editable in the UI
  • Great for rapid prototyping

Creating Collections

Basic Collection

Create a new file in src/collections/ with a .collection.ts extension:

Blog Posts Collection

Syncing Collections

Collections are automatically synced on server startup. You can also manually sync:

Sync Collections


Field Types

CatCMS supports 30+ field types for building rich content schemas:

Text Fields

  • Name
    string
    Type
    string
    Description

    Single-line text input. Use for titles, names, short text.

  • Name
    textarea
    Type
    string
    Description

    Multi-line plain text. Use for descriptions, notes, long text.

  • Name
    email
    Type
    string
    Description

    Email with validation. Use for contact emails, author info.

  • Name
    url
    Type
    string
    Description

    URL with validation. Use for links, external resources.

  • Name
    slug
    Type
    string
    Description

    URL-friendly identifier. Use for page URLs, SEO paths.

  • Name
    color
    Type
    string
    Description

    Color picker. Use for theme colors, UI customization.

Rich Content

  • Name
    richtext
    Type
    string
    Description

    WYSIWYG HTML editor. Use for blog posts, articles, formatted content.

  • Name
    markdown
    Type
    string
    Description

    Markdown editor. Use for documentation, technical content.

  • Name
    json
    Type
    object
    Description

    JSON editor. Use for structured data, API responses.

Numbers and Dates

  • Name
    number
    Type
    number
    Description

    Numeric input. Use for prices, quantities, ratings.

  • Name
    date
    Type
    string
    Description

    Date picker (no time). Use for birthdays, deadlines.

  • Name
    datetime
    Type
    string
    Description

    Date and time picker. Use for publish dates, events.

Selections

  • Name
    select
    Type
    string
    Description

    Dropdown (single choice). Use for categories, status fields.

  • Name
    multiselect
    Type
    array
    Description

    Dropdown (multiple choices). Use for tags, multiple categories.

  • Name
    radio
    Type
    string
    Description

    Radio buttons. Use for status, visibility options.

  • Name
    checkbox
    Type
    boolean
    Description

    Boolean checkbox. Use for feature toggles, flags.

Media and Files

  • Name
    media
    Type
    string
    Description

    Image/media picker. Use for featured images, avatars.

  • Name
    file
    Type
    string
    Description

    File upload. Use for PDFs, documents, downloads.

Relationships

  • Name
    reference
    Type
    string
    Description

    Reference to another collection. Use for authors, categories.

  • Name
    array
    Type
    array
    Description

    Array of items. Can contain any field type.


Validation

Built-in Validators

Field Validation

Validation Rules

  • required - Field must have a value
  • minLength / maxLength - String length constraints
  • minimum / maximum - Number range constraints
  • pattern - Regular expression validation
  • enum - Must be one of specified values
  • default - Default value if not provided

Examples

E-commerce Product

Product Collection

Documentation Page

Docs Collection

Event Management

Events Collection


Using Collections

Query Content

Fetch Collection Content

API Endpoints

Collections automatically get REST API endpoints:

GET /api/collections/{collection}/content
Get all content from a collection
GET /api/content/{id}
Get single content item
POST /admin/content Auth required
Create new content
PUT /admin/content/{id} Auth required
Update content
DELETE /admin/content/{id} Auth required
Delete content

Best Practices

Collection Design Tips

  • Use descriptive field names that reflect your content model - Set appropriate validation rules to maintain data quality - Use references for relationships between collections - Enable search on fields that users will query frequently - Set reasonable defaults for optional fields

Performance Considerations

  • Limit the number of fields in listFields to improve list performance - Use appropriate field types (e.g., select instead of string for fixed options) - Index frequently queried fields in your database

Next Steps

Was this page helpful?