Skip to main content

Aggregate design canvas

ddd-crew Aggregate Design Canvas v1.1, for the two aggregates. There is also a third modelling element that is not an aggregate: the pure detector (internal/domain/detection), which has no state.

ReplenishmentRequest (internal/domain/replenishment)​

SectionContent
NameReplenishmentRequest (type Request), the richest aggregate
DescriptionOne decision to move quantity units of one SKU from one reserve bin to one forward bin, and how it ended
State transitionsRequested to Completed or Cancelled; both final. version is 1 when planned and +1 per transition.
LifecyclePlan creates it; Complete and Cancel close it; Restore rebuilds it from a snapshot and validates everything the snapshot can show
CommandsPlan(PlanInput), Complete(Relocation, at), Cancel(reason, at)
EventsReplenishmentRequested, ReplenishmentCompleted, ReplenishmentCancelled (plain domain facts; the outbound adapter maps them to CloudEvents)
Invariants1. at most one open request per (site, forward bin, SKU), enforced by the use case and a partial unique index; 2. quantity >= 1 and projected + quantity <= policy max; 3. source differs from the forward bin, same site, a reserve-zone bin, quantity <= source usable; 4. completion only by a REPLENISHMENT relocation whose source_ref is the id and whose SKU, from bin and to bin match; 5. a newer slot plan that drops the assignment cancels it with ASSIGNMENT_CHANGED
Corrective policiesnone: a request that stays open is cancelled by an operator or by a slot plan or policy change
Throughputlow: created by detection, closed once
Sizesmall: about 17 fields, no collections
Concurrencyoptimistic: every UPDATE is WHERE version = <loaded>; a mismatch is concurrent-modification. The partial unique index decides racing creators.
Repositoryports.RequestRepo (Postgres table replenishment_requests; an in-memory test double exists for unit tests only)

ReplenishmentPolicy (internal/domain/policy)​

SectionContent
NameReplenishmentPolicy (type Policy), a versioned value object keyed by (site, SKU)
DescriptionThe explicit MIN_MAX rule of one pick face
StateminQty, maxQty, multiple, version; no lifecycle states
CommandsNew (declares at version 1), WithBounds (a new value at version + 1), Restore
EventsReplenishmentPolicyDeclared (the Declaration fact), analytics topic only
Invariantssite and SKU not blank; 0 <= minQty < maxQty; multiple >= 1; version >= 1
Concurrencyoptimistic through If-Match: create when absent, replace or delete only at the loaded version
Repositoryports.PolicyRepo (table policies)
Cross-aggregate behaviourremoving a policy cancels the open requests of its site and SKU with POLICY_REMOVED in the same unit of work (use case RemovePolicy)

Source: internal/domain/replenishment/request.go, internal/domain/replenishment/values.go.