State Lens — Lifecycles
Summary
Section titled “Summary”State Lens answers: which lifecycle states and transitions are declared for this part of the system?
When to use it
Section titled “When to use it”Use it when allowed changes over time need an explicit view: a booking moves from pending to confirmed, or an order from packed to shipped. Start with three states and named triggers. State Lens references domain and storage concepts; it is distinct from the planned standalone STM model. Do not assume that displaying a machine provides a simulator.
Before you begin
Section titled “Before you begin”Choose one entity with a meaningful lifecycle. List its states and the business events or actions that trigger changes.
Understand the model
Section titled “Understand the model”Explain the state before explaining the arrow
Section titled “Explain the state before explaining the arrow”A booking can be pending, confirmed or cancelled. Each state should have a clear business meaning. A transition describes a permitted change and names the trigger that requests or causes it. A useful first machine is small enough that someone can narrate every transition without guessing.
A state machine is different from a screen map. A confirmed booking may be displayed on several screens, and one screen may show bookings in many states. Keep the domain lifecycle separate from navigation. Where a state corresponds to an aggregate concept or storage enum, link the source rather than silently maintaining a second independent definition.
Read validation at the right level
Section titled “Read validation at the right level”A transition to an undeclared state is structurally invalid. A well-formed declaration can still express a poor lifecycle, omit a necessary transition or fail to match deployed behavior. Review those questions against business examples. Stronger claims about reachable states or temporal properties need an analysis method that actually checks them.
State Lens also makes provenance useful. A state or invariant can point back to the model element it describes. This helps a reviewer discover whether a lifecycle change came from an approved domain change or an interpretation of runtime observations. The current layer should not be confused with a generic statechart runtime. When a simulator or implementation runner is used, its supported semantics and assumptions must be stated explicitly.
Worked example
Section titled “Worked example”Describe Pending → Confirmed and Pending → Cancelled for a booking.
- Name the triggers confirm and cancel.
- Explain whether Confirmed → Cancelled is allowed under the business rule.
- Add a deliberately invalid transition to a nonexistent Archived state and run structural validation where available.
- Correct the missing state or remove the invalid reference, then review the intended lifecycle again.
The structural error is a machine-checkable problem. Agreement that the allowed transitions fit the business remains a domain review; enforcement belongs in implementation tests.
Practice examples
Section titled “Practice examples”These four exercises are lesson briefs. Their dedicated CtxBazaar recipes and browser launch actions are planned; see Learning with models for available downloads and the meaning of each result.
| Exercise | Try this | Expected observation |
|---|---|---|
| Booking lifecycle | Describe pending, confirmed and cancelled with named transition triggers. | A reviewer can identify the intended lifecycle paths. |
| Orphan transition | Point a transition at a state that does not exist. | Structural validation reports the missing state rather than accepting the declaration. |
| Aggregate provenance | Link the booking machine to its DDD aggregate and status representation. | A reader can locate the source concepts without duplicating their authority. |
| Terminal state review | Review a shipped-order state with no cancellation transition. | Explain the intended restriction; runtime enforcement still requires a test or verified adapter. |
Common mistakes
Section titled “Common mistakes”- Confusing the screen currently displayed with the domain’s lifecycle state.
- Assuming a structurally valid machine proves all intended states are reachable.
- Calling a rendered machine a simulation when no simulator has run.
Visual walkthrough
Section titled “Visual walkthrough”A booking changes state—and an orphan arrow is caught. Three state nodes appear; a trigger moves the conceptual focus; an arrow to an unnamed destination is highlighted as a structural error.
Pause and predict: Would adding the missing state automatically prove that the lifecycle is correct?
This is the text storyboard for a proposed short illustrated film. The written walkthrough and exercises are available now; a published movie will be added after its scenes, captions and model references have been reviewed.
Background and history
Section titled “Background and history”State-machine and statechart methods make behavior explicit through states and transitions. Stately’s introduction to its editor shows a contemporary tool that separates designing a machine from simulating one. State Lens is ContextBrew’s lifecycle layer, with its own representation and cross-model provenance; it does not imply XState compatibility.
The lens names machines, states, transitions, triggers and invariant references. Its structural validator can identify links to nonexistent states. That is useful evidence about the declaration, but different from proving reachability, temporal properties or deployed behavior. Link a machine back to its aggregate or enum so a lifecycle explanation has a clear source. A simulator, runtime trace or implementation test must declare its own assumptions and runner before producing stronger conclusions.
Alternatives and trade-offs
Section titled “Alternatives and trade-offs”A transition table is often enough for a small lifecycle. XState/statecharts offer an execution-oriented toolchain; formal temporal methods answer stronger verification questions at a higher cost. DDD carries business invariants and SCM carries navigation, which should not be confused with domain state.
References
Section titled “References”- Stately’s introduction to its editor
- Learning with models — choose a practice workflow and interpret its results.
