Skip to main content

Aggregate Design Canvas

Following the ddd-crew Aggregate Design Canvas (v1.1), one canvas per aggregate root found in internal/domain/. There are six: StockUnit, Bin, Reservation, ProductClassification, Container, Relocation. Every invariant below is enforced in the domain layer (or, where noted, in the use case that owns the cross-aggregate rule) and has a failing-path test.

Aggregates reference each other by identity, never by pointer: a Reservation holds Allocation{StockUnitID, BinID} values, a StockUnit holds a BinId. Each aggregate is loaded, changed and saved through its own repository port, and every Save is version-guarded (ADR 0019). A use case that touches several aggregates (stow, revoke, confirm-pick, expiry, relocate, break-case) keeps them consistent inside one UnitOfWork transaction (ADR 0017) — the one place this context deliberately trades "one aggregate per transaction" for a single database transaction.

Throughput and size figures are estimates for a single mid-size fulfilment centre, not measurements — the service has no production traffic.


StockUnit​

1. Name​

StockUnit — internal/domain/stock.StockUnit

2. Description​

A quantity of one SKU at one bin, with a reserved portion and a lifecycle state. It is the core aggregate of the context: every physical item has exactly one known bin, or is flagged UNLOCATED. Total stock for a SKU is a sum across units; there is deliberately no "SKU balance" aggregate to contend on.

FieldMeaning
idIdentity, minted by StockRepo.NextID
skuItem scan
binIDLocation scan — never changes after creation
quantityOn-hand at this bin
reservedPortion bound to demand
stateAVAILABLE / RESERVED / PICKED / REMOVED / UNLOCATED
versionOptimistic-concurrency metadata, never read by business logic

3. State Transitions​

Source: internal/domain/stock/state.go, internal/domain/stock/stock_unit.go. Omitted: ReleaseReservation on a PICKED unit (state stays PICKED); Pick performs no state check of its own, so a still-reserved UNLOCATED unit can be picked into PICKED/REMOVED — the guard is that RunCycleCount only marks units it can count.

MarkUnlocated is deliberately unconditional — it takes no error return. A cycle count that finds stock missing must always be able to say so.

4. Enforced Invariants​

#InvariantEnforced byFailing-path test
S1A stow requires both an item scan and a location scanNewStockUnit → stock.ErrStowRequiresItemAndLocationTestNewStockUnit_RequiresSKU, TestNewStockUnit_RequiresBin
S2Quantity is never negativeshared.NewQuantity / Quantity.Sub → shared.ErrNegativeQuantityTestNewQuantity_RejectsNegative, TestQuantity_Sub_RejectsNegativeResult
S3A stow of zero or fewer units is invalidNewStockUnit → shared.ErrZeroQuantityTestNewStockUnit_RejectsZeroQuantity
S4Reserved never exceeds usable — no negative usableReserve → stock.ErrInsufficientUsableTestStockUnit_Reserve_ExceedsUsable_Rejected
S5Unlocated or removed stock is never reservable and contributes 0 usableReserve → stock.ErrUnitUnlocated; Usable() returns 0TestStockUnit_Reserve_UnlocatedUnit_Rejected, TestStockUnit_Usable_RemovedState_IsZero
S6A pick cannot exceed what was reserved, nor what is on handPick → stock.ErrInsufficientReservedTestStockUnit_Pick_ExceedsReserved_Rejected, TestStockUnit_Pick_ExceedsOnHandQuantity_Rejected
S7Release cannot return more than was reservedReleaseReservation → stock.ErrInsufficientReservedTestStockUnit_ReleaseReservation_ExceedsReserved_Rejected
S8No lost updatepostgres.StockRepo.Save version guard → usecases.ErrConcurrentModificationoptimistic_concurrency_integration_test.go

5. Corrective Policies​

  • Revoke / expiry release. When a reservation is revoked or lazily expired, releaseAllocations calls ReleaseReservation on every unit it drew from, in the same transaction.
  • Cycle-count shortfall. RunCycleCount marks whole units UNLOCATED until the shortfall is covered, so lost stock stops counting toward usable at once. Overage is not corrected here — it is reported for a separate receiving/audit process.
  • Concurrent modification. A lost version race surfaces as 409; the caller re-fetches and retries.

