Class diagram
Synced from returns-processing
This page is a copy of docs/docs/ddd/class-diagram.md on develop, derived from that repository's code. Edit it there, then re-sync.
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 wins outright; then the table's exact (grade, class) entry or its*default; then a RESTOCK the table returned is demoted tovetoOutcomewhen the grade is below B 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.