9. Product classification as SKU-level master data, enforced at stow time
Status
Accepted. Ownership part ("this service owns ProductClassification as
source of truth") superseded by ADR 0034:
product-master owns it and this service keeps a local copy; the stow-time
placement rules stay in force.
Context
Nothing in this bounded context knew whether a SKU was hazardous, fragile,
temperature-sensitive, oversized, or high-value. StowStock placed any SKU
into any free bin subject only to capacity (ADR 0002's chaotic storage) — a
correct model of space, but silent on handling. In a real warehouse that
gap is a safety and compliance problem: a hazmat item stowed next to ordinary
stock, or a frozen item stowed in an ambient zone, is not a capacity failure
the existing invariants would ever catch.
Two questions had to be answered before any enforcement could be built:
-
Who owns this classification? It is a property of the product, not of any physical holding — a SKU is Hazmat regardless of which bin, or how many bins, currently hold it. That makes it master data, and
warehouse-systems-ddd.md's WMS/WES split places master data ownership in the WMS tier.inventory-storagealready ownsStockUnit(what is held where) and now also ownsProductClassification(what a SKU is) — two separate aggregates, both keyed by SKU-adjacent identity, neither derived from the other. -
Where does the placement rule actually get enforced? The rule needs two facts at the moment of stow: what the SKU requires, and what the target bin's zone provides. This service has the first (once it owns classification) but not the second —
facility-layoutis the bounded context that modelsZone.HazmatandZone.TemperatureClass. Enforcing the rule here therefore requires a cross-context read, in parallel withfacility-layoutadding a newGET /locations/{locationCode}/classificationendpoint for exactly this purpose.
Constraints that shaped the answer:
- The taxonomy is closed. Hazmat/Fragile/TemperatureSensitive/Oversized/
HighValue is fixed business vocabulary — unlike
location.LocationType(an open tag list on a Zone), there is no operational reason to let this set grow ad hoc. A closed Go enum with a validating parser is the right shape, not an open string tag. - This service does not own
facility-layout's domain model, and never will.TemperatureClassalready exists there asZone.TemperatureClass. Importing that package across a repository boundary would violate the bounded-context rule (warehouse-systems-ddd.md: no shared Go code across contexts) as badly as importing its database would. - A cross-service HTTP dependency changes the failure surface of
StowStock. Before this change,StowStock's availability depended only on this service's own repos. Adding a synchronous read to another service means facility-layout being down can now block a stow — but only if handled carelessly. The existing precedent in this platform (fulfillment-execution's documentedpath_id-prefix simplification in itsINTEGRATION.md) shows the house style: make integration simplifications explicit rather than silently correct, and keep the blast radius as small as the actual risk. - The existing test suite, CI, and deployments must be unaffected. The
same requirement that shaped ADR 0004's
EVENT_PUBLISHER=kafka|logpattern applies here.
Decision
We will add ProductClassification as a new aggregate this service owns
as source of truth, and enforce hazmat/temperature placement rules in
StowStock via a synchronous read from facility-layout, with a documented
fail-open/fail-closed asymmetry.
-
New domain package
internal/domain/product/.HandlingTagis a closedstringenum (Hazmat,Fragile,TemperatureSensitive,Oversized,HighValue) with a validatingParseHandlingTag.ProductClassificationis the aggregate root, keyed bySKU, holding aHandlingTagsset and aTemperatureClass. Its invariant:TemperatureSensitiverequires a valid, non-emptyTemperatureClass; absence ofTemperatureSensitivemeansTemperatureClassmust be empty. Construction/replacement raisesProductClassified(sku, tags, temperatureClass, occurredAt). -
A deliberate, small duplication of
TemperatureClass. This package defines its ownTemperatureClass(Ambient/Chilled/Frozen) — identical by name and meaning to facility-layout'sZone.TemperatureClass, but a distinct Go type owned by this repository. This is the same pattern already in force for the shared words "Zone" and "Location" across these two contexts (see the ubiquitous-language "words that mean something different elsewhere" table): bounded contexts do not share Go types across repository boundaries, even when the underlying concept and its valid values genuinely coincide. Translating at the integration edge (the outbound adapter, below) is the Anti-Corruption Layer, not an annoyance to engineer away. -
New use case
ClassifyProduct(ProductClassificationRepo.Save,EventPublisher,Clock) registers or replaces a SKU's classification. It is idempotent by SKU — re-classifying an already-classified SKU replaces rather than errors, the same "replace, don't error" patternfulfillment-execution'sRegisterStationalready uses for a structurally identical situation (recertifying a station). -
New outbound port
LocationClassificationLookupreturns aproduct.SlotAttributes{Hazmat, TemperatureClass, Known}for aBinId.Known=falsemeans "no constraint info available for this bin, permit the stow" — the fail-open default for any bin facility-layout has not (yet) modeled. -
BinIdvalues are treated as facility-layoutLocationCodevalues directly. No translation table, no lookup-of-a-lookup. This is a documented cross-context simplification, in the same spirit asfulfillment-execution'spath_id-prefix convention: both bounded contexts already code physical slots as short human-readable strings (A-1-1), and assuming the same string identifies the same physical location across the platform is a reasonable simplification for this round, not a permanent guarantee. The same assumption is restated where it is relied upon, in thefacilitylayout.Clientdoc comment (internal/adapters/outbound/facilitylayout/client.go). A future divergence between the two contexts' coding schemes would require a real translation layer here. -
Two adapters behind the port, selected by
LOCATION_LOOKUP_MODE(http|permissive), defaultpermissive.facilitylayout.Clientis a plainnet/httpGET againstFACILITY_LAYOUT_BASE_URL + /locations/{locationCode}/classification;facilitylayout.PermissiveLookupis a no-op that always returnsKnown=false. This is exactly theEVENT_PUBLISHER=kafka|logpattern from ADR 0004, applied to an inbound dependency instead of an outbound one, for an identical reason: existing tests, CI, and deployments that do not opt in see zero behavioural change. -
A 404 from facility-layout is
Known=false(fail-open). That location simply is not modeled there yet — treating it as a hard error would make classification enforcement a precondition for every stow in the system, which is a far larger blast radius than the safety problem being solved. -
Any transport or 5xx error is
ErrLocationClassificationUnavailable— but StowStock only surfaces it as a stow-blocking failure when the SKU being stowed carriesHazmatorTemperatureSensitive. This is the deliberate fail-open/fail-closed asymmetry at the heart of this decision: classified, rule-relevant SKUs fail closed (a hazmat item cannot be stowed blind when the safety check itself is unavailable), while every other SKU — unclassified, or classified with onlyFragile/Oversized/HighValue— is never blocked by a facility-layout outage. The whole stow path's availability is not coupled to facility-layout's; only the availability of stowing specifically hazmat/temperature-sensitive inventory is. -
StowStockgains two optional, nil-safe struct fields:Classifications ports.ProductClassificationRepoandLocationLookup ports.LocationClassificationLookup. When either is nil,StowStockbehaves exactly as it did before this ADR — no placement check runs at all. Every pre-existingStowStocktest (and every construction ofStowStockinfeatures_test.go,server_test.go,cmd/mcp) continues to compile and pass unmodified. -
New typed errors
ErrHazmatZoneRequiredandErrTemperatureClassMismatch, mapped to409 Conflictvia RFC 7807 (ADR 0005), consistent with every existing conflict-class error inadapters/inbound/http/errors.go. -
New REST surface:
PUT /products/{sku}/classification(create or replace;201/200) andGET /products/{sku}/classification(200/404), following the existing DTO/writeJSON/writeErrorconventions exactly.
Consequences
Easier
- Real hazmat/temperature safety at stow time, not just a capacity check. The two riskiest handling categories in the taxonomy are now actively enforced, not merely recorded.
- Classification is a first-class, queryable resource independent of
physical stock — a SKU can be classified before it is ever received, and
the classification survives every stow/pick/cycle-count cycle its
StockUnits go through. - Fully additive to the existing StowStock contract. No existing test,
deployment, or caller changes behaviour unless it opts into
LOCATION_LOOKUP_MODE=httpand actually classifies a SKU. - The permissive default keeps the blast radius contained. A team can ship this ADR's code without also standing up the cross-service dependency — enforcement is opt-in at deploy time, exactly like Kafka publishing was.
Harder
- A cross-service HTTP dependency now exists on the stow path, where
none did before. Even scoped to classified SKUs only, this is new
operational surface: a new client, a new timeout to tune
(
facilitylayout.DefaultTimeout), a new external failure mode to monitor. - The fail-open/fail-closed asymmetry is a judgment call, not a law of physics. Treating an unknown bin as safe-to-stow (fail-open) is a reasonable default while facility-layout's location catalog is still being populated, but it means a genuinely hazmat-restricted zone that facility-layout simply hasn't modeled yet will not be protected. This is the same class of tradeoff ADR 0004 made explicit for at-least-once Kafka delivery: recorded here rather than silently assumed.
- The
BinId-as-LocationCodesimplification is load-bearing and undocumented anywhere in code — only here and in this ADR. If the two contexts' coding schemes ever diverge, every classified SKU's placement check silently starts consulting the wrong location, most likely surfacing as unexplained fail-opens (mismatched codes look like unknown bins) rather than a loud error. TemperatureClassnow exists as two distinct Go types with identical values across two repositories. Anyone readingproduct.TemperatureClasswithout this ADR could reasonably assume it is the same type as facility-layout'sZone.TemperatureClassand try to share code between them; there is no compiler check preventing that mistake, only this record and the ubiquitous-language table.ClassifyProduct's idempotent-replace semantics have no audit trail. Re-classifying a SKU (e.g. narrowing it from Hazmat to non-Hazmat) simply overwrites the prior classification; there is no history of what a SKU used to be classified as, unlikeReservation's append-onlyAllocations. If classification history ever becomes a compliance requirement, this will need revisiting.