6. Handled Commands​

CommandMethodUse case / entry point
StowNewStockUnitStowStock — POST /stowages
ReserveReserveReserveStock — POST /reservations
Release reservationReleaseReservationRevokeReservation (DELETE /reservations/{id}, MCP revoke_reservation), lazy expiry
PickPickConfirmPick — POST /reservations/{id}/pick-confirmations, and per ACTIVE reservation from ConfirmPicksForOrder on TaskCompleted: the picked line's reservation when the event carries line_no (ADR 0036), the order's on its last pick otherwise (ADR 0035)
Mark unlocatedMarkUnlocatedRunCycleCount — POST /bins/{binId}/cycle-counts

7. Created Events​

The aggregate itself raises nothing; the use cases build these from it (internal/domain/shared/events.go).

EventFull CloudEvents typeRaised by
StockReceivedcom.warehouse.wms.inventory-storage.stock.StockReceivedReceiveStock (no unit exists yet)
ItemStowedcom.warehouse.wms.inventory-storage.stock.ItemStowedStowStock
LocationRecordednot published (would be ...stock.LocationRecorded) — decided 2026-10-06: stays in-process, no consumerStowStock
ItemUnlocatedcom.warehouse.wms.inventory-storage.stock.ItemUnlocatedRunCycleCount

8. Throughput (estimate)​

High. Every stow creates one unit; every reservation, revoke, pick and expiry touches one or more units of a SKU. Contention concentrates on fast movers whose few units are drawn by many concurrent reservations — the reason Save is version-guarded.

9. Size (estimate)​

Small: seven fields. A unit lives from stow until REMOVED or UNLOCATED — typically a few to a few dozen state changes over hours to weeks, depending on how many reservations draw from it.


Bin​

1. Name​

Bin — internal/domain/location.Bin

2. Description​

A coded slot in chaotic storage: an id, a capacity and an occupancy. Any SKU may occupy any free bin; the only hard constraint is sum(stock in bin) <= capacity. The Bin has no SKU field and no SKU affinity — that absence is what makes storage chaotic rather than fixed-slot. It knows nothing about zones or aisles (that is facility-layout).

FieldMeaning
idBin code, e.g. A-1-1
capacityMaximum units the slot holds
occupiedUnits currently stowed
versionOptimistic-concurrency metadata

3. State Transitions​

Bin has no status enum; the states below are derived from occupied and IsFull().

Source: internal/domain/location/bin.go, internal/application/usecases/register_bin.go. Omitted: rejected transitions (they return errors and leave state unchanged); a bin is never deleted.

4. Enforced Invariants​

#InvariantEnforced byFailing-path test
B1occupied <= capacity; a full bin rejects a stowOccupy → location.ErrBinFullTestBin_Occupy_ExceedsCapacity_Rejected, TestStowStock_ExceedsBinCapacity_Rejected
B2Capacity must be positiveNewBin / Resize → location.ErrInvalidCapacityTestNewBin_RejectsInvalidCapacity
B3A bin needs an idNewBin → shared.ErrEmptyBinIDTestNewBin_RejectsEmptyID
B4A bin can never be resized below what it holds (exactly to occupancy is allowed)Resize → location.ErrCapacityBelowOccupancyTestBin_Resize, TestRegisterBin, TestRegisterBin_Endpoint
B5You cannot release more than is occupiedRelease → location.ErrReleaseExceedsOccupancyTestBin_Release_ExceedsOccupancy_Rejected
B6Occupying or releasing zero units is meaninglessOccupy / Release → shared.ErrZeroQuantityTestBin_Occupy_RejectsZeroQuantity, TestBin_Release_RejectsZeroQuantity
B7A resize racing a stow never clobbers occupancypostgres.LocationRepo.Save version guard → usecases.ErrConcurrentModificationoptimistic_concurrency_integration_test.go

5. Corrective Policies​

  • Pick frees capacity. ConfirmPick calls Bin.Release for each allocation in the same transaction as the StockUnit.Pick.
  • Declarative convergence. RegisterBin is idempotent: repeating it with the same capacity is a no-op, so an inventory-control client can safely re-send its whole bin list.

6. Handled Commands​

