# PyCharter Examples

## domain_lifecycle_pystator_example.py

Demonstrates **domain entity contracts** with **lifecycle binding** and optional integration with PyStator:

1. Build an in-memory domain contract (order and weekly optimization) with `metadata.governance_rules.lifecycle`.
2. Read `state_machine_name` and `state_field` via `get_domain_entity_info()`.
3. Validate payloads with PyCharter's `Validator`.
4. Optionally call PyStator API to process an event (requires `pystator api` running).

**Run from repo root:**

```bash
python examples/domain_lifecycle_pystator_example.py
```

To exercise the PyStator API path, start PyStator and set the API base URL:

```bash
pystator api   # in another terminal, default port 8004
PYSTATOR_API_URL=http://localhost:8004 python examples/domain_lifecycle_pystator_example.py
```

See [Domain Models and Lifecycle](../docs/guides/domain-models-and-lifecycle.md) for the full guide.
