Skip to main content

Use cases

Synced from inbound-receiving

This page is a copy of docs/docs/ddd/use-cases.md on develop, derived from that repository's code. Edit it there, then re-sync.

DockAppointment moved (ADR 0019)

The dock appointment is owned by dock-scheduling since ADR 0019. This context keeps a read-only local copy fed by dock-scheduling's DockAppointmentBooked / DockAppointmentCancelled, no longer books, checks in, cancels or completes appointments, and no longer raises the four DockAppointment* events (the one-shot api republish-appointments backfill that re-announced them was removed, ADR 0022). Where this page describes those commands, rules or events, read it as the pre-transfer design; the page is not yet rewritten.

Application services in internal/application/usecases. The six REST write use cases (RegisterAsn, CancelAsn, OpenReceipt, ReceiveLine, ReceiveScan, CloseReceipt) embed Writer (writer.go), which runs load, command, version-guarded save and outbox insert in one ports.UnitOfWork; so do the two stow consumer use cases. The eleven consumer use cases (consumers*.go) claim the CloudEvents id and apply the effect in one unit of work. The three appointment write use cases (BookAppointment, CheckInAppointment, CancelAppointment) no longer exist: their routes answer 410 appointment-moved (ADR 0019).

Commands​

Use caseInboundWhat it does
RegisterAsnPOST /asns (Idempotency-Key required)Builds the ASN (asn.Register), with PRODUCT_MODE=kafka checks every line's SKU against known_skus (422 unknown-sku), then saves it unless the number exists (409 asn-already-exists). 201, ASNRegistered.
CancelAsnPOST /asns/{asnNumber}/cancellationsLoads the ASN, checks If-Match, cancels a Registered one. 200, ASNCancelled. 409 asn-in-progress while Receiving, 409 asn-terminal when Closed or Cancelled.
OpenReceiptPOST /receipts (Idempotency-Key required)In one unit of work: loads the ASN (422 unknown-asn), validates the optional appointment against the local copy (422 unknown-appointment, 422 asn-not-on-appointment, 409 appointment-cancelled) and takes its door, opens the receipt against the ASN snapshot, requires no open receipt for the ASN (409 receipt-already-open), moves the ASN to Receiving and saves both. 201, ReceiptOpened.
ReceiveLinePOST /receipts/{receiptId}/lines (Idempotency-Key required, not naturally idempotent)Loads the receipt, checks If-Match, records the quantity as Good or Damaged. 201, ReceiptLineReceived. 409 receipt-closed, 422 line-not-on-asn, 400 invalid-condition.
ReceiveScanPOST /receipts/{receiptId}/scans (Idempotency-Key required)Receives by scan: an SSCC accepts the carton's manifest, a case GTIN books cases x units per pack, an each GTIN books eaches. A refused scan is not an error: it commits the finding and books nothing. ReceiptLineReceived and ReceiptCartonReceived for an accepted scan, CartonDiscrepancyRaised per finding.
CloseReceiptPOST /receipts/{receiptId}/closuresIn ONE unit of work: closes the receipt (computing the discrepancies), completes the ASN and evaluates the dock-to-stock fact. 200, CartonDiscrepancyRaised (a MissingCarton per manifest carton never accepted), ReceiptClosed and, when the evidence is complete, ReceiptStowCompleted. 409 receipt-closed. It no longer completes the appointment (ADR 0019).

Queries​

Use caseInboundWhat it does
GetAsnGET /asns/{asnNumber}One ASN with lines, state and version (also the ETag); 404 asn-not-found.
ListAsnsGET /asnsPages in ascending ASN-number order, optional state filter.
GetAsnCartonsGET /asns/{asnNumber}/cartonsThe announced cartons with their receive status.
GetAppointmentGET /appointments/{appointmentId}One appointment from the local copy (deprecated, kept pending a decision, ADR 0022); 404 appointment-not-found.
ListAppointmentsGET /appointments(deprecated, same) Pages by windowStart then id; filters door, state, and from / to (windows overlapping [from, to)).
GetCartonLabelGET /receipts/{receiptId}/cartons/{lpn}/labelThe label of one received carton.
GetReceiptGET /receipts/{receiptId}One receipt with the discrepancies as they stand now; 404 receipt-not-found.
ListReceiptsGET /receiptsPages by receipt id; filters asnNumber, state.
ListDocksGET /docksThe known inbound dock doors in door-code order plus the current DOCK_DOOR_MODE.

