Skip to main content

Sequence Diagrams

Released at v0.1.4, applied to the k3s cluster

Derived from model/model.yaml. The customer-payments service is built on develop (IQVO/customer-payments at 054b3de, checked 2026-12-02), released at v0.1.4 and applied to the k3s cluster: the api and the A2A agent are deployed, the MCP server is registered in warehouse-infra and switched off. Every Err... name, REST route and CloudEvents type of this context named on this page exists in the service; where the built service differs from the model's design, the page says so (As built) or the context's Service and operations section lists it.

One UML sequence diagram per command use case on Use Cases. Participant names are the packages and ports the model designs, from the Class Diagram:

  • http, kafka consumer and scheduler are the inbound adapters. As built (054b3de), two more, mcp (cmd/mcp) and a2a (cmd/a2a), serve the four reads only (diagram 9).
  • The use case is in internal/application/usecases.
  • PaymentProvider is the outbound adapter behind the Anti-Corruption Layer port (Authorize, Capture, Void, Refund, Reauthorize, ReduceAuthorization); the payment-provider simulator answers behind it. It is the context's only synchronous dependency.
  • Postgres stands for the repositories, the parked facts, the outbox, the inbox and the idempotency store. They share one transaction through UnitOfWork.
  • Relay / Kafka is the outbox relay. It reads committed outbox_events rows and publishes them to retailnetwork.customer-payments.events — the only topic the context writes to (all eight events are analytics-only by design).

The provider call is made before the transaction opens and carries the deterministic key per (operation, authorizationId, groupNo); a crash between the call and the commit repeats the call with the same key. Every save is conditional on the loaded version (optimistic concurrency). Full CloudEvents types are on Domain Events.

1. AuthorizePayment (REST POST /payment-authorizations)​

Derived from: model.yaml → contexts[customer-payments].aggregates[PaymentAuthorization].commands[AuthorizePayment], .invariants, .notes, .rest["POST /payment-authorizations"], .sync_calls, .publishes[PaymentAuthorized, PaymentDeclined].

Omitted: the optimistic-concurrency branch (a new row has none). A unique index on the session's live authorization also catches two concurrent first calls under different keys: the loser's insert fails and is answered 409 duplicate-authorization. A sequential second authorize under a different key is not an error: it returns the existing live authorization with 200.

2. VoidAuthorization (REST POST /payment-authorizations/authorizationId/voids)​

Derived from: model.yaml → contexts[customer-payments].aggregates[PaymentAuthorization].commands[VoidAuthorization], .transitions, .rest, .sync_calls; contexts[checkout].sync_calls[VoidAuthorization].

Omitted: the scheduler trigger of VoidUnboundAuthorizations, which runs the same use case without the HTTP branches (no Idempotency-Key; the authorization is selected as unbound for 24 h).

3. RequestRefund and RecordRefundOutcome (REST POST /refunds, Kafka PackageLost, PackageReturned)​

Derived from: model.yaml → contexts[customer-payments].aggregates[Refund] (commands, transitions, invariants), .policies[RefundOnLostPackage, RefundOnReturnToSender], .rest["POST /refunds"], .sync_calls, .publishes[RefundIssued, RefundFailed].

Omitted: the optimistic-concurrency branch and RetryRefund (FAILED → REQUESTED, at most 5 attempts, then the refund stays FAILED with an operator alert; ErrOverRefund counts REQUESTED and issued refunds, never FAILED). On the policy path the group comes from the tracking number stored on its allocation at capture (H6), and the refund carries groupNo and authorizationId (H12). The REST route answers 201 with the refund in its final state when the provider replies in the same request; a slower outcome would leave REQUESTED visible through GET /refunds, a detail the model does not specify.

4. CaptureAllocation (Kafka FulfillmentShipped)​

Derived from: model.yaml → contexts[customer-payments].consumes[FulfillmentShipped], .policies[CaptureOnShipment], .aggregates[PaymentAuthorization] (commands, transitions, invariants), .read_models, .sync_calls, .publishes[PaymentCaptured].

