Skip to main content

Aggregate Design Canvas

Following the ddd-crew Aggregate Design Canvas v1.1. Three aggregate roots: SellerAccount, InboundPlan and InboundShipment (with the Carton entity). Go packages: internal/domain/seller, internal/domain/inboundplan and internal/domain/inboundshipment, with the read-model value types in internal/domain/network and the GS1 value objects in internal/domain/shared/gs1. Each aggregate is rebuilt from a Snapshot by Restore, which re-validates every invariant, and carries an optimistic-concurrency version (409 concurrent-update on a lost race). Decisions: ADR 0002.

SellerAccount​

Description. A seller organisation and the owner of the stock it sends. Identified by sellerId; ownerRef equals it.

Source: internal/domain/seller/seller.go.

InvariantError
sellerId is unique (1 to 64 characters of A-Z a-z 0-9 . _ -)ErrSellerExists
name is non-blank, trimmed, at most 120 characters; a suspension reason at most 200ErrValidation
A suspended seller creates no plan, shipment or carton and ships nothingErrSellerSuspended

Suspending a suspended seller and reinstating an active one are no-ops that raise no event.

Commands: OnboardSeller, SuspendSeller, ReinstateSeller. Events: SellerOnboarded, SellerSuspended, SellerReinstated. Throughput: rare. Size: tens to thousands.

InboundPlan​

Description. What a seller intends to send to one node, in eaches, and how it will pack it. Value objects: PackingOption(INDIVIDUAL|CASE_PACKED), Line{catalogItemId, gtin, qtyEaches}.

Source: internal/domain/inboundplan/plan.go.

InvariantError
Destination node is ACTIVE with the INBOUND capability, when the plan is created and when it is confirmedErrNodeCannotReceive
The seller is ACTIVE when the plan is created and confirmedErrSellerSuspended
1 to 500 lines, one per catalogue item; every line names a catalogItemId, a valid non-variable-measure GTIN and qtyEaches from 1 to 2147483647ErrValidation
Only a DRAFT plan is confirmed or cancelled; a shipment needs a CONFIRMED planErrIllegalTransition

Whether the item is live is not checked (no CatalogItemCreated or CatalogItemDiscontinued is consumed), nor is a CASE_PACKED line checked against the packaging view at plan time: that is enforced on AddCarton.

Commands: CreateInboundPlan, ConfirmInboundPlan, CancelInboundPlan. Events: InboundPlanConfirmed. Cancelling raises no event. Throughput: low to medium. Size: one row plus its lines (JSONB).

InboundShipment and Carton​

Description. One physical consignment of a plan to one node. The Carton entity is one SSCC logistic unit with its contents. Value objects: SSCC, GTIN, Kind(HOMOGENEOUS_CASE|MIXED), Content{catalogItemId, gtin, qtyEaches, lot?, expiry?}, ReceiptStatus(RECEIVED|MISSING|UNEXPECTED|DAMAGED).

Source: internal/domain/inboundshipment/{shipment,carton,receipt}.go.

InvariantError
A HOMOGENEOUS_CASE carton holds exactly one item, one GTIN and one quantity; in a CASE_PACKED plan every carton is oneErrCasePackNotUniform
The carton's qtyEaches equals unitsPerPack of an active CASE level with this GTIN in catalog_pack_levelsErrCaseQtyMismatchesGtin
Carton gross weight within the node's maxCartonWeightG (when declared)ErrCartonOverweight
Carton dimensions fit the node's maxCartonDimsMm in some orientation (when declared)ErrCartonOversize
An SSCC is unique in the shipment and network-wide (sscc_registry)ErrSsccNotUnique
An SSCC (and a parentSscc) has 18 digits and a valid mod-10 check digitErrInvalidSscc
Each item is on the plan and the eaches over the plan's shipments do not exceed the plan line; a single-shipment plan must match every line exactly at labellingErrCartonContentsMismatchPlan
Node able to receive when the shipment is created, labelled and shipped; a pallet (parentSscc) needs acceptsPallets not falseErrNodeCannotReceive
Seller ACTIVE when the shipment is created, cartons added, labelled and shippedErrSellerSuspended
No ship without every carton sealed by labellingErrShipmentNotLabelled
At most 1000 cartons, 100 content lines per carton, lot at most 20 charactersErrValidation
A receipt closes nothing twice: the first answer for a carton is final and a receipt for a closed shipment is a no-opnone

Commands: CreateInboundShipment, AddCarton, LabelShipment, ShipInboundShipment, and RecordReceipt (invoked by the consumer use case ApplyInboundReceipt). Events: InboundShipmentLabelled, InboundShipmentShipped, InboundShipmentReceived, InboundDiscrepancyRecorded, SellerComplianceViolationRecorded. Throughput: medium; cartons dominate. Size: one row per shipment, its cartons and unexpected SSCCs in JSONB columns, retained for audit.

An aggregate this size is a consistency choice: carton checks need the whole carton set (uniform quantity, plan totals), so the cartons are children, not aggregates. A shipment of thousands of cartons is the cost; splitting it into several shipments of one plan is the relief valve (the plan accepts several shipments).

Read models​

Read modelTableFed by
NodeInboundViewnode_inbound_viewsNodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetired
CatalogPackagingViewcatalog_pack_levelsCatalogItemPackagingDeclared, CatalogItemPackLevelRetired
Seller scorecardseller_scorecard_receipts, seller_scorecard_occurrencesNo event: this service's own facts (one row per closed shipment, one per discrepancy or violation), written in the transaction of each applied receipt; read by GET /sellers/{sellerId}/scorecard (ADR 0005)