Class diagram
The domain model exactly as it exists in internal/domain (field and
method names taken from the code; pure Go, no I/O).
Facts worth knowing that the diagram cannot show:
RequestandOpenare package functions ofreturnauthorizationandreturnreceipt(they validate the input and build the aggregate);DecideForLine,DecideandDeclareare package functions ofdisposition. Everything after creation is a method on the aggregate — exceptDecide, which is a pure function over (grade, classification, policy) with no receiver.Statusis a string type:REQUESTED | AUTHORIZED | REJECTED | RECEIVED | CLOSED, withREJECTEDandCLOSEDterminal. v1 decides in one transaction (REQUESTED → AUTHORIZED insideAuthorizeReturn);Reject,MarkReceivedandCloseare implemented and repository-tested but have no v1 use case caller.RejectionCodeis a string type:LINE_NOT_MANIFESTED,RETURN_WINDOW_EXPIRED,OPEN_RMA_EXISTS,QUANTITY_EXCEEDS_POLICY;RejectionCodeFormaps the typed domain errors to the codes at the HTTP edge.- A
Lineis built byMatchedLineorUnexpectedLineonly, so a line is always exactly one kind — the zeroLine(the refused third state) failsOpen.LineKindisMATCHED | UNEXPECTED. Decide's order of precedence: a forced outcome on the classification overrides the table, exceptforce:DISPOSE, which is a RESTOCK guardrail rather than an outcome; then the table's exact (grade, class) entry or its*default; then a RESTOCK (table or forced) is demoted tovetoOutcomewhen the grade is below B, the SKU is DISPOSE-classified, or the SKU is hazmat without a DOT rating.- The domain events (
ReturnAuthorized… in each aggregate'sevents.go) are plain structs with a per-packageHeaderandOccurredAt(); they know nothing of CloudEvents or Kafka — the outbound adapter maps them (ADR 0004). - Repositories persist and restore through the immutable
Snapshot(each aggregate'ssnapshot.go;Restorevalidates, so a corrupt row can never become a live aggregate); the views DTO (internal/application/views) is what inbound adapters see. shared.ID(validated, non-blank, no NUL),shared.Quantity(an integer ≥ 1),shared.SiteID,shared.Grade(A | B | C | SCRAP) andshared.OrderLineRefwith the work-unit formula{order_id}-line-{line_no}(WorkUnit(), the reverse of fulfillment-execution'sorder_ref) are the shared value objects.