Entities & Fields
Entities are persistent domain objects that form the backbone of your product's data model. They have identity, exist over time, and are referenced by workflows, surfaces, and rules. Alongside entities, you can define value objects, enums, actors, rules, and other domain constructs.
Defining an Entity
entity invoice {
invoice_id: uuid
customer: crm.customer
total: money
status: invoice_status = draft
notes: optional<string>
line_items: list
created_at: datetime
}
enum invoice_status {
draft
issued
paid
overdue
cancelled
} Field Types
| Category | Types |
|---|---|
| Primitives | string, integer, decimal, boolean, datetime, date, uuid |
| Rich types | money, email, phone, url, binary |
| Generics | optional<T>, list<T> |
| References | crm.customer (cross-module entity ref) |
| Defaults | status: invoice_status = draft |
Value Objects
Value objects are structured types without identity - they are compared by value, not by reference. Use them for addresses, money, coordinates, and other composite types.
value address {
street: string
city: string
state: string
zip: string
country: string
}
value line_item {
description: string
quantity: integer
unit_price: money
}Enums
Enums define a closed set of named values. Members can carry optional metadata for priority, labeling, or other properties.
enum priority {
low { label: "Low Priority" }
medium { label: "Medium Priority" }
high { label: "High Priority" }
critical { label: "Critical", escalation: true }
}Actors & Capabilities
Actors represent user roles or system identities. Capabilities group related permissions that actors can be granted.
actor customer {
title: "Customer"
description: "External customer who places orders"
}
actor accountant {
title: "Accountant"
description: "Internal staff managing invoices"
}
capability invoicing {
title: "Invoice Management"
actors: [accountant]
}Rules
Rules express business constraints that are enforced across workflows and surfaces.
rule customer_must_exist {
entity: invoice
condition: customer != null
message: strings.customer_required
}
rule total_positive {
entity: invoice
condition: total > 0
message: strings.total_must_be_positive
}Entity Lifecycle
Entity lifecycle is modeled through enums and workflow transitions. Define an enum for the entity's states, then use workflow transitions blocks to declare valid state changes. The compiler validates that all transitions are reachable and valid.
workflow issue_invoice {
transitions {
invoice.status: draft -> issued
}
}
workflow pay_invoice {
transitions {
invoice.status: issued -> paid
}
}
workflow cancel_invoice {
transitions {
invoice.status: draft -> cancelled
invoice.status: issued -> cancelled
}
}