Skip to main content

Aggregate Design Canvas

Following the ddd-crew Aggregate Design Canvas v1.1. Part of the DDD artifact pack. The domain package (internal/domain/**) has exactly three aggregate roots: processpath.ProcessPath, cptschedule.CPTSchedule and processflow.ProcessFlow. The narrative "why" behind the invariants lives in Aggregates & Invariants.

ProcessPath​

1. Name​

ProcessPath (internal/domain/processpath/process_path.go), identity shared.PathId.

2. Description​

The operator-configurable definition of one process path: its canonical id, the matchPrefix rule consumers use to resolve caller-supplied ids, whether it is Direct, the capabilities required to work it, an optional destination location role, and its fulfillment capability contract (cycleTimeP95, eligibility), and its intake: the demand sources allowed to route work onto it (ADR 0034). Persisted by natural key; never deleted.

3. State Transitions​

Source: processpath.Status (StatusActive = "ACTIVE", StatusDeactivated = "DEACTIVATED"), Define, (*ProcessPath).Revise, (*ProcessPath).Deactivate. Omits: Rehydrate (reconstruction, not a transition).

4. Enforced Invariants​

InvariantEnforced by
pathId non-emptyprocesspath.ErrEmptyPathId in Define
matchPrefix non-emptyprocesspath.ErrEmptyMatchPrefix in validate (Define + Revise)
matchPrefix lower-case, never coercedprocesspath.ErrMatchPrefixNotLowercase in validate
at least one required capabilityprocesspath.ErrNoRequiredCapabilities in validate
destinationLocationRole empty or Drop/WorkCenter/Shippingshared.ErrInvalidDestinationLocationRole via shared.ParseDestinationLocationRole
intake is a set of known demand sources (no unknown, blank or repeated value); [] is validshared.ErrInvalidIntake via shared.ParseIntake (an Intake can only be built through it)
cycleTimeP95 strictly positiveprocesspath.ErrInvalidCycleTime in validate (also returned by the HTTP adapter for an unparsable duration)
only an Active path can be revisedprocesspath.ErrPathDeactivated in Revise
pathId, direct, destinationLocationRole immutableRevise has no parameter for them
an id is never re-defined, active or deactivatedusecases.ErrPathAlreadyExists in DefinePath (use case, needs the repo): a FindByID pre-check, backed by the insert-only ports.ProcessPathRepo.Create (INSERT ... ON CONFLICT (id) DO NOTHING → ports.ErrAlreadyExists) so two concurrent defines of one id cannot both succeed
a path that a CPT schedule lists cannot be deactivatedusecases.ErrPathReferencedByCPTSchedule in DeactivatePath, via ports.CPTScheduleRepo.ListSiteIDsReferencingPath (409 path-referenced-by-cpt-schedule, ADR 0026); race-free since the path row is read FOR UPDATE first and DefineCPTSchedule holds FOR SHARE on every path it lists until commit (ports.ProcessPathRepo.FindByIDForUpdate / LockByIDsForShare, ADR 0028)
a path that an ACTIVE process flow has a stage on cannot be deactivatedusecases.ErrPathInActiveFlow in DeactivatePath, via ports.ProcessFlowRepo.ListActiveFlowIDsReferencingPath (409 path-in-active-flow, ADR 0042); same lock order as the schedule rule, DefineProcessFlow holds FOR SHARE on every path it names until commit
no lost update between load and saveports.ErrConcurrentModification from the version-guarded upsert in postgres.ProcessPathRepo.Save (ADR 0017) — used by revise and deactivate, not by create

5. Corrective Policies​

  • Invalid input is rejected synchronously (422 RFC 7807); nothing is persisted or published — no compensating action is needed.
  • 409 concurrent-modification: the client reloads and retries.
  • Deactivation is not a compensating action for anything downstream: this context only publishes ProcessPathDeactivated, and each consumer applies it to its own local catalogue (for example the applyDeactivated handlers in the sibling kafkacatalog / processpathcache consumers). What happens to work already in flight is each consumer's decision.
  • A path that any CPT schedule still lists is not deactivated: the command is refused with 409 path-referenced-by-cpt-schedule naming the sites, and the operator revises those schedules first (ADR 0026). The schedule is never pruned automatically and no CPTScheduleChanged is raised as a side effect of a deactivation.
  • A path that an ACTIVE process flow has a stage on is not deactivated either: 409 path-in-active-flow naming the flows; the operator revises or retires those flows first (ADR 0042).

6. Handled Commands​

CommandEntry pointUse case
Define pathPOST /process-pathsusecases.DefinePath → processpath.Define
Revise pathPUT /process-paths/{pathId}usecases.RevisePath → (*ProcessPath).Revise
Deactivate pathDELETE /process-paths/{pathId}usecases.DeactivatePath → (*ProcessPath).Deactivate

7. Created Events​

  • com.warehouse.wes.process-path-management.processpath.ProcessPathCreated
  • com.warehouse.wes.process-path-management.processpath.ProcessPathUpdated (only when changed)
  • com.warehouse.wes.process-path-management.processpath.ProcessPathDeactivated (only from ACTIVE)

8. Throughput​

Estimate. Operator-driven configuration: tens of commands per day at most, close to zero concurrency per instance. Reads (GET, MCP) dominate writes; consumers do not read over REST at all.

9. Size​

Estimate. Lifetime of years. Roughly 1 Created + a handful of Updated + at most 1 Deactivated event per instance (under ~20). State is a few hundred bytes; the catalogue holds tens of paths, not thousands.

CPTSchedule​

1. Name​

CPTSchedule (internal/domain/cptschedule/cpt_schedule.go), identity shared.SiteId; child entity Cutoff (local identity cptId).

2. Description​

A site's recurring Critical Pull Time schedule: an IANA timezone and one or more cutoffs (cptId, localTime, daysOfWeek, shipMethod, eligiblePathIds). Modelled once per site because a CPT belongs to a departure, not to a path (ADR 0010). Always replaced wholesale.

3. State Transitions​

The aggregate has no status enum; it exists or it does not.

Source: cptschedule.Define, (*CPTSchedule).Revise, usecases.DefineCPTSchedule. Omits: Rehydrate.

4. Enforced Invariants​

InvariantEnforced by
timezone non-emptycptschedule.ErrEmptyTimezone
timezone is a valid IANA zonecptschedule.ErrInvalidTimezone (time.LoadLocation)
at least one cutoffcptschedule.ErrNoCutoffs
cptId unique within the schedulecptschedule.ErrDuplicateCptId
cptId non-emptycptschedule.ErrEmptyCptId (NewCutoff)
localTime present and strict HH:MMcptschedule.ErrEmptyLocalTime, cptschedule.ErrInvalidLocalTime
daysOfWeek non-empty, each Mon..Suncptschedule.ErrNoDaysOfWeek, cptschedule.ErrInvalidDayOfWeek
shipMethod non-emptycptschedule.ErrEmptyShipMethod
eligiblePathIds non-emptycptschedule.ErrNoEligiblePathIds
every eligible path id is an Active ProcessPath (cross-aggregate)usecases.ErrIneligiblePathId in DefineCPTSchedule.validateEligiblePathIds
no lost updateports.ErrConcurrentModification from postgres.CPTScheduleRepo.Save

5. Corrective Policies​

  • Invalid schedule → 422, nothing stored or published.
  • Concurrent writer → 409, reload and retry.
  • Consumers compute concrete cutoff instants themselves from (local_time, days_of_week, timezone); this context never publishes absolute timestamps.

6. Handled Commands​

CommandEntry pointUse case
Define or revise CPT schedulePUT /sites/{siteId}/cpt-scheduleusecases.DefineCPTSchedule → cptschedule.Define or (*CPTSchedule).Revise

7. Created Events​

  • com.warehouse.wes.process-path-management.cptschedule.CPTScheduleChanged — full snapshot, on first define and on every real revision.

8. Throughput​

Estimate. One schedule per site, revised when carrier departures change — a few writes per site per week.

9. Size​

Estimate. Lifetime of the site. Tens of cutoffs per schedule; one event per revision, so a few hundred events per instance over years.

ProcessFlow​

1. Name​

ProcessFlow (internal/domain/processflow/process_flow.go), identity processflow.FlowId.

2. Description​

The ordered sequence of process-path stages a workload passes through (for example PICK, REBIN, PACK, SLAM): name, ordered stages (each a Stage of pathId and processType), status and a published version (ADR 0042). A ProcessPath is one stage; the flow says which stage follows which. Persisted by natural key; never deleted, retired instead.

3. State Transitions​

Source: processflow.Status (StatusActive = "ACTIVE", StatusRetired = "RETIRED"), Define, (*ProcessFlow).Revise, (*ProcessFlow).Retire. Omits: Rehydrate; a Revise that changes nothing (no event, same version).

4. Enforced Invariants​

InvariantEnforced by
flowId non-emptyprocessflow.ErrEmptyFlowId in Define
name non-emptyprocessflow.ErrEmptyName in validate
at least one stageprocessflow.ErrNoStages
each stage's pathId non-emptyprocessflow.ErrEmptyStagePathId (NewStage)
processType is one of PICK, REBIN, PACK, SLAM, DISPATCH, ARRIVAL, RELOCATE, REPLENISHprocessflow.ErrInvalidProcessType (NewStage, validate)
a pathId appears at most once in a flowprocessflow.ErrDuplicateStagePath
only an ACTIVE flow can be revisedprocessflow.ErrFlowRetired in Revise
version starts at 1, +1 per accepted change, unchanged by a no-opDefine, Revise, Retire
every stage's pathId is an Active ProcessPath (cross-aggregate)usecases.ErrIneligibleStagePath in DefineProcessFlow.lockAndValidateStagePaths, under LockByIDsForShare
no lost update; a concurrent first define of one idports.ErrConcurrentModification from postgres.ProcessFlowRepo.Save, and from Create reporting ports.ErrAlreadyExists

5. Corrective Policies​

  • Invalid flow → 422, nothing stored or published.
  • Concurrent writer → 409, reload and retry.
  • A retired flow is never revived; define a new flowId instead.
  • Consumers apply a flow event only when its version is greater than the one they hold; the start-up republish re-sends each ACTIVE flow as ProcessFlowRevised at its current version (ADR 0038, ADR 0042).

6. Handled Commands​

CommandEntry pointUse case
Define or revise process flowPUT /process-flows/{flowId}usecases.DefineProcessFlow → processflow.Define or (*ProcessFlow).Revise
Retire process flowDELETE /process-flows/{flowId}usecases.RetireProcessFlow → (*ProcessFlow).Retire

7. Created Events​

  • com.warehouse.wes.process-path-management.processflow.ProcessFlowDefined
  • com.warehouse.wes.process-path-management.processflow.ProcessFlowRevised (only when changed, and on every start-up republish of an ACTIVE flow)
  • com.warehouse.wes.process-path-management.processflow.ProcessFlowRetired (first retirement only)

Each carries the full state (flow_id, name, stages[], status, version).

8. Throughput​

Estimate. Flows describe the floor's topology and change when a process is re-laid out — a handful of writes per flow per quarter.

9. Size​

Estimate. A few flows per site and a few stages each; one event per accepted change, so tens of events per flow over its life.

Not aggregates​

TypeWhat it is
shared.Eligibility, shared.DestinationLocationRole, shared.PathId, shared.SiteId, shared.Capability, cptschedule.WeekdayValue objects / identity types
cptschedule.CutoffEntity inside CPTSchedule
processflow.Stage, processflow.ProcessType, processflow.FlowIdValue objects inside / identity of ProcessFlow
report.CatalogueReport, report.Row (internal/analytics/report)Read model of the analytics projection — built by pathmgmt-projector, served by pathmgmt-reports
processPathResponse, cptScheduleResponse, processFlowDTO, MCP DTOsAdapter DTOs
Consumer catalogue caches in sibling reposTheir read models, not part of this context