# One form for every type

Every type is declared the same way, `type Name = Base { ... }`. The base
says what the type is built from, and the block holds the details: rules for
a number or text, fields for an object, variants for an enum. An `entity` is
declared on its own, because it is more than a type: it is stored, and it has
actions, queries and policy ([Data](data.md)).

```jadpo
type ItemPrice = Decimal {  // rules on a number
    scale: 2
    min: 0.00
}

type StockCode = Text {  // rules on text
    pattern: "[A-Z]{3}-[0-9]{4}"
}

type OrderId = Uuid {}  // a new identity type with no extra rules

type OrderLine = Object {  // fields
    sku: StockCode
    price: ItemPrice
}

type OrderStatus = Enum {  // variants
    pending
    paid
    shipped
}

type PaymentOutcome = Enum {  // variants that carry fields
    pending
    paid: {
        receipt_id: ReceiptId
    }
    declined: {
        reason: DeclineReason
    }
}

type CreateOrder = Input {  // an object arriving from outside
    lines: List<OrderLineRequest>
    note: OrderNote {
        optional: true
    }
}

type OrderView = Output {  // an object sent back
    id: Order.id
    total: ItemPrice
}
```

- `Object`, `Enum`, `Input` and `Output` are only ever used as a base here.
  There is no anonymous object written inline; every shape has a name.
- `Input` objects may have `optional` and `default` fields and are the only
  objects a route accepts. `Output` objects are the only objects a route
  returns.
- There are no `value`, `enum`, `input` or `output` keywords, and the
  `types/` folder holds only `type` declarations.
