> ## Documentation Index
> Fetch the complete documentation index at: https://docs.threadify.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating a Contract

> Define business rules and validation logic for your workflows

**Contracts** define business rules and validation logic that enforce how steps should execute and relate to each other. They provide real-time validation and ensure business processes follow defined patterns.

### Contract Properties

* **Name** - Unique identifier for the contract
* **Version** - Supports contract evolution
* **Rules** - Validation logic for steps and transitions
* **Entry Points** - Valid starting steps
* **Terminal Steps** - Steps that complete the thread
* **Timeouts** - Maximum duration for steps and threads

### Contract Structure

<CodeGroup>
  ```yaml YAML theme={null}
  contract_name: order_fulfillment
  version: 1
  description: E-commerce order fulfillment workflow

  # Entry points - where threads can start
  entry_points:
    - order_placed

  # Parties involved in the workflow
  parties:
    - merchant
    - logistics

  # Steps in the workflow
  steps:
    - id: order_placed
      owner: merchant
      type: managed
      timeout: 5m
      business_context:
        required:
          - order_id
          - product_id
          - quantity
        optional:
          - customer_notes

    - id: inventory_checked
      owner: merchant
      type: managed
      timeout: 1m
      business_context:
        required:
          - in_stock
          - warehouse_id

    - id: shipment_created
      owner: logistics
      type: managed
      timeout: 24h
      business_context:
        required:
          - tracking_number
          - carrier_name

  # Transitions define valid step flows
  transitions:
    - from: order_placed
      to:
        - inventory_checked

    - from: inventory_checked
      to:
        - shipment_created
        - order_cancelled

  # Terminal steps - where threads can end
  terminal_steps:
    - order_delivered
    - order_cancelled

  # Thread-level timeout
  max_duration: 7d
  ```
</CodeGroup>

### Key Components

| Component        | Description                                        |
| ---------------- | -------------------------------------------------- |
| `contract_name`  | Unique identifier for the contract                 |
| `version`        | Contract version number (supports evolution)       |
| `entry_points`   | Valid starting steps for threads                   |
| `parties`        | Roles involved in the workflow                     |
| `steps`          | Step definitions with timeouts and required fields |
| `transitions`    | Valid step-to-step flows                           |
| `terminal_steps` | Steps that complete the thread                     |
| `max_duration`   | Thread-level timeout                               |

### Next Steps

<CardGroup cols={2}>
  <Card title="Working with Contracts" icon="file-contract" href="/core-concepts/working-with-contracts">
    Learn how to use contracts in your code
  </Card>

  <Card title="Tracking Workflows" icon="route" href="/core-concepts/tracking-workflows">
    Record steps in your workflow
  </Card>
</CardGroup>
