ADR 0042: The layout and transport orders work in a Facility, products in a Business Unit, and unconverted callers use the default Facility
Status: Accepted. Converts the product, tasks and layout consumers that ADR 0040 left keyed on the owning Business Unit. The stock, orders, fulfilment and other consumers ADR 0040 lists stay as that record describes them until each one converts.
Context
ADR 0040 made the Facility a row and put it on the layout, but the consumers still asked for "the
owner's" layout: the location finder, the layout ports and the transport-order port took a
clientId or read an ambient TenantContext, and the database filled the Facility in behind them.
A few of those reads were wrong once a Business Unit could own a second Facility. The staging
lookups listed the areas of every Facility, the clearing lookup assumed one clearing location for
the whole system, and the putaway candidate query had no Facility predicate.
The end state is a Karyo that works with Company, Business Unit and Facility and not with the legacy stock owner. Karyo has no users, so a change here may be disruptive, and compatibility code has no reason to exist.
Decision
- A layout port names its Facility.
StorageLocationLookup,StorageStrategyLookup,WorkingAreaLookup,StagingLocationLookup,ClearingLocationLookup,LocationAreaUsageLookup,FixAssignmentLookup,ItemDataAreaLookup,TransportDemandLookup,LocationFinder,LocationLockPort,LocationFilterandPutawayLocationStrategytake a typedFacilityId. The layout services, repositories and resources take the Facility as a plain id and filter onfacility_id. No ambient overload remains. A location, strategy, fixed assignment, item-area row, area or reservation outside the named Facility is treated as unknown. - A transport order belongs to a Facility.
TransportOrderis aFacilityEntity.TransportOrderPorttakes aFacilityId, and the four commands that mint an order carry one instead of aclientId. The queue, the claim and the open-demand reads filter on the Facility. The Business Unit of the order is the Facility's own, and it is still the owner the inventory ports take. - A product read names its Business Unit.
ProductLookup.findById,findNamesByIdsandfindMeasuresByIds, andSubstitutionLookup.findSubstitutes, take the owning Business Unit and return only that unit's products. The ambient overloads andfindReadableOwnedByare deleted, and no read grant widens or narrows the answer.findMeasuresOfHeldProductsstays owner-independent because its caller already holds the product ids.facilityPolicytakes the unit and the Facility. - A caller that holds only a Business Unit uses its default Facility. Stock, orders, fulfilment,
waves, cross-dock, the replenishment scan, work dispatch, counts and the purge-blocker lookup of
the tasks module call
OrganizationLookup.requireDefaultFacilityId(orfindDefaultFacilityIdwhere "no Facility" is an answer) and pass the result. Each of those call sites is a bridge that the conversion of its own module deletes. The bridge is correct while a unit has one Facility. - Warehouse setup reads no ambient context.
WarehouseSetupServicetakes the Facilities the caller may write in from the resource and refuses a target outside them. - A location's
client_idstays data. It is always the Business Unit of the location's Facility. The finder compares no owner: a Facility has one owner.
Consequences
- Two Facilities of one Business Unit can each have a clearing location, a pack and a ship staging area, a picking area and a transport queue, and the finder never offers one Facility's location for another's unit load.
- A product reference no longer succeeds because the caller may read a sibling unit. The write-only and read-only differences the earlier inventory table described for product references are gone.
config/scope-consumers.jsonshrinks: the product, finder and setup files no longer opt in to raw scope, the layout repositories and most ofTransportOrderRepositoryno longer nameclient_id, and the layout, product and filter ports leave the list of ports without a scope. The fourTransportOrderPortcreate methods stay on it, because the Facility travels inside the command and the guard reads only the parameters.- The default-Facility bridge is a known wart: it sits in the callers of every converted port until
their modules convert, and a Business Unit with no default Facility fails with an
IllegalStateExceptionthere. The database already guarantees one for every positive unit. StorageStrategy.onlyClientLocationand the sharedclient_id = 0location are not read by the finder. The strategy field stays until the form is reworked, as ADR 0040 says.
Alternatives considered
- Pass the Business Unit and resolve the Facility inside layout. Rejected: the layout would need the organization lookup and would hide the Facility that a second Facility makes a real choice.
- Keep the ambient overloads for the callers that have no Facility. Rejected: they are the reads that failed on a scheduler thread, and each one is a place the final model has to find and delete again.
- Make the callers carry a Facility now. Rejected for this step: the stock, orders, fulfilment and wave rows still belong to a Business Unit, so a Facility taken from the row would be the same default one the bridge returns, with more code.
- Teach the port guard to read a Facility inside a command. Not recorded; the four exemptions are the smaller change.
Evidence
services/warehouse-layout-service/karyo-layout-api/src/main/kotlin/com/karyo/layout/spi/- the ports aboveservices/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/LocationFinderService.ktandrepository/StorageLocationRepository.kt-findPutawayCandidatesservices/task-service/karyo-tasks-api/src/main/kotlin/com/karyo/tasks/spi/TransportOrderPort.ktandkaryo-tasks-core/.../domain/model/TransportOrder.ktservices/product-service/karyo-product-api/src/main/kotlin/com/karyo/product/spi/ProductLookup.ktservices/auth-service/karyo-auth-api/src/main/kotlin/com/karyo/auth/spi/OrganizationLookupExt.kt- the bridge helpersconfig/scope-consumers.jsonandservices/karyo-app/src/test/kotlin/com/karyo/security/guards/- the registry and the guards that hold itservices/karyo-app/src/test/kotlin/com/karyo/layout/FacilityLayoutScopeTest.kt,layout/service/LocationFinderTest.kt,tasks/service/TransportDemandLookupTest.ktandproduct/service/DefaultProductLookupNamesTest.kt- the behaviour above
Related
- ADR 0006 and ADR 0007 - the module boundary the ports sit on
- ADR 0039 - the registry
- Identity and tenancy