Documentation/ Decision records
ADR 0006: `-api` modules hold contracts, `-core` modules hold implementations, and no core depends on another
Status: Accepted
Context
Every module runs in one process (ADR 0001), so nothing at runtime stops one module from reaching into another's entities and services. The boundary between modules is only as strong as the build graph that describes it. Held, it keeps each domain understandable on its own, lets a client's extension compile against contracts rather than implementations (ADR 0019), and lets the engine modules plug into the product through published seams (ADR 0029).
Decision
- Each domain is a pair of modules.
karyo-<domain>-apiholds DTOs, SPI interfaces and the event payloads other modules observe.karyo-<domain>-coreholds JPA entities, repositories, services and REST resources. - A
-coredepends on its own-api, on other modules'-api, and onlibs/*. It never depends on another module's-core, apart from the two waivers below. - When a dependency would point the wrong way, the module that needs the answer declares the
interface in its own
-apiand the module that has the answer implements it.PurgeBlockerLookupis declared in inventory and implemented by fulfillment, orders, stocktaking and tasks (PurgeBlockerLookup);PickZoneLookupis declared in fulfillment (PickZoneLookup). - An event payload that another module observes is declared in the firing module's
-api, so the observer needs no edge to the firing module's core (WavePickActivityEvent). -apimodules depend on each other withimplementation, except where a module's own public signatures expose the other's types, which needsapi(...). The edges that do are listed in Modules and boundaries.- Every module whose beans the application must discover carries a
META-INF/beans.xml; thirty-two modules do. - Two waivers, recorded as waivers and not as precedent. A third,
karyo-ai-core(the Copilot's tool wrappers over domain services), was retired with the Copilot (ADR 0041):karyo-demodepends on eight other cores. It is a leaf module that is off in production and invisible when off - its routes answer 404 unlessKARYO_DEMO=on- and it reuses the domain entities and repositories to construct back-dated demo data (services/demo-service/karyo-demo/build.gradle.kts,dependencies (cross-core waiver comment);DemoEnabledFilter;services/karyo-app/src/main/resources/application.yaml,karyo.demo).- The monitors engine,
karyo-monitors-core, depends onkaryo-replenishment-coreto call the replenishment service's needs query. Its reason is not recorded.karyo-replenishment-apiholds only its DTOs andReplenishmentStrategy, so there is no SPI the engine could have used instead.
- A new
-core-to--coredependency needs, at minimum, a justification comment in the build file. Unless it is a production-disabled leaf, the right answer is an SPI in the owning-api.
Consequences
- The contract surface is explicit: each
-apiis what other modules, extensions and the engine modules may rely on. - Which bean satisfies an SPI is resolved by CDI at runtime. The graph shows who consumes a contract, not who fulfils it.
- A Gradle task enforces the rule.
verifyModuleBoundariesreads the project dependencies from Gradle's own project model and fails on a new-core-to--coreedge outside the waivers above, and on a waiver that no longer matches an edge. It runs before every test task and withcheck. There is still no ArchUnit test or Detekt rule: the task looks at declared project dependencies and nothing else. - The Gradle graph is one of four coupling channels, not the whole picture. Modules also couple through the shared schema (ADR 0011), through CDI events that observers bind by type (ADR 0008), and through SPI implementations resolved at runtime (Modules and boundaries).
- Every cross-module question costs an interface in the owning
-api: thirty-seven lookup, port and guard interfaces sit in the-apimodules. - A
-corecannot boot on its own, so its tests run in the aggregator against the real implementation of every SPI it consumes (ADR 0001).
Alternatives considered
- One module per domain, with no
-api/-coresplit. Rejected: contract and implementation would blur into one unit that can only be consumed whole, and extracting a module later would be impossible. The split costs little. - A network boundary between modules. Rejected; see ADR 0001.
Evidence
settings.gradle.kts,include- every domain as an-api/-corepairservices/demo-service/karyo-demo/build.gradle.kts,dependencies (cross-core waiver comment)- waiver 1 and its commentservices/demo-service/karyo-demo/src/main/kotlin/com/karyo/demo/api/v1/DemoEnabledFilter.kt,DemoEnabledFilter- the demo routes answer 404 when offservices/inventory-service/karyo-inventory-api/src/main/kotlin/com/karyo/inventory/api/spi/PurgeBlockerLookup.kt,PurgeBlockerLookup- declare here, implement there, four implementorsservices/fulfillment-service/karyo-fulfillment-api/src/main/kotlin/com/karyo/fulfillment/event/WavePickActivityEvent.kt,WavePickActivityEvent- a payload placed in-apito avoid a core edgeservices/wave-service/karyo-wave-api/build.gradle.kts,api(project(":services:order-service:karyo-orders-api"))- one of theapi(...)edges between-apimodulesbuildSrc/src/main/kotlin/com/karyo/conventions/VerifyModuleBoundaries.kt,VerifyModuleBoundaries- the rule and its two waivers as a Gradle task- Modules and boundaries