Process — business processes as state machines

A node type declares its business process once, in its configuration. The … menu then offers exactly the moves whose business rules hold now. It follows the node as the node changes. Opening a move shows the rules it requires, each marked ✓ or ✗, the input it asks for, and the button that takes it.

What happens when a move is taken

  1. Re-check: the server reads the node and the input, then checks every rule again.
  2. Pre-processing: the move's Before steps run; any of them may refuse with a reason.
  3. Write: the new state is written, after the move's After steps.
  4. History: an entry is recorded beside the node, at {node}/_Process/{at}-{move}, of type Process/Transition.

Declaring a process

public static readonly ProcessDefinition<Deal> Definition =
    Process.Of<Deal>("Sales")
        .StateOf(d => d.Status, (d, s, today) => d with { Status = s, StatusChangedAt = today })
        .States("Received", "Quoted", "Bound", "Declined")
        .Initial("Received")
        .Terminal("Bound", "Declined")
        .Move("quote", "Send the offer", ["Received"], "Quoted")
            .Requires("PRICED", "The deal is priced", c => c.Content.Priced)
            .After((c, d) => d with { QuotedOn = c.Today })
        .Move("decline", "Decline", ["Received", "Quoted"], "Declined")
            .Asks(nameof(ProcessInput.Reason)).Closing()
        .Build();

The node type then adds shared=@Process/Source to its sources, and .AddProcess(Definition) to its configuration.

The vocabulary

Clause What it declares
StateOf(get, set) Where the state is stored on the content. The vocabulary is open: strings, not an enum.
States(…) · Initial(…) · Terminal(…) The states. A terminal state offers no move.
Move(id, label, from, to) A move. to: null keeps the state, for a move that records, waits or chases.
.Requires(id, text, holds) A business rule the move requires. It is refused by its id when the rule does not hold.
.Before(step) Pre-processing on the server. A non-null answer refuses the move with that reason.
.After(step) Post-processing: the content after the move.
.Asks(field) The input the move's page asks: Reason, Choice or Date. It is required unless declared otherwise.
.Closing() A closing move such as decline or lose.
.Gates("Approval") Declared on the process, before the moves. Each move also requires the gates the related node {node}/Approval publishes for it.

Some rules belong to another node and to another package's code. An approval form knows whether its sign-offs are complete, and an intake record knows whether its checks pass. That node type publishes its gates with config.AddProcessGates(host => …): a list of ProcessGate { Id, Text, Holds, Tags }, where the tags name the moves the gate guards. They appear as data in its ProcessGates area.

A process that declares .Gates("Approval") reads that area live, as plain JSON, so neither node type compiles the other. A failing gate refuses the moves it is tagged with, exactly like a declared rule. A related node that does not exist publishes no gates. When a move is taken, a related node that exists but does not answer refuses the move.

Checks