ADR 0002: Aggregates, invariants and assumptions
Status
Accepted (2026-10-25).
Context
The design source is warehouse-docs storefront/model/model.yaml, context
product-content, with the FINAL model-gap decisions of the storefront campaign
applied on top (they override the model where they differ). This ADR records the
aggregates as built and every assumption (A1, A2, ...) taken where the model and the
decisions are silent. Each assumption is also reported to the orchestrator as a
model_gap.
Decision
Aggregates
- ProductContent (
internal/domain/content, rootcatalogItemId): description, bullets (at most 10), attributes{name, value, unit?}(at most 50), media{mediaId, url, altText, role PRIMARY|GALLERY}(at most 12),primaryCategoryId,revision,publishedRevision.- States
DRAFT -> PUBLISHED -> RETIRED, plusDRAFT -> DRAFT(ReviseDraft),PUBLISHED -> PUBLISHED(ReviseContent, then PublishContent with the new revision) andDRAFT -> RETIRED(DiscardDraft, reasonDISCARDED, no event, and RetireOnDiscontinue, reasonDISCONTINUED). - Errors:
ErrUnknownCatalogItem,ErrItemDiscontinued,ErrIncompleteContent,ErrUnknownCategory,ErrContentRetired,ErrTooManyBullets,ErrTooManyAttributes,ErrTooManyMedia.
- States
- CategoryTree (
internal/domain/category, rootcategoryTreeId=main): ONE live aggregate with no draft state. Every command (CreateCategory, MoveCategory, RenameCategory, PublishCategoryTree) applies to the live tree and publishes a new version. Errors:ErrCategoryCycle,ErrMaxDepth(4),ErrDuplicateSiblingName,ErrCategoryInUse. Categories are never deleted, only created, moved and renamed: there is no remove-category command by design, andErrCategoryInUseis declared to guard a future removal (model-gap decision 4); nothing raises it today. - The two aggregates share no state. The only cross-aggregate fact is whether a
category exists in the current tree, which the use case passes to ProductContent as
the
content.Categoriesinterface.
Assumptions
- A1 Revisions.
revisionis the number of the current shape of the content: 1 at creation, plus one for every ReviseDraft and ReviseContent.publishedRevisionis the revision last published (0 = never). PublishContent publishes the CURRENT revision. Publishing PUBLISHED content whoserevision == publishedRevisionhas nothing new to publish: the call succeeds, changes nothing and raises no event, so everyProductContentPublishedcarries a revision above the previous one and a repeated publish is harmless.ProductContentRetired.revisionis the revision at retirement. - A2 Integers. Every bounded integer fits a Postgres
integer. - A3 Time. Instants are UTC, truncated to the microsecond Postgres stores. The
CloudEvents
timeof an event is the aggregate'supdatedAtafter the change. - A4 One revise route.
POST /product-contents/{catalogItemId}/revisionsis ReviseDraft for a DRAFT and ReviseContent for PUBLISHED content; the state picks the command. The body replaces the whole editable content. PUBLISHED content must stay complete (incomplete-contentotherwise), so it is always publishable. A revise of RETIRED content is 409content-retired. - A5 Retirement reasons.
retiredReasonisMANUAL(RetireContent on PUBLISHED content),DISCARDED(DiscardDraft) orDISCONTINUED(RetireOnDiscontinue). It is on the REST read, not on the event (the event keeps the model's data list). RetireContent of a DRAFT or of RETIRED content is 409illegal-transition; a DRAFT is discarded instead. - A6 New routes.
DELETE /product-contents/{catalogItemId}/draft(DiscardDraft) andPOST /category-tree-publications(PublishCategoryTree, decision 1). PublishCategoryTree changes no category: it publishes the live tree again under a new version, the way to re-send it to a consumer. - A7 The tree. It is created by the first CreateCategory. Before that,
GET /categoriesanswers version 0 and an empty list. The tree version is the aggregate version. Category ids are minted by the service (cat-and 12 hex characters). Names are trimmed, 1 to 100 characters, without/; siblings are compared case-insensitively; a category path is the names from the root joined with/; the tree holds at most 5000 categories. Moving or renaming to the current parent or name still publishes a new version. - A8 Category errors. An unknown
categoryIdin the path (move, rename) is 404not-found. An unknown parent in a body (create, move) is 422unknown-category, like an unknownprimaryCategoryId. A move never raisescategory-in-use. - A9 Duplicate create. A second CreateProductContent for an item is 409
concurrent-update(the primary key oncatalogItemIdis the guard). - A10 Item errors.
unknown-catalog-itemanditem-discontinuedare 422. ErrUnknownCatalogItem applies to CreateProductContent and PublishContent; ErrItemDiscontinued too (decision 7). Revise, retire and discard do not look at the item. - A11 Collection and field limits. Beyond the three bounds (10/50/12, decision 5): description at most 4000 characters, a bullet 1 to 300, an attribute name 1 to 100, value 1 to 300, unit at most 20, a medium URL an absolute http(s) URL of at most 2048 characters, alt text 1 to 200, media ids valid and unique within the content. The collection bounds are checked before the fields, the fields before the category. A DRAFT may be incomplete (no description, no media, no category); completeness is the publish gate.
- A12 Listing.
GET /product-contentslists every state ordered bycatalogItemId; the opaquecursorencodes the lastcatalogItemIdof the previous page (ADR 0007) andnextCursoris that cursor, absent on the last page; the default page is 100 and the limit is 1 to 500. - A13 Idempotency. Every write takes an
Idempotency-Key(1 to 128 characters, remembered 24 hours by key (global since ADR 0007)). A repeated key with the same request body replays the stored response (markedIdempotency-Replayed: true); with a different body it is 409idempotency-key-reused. Every response below 500 is stored, client errors included, so a client retrying after a 4xx needs a fresh key; a 5xx is not stored. - A14 Ids. A
catalogItemIdis an opaque id of 1 to 64 characters fromA-Za-z0-9._:-starting with a letter or digit (shared.ValidID). Any other id is 422validation-failedon REST and a dead-lettered message on the consumer. - A15 Analytics. The model declares no analytics-only event; the
retailnetwork.product-content.analyticstopic receives nothing.
Consequences
- A DRAFT can be edited and discarded; PUBLISHED content can be edited and published again; shoppers (through product-discovery) only ever see published revisions.
- The tree is small (~10^3 categories), so it is stored as one row and every event carries the whole tree.