Skip to main content

Aggregate Design Canvas

As built

Derived from network/model/model.yaml. This context's service is built (IQVO/customer-returns, decided by ADR 0012); the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses. Where the model left a choice open, the service's own ADRs 0001 to 0005 record what it does.

Following the ddd-crew Aggregate Design Canvas v1.1. One aggregate root: ReturnAuthorization. Go packages (as built): internal/domain/returnauthorization, with the read-model value types in internal/domain/network.

ReturnAuthorization​

Description. One authorized return of one order group (orderId and groupNo) and its lines: the reason, the decided disposition, the method, the destination and origin nodes, the linked reverse-label tracking numbers and the state. Identified by authorizationId, minted by the service with the prefix ret-. Value objects: ReturnLine{lineNo, catalogItemId, quantity, unitPriceCents, ownerRef}, ReturnReason, Disposition, ReturnMethod, PickupWindow{pickupWindowStart, pickupWindowEnd}, CancelReason and OutcomeLine{catalogItemId, ownerRef, qtyRestockable, qtyUnsellable}.

Derived from: model.yaml → contexts[customer-returns].aggregates[ReturnAuthorization].states, .transitions, .commands.

A KEEP closes at once: the model writes it as the transition from AUTHORIZED to CLOSED_KEEP by AuthorizeReturn, and the service creates the authorization directly in CLOSED_KEEP. MarkInTransit and MarkPickupFailed exist in the domain with no caller, so IN_TRANSIT and PICKUP_FAILED are reachable by no route or consumer today. CancelReturn is both the shopper's cancellation and the lazy expiry.

InvariantError
1 to 50 lines, each quantity at least 1, a known reason, disposition and method; expiresAt = authorizedAt + 30 daysErrValidation
The order group is SHIPPED or DELIVERED in OrderGroupView when the return is authorized (checked by the use case)ErrGroupNotShipped
Every lineNo of the request resolves against the placed group (checked by the use case)ErrUnknownLine
A disposition exists: KEEP applies, or the region has an ACTIVE returns centre, or a sourcing fact named the fulfilling nodeErrNoReturnDestination
KEEP has no destination node and no label and is CLOSED_KEEP at once; PICKUP has both window bounds inside the interval from authorizedAt to expiresAt and is never KEEPErrValidation
At most 5 tracking numbers, packageNo 1 to 5 (service ADR 0002 names it ErrMaxPackages; the code returns the shared validation error)ErrValidation
Cancel only while AUTHORIZED; a label only while AUTHORIZED with a disposition other than KEEP; an outcome only while AUTHORIZED or IN_TRANSITErrIllegalTransition
An authorization past expiresAt is cancelled on the next read, label or outcome callErrAuthorizationExpired
A label is issued only when the reverse-label route answers with a tracking numberErrLabelUnavailable
An applied outcome names each authorized item at most once, with at least one unit and never more than the authorized quantityErrValidation

Corrective policies. LazyExpiry cancels an expired authorization on the next touch. FirstFittingOutcomeCompletes completes the first open authorization an outcome fits and records every other outcome as a fact. UnexpectedLinesStayFacts keeps lines the authorization never covered out of the published event.

CommandInbound route or triggerIssued by
AuthorizeReturnPOST /return-authorizationsshopper / storefront
IssueLabelPOST /return-authorizations/{authorizationId}/labelsshopper / storefront
CancelReturnPOST /return-authorizations/{authorizationId}/cancellations; also the lazy expiryshopper / storefront; any touch after expiresAt
ApplyOutcomethe consumer of the vendor's graded outcome (no HTTP)not triggered today: the producer is not on develop
MarkInTransitnoneno caller as built
MarkPickupFailednoneno caller as built
EventRaised whenFull CloudEvents type
ReturnAuthorizedAuthorizeReturn is saved, for every disposition, KEEP includedcom.retailnetwork.commerce.customer-returns.returnauthorization.ReturnAuthorized
ReturnLabelIssuedIssueLabel links a tracking number, once per packagecom.retailnetwork.commerce.customer-returns.returnauthorization.ReturnLabelIssued
ReturnCompletedthe first fitting graded outcome is appliedcom.retailnetwork.commerce.customer-returns.returnauthorization.ReturnCompleted
ReturnCancelledCancelReturn is saved (reason SHOPPER_REQUESTED or EXPIRED)com.retailnetwork.commerce.customer-returns.returnauthorization.ReturnCancelled

Throughput: low to medium, a share of shipped groups. Size: one row per authorization with its lines and tracking numbers.

Read models​

Read modelFed by
OrderGroupViewCustomerOrderPlaced (writes PROMISED per group with the destination postal prefix, the witness node and the placed lines) and the terminal ShopperNoticeDecided families GROUP_SHIPPED, GROUP_DELIVERED, GROUP_LOST, GROUP_RETURNED. Order tolerant: a notice before its placed event creates the row, and a placed event never demotes a status a notice already set.
ReturnsNetworkViewNodes from NodeRegistered, NodeActivated, NodeSuspended, NodeRetired (only ACTIVE RETURNS_CENTER nodes are candidates); prefixes from ServiceAreaAssigned (the highest assignmentVersion wins); origins from FulfillmentLocked (the fulfilling node) and FulfillmentReleasedToNode (the per-item ownerRef).
ReturnOutcomeFactsNo modelled event: every graded outcome as received, with a per-line unexpected flag. Its feeding consumer is built; the producer's event is not on develop.