CommandMethodUse case / entry point
Register / resizeNewBin, ResizeRegisterBin — PUT /bins/{binId}
OccupyOccupyStowStock — POST /stowages
ReleaseReleaseConfirmPick — POST /reservations/{id}/pick-confirmations, and per ACTIVE reservation from ConfirmPicksForOrder on TaskCompleted: the picked line's reservation when the event carries line_no (ADR 0036), the order's on its last pick otherwise (ADR 0035)

7. Created Events​

RegisterBin raises no event (ADR 0025). The cycle-count facts are grouped under the bin entity because they are about a bin, though RunCycleCount reads StockUnits and never loads the Bin aggregate:

EventFull CloudEvents type
CycleCountCompletedcom.warehouse.wms.inventory-storage.bin.CycleCountCompleted
DiscrepancyDetectedcom.warehouse.wms.inventory-storage.bin.DiscrepancyDetected

8. Throughput (estimate)​

High on stow and pick (every stow and every confirmed allocation writes its bin), low on registration (layout changes). Hot spots are bins near the receive dock under chaotic stow.

9. Size (estimate)​

Tiny: four fields. Long-lived — a bin exists as long as the physical slot, accumulating one change per stow and per picked allocation (thousands over its life), but each change only moves two integers.


Reservation​

1. Name​

Reservation — internal/domain/reservation.Reservation

2. Description​

A revocable, expiring binding of a quantity of a SKU to a demand. It records Allocations — which StockUnit it drew from, the pick location (BinID, ADR 0025) and how much — so a revoke returns exactly that quantity and a confirm-pick consumes exactly it. Nothing binds a future reservation to the same holding: that is what makes a failed pick recoverable (ADR 0003).

FieldMeaning
idIdentity, minted by ReservationRepo.NextID
sku, quantityWhat is claimed
demandRefOpaque upstream reference (order + line); replay-guard and lookup key
lineNoOptional order line the reservation is for (line_no, nullable; ADR 0036). Set at creation from POST /reservations's lineNo, immutable, nil when unknown (a reservation made before migration 0035, or by a client that does not send it); with demandRef it is what the TaskCompleted consumer confirms by
allocations[]Allocation{StockUnitID, BinID, Quantity}
statusACTIVE / CONFIRMED / REVOKED / EXPIRED
createdAt, expiresAtexpiresAt = createdAt + timeout (default 30 min)
versionOptimistic-concurrency metadata

3. State Transitions​

Source: internal/domain/reservation/reservation.go, internal/application/usecases/reservation_expiry.go. Omitted: the rejected transitions — any call on a non-ACTIVE reservation returns ErrAlreadyResolved.

4. Enforced Invariants​

#InvariantEnforced byFailing-path test
R1Reserved quantity ≤ usable quantity at reserve timeReserveStock.allocate → usecases.ErrInsufficientUsable; StockUnit.Reserve re-checks per unitTestReserveStock_ExceedsUsable_Rejected
R2Revoke returns quantity to usableRevokeReservation → releaseAllocations → StockUnit.ReleaseReservationTestRevokeReservation_ReturnsQuantityToUsable, TestStockUnit_ReleaseReservation_ReturnsToUsable
R3No double-consume: only ACTIVE may transitionRevoke / Confirm / Expire → reservation.ErrAlreadyResolvedTestReservation_Revoke_Twice_Rejected, TestReservation_Confirm_Twice_Rejected, TestReservation_Expire_Twice_Rejected, TestConfirmPick_AfterRevoke_Rejected
R4Expires after a timeout; never confirmed lateIsExpired(now); Confirm → reservation.ErrExpiredTestReservation_IsExpired, TestReservation_Confirm_AfterExpiry_Rejected
R5Must allocate against somethingNew → reservation.ErrNoAllocationsTestNew_RequiresAtLeastOneAllocation
R6One active reservation per (demandRef, SKU, quantity, and line when the request names one) — best effort; an ACTIVE reservation with no line still answers a line-aware retryReserveStock.activeReservationFor / isReplayOf (use case, not DB-enforced)reserve_stock_multi_line_test.go, reserve_stock_line_test.go
R7Empty demandRef is rejectedHTTP handler → 400 missing-demand-refserver_test.go
R8lineNo, when present, is between 1 and 2147483647 (the 32-bit line_no column)reservation.ValidLineNo in NewForLine → reservation.ErrInvalidLineNo; HTTP handler → 400 invalid-line-no; TaskCompleted line_no outside the range → ErrMalformedPickCompletion (dead-lettered); column INTEGER CHECK (line_no IS NULL OR line_no >= 1)TestNewForLine_RejectsANonPositiveLineNo, TestNewForLine_LineNoBoundaryTable, TestReserveStock_Endpoint_NonPositiveLineNo_Rejected, TestReserveStock_Endpoint_LineNoBoundaryTable

