E-Commerce Platform

This flagship example models a practical e-commerce fulfilment journey as a set of DCL language assets. It is intentionally architectural: the model separates customer ordering, warehouse work, delivery, locally owned events, operational policies, and order lifecycle coordination.

The source files shown on this page are validated with the current compiler: DCL v0.9, compiler 0.1.0.

Open in Playground

Overview

The platform is split by business responsibility. Storefront owns the customer-facing order submission language, including basket and checkout inputs, OrderCreated, and checkout policies. Warehouse owns fulfilment inputs and warehouse events. Delivery owns courier confirmation and delivery events. A small Coordination context depends on the operating contexts only to supervise the end-to-end lifecycle.

Customer
  -> Ecommerce.Storefront emits OrderCreated
  -> Ecommerce.Warehouse emits OrderPickedEvent
  -> Ecommerce.Warehouse emits PackageReadyForDelivery
  -> Ecommerce.Delivery emits PackageDelivered
  -> Ecommerce.Coordination reaches Delivered

Context Map

Ecommerce.Storefront
  owns: customer shopping, checkout, and order submission
  actors: Customer, InventorySystem, PaymentProvider
  shapes: ProductSearch, BasketItemInput, SubmitOrderInput
  events: OrderCreated
  policies: CheckoutReliability, OrderAudit
  capabilities: BrowseProducts, AddToBasket, Checkout,
                SelectPaymentMethod, CaptureShippingAddress,
                CaptureBillingAddress, SubmitOrder

Ecommerce.Warehouse
  owns: picking, packaging, and warehouse readiness events
  actor: WarehouseOperator
  shape: FulfilmentOrderInput
  events: OrderPickedEvent, PackageReadyForDelivery
  capabilities: PickOrder, PackageOrder

Ecommerce.Delivery
  owns: courier confirmation and delivery completion events
  actor: Courier
  shape: DeliveryConfirmationInput
  event: PackageDelivered
  capability: DeliverPackage

Ecommerce.Coordination
  owns: cross-context lifecycle supervision
  depends on Storefront, Warehouse, Delivery
  supervising capability: ManageOrderFulfilment

Actors

The model includes the customer-facing actor, operational actors, and two system actors. The system actors let the language distinguish responsibilities around stock ownership and payment processing without binding to a runtime.

ecommerce/storefront/actors.dcl
language dcl 0.9

context Ecommerce.Storefront {
  actor Customer is human
  actor InventorySystem is system
  actor PaymentProvider is system
}
ecommerce/warehouse/actors.dcl
language dcl 0.9

context Ecommerce.Warehouse {
  actor WarehouseOperator is human
}
ecommerce/delivery/actors.dcl
language dcl 0.9

context Ecommerce.Delivery {
  actor Courier is human
}

Storefront Context

Storefront captures the customer path from product discovery through order submission. It demonstrates intents from Customer, validation rules, persistence and integration effects, event emission, and policy attachment.

ecommerce/storefront/shapes.dcl
language dcl 0.9

context Ecommerce.Storefront {
  shape ProductSearch {
    query: Text required
    category: Text
  }

  shape BasketItemInput {
    basketId: Uuid required
    productId: Uuid required
    quantity: Number required
  }

  shape BasketCheckoutInput {
    basketId: Uuid required
    customerId: Uuid required
  }

  shape PaymentMethodInput {
    basketId: Uuid required
    paymentToken: Text required
  }

  shape ShippingAddressInput {
    basketId: Uuid required
    recipientName: Text required
    line1: Text required
    city: Text required
    postalCode: Text required
    country: Text required
  }

  shape BillingAddressInput {
    basketId: Uuid required
    line1: Text required
    city: Text required
    postalCode: Text required
    country: Text required
  }

  shape SubmitOrderInput {
    orderId: Uuid required
    basketId: Uuid required
    customerId: Uuid required
    paymentToken: Text required
    shippingPostalCode: Text required
  }
}
ecommerce/storefront/policies.dcl
language dcl 0.9

context Ecommerce.Storefront {
  policy CheckoutReliability {
    family reliability
    retry {
      attempts 3
      backoff exponential
    }
    idempotency required
    timeout 5 minutes
  }

  policy OrderAudit {
    family governance
    audit required
    retention 7 years
  }
}
ecommerce/storefront/browse-products.dcl
language dcl 0.9

context Ecommerce.Storefront {
  capability BrowseProducts {
    intent ProductSearch from Customer

    outcomes {
      ProductsReturned
      InvalidSearch
    }

    rule SearchTermPresent: input.query is present

    when {
      SearchTermPresent violated then InvalidSearch
      otherwise then ProductsReturned
    }
  }
}
ecommerce/storefront/basket.dcl
language dcl 0.9

context Ecommerce.Storefront {
  effect AddBasketItemRecord is persistence

  capability AddToBasket {
    intent BasketItemInput from Customer

    outcomes {
      ItemAdded
      ProductUnavailable
      InvalidQuantity
    }

    rule QuantityPositive: input.quantity is greater than 0

    effect AddBasketItemRecord

    when {
      QuantityPositive violated then InvalidQuantity
      AddBasketItemRecord unresolved then ProductUnavailable
      otherwise then ItemAdded
    }
  }
}
ecommerce/storefront/checkout.dcl
language dcl 0.9

