Finance Domain Pattern

@namespace "com.example.finance"
@version "1.0.0"

Dimension "Currency"
Unit "USD" of "Currency" factor 1 base "USD"

Entity "Account" in finance
Entity "Ledger" in finance
Resource "Money" USD in finance

Flow "Transfer"
  @cqrs { "kind": "command" }
  @tx { "transactional": true }
  @idempotency { "enabled": true, "key": "transferId" }
from "Account" to "Account"

Flow "TransferCompleted"
  @cqrs { "kind": "event" }
  @outbox { "mode": "required" }
from "Ledger" to "EventBus"

Policy no_overdraft
  per Constraint Prohibition priority 10
as: forall a in entities where a.name = "Account": (a.balance >= 0)