ADR 0006: Catalogue GTIN and packaging hierarchy, and the optional owner of a listing
Status
Accepted (2026-10-24).
Context
Sellers will ship inbound stock in cartons identified by GS1 GTINs, and the network needs to tell a case of 24 from a case of 12 of the same item, and stock owned by a seller from stock the operator owns. Two things were missing:
- No identifier, no pack levels. A
CatalogItemwas title, dimensions, weight and two flags. The fleet's product-master already models the same thing (its ADR 0011): a packaging hierarchy of GS1 pack levels, with the content quantity of a GTIN immutable. Diverging would make every later integration (the seller inbound loop reads these events) translate between two models. - One listing per (item, node). A seller's stock of an item on a node could not be told from the operator's.
Both changes must be additive: a caller that never sends the new fields sees the service exactly as before.
Decision
Identifier and packaging (mirrors product-master ADR 0011)
identifiers.gtinon a catalogue item is optional. It is validated with the template'sinternal/domain/shared/gs1value objects (installed with the template'smigrate_v3.py --with-gs1, never hand-edited): 8, 12, 13 or 14 digits, mod-10 check digit, normalised to 14 digits; a variable measure GTIN (indicator digit 9) is refused. Wrong GTIN isinvalid-gtin(422).- A GTIN identifies one thing, forever. It may be held by one item (as its
identifier) or by one pack level of one item, retired levels included. A
second holder is
gtin-already-assigned(409). The use case pre-checks (CatalogRepository.FindByGTIN); a partial unique index oncatalog_items.gtinand a unique constraint oncatalog_item_pack_levels.gtinare the backstop and map to the same error. - Pack levels are
EACH < INNER < CASE < PALLET, each{level, gtin, childGtin?, unitsPerPack, dimsMm?, grossWeightG?, active}inside theCatalogItemaggregate (one transaction, one version per save). Quantities are in eaches:unitsPerPackis 1 for EACH, at least 2 above it, and a multiple of the child's, at least twice (invalid-pack-quantity, max 1,000,000). A level above EACH names thechildGtinof an active, lower level of the same item (pack-level-order); a gross weight below the weight of the contents, when the child's is known, isinvalid-pack-dimensions. Availability stays in eaches: a pack level is a conversion plus an identity, never a second ledger. unitsPerPackis immutable per GTIN.PUT /catalog-items/{id}/packaging/{level}with the GTIN of the ACTIVE level and another count or child ispack-quantity-immutable(409). The identical declaration changes nothing and raises nothing; newdimsMm/grossWeightGon an active GTIN are updated in place (and published again asCatalogItemPackagingDeclared). A new GTIN at a level that has an active one supersedes it: the old level is retired (CatalogItemPackLevelRetired) and the new one declared (CatalogItemPackagingDeclared) in ONE aggregate version, both events carrying it. A retired GTIN stays on the item (so a document naming it still resolves) and can never be declared again.POST /catalog-items/{id}/packaging/{level}:retire(the repo's colon-verb style, like:discontinue) retires the active definition; retiring a level that only has history is a no-op, a level never declared ispack-level-not-found(404). A DISCONTINUED item takes no packaging change (illegal-transition). Both routes sit behind the Idempotency-Key middleware and answer 200 with the item;GET /catalogandGET /catalog/{id}carryidentifiersandpackaging[](omitted when empty).- Events
CatalogItemPackagingDeclared {catalogItemId, level, gtin, childGtin?, unitsPerPack, declaredAt}andCatalogItemPackLevelRetired {catalogItemId, level, gtin, retiredAt}, entitycatalogitem, typecom.retailnetwork.commerce.offer-availability.catalogitem.<Event>(this service's tier segment iscommerce, ADR 0004), same topic, key and outbox.CatalogItemCreatedgains an optionalgtin. All additive: payloads that omit the new optional fields are unchanged, so existing consumers and goldens stay valid. ADR 0004 andapis/asyncapi.yamllist them. - Persistence: migration
0002addscatalog_items.gtinandcatalog_item_pack_levels(rewritten with the item inside its transaction,seqkeeps declaration order, at most one active definition per item and level).
Owner of a listing
ListingandAvailabilitygain an optionalownerRef(thesellerId). Absent means operator-owned. There is one listing per (catalogItemId, nodeId, ownerRef):listings.owner_refisNOT NULL DEFAULT ''and the unique constraint becomes(catalog_item_id, node_id, owner_ref), so every existing row keeps its meaning and the old uniqueness still holds for it.POST /listingsacceptsownerRef;ListingCreatedandListingAvailabilityChangedcarry it when set. A feed line names alistingId, so feeds, staleness, suppression and restoring need no change: the owner is a property of the listing they already address.
Out of scope and follow-ups
- order-sourcing seller-awareness. Sourcing and the promise do not yet
distinguish seller-owned from operator-owned availability when they read
ListingAvailabilityChanged; they must be made seller-aware (useownerRef) before sellers' stock is sold. Tracked as a follow-up in that service, not done here. - Measured (versus declared) pack dimensions, which product-master models, are not mirrored: this context only keeps what the merchandiser declares.
pack-levelweights are checked against the child only when both are given.
Consequences
- The seller inbound context can validate case contents against the pack levels it
consumes from
CatalogItemPackagingDeclared/CatalogItemPackLevelRetired. - A changed count is a new GTIN and a new event pair, never a mutation: a consumer's local view can be keyed by GTIN and never needs a correction.
- Dropping the old
(item, node)constraint is irreversible for data with two owners: the down migration fails if two listings share an item and node.
Addendum 2026-11-13: current state
- Item 5 names
POST /catalog-items/{id}/packaging/{level}:retireand:discontinue. Those colon-verb routes no longer exist: ADR 0011 replaced them withPOST /catalog-items/{catalogItemId}/packaging/{level}/retirementsandPOST /catalog-items/{catalogItemId}/discontinuations(apis/openapi.yaml,internal/adapters/inbound/http/handlers.go);TestRetiredRoutesAreGonepins the old paths as gone. - The follow-up "order-sourcing seller-awareness" is done in those services: order-sourcing copies
ownerReffromListingCreatedandListingAvailabilityChangedinto its listing (internal/adapters/inbound/kafka/handlers.go, its ADR 0012, accepted 2026-11-08) and delivery-promise keys itsAvailabilityViewby (item, node,ownerRef) (its ADR 0017, accepted 2026-11-08).