context Ecommerce.Storefront {
  effect StartCheckoutSession is persistence
  effect StorePaymentMethod is persistence
  effect StoreShippingAddress is persistence
  effect StoreBillingAddress is persistence

  capability Checkout {
    intent BasketCheckoutInput from Customer

    outcomes {
      CheckoutStarted
      EmptyBasket
    }

    effect StartCheckoutSession

    when {
      StartCheckoutSession unresolved then EmptyBasket
      otherwise then CheckoutStarted
    }
  }

  capability SelectPaymentMethod {
    intent PaymentMethodInput from Customer

    actors {
      payer: Customer
      processor: PaymentProvider
    }

    outcomes {
      PaymentMethodSelected
      PaymentMethodRejected
    }

    rule PaymentTokenPresent: input.paymentToken is present

    effect StorePaymentMethod

    when {
      PaymentTokenPresent violated then PaymentMethodRejected
      StorePaymentMethod unresolved then PaymentMethodRejected
      otherwise then PaymentMethodSelected
    }
  }

  capability CaptureShippingAddress {
    intent ShippingAddressInput from Customer

    outcomes {
      ShippingAddressCaptured
      InvalidShippingAddress
    }

    rule PostalCodePresent: input.postalCode is present

    effect StoreShippingAddress

    when {
      PostalCodePresent violated then InvalidShippingAddress
      StoreShippingAddress unresolved then InvalidShippingAddress
      otherwise then ShippingAddressCaptured
    }
  }

  capability CaptureBillingAddress {
    intent BillingAddressInput from Customer

    outcomes {
      BillingAddressCaptured
      InvalidBillingAddress
    }

    rule BillingPostalCodePresent: input.postalCode is present

    effect StoreBillingAddress

    when {
      BillingPostalCodePresent violated then InvalidBillingAddress
      StoreBillingAddress unresolved then InvalidBillingAddress
      otherwise then BillingAddressCaptured
    }
  }
}
ecommerce/storefront/order.dcl
language dcl 0.9

context Ecommerce.Storefront {
  effect ReserveInventory is invocation
  effect ProcessPayment is invocation
  effect PersistOrder is persistence

  event OrderCreated is {
    orderId: Uuid required
    customerId: Uuid required
  }

  capability SubmitOrder {
    intent SubmitOrderInput from Customer

    actors {
      buyer: Customer
      stockOwner: InventorySystem
      processor: PaymentProvider
    }

    outcomes {
      OrderAccepted
      PaymentDeclined
      StockUnavailable
      OrderRejected
    }

    rule ShippingPostalCodePresent: input.shippingPostalCode is present

    effects {
      ReserveInventory
      ProcessPayment after ReserveInventory
      PersistOrder after ProcessPayment
    }

    events {
      emits OrderCreated
    }

    policies {
      CheckoutReliability governs capability
      OrderAudit governs event OrderCreated
    }

    when {
      ShippingPostalCodePresent violated then OrderRejected
      ReserveInventory unresolved then StockUnavailable
      ProcessPayment unresolved then PaymentDeclined
      PersistOrder unresolved then OrderRejected
      otherwise then OrderAccepted
    }
  }
}

Warehouse Context

Warehouse owns fulfilment work after the storefront creates an order. The context defines the fulfilment input and emits warehouse-owned events that the supervising lifecycle can observe.

ecommerce/warehouse/fulfilment.dcl
language dcl 0.9

context Ecommerce.Warehouse {
  effect RecordPick is persistence
  effect CreateParcel is persistence

  shape FulfilmentOrderInput {
    orderId: Uuid required
  }

  event OrderPickedEvent is {
    orderId: Uuid required
  }

  event PackageReadyForDelivery is {
    orderId: Uuid required
  }

  capability PickOrder {
    intent FulfilmentOrderInput from WarehouseOperator

    outcomes {
      OrderPicked
      ItemMissing
    }

    effect RecordPick

    events {
      emits OrderPickedEvent
    }

    when {
      RecordPick unresolved then ItemMissing
      otherwise then OrderPicked
    }
  }

  capability PackageOrder {
    intent FulfilmentOrderInput from WarehouseOperator

    outcomes {
      OrderPackaged
      PackagingFailed
    }

    effect CreateParcel

    events {
      emits PackageReadyForDelivery
    }

    when {
      CreateParcel unresolved then PackagingFailed
      otherwise then OrderPackaged
    }
  }
}

Delivery Context

Delivery records the courier confirmation and emits the final package event. A failed delivery remains explicit as a capability outcome instead of being hidden inside infrastructure behavior.

ecommerce/delivery/delivery.dcl
language dcl 0.9

context Ecommerce.Delivery {
  effect RecordDeliveryProof is persistence

  shape DeliveryConfirmationInput {
    orderId: Uuid required
    deliveredAt: DateTime required
    proofOfDelivery: Text
  }

  event PackageDelivered is {
    orderId: Uuid required
  }

  capability DeliverPackage {
    intent DeliveryConfirmationInput from Courier

    outcomes {
      Delivered
      DeliveryFailed
    }

    effect RecordDeliveryProof

    events {
      emits PackageDelivered
    }

    when {
      RecordDeliveryProof unresolved then DeliveryFailed
      otherwise then Delivered
    }
  }
}

Event Flow

Cross-context coordination happens through declared events. The flow is: customer submits an order, Storefront emits its OrderCreated event, Warehouse emits OrderPickedEvent and PackageReadyForDelivery, Delivery emits PackageDelivered, and the lifecycle reaches Delivered.

Storefront.SubmitOrder
  emits OrderCreated

Warehouse.PickOrder
  emits OrderPickedEvent

Warehouse.PackageOrder
  emits PackageReadyForDelivery

Delivery.DeliverPackage
  emits PackageDelivered

Order Lifecycle

Supervising lifecycle syntax is supported by the current compiler, so this lifecycle is compiled as current DCL. ManageOrderFulfilment names Storefront, Warehouse, and Delivery capabilities as contributors and advances through Submitted, Picking, Packaging, OutForDelivery, and Delivered.

ecommerce/order-lifecycle.dcl
language dcl 0.9

context Ecommerce.Coordination {
  depends on Ecommerce.Storefront
  depends on Ecommerce.Warehouse
  depends on Ecommerce.Delivery

  capability ManageOrderFulfilment {
    intent FulfilmentOrderInput from Customer

    outcome OrderLifecycleOpened

    policies {
      OrderAudit governs lifecycle
    }

    observe {
      lifecycle transitions
      event OrderCreated count as ecommerce_orders_created
      event PackageDelivered count as ecommerce_packages_delivered
    }

    when {
      always then OrderLifecycleOpened
    }

    supervises lifecycle OrderFulfilment {
      identity orderId

      contributors {
        SubmitOrder
        PickOrder
        PackageOrder
        DeliverPackage
      }

      begin Submitted

      step Submitted waits for event OrderCreated from SubmitOrder

      step Picking waits for event OrderPickedEvent from PickOrder

      step Packaging waits for event PackageReadyForDelivery from PackageOrder

      step OutForDelivery waits for event PackageDelivered from DeliverPackage

      end Delivered
      end Failed

      move Submitted to Picking
        on event OrderCreated from SubmitOrder

      move Picking to Packaging
        on event OrderPickedEvent from PickOrder

      move Packaging to OutForDelivery
        on event PackageReadyForDelivery from PackageOrder

      move OutForDelivery to Delivered
        on event PackageDelivered from DeliverPackage

      move Picking to Failed
        on outcome ItemMissing from PickOrder

      move Packaging to Failed
        on outcome PackagingFailed from PackageOrder

      move OutForDelivery to Failed
        on outcome DeliveryFailed from DeliverPackage
    }
  }
}

What This Demonstrates

  • Actors for customers, warehouse operators, couriers, and external systems.
  • Contexts with explicit dependencies and business-owned declarations.
  • Capabilities with intents, outcomes, rules, effects, events, and policies.
  • Cross-context event flow without a generic shared declarations context.
  • A compiled supervising lifecycle that coordinates multiple contributors.
  • Multi-file composition using source files under website/src/examples/ecommerce.

Complete Source

Compile all files together from the repository root with:

cd compiler
go run ./cmd/dcl check ../website/src/examples/ecommerce/storefront/actors.dcl ../website/src/examples/ecommerce/storefront/shapes.dcl ../website/src/examples/ecommerce/storefront/policies.dcl ../website/src/examples/ecommerce/storefront/browse-products.dcl ../website/src/examples/ecommerce/storefront/basket.dcl ../website/src/examples/ecommerce/storefront/checkout.dcl ../website/src/examples/ecommerce/storefront/order.dcl ../website/src/examples/ecommerce/warehouse/actors.dcl ../website/src/examples/ecommerce/warehouse/fulfilment.dcl ../website/src/examples/ecommerce/delivery/actors.dcl ../website/src/examples/ecommerce/delivery/delivery.dcl ../website/src/examples/ecommerce/order-lifecycle.dcl
  • website/src/examples/ecommerce/storefront/actors.dcl
  • website/src/examples/ecommerce/storefront/shapes.dcl
  • website/src/examples/ecommerce/storefront/policies.dcl
  • website/src/examples/ecommerce/storefront/browse-products.dcl
  • website/src/examples/ecommerce/storefront/basket.dcl
  • website/src/examples/ecommerce/storefront/checkout.dcl
  • website/src/examples/ecommerce/storefront/order.dcl
  • website/src/examples/ecommerce/warehouse/actors.dcl
  • website/src/examples/ecommerce/warehouse/fulfilment.dcl
  • website/src/examples/ecommerce/delivery/actors.dcl
  • website/src/examples/ecommerce/delivery/delivery.dcl
  • website/src/examples/ecommerce/order-lifecycle.dcl