Omitted: the version-conflict retry. An unexpected error is not acknowledged, so the event is redelivered and the deterministic provider key makes the repeated Capture safe. The capture happens before the guards in this drawing; an implementation may run the aggregate guards first, so a capture the aggregate would refuse never reaches the provider (the model does not fix the order).

5. ReleaseAllocation (Kafka FulfillmentCancelled, FulfillmentUnsourceable)​

Derived from: model.yaml → contexts[customer-payments].consumes[FulfillmentCancelled, FulfillmentUnsourceable], .policies[ReleaseOnCancellation, ReleaseOnUnsourceable], .aggregates[PaymentAuthorization] (commands, invariants), .publishes[PaymentReleased].

Omitted: the provider-error branch. A partial release calls the provider port's ReduceAuthorization(amount) (H4). The reason is CANCELLED for FulfillmentCancelled and UNSOURCEABLE for FulfillmentUnsourceable; the state follows the allocations, so releasing the last one gives RELEASED (or CAPTURED when some were captured) (H3).

6. BindOrder and apply parked facts (Kafka CheckoutCompleted)​

Derived from: model.yaml → contexts[customer-payments].consumes[CheckoutCompleted], .policies[BindOrderOnCheckoutCompleted], .read_models[ParkedFulfillmentFacts], .aggregates[PaymentAuthorization].commands[BindOrder].

Omitted: the transactional detail of each applied fact (see sequences 3 to 5). The bind commits first, so a fact arriving while the parked ones are applied already finds a bound order; the model does not fix whether the bind and the replay share one transaction.

7. ReauthorizePayment (scheduler)​

Derived from: model.yaml → contexts[customer-payments].policies[ReauthorizeBeforeExpiry], .aggregates[PaymentAuthorization].commands[ReauthorizePayment], .sync_calls.

Omitted: the idempotency detail — the scan selects only authorizations close to expiry and the provider key is deterministic, so a second sweep repeats the same call. A successful reauthorization keeps the state AUTHORIZED and records the new expiresAt and provider reference (H1); a provider decline moves the authorization to EXPIRED (H2). A provider timeout is retried by the next sweep.

8. ExpireAuthorization (provider decline on re-authorization)​

Derived from: model.yaml → contexts[customer-payments].aggregates[PaymentAuthorization] (commands[ExpireAuthorization], transitions, events), .publishes[PaymentAuthorizationExpired].

Omitted: the trigger's own flow (sequence 7). ExpireAuthorization is raised by a provider decline on re-authorization (H2); the diagram draws the two transitions into EXPIRED and the event they raise.

9. Payment status over MCP or A2A (read-only)​

Source: internal/adapters/inbound/mcp/tools.go, resources.go, prompts.go, internal/adapters/inbound/a2a/skills.go, cmd/mcp/main.go, cmd/a2a/main.go.

As built (054b3de): the four reads are use cases in internal/application/usecases, and they are the whole agent surface. MCP (cmd/mcp, the complete surface of service ADR 0007): get_payment_authorization, list_payment_authorizations, get_refund and list_refunds, all L1 inform with _meta com.warehouse/authority: L1 in the pinned registry tool_registry.golden.json, plus one scoped resource, warehouse://customer-payments/orders/{orderId}/payment-status, and one prompt, investigate_order_payment; served stateless on :8090 at /mcp. A2A (cmd/a2a, service ADR 0005): get_payment_status (GetAuthorization or ListAuthorizations) and get_refund_status (GetRefund or ListRefunds), both tagged authority:L1; one message per request (streaming: false), served on :8093 at / and /a2a with the Agent Card at /.well-known/agent-card.json. Neither binary holds a write use case, a unit of work, the outbox, a consumer or the payment provider: an agent can ask where a payment or a refund stands and can never authorize, void, capture, release or refund. No PSP token or payment instrument crosses either. There is no auth on either; the in-cluster boundary is the access control. Omitted: the MCP initialize handshake, the resource and prompt calls, and the A2A JSON-RPC envelope.