Spec Canvas Docs
Spec Formats

Data Spec

Reference for the Data Spec format — document structure, fields, and validation rules.

This page describes the structure of a Data Spec document. A Data Spec describes the logical data model of an application — business entities, their fields, and relationships. It is not a physical database schema but a conceptual model that AI agents can interpret to generate database schemas, API endpoints, validation logic, and more.

For methodology and workflows, see How It Works. For advanced techniques, see Patterns & Practices.

Public format file: data-spec-format-0-0-1.yaml

Document Root

A Data Spec document is a YAML file with the following top-level fields.

FieldTypeRequiredDescription
docTypestringyesAlways data-spec
format_versionstringyesFormat version (e.g., "0.0.1")
metadataobjectyesDocument metadata
descriptionstringnoDetailed description of the system
enumsobjectnoEnumeration definitions
entitiesobjectyesEntity definitions (the core of the spec)
relationsarraynoRelationships between entities
diagramobjectnoVisualization settings

Metadata

The metadata object describes the data model.

FieldTypeRequiredDescription
namestringyesName of the system or data model
versionstringnoVersion of this Data Spec
authorstringnoAuthor name
created_atdatenoCreation date
updated_atdatenoLast update date
description_shortstringnoOne-line summary

Description

An optional multi-line text field at the document root. Describes the system's purpose, goals, and main capabilities.

description: |
  Task management system for small teams.
  Supports projects, tasks with deadlines, and team collaboration.
  Integrates with calendar and notification services.

Enums

Enumerations define fixed sets of values used by entity fields. Each enum is defined under enums with a unique name (snake_case).

Short Form

For simple enums without descriptions per value.

enums:
  task_status:
    values: [draft, active, completed, archived]
    description: "Lifecycle status of a task"

Full Form

For enums where each value needs a label or description.

enums:
  priority:
    description: "Task priority level"
    values:
      - name: low
        label: Low
        description: "Can be done when time allows"
      - name: medium
        label: Medium
        description: "Should be done this week"
      - name: high
        label: High
        description: "Must be done today"
      - name: critical
        label: Critical
        description: "Requires immediate attention"

Entities

Entities are the core of a Data Spec. Each entity represents a business object and is defined under entities with a unique name (snake_case).

FieldTypeRequiredDescription
labelstringnoHuman-readable name
descriptionstringnoWhat this entity represents
table_namestringnoDatabase table name if different from the entity name
fieldsobjectyesField definitions
unique_constraintsarraynoComposite unique constraints

Fields

Each field is defined under fields with a unique name (snake_case).

FieldTypeRequiredDescription
typestringyesData type (see below)
labelstringnoHuman-readable field name
descriptionstringnoWhat this field represents
requiredbooleannoField is required for business logic (default: false)
pkbooleannoPrimary key (default: false)
uniquebooleannoUnique constraint (default: false)
defaultanynoDefault value (e.g., now, uuid_generate_v4(), or a literal)
fkstringnoForeign key reference in format entity_name.field_name

Field Types

Seven base logical types are available.

TypeDescription
stringText value
integerWhole number
decimalNumber with decimal precision
booleanTrue or false
datetimeDate and time
uuidUniversally unique identifier
jsonArbitrary JSON structure

A field type can also reference an enum name defined in the enums section.

fields:
  status:
    type: task_status    # references the task_status enum
    required: true

Unique Constraints

Composite unique constraints define combinations of fields that must be unique together.

unique_constraints:
  - [project_id, task_number]
  - [user_id, email_type]

Entity Example

entities:
  task:
    label: Task
    description: "A unit of work assigned to a user within a project"
    fields:
      id:
        type: uuid
        pk: true
      title:
        type: string
        required: true
        description: "Task title"
      status:
        type: task_status
        required: true
        default: draft
      priority:
        type: priority
        required: true
        default: medium
      due_date:
        type: datetime
        description: "Deadline for the task"
      project_id:
        type: uuid
        required: true
        fk: project.id
      assignee_id:
        type: uuid
        fk: user.id
      created_at:
        type: datetime
        default: now
    unique_constraints:
      - [project_id, title]

Relations

Relations describe logical relationships between entities. Each relation is bidirectional (entity_a ↔ entity_b) with a specified cardinality.

FieldTypeRequiredDescription
entity_astringyesFirst entity name
entity_bstringyesSecond entity name
cardinalitystringyesone_to_one, one_to_many, or many_to_many
labelstringnoShort relationship name (e.g., "contains", "assigns")
descriptionstringnoDetailed description of the relationship

Cardinality Types

CardinalityMeaningExample
one_to_oneEach A has exactly one BUser → Profile
one_to_manyEach A has many BProject → Tasks
many_to_manyA has many B, B has many AStudents ↔ Courses

Relations Example

relations:
  - entity_a: project
    entity_b: task
    cardinality: one_to_many
    label: "contains"
    description: "A project contains multiple tasks"

  - entity_a: user
    entity_b: task
    cardinality: one_to_many
    label: "is assigned"
    description: "A user can be assigned to multiple tasks"

  - entity_a: user
    entity_b: project
    cardinality: many_to_many
    label: "participates in"
    description: "Users participate in multiple projects, projects have multiple members"

Diagram

Optional visualization settings for ER diagrams. Used by Spec Canvas to render entity relationship diagrams.

FieldTypeRequiredDescription
formatstringnoVisualization format (e.g., mermaid)
hintsobjectnoLayout hints for diagram nodes

Node Hints

Each entity can have optional positioning and styling hints under hints.nodes.

FieldTypeDescription
xnumberHorizontal position
ynumberVertical position
groupstringLogical group or subdomain name
colorstringNode color (hex)
diagram:
  format: mermaid
  hints:
    nodes:
      project:
        x: 100
        y: 100
        group: core
        color: "#4CAF50"
      task:
        x: 300
        y: 100
        group: core
        color: "#2196F3"

Using with UI Spec

When a Data Spec and a UI Spec exist in the same project, the UI Spec can reference entities and fields in block purposes. AI agents understand these references and use them for type-safe code generation.

# In a UI Spec block:
purpose: "Form for creating a new Task. Fields: Task.title (required), Task.priority (dropdown), Task.due_date (date picker), Task.assignee_id (user selector)"

The AI agent reads the Data Spec to understand field types, constraints, enum values, and relationships — and generates appropriate UI controls, validation, and data binding. For more on integrating Data Spec with UI Spec, see Patterns & Practices.

On this page