Lists use cursor paging: limit 1..500 (default 100) and the opaque cursor that is the previous page's nextCursor; a bad value is 400 invalid-query (usecases.ErrInvalidListQuery).

Event-driven use cases (local copies)​

Use caseTriggered byWhat it does
ApplyProductRegisteredProductRegistered on warehouse.product-master.eventsClaims the CloudEvents id (consumer product-registry) and upserts the SKU into known_skus, in one unit of work. Returns applied or duplicate; an invalid SKU is ErrInvalidEvent, claimed nothing.
ApplyLocationSlotRegisteredLocationSlotRegistered on warehouse.facility.eventsIgnores anything but role=Dock with dockFlow Inbound or Both (ignored); otherwise claims the id (consumer dock-door-registry) and upserts the door.
ApplyLocationSlotDecommissionedLocationSlotDecommissionedClaims the id and removes the door; a code that is not a known door is a no-op success.
ApplyPackLevelDeclared, ApplyPackLevelRetiredProductPackLevelDeclared / ProductPackLevelRetired on warehouse.product-master.eventsKeep the packaging view used by case-level scans.
ApplyDockAppointmentBooked, ApplyDockAppointmentCancelled, ApplyDockAppointmentRescheduled, ApplyDockAppointmentDoorReassigneddock-scheduling's DockAppointment* types on warehouse.dock-scheduling.eventsKeep the appointments local copy, guarded by the event version; raise no event (ADR 0019, ADR 0020).
ApplyVisitCheckedIn, ApplyContainerStowedVisitCheckedIn on warehouse.yard-management.events, ContainerStowed on warehouse.inventory.eventsStore the arrival or the stow, then evaluate the dock-to-stock fact and may raise ReceiptStowCompleted (ADR 0021).

Analytics read side (outside internal/application)​

The analytics binaries do not use the application layer; their "use cases" are the ports in internal/analytics/report (ADR 0006):

PortTriggerWhat it does
report.Projection.Applythe events on warehouse.inbound-receiving.analytics it knows (ten kinds: six of the eight current types plus the four historical dockappointment types, ADR 0022; the two carton types are ignored), consumed by cmd/inbound-projectorClaims the CloudEvents id in analytics_processed_events and folds the event into asn_facts, appointment_facts, receipt_facts, receipt_line_events or receipt_discrepancies in one analytical transaction. A deterministic rejection (report.ErrRejected) is dead-lettered to warehouse.inbound-receiving.analytics.dlq.
report.Reader.PerformanceDays + CurrentGET /reports/receiving-performance on cmd/inbound-reportsPer-UTC-day counts and p50/p95 timings over [from, to) (default the last 30 days, at most 366) plus today's open receipts and expected arrivals.
report.Reader.LastEventAtGET /reports/freshnessas_of and lag_seconds of the projection.

Response shapes: Runbook — Reports API.

Cross-cutting behaviour​

  • Idempotency. Idempotency-Key on every POST: a replay returns the original response (Idempotency-Replayed: true), the same key with another request is 409 idempotency-key-reused.
  • Optimistic concurrency. Every save is guarded by the loaded version; a race is 409 concurrent-modification, a stale If-Match is 412 version-mismatch.
  • Errors are RFC 7807 problems from one table, problemCatalogue in internal/adapters/inbound/http/errors.go.

Acceptance scenarios are in features/*.feature (7 files, 71 scenarios: register_asn, dock_appointments, receiving, idempotent_replays, list_receipts_and_docks, dock_door_registry, probes; godog, features_test.go and features_wave2_test.go). See Testing.