# Entities

> How a recipe declares its tables — name, row count, fields, and the table-level constructs that shape whole rows.

Section: Recipes · Type: concept · Last updated: 2026-09-13

An entity is one table. It has a name, a row count, a list of fields, and optionally a construct that shapes whole rows at once: a constraint across columns, a flow through statuses, a tree, or a graph. The engine builds parents before children, so a table that others point at is always generated first.

## The picture

Recipe (one JSON file) → Entities (tables) → Fields (columns) → Rows (generated)

A recipe holds entities; an entity holds fields; the engine fills the rows.

## Table-level keys

- rows — How many rows this table gets.
- constraints (e.g. dispatched_on >= ordered_on) — A rule across columns that every row must satisfy. One per line. Dates compare as dates. Rows that fail are re-rolled, and the receipt says how often.
- flow — A status that is the end of a real journey, with dates in order. Names the status column, the legal moves between states, and which date column marks each one.
- tree — A hierarchy built level by level — loops impossible.
- graph — Parts connected through an edge table, quantities multiplied.

## Every key an entity accepts

- constraints, fields, flow, graph, name, no_overlap, rows, tree

## A two-table recipe

```json
{
  "project": "orders",
  "seed": 42,
  "output": {
    "format": "csv"
  },
  "entities": [
    {
      "name": "Customer",
      "rows": 50,
      "fields": [
        {
          "name": "id",
          "type": "id",
          "unique": true
        },
        {
          "name": "name",
          "type": "person.fullName"
        }
      ]
    },
    {
      "name": "Order",
      "rows": 200,
      "fields": [
        {
          "name": "id",
          "type": "id",
          "unique": true
        },
        {
          "name": "customer_id",
          "ref": "Customer.id"
        },
        {
          "name": "amount",
          "type": "finance.amount",
          "min": 5,
          "max": 900
        }
      ]
    }
  ]
}
```

Customer is built first because Order points at it.

> **Constructs are objects** — tree, flow, graph and no_overlap take an object whose sub-keys are read from the engine’s own structs; the Recipe keys reference lists each one. A construct the engine does not recognise is reported by validate_recipe, never silently ignored.

## Common questions

**Do I have to set rows on every table?**

No. A table without rows takes the run default — 100 from the CLI, or what --rows sets. A table that states its own count keeps it, whatever the flag says.

**What order are tables generated in?**

Parents before children. The engine reads ref fields to find the dependency order, so a foreign key always points at a row that already exists.

## Related

- [Fields & types](https://theworklens.com/docs/recipes/fields): Every field key a recipe accepts, the 20 value types the engine generates, and how a field declares a checksum-valid identifier.
- [Relationships](https://theworklens.com/docs/recipes/relationships): How tables point at each other — ref, scope and fanout on a field, and the relationship kinds a recipe can declare.
- [Recipe schema](https://theworklens.com/docs/reference/recipe-schema): The 13 top-level keys of a recipe, the minimal example, and what the engine supports and does not — from the schema it serves to agents.

_← Previous: [Recipes](https://theworklens.com/docs/recipes) · Next: [Fields & types](https://theworklens.com/docs/recipes/fields) →_

_Keys and one-line meanings come from the studio’s own reference tab and the engine vocabulary. Source: recipe-rules.ts + recipe-vocab.json._

_Canonical: https://theworklens.com/docs/recipes/entities · This copy: https://theworklens.com/docs/recipes/entities.md_
