Tutorial: Adopt the CDX Approval Template
Use the shared approval family instead of rebuilding approval orchestration in each product.
1. Create the Factory
final approvalFactory = ApprovalWorkflowHandlerFactory.standard(
code: 'directory.entity-master-approval',
version: 1,
digest: 'directory.entity-master-approval:v1',
);The factory owns the workflow definition, schemas, work item references, revision loop, sequential and parallel strategies, quorum behavior, and terminal outcome vocabulary.
2. Implement Product Operations
The product owns IAM resolution and atomic domain effects:
final handlers = [
approvalFactory.refs.initialize.implement(initializeApproval),
approvalFactory.refs.refresh.implement(refreshApproval),
approvalFactory.refs.applyEffect.implement(applyApprovalEffect),
];applyApprovalEffect must update the product row, append its domain event, and record its effect receipt atomically under the operation idempotency key.
3. Build and Register the Handler
final approvalHandler = approvalFactory.buildHandler();
final module = WorkflowModule(
name: 'directory-approval',
workflows: [approvalHandler],
operations: handlers,
work: [
approvalFactory.refs.approvalWork,
approvalFactory.refs.revisionWork,
],
);4. Start Through the Service
Start with a typed ApprovalStart envelope containing the item snapshot, resolved policy snapshot, submitter, concrete audience levels, and execution policy. Product clients call the workflow service; Flutter does not call workflow storage.
5. Render the Inbox
cdx_feature_workflows renders server-provided WorkAction values, workflow status, and operation history. It does not reconstruct audience or approval policy.
6. Verify Adoption
- Test zero-, one-, and multi-level plans.
- Test sequential, parallel, and quorum execution.
- Test rejection, revision, resubmission, cancellation, and failure.
- Test repeated group slots and submitter exclusion.
- Test idempotent domain-effect application.
- Verify the product API and inbox use the same work item identifiers.