examples/src/migrate-one-endpoint/migrate-one-endpoint.ts. Execute it directly from the repository root with:
1. Before: A Typical Express Controller with Manual Plumbing
Most backend endpoints start simple and gradually accumulate retry loops, manual rollback state flags, and nestedtry/catch blocks:
2. Step-by-Step Migration (Zero Service Changes)
Notice thatinventoryService, paymentService, and shippingService are ordinary async TypeScript modules. Do not change them. Instead, wrap each call in Step.create() and attach its retry and rollback policy directly to the step.
Step A: Install @siglo/core
@siglo/express, @siglo/fastify, or @siglo/hono):
Step B: Wrap Your Existing Service Calls in Step.create
Create workflows/checkout.workflow.ts:
Step C: Call the Flow from Your Route Handler
You can either invokecheckoutWorkflow.run() directly inside your existing controller or mount it as a one-liner using @siglo/express, @siglo/fastify, or @siglo/hono:
3. What You Just Gained (With Zero New Infrastructure)
By migrating that single endpoint:- Guaranteed LIFO Rollbacks: If
createShipmentfails,chargeCustomerrefunds the payment first, andreserveStockreleases the inventory second. - Instant Architecture Diagrams in PRs: Run
npx @siglo/cli export workflows/checkout.workflow.ts --format=mermaidto generate an up-to-date Mermaid diagram with retry, timeout, and saga badges. - Deterministic Unit Tests in
<5ms: Test retries and rollbacks deterministically without hitting real APIs or waiting on real timers using@siglo/testing(createWorkflowHarness,FakeClock,mockStep). - Drop-In Observability: Add
@siglo/monitorfor a live local DevTools waterfall (http://localhost:4000) or@siglo/opentelemetryfor automatic step-level spans in Jaeger, Grafana, or Datadog.
