Model Spec
Define your data model using attributes, relationships, and config options.
A Model Spec is the foundation of every Locospec application. It defines the structure of your data: fields, types, relationships, and configuration—used to auto-generate queries, filters, forms, and more.
🧩 Basic Structure
🔑 Required Fields
| Field | Type | Description |
|---|---|---|
name | string | Unique name (used in URLs, etc.) |
type | "model" | Type identifier |
label | string | Human-friendly label |
config | object | DB connection & primary key info |
attributes | object | Field definitions |
⚙️ config
Defines how the model connects to your database and behaves at runtime.
| Key | Type | Description |
|---|---|---|
primaryKey | string | Primary key column (default: id) |
labelKey | string | Key to display as a label in dropdowns, etc. |
connection | string | DB connection name |
softDelete | boolean | Enable soft delete support |
deleteColumn | string | Column used for soft deletes (default: deleted_at) |
table | string | (optional) override inferred table name |
🧱 attributes
Defines the fields and data types for this model.
Each attribute supports:
type: Data type (e.g.,string,uuid,timestamp,jsonb, etc.)label: Human-readable labelgenerations: Rules for automatic value generation (e.g. slug, UUID)validations: Field-level validation rules with custom messages
🔗 relationships
Defines links to other models.
Supported types:
belongs_tohas_onehas_many
Each relationship defines:
model: Related model nameforeignKey: Foreign key on current or related modellocalKey/ownerKey: Column used for joining
🎯 scopes
Reusable filter logic for this model.
Each scope is a named filter, used in views and queries to simplify logic.
🧪 aliases
Virtual fields used for referencing nested paths or transforming data using JMESPath expressions.
| Field | Description |
|---|---|
source | Path to another attribute, supports dot notation |
transform | A JMESPath expression used to derive or modify values |
🖼 defaultView
Declare a quick, opinionated default view for this model.
Useful when bootstrapping UI tables without writing a full view spec.