# Entity schemas

> The JSON format for declaring tables, fields, types and defaults.


```json
{
  "name": "Task",
  "type": "object",
  "properties": {
    "title":    { "type": "string", "description": "What needs doing" },
    "done":     { "type": "boolean", "default": false },
    "priority": { "type": "string", "enum": ["low", "medium", "high"], "default": "medium" },
    "due":      { "type": "string", "format": "date" },
    "tags":     { "type": "array", "items": { "type": "string" } },
    "estimate": { "type": "number" }
  },
  "required": ["title"],
  "rls": { "read": true, "create": true, "update": { "created_by": "{{user.email}}" }, "delete": { "created_by": "{{user.email}}" } }
}
```

## Rules

- `name` is PascalCase and must match how you call it: `ds.entities.Task`.
- `type` is always `"object"`; put `properties` at the top level.
- Field types: `string`, `number`, `integer`, `boolean`, `array`, `object`. Useful string formats: `date`, `date-time`, `email`, `uri`.
- `default` fills missing fields on create; `required` rejects creates that lack them.
- `rls` is optional; see [Security rules](/docs/developers/backend/security).
- Comments (`//`) are allowed — the files are read as JSONC.

## Relationships

Store the related record's `id`: an `Order` with `customer_id`, then `ds.entities.Customer.get(order.customer_id)` or `filter({ customer_id })`.