5. Corrective Policies​

  • Lazy expiry. expireIfDue runs on every read path (GetReservationsByDemandRef, ReserveStock's replay guard, RevokeReservation, ConfirmPick): a timed-out ACTIVE reservation is released, set EXPIRED and ReservationExpired is raised in one transaction. There is no background sweeper.
  • Revoke as compensation. A failed physical pick is compensated by DELETE /reservations/{id}; deciding what to do next is wes-work-planning's or order-management's call, not this context's.

6. Handled Commands​

CommandMethodUse case / entry point
ReserveNew, NewForLineReserveStock — POST /reservations (Idempotency-Key, optional lineNo, ADR 0036)
RevokeRevokeRevokeReservation — DELETE /reservations/{id}, MCP revoke_reservation
Confirm pickConfirmConfirmPick — POST /reservations/{id}/pick-confirmations, and per ACTIVE reservation from ConfirmPicksForOrder on TaskCompleted: the picked line's reservation when the event carries line_no (ADR 0036), the order's on its last pick otherwise (ADR 0035)
ExpireExpirelazy, inside the four read paths above

7. Created Events​

EventFull CloudEvents typeTopics
StockReservedcom.warehouse.wms.inventory-storage.reservation.StockReservedintegration + analytics
ReservationRevokedcom.warehouse.wms.inventory-storage.reservation.ReservationRevokedintegration + analytics
ReservationExpiredcom.warehouse.wms.inventory-storage.reservation.ReservationExpiredanalytics only
StockPickedcom.warehouse.wms.inventory-storage.reservation.StockPickedanalytics only

8. Throughput (estimate)​

Highest of the six: one reservation per order line, plus one revoke or confirm each, plus reads by demandRef from the Order Lifecycle console. Each reservation is written by one caller at a time, so per-instance contention is low; contention moves to the StockUnits it draws from.

9. Size (estimate)​

Small: a handful of fields plus usually one to three allocations. Short lifetime — two to three events (created, then confirmed / revoked / expired) within the 30-minute default timeout. Rows are never deleted.


ProductClassification​

1. Name​

ProductClassification — internal/domain/product.ProductClassification

2. Description​

SKU-level master data, independent of any StockUnit or bin, describing how an item must be handled. product-master is the source of truth (ADR 0034, superseding the ownership part of ADR 0009); this aggregate is a version-guarded local copy of it: a closed set of HandlingTags, a TemperatureClass required only for TemperatureSensitive SKUs, and an optional US DOT hazard class meaningful only for Hazmat SKUs (ADR 0010). StowStock enforces placement and same-bin segregation from it; no sibling context reads it from here any more (the REST GET was removed at stage E).

FieldMeaning
skuThe classified SKU (identity)
handlingTagsSet of Hazmat / Fragile / TemperatureSensitive / Oversized / HighValue
temperatureClassAmbient / Chilled / Frozen, or empty
dotHazardClass1-9, or 0 (DOTHazardClassUnspecified)

3. State Transitions​

No status enum: a classification either does not exist or is current, and re-classifying replaces it wholesale.

Source: internal/domain/product/classification.go, internal/application/usecases/apply_product_classification.go. Since ADR 0034 the rows are a version-guarded local copy of product-master's classification; this service no longer authors them. Omitted: there is no delete or unclassify operation.

4. Enforced Invariants​

#InvariantEnforced byFailing-path test
P1At least one handling tagNew → product.ErrNoHandlingTagsTestNew_TableDriven/no_tags_rejected
P2HandlingTag is a closed enumParseHandlingTag / New → product.ErrUnknownHandlingTagTestParseHandlingTag/unknown, TestNew_TableDriven/unknown_tag_rejected
P3Tags form a setNew → product.ErrDuplicateHandlingTagTestNew_TableDriven/duplicate_tag_rejected
P4TemperatureSensitive requires a valid TemperatureClassNew → product.ErrTemperatureClassRequired / product.ErrUnknownTemperatureClassTestNew_TableDriven/temperature_sensitive_without_class_rejected
P5No TemperatureClass without TemperatureSensitiveNew → product.ErrTemperatureClassNotApplicableTestNew_TableDriven/temperature_class_without_temperature_sensitive_tag_rejected
P6DOTHazardClass only with HazmatNew → product.ErrDOTHazardClassNotApplicableTestNew_TableDriven/dot_hazard_class_without_hazmat_tag_rejected
P7DOTHazardClass in 1-9ParseDOTHazardClass / New → product.ErrInvalidDOTHazardClassTestNew_TableDriven/dot_hazard_class_out_of_range_rejected
P8Hazmat never requires a DOT classNew accepts DOTHazardClassUnspecifiedTestNew_TableDriven/hazmat_alone_succeeds

Rules this aggregate's data drives, enforced in StowStock (they span a classification, a bin's occupants and facility-layout's zone data):

RuleError
Hazmat SKU needs a hazmat-rated zoneusecases.ErrHazmatZoneRequired
Temperature-sensitive SKU needs a matching zone temperature classusecases.ErrTemperatureClassMismatch
Zone lookup failed for a classified SKU (fail-closed)usecases.ErrLocationClassificationUnavailable
Incompatible DOT classes may not share a bin (49 CFR §177.848, four simplifications)usecases.ErrHazmatClassIncompatible via product.Incompatible

Unclassified SKUs, unknown bins and unclassified occupants are fail-open.

5. Corrective Policies​

  • Re-classification replaces. Corrections are made in product-master (ADR 0034); a newer version replaces the local copy wholesale.
  • None for already-stowed stock: re-classifying a SKU does not re-check bins it already occupies.

6. Handled Commands​

CommandMethodUse case / entry point
Apply product-master's classificationproduct.NewApplyProductClassification — Kafka warehouse.product-master.events (PUT /products/{sku}/classification was removed at stage E)

7. Created Events​

None. The aggregate raises no event since ADR 0034. The legacy com.warehouse.wms.inventory-storage.product.ProductClassified (published on every write from 2026-10-06 under ADR 0031) and the RepublishProductClassifications backfill were removed at stage E (2026-10-17).

8. Throughput (estimate)​

Low writes (product-master's ProductClassified messages), high reads: every classified-SKU stow. Siblings keep their own copies from product-master's events; the REST read GET /products/{sku}/classification was removed at stage E.

9. Size (estimate)​

Tiny: four fields. Lives as long as the SKU; a handful of re-classifications over its life.


Container​

1. Name​

Container — internal/domain/container.Container

2. Description​

The identity of one physical sealed case in storage, keyed by its LPN — the carton's SSCC, or an internal LPN minted by inbound-receiving for an unlabelled carton (ADR 0045, as built per ADR 0046). A Container does not hold stock: the eaches stay on a StockUnit in the ledger; the Container adds identity and a pack state on top of it, linked 1:1 through stockUnitID while the case is stowed. The receipt carries no site: the first stow sets the container's site from the bin's site.

FieldMeaning
lpnIdentity — 1 to 64 characters of [A-Za-z0-9._-]
sku, gtin, unitsPerPackWhat the case holds and how it packs
quantityEaches in the case; in v1 always equals unitsPerPack (one case)
ownerRefOwner of the stock (owner-segregated stock, ADR 0045)
siteIDSet at the first stow from the bin; never changes afterwards
binIDWhere the case sits; empty until stowed and after emptying
stateSEALED / OPEN / EMPTY
lot, expiryCarried from the receipt (AI 10 / AI 17), never interpreted
stockUnitIDThe 1:1 link to the backing SEALED_CASE StockUnit
receiptID, lineNoProvenance: the receipt line the carton arrived on
versionOptimistic-concurrency metadata (ADR 0019)

3. State Transitions​

Source: internal/domain/container/container.go, internal/application/usecases/stow_container.go, break_case.go, container_unit_exit.go. In v1 OPEN exists only inside one break transaction: BreakCase runs Break and Decant in one UnitOfWork, so a stored container is always SEALED or EMPTY. Omitted: the rejected transitions (they return errors and leave state unchanged).

4. Enforced Invariants​

#InvariantEnforced byFailing-path test
C1A sealed container holds exactly one case: quantity == unitsPerPack (cases is 1 in v1)Register → container.ErrContainerQuantityMismatchTestRegisterEnforcesQuantityEqualsUnitsPerPackTimesOneCase
C2The LPN is 1–64 characters of [A-Za-z0-9._-]Register → container.ErrInvalidLPNTestRegisterRejectsInvalidIdentity
C3Provenance is complete: receipt id present, line no ≥ 1, lot ≤ 20 and expiry ≤ 32 charactersRegister → container.ErrInvalidContainerTestRegisterRejectsInvalidIdentity
C4Only a SEALED container can be stowed, broken or emptied wholeStow / Break / EmptyWhole → container.ErrContainerNotSealedTestStowRequiresASealedContainer, TestBreakNeedsSealedAndStowed
C5A break needs a stowed container and conserves eaches: the produced quantity equals the container quantity, no more and no fewerBreak → container.ErrContainerNotStowed, container.ErrBreakNotConservingTestBreakNeedsSealedAndStowed, TestBreakConservesQuantity
C6Only an OPEN container decantsDecant → container.ErrContainerNotOpenTestDecantNeedsAnOpenContainer
C7A container never changes site: the first stow sets it from the bin, a later stow must stay in that siteStow → container.ErrContainerNotAtSiteTestRestowToAnotherSiteIsRejected, TestRestowMovesTheUnitWithinTheSiteAndRefusesAnotherSite
C8A sealed case stows only in a CASE or PALLET bin — a bin with no recorded handling unit fails closed; loose eaches go to EACH or unrecorded binsStowContainer via ports.BinHandlingUnitLookup → container.ErrBinHandlingUnitMismatchTestHandlingUnitAcceptance, TestStowContainerRejections
C9A reserved case is never re-stowed or broken: the reservation names the case, not its eachesStowContainer / BreakCase → container.ErrContainerReservedTestReservedContainerCannotBeRestowed
C10No lost updatepostgres.ContainerRepo.Save version guard → usecases.ErrConcurrentModificationcontainer_integration_test.go

5. Corrective Policies​

  • Double-count guard. ContainerLinker settles a pending carton link only while sum(container qty) per (receipt id, line no) stays within the booked quantity, so a container can never exist for units the ledger has not counted — whichever of ReceiptLineReceived and ReceiptCartonReceived arrives first. A rejected link keeps its reason on the row for audit (QUANTITY_MISMATCH, GTIN_BELONGS_TO_OTHER_SKU, GTIN_IS_NOT_A_CASE, LPN_REGISTERED_AT_ANOTHER_RECEIPT_LINE, INVALID_CONTAINER).
  • Idempotent stow. Stowing a container into the bin it already occupies changes nothing; re-stowing within the same site moves its SEALED_CASE unit.
  • Rejected break changes nothing. Conservation is checked before any stock moves; a rejected break leaves the sealed case and the ledger untouched.

6. Handled Commands​

CommandMethodUse case / entry point
RegisterRegisterContainerLinker.Settle — pending links from inbound-receiving's ReceiptCartonReceived (Kafka), settled once the receipt line is booked
StowStowStowContainer — POST /containers/{lpn}/stowages
Break caseBreak, DecantBreakCase — POST /containers/{lpn}/case-breaks
Empty wholeEmptyWholecontainer_unit_exit — a confirmed whole-case pick or a cycle-count shortfall, inside the caller's UnitOfWork
Read—GetContainer — GET /containers/{lpn}, MCP get_container; ListBinContainers — GET /bins/{binId}/containers

7. Created Events​

All four go to the integration topic warehouse.inventory.events, keyed by LPN (ADR 0045/0046).

EventFull CloudEvents typeRaised by
ContainerRegisteredcom.warehouse.wms.inventory-storage.container.ContainerRegisteredContainerLinker on settle (no quantity booked, no site yet)
ContainerStowedcom.warehouse.wms.inventory-storage.container.ContainerStowedStowContainer
CaseBrokencom.warehouse.wms.inventory-storage.container.CaseBrokenBreakCase — eaches conserved from fromBin to looseBin
ContainerEmptiedcom.warehouse.wms.inventory-storage.container.ContainerEmptiedBreakCase (reason BROKEN), whole-case exit (PICKED, UNLOCATED)

8. Throughput (estimate)​

Moderate: one container per received sealed carton, one stow each, and a break or whole-case exit per case consumed. Registration rate follows inbound receiving; breaks follow each-picking demand for case-packed SKUs.

9. Size (estimate)​

Small: fifteen fields, most set once at registration. A container lives from receipt until the case is empty — days to weeks — with one stow, at most a few re-stows inside its site, and one terminal break or whole-case exit.


Relocation​

1. Name​

Relocation — internal/domain/relocation.Relocation

2. Description​

One intra-site move of a quantity of one SKU from a source bin to a destination bin of the same site (ADR 0039). It is the stock ledger's record of slot-plan execution (slotting-optimization's approved plans, normally via RELOCATE tasks) and of manual re-slotting — and, since ADR 0041, of pick-face replenishment: a completed REPLENISH task is applied as a REPLENISHMENT relocation. Both bins and every touched StockUnit change in one transaction, the ledger never goes negative, and the record answers GET /relocations/{id}.

FieldMeaning
idIdentity, minted by RelocationRepo.NextID
siteIDThe site both bins must belong to; a relocation never crosses sites
sku, quantityWhat moves
fromBin, toBinSource and destination; always different
reasonSLOTTING / CONSOLIDATION / MANUAL (operator-requested), REPLENISHMENT (system-set only, ADR 0041)
sourceRefCaller's correlation reference, ≤ 200 characters (request_ref of a REPLENISH task)
legsOnce applied: which source StockUnits contributed how much
destinationStockUnitIDOnce applied: the new destination StockUnit
occurredAtOnce applied: when the move happened

3. State Transitions​

No status enum: a relocation is requested, then applied exactly once.

Source: internal/domain/relocation/relocation.go. Every rule is checked before anything changes, so a rejected Apply leaves the units, the bins and the relocation untouched.

4. Enforced Invariants​

#InvariantEnforced byFailing-path test
L1Source and destination bins differNew → relocation.ErrSameBinTestNew_RejectsInvalidSpecs
L2The reason is in the closed set; REPLENISHMENT is system-set only — New accepts it, the operator-facing ParseReason behind POST /relocations rejects itNew / ParseReason → relocation.ErrUnknownReasonTestParseReason, TestReplenishmentReason_AcceptedByNewRejectedByParseReason
L3The moved quantity is positiveNew → shared.ErrZeroQuantityTestNew_RejectsInvalidSpecs
L4sourceRef is at most 200 charactersNew → relocation.ErrSourceRefTooLongTestNew_RejectsInvalidSpecs, TestNew_SourceRefAtTheLimitIsAccepted
L5Both bins are the ones the relocation names and belong to its siteApply → relocation.ErrBinMismatch, relocation.ErrBinNotAtSiteTestApply_BinsMustBeTheOnesNamed, TestApply_BinsMustBelongToTheSite
L6A relocation moves stock exactly onceApply → relocation.ErrAlreadyAppliedTestApply_TwiceIsRejected
L7The usable quantity covers the move, the destination has room and the source occupancy covers the move — all checked before any changeApply → stock.ErrInsufficientUsable, location.ErrBinFull, location.ErrReleaseExceedsOccupancyTestApply_InsufficientUsableChangesNothing, TestApply_DestinationFullChangesNothing, TestApply_SourceOccupancyBelowTheQuantityIsRejected, TestApply_NoUnitsIsInsufficient
L8Only usable units of the SKU in the source bin are drawn, in ascending unit id, so concurrent movers lock rows alikeApply draw planTestApply_SkipsReservedQuantityOtherSKUsOtherBinsAndDeadUnits, TestApply_StopsDrawingOnceTheQuantityIsCovered, TestRelocation_ConcurrentMoversOfTheSameStock

5. Corrective Policies​

  • Check before change. A rejected Apply mutates nothing: when the source release fails after the destination was occupied, the occupancy is restored, so neither bin changes.
  • Dead-letter the hopeless. A RELOCATE or REPLENISH task completion that can never apply (missing field, unknown bin, other site, same bin, insufficient usable, destination full) is dead-lettered at once rather than retried.
  • Replenishment closes the loop. ApplyReplenishTask applies the move with sourceRef = the replenishment request id, so pick-face-replenishment can close its request from StockRelocated.

6. Handled Commands​

CommandMethodUse case / entry point
Request a moveNew, ApplyRelocateStock — POST /relocations
Apply a completed RELOCATE taskNew, ApplyApplyRelocationTask — Kafka TaskCompleted (task_type=RELOCATE, additive relocation_ref), consumer task-completed-relocate (ADR 0039)
Apply a completed REPLENISH taskNew, ApplyApplyReplenishTask — Kafka TaskCompleted (task_type=REPLENISH, required request_ref), consumer task-completed-replenish (ADR 0041)
Read—GetRelocation — GET /relocations/{id}, MCP get_relocation

7. Created Events​

EventFull CloudEvents typeTopicRaised by
StockRelocatedcom.warehouse.wms.inventory-storage.stock.StockRelocatedwarehouse.inventory.events, keyed by relocation idRelocation.Event() from the applied relocation, published by RelocateStock

RelocateStock also raises two BinStockLevelChanged (source then destination, ADR 0040) from the same transaction. Known consumers of StockRelocated: slotting-optimization (slot-plan execution progress; acts only on SLOTTING) and pick-face-replenishment (closes a request when reason=REPLENISHMENT and source_ref is its request id).

8. Throughput (estimate)​

Low to moderate: one relocation per executed slot-plan move, replenishment or manual re-slot — far below reservation traffic, but each move writes both bins, every source unit it draws from and the new destination unit in one transaction.

9. Size (estimate)​

Small: the spec plus, once applied, one leg per contributing source unit (usually one) and the destination unit id. Rows are never deleted; the record is the audit trail of every intra-site move.


Read models and projections (not aggregates)​

Read modelWhereBuilt from
Usable inventory per SKUusecases.GetUsable → UsableInventoryΣ StockUnit.Usable() at read time — never stored
Bin occupancy (MCP get_bin_occupancy)inbound/mcp → toBinOccupancyStockRepo.FindByBin at read time
Bin capacity viewusecases.GetBinthe Bin aggregate, read-only
Reservations by demand refusecases.GetReservationsByDemandRefReservationRepo.FindByDemandRef (with lazy expiry)
Facility location cacheoutbound/facilitycache.Consumerwarehouse.facility.events, in memory, rebuilt on every start
Inventory Flow & Accuracy reportinternal/analytics/report, table flow_accuracy_rollupwarehouse.inventory.analytics, written only by cmd/inventory-projector

Value objects (internal/domain/shared)​

TypeRuleErrors
SKUNon-emptyErrEmptySKU
BinIdNon-emptyErrEmptyBinID
QuantityNon-negative; every arithmetic operation that would go negative errors rather than clamping. NewPositiveQuantity also rejects zero.ErrNegativeQuantity, ErrZeroQuantity

Quantity.Sub is the workhorse of the "no negative usable" rule and is where boundary tests were added during mutation testing.

The four named invariants​

CLAUDE.md singles out four as the Definition of Done for the context:

InvariantDomain testUse-case test
Bin-capacity rejectionTestBin_Occupy_ExceedsCapacity_RejectedTestStowStock_ExceedsBinCapacity_Rejected
Stow requires item + locationTestNewStockUnit_RequiresSKU / _RequiresBin—
Reservation ≤ usableTestStockUnit_Reserve_ExceedsUsable_RejectedTestReserveStock_ExceedsUsable_Rejected
Revoke returns to usableTestStockUnit_ReleaseReservation_ReturnsToUsableTestRevokeReservation_ReturnsQuantityToUsable

All four are also covered as black-box Gherkin scenarios under features/, driven through the real HTTP router. See the class diagram for the types and the sequence diagrams for how the use cases drive these aggregates.