Karyo
Documentation/ Decision records

ADR 0019: Extensions are compiled into the build; nothing is uploaded into a running image

Karyo 2.1.1rendered at build time
On this page

Status: Accepted

Context

Implementers need to change Karyo's behaviour for a client - a stock-selection filter, a putaway strategy, a carrier adapter - without forking the source.

Karyo is a Quarkus application packaged as a fast-jar image. Quarkus discovers CDI beans during build-time augmentation, so the set of beans an image contains is fixed when it is built: a JAR placed beside a running process is invisible to it.

Extension code runs inside the application process with the same trust as Karyo's own code. Nothing sandboxes it.

Decision

  • An extension is a module compiled against the Apache-2.0 -api modules and the CDI API only, never against a -core. It carries META-INF/beans.xml, is added to the application build before Quarkus augmentation, and the image is rebuilt.
  • There is no runtime plugin mechanism: no upload endpoint, no hot discovery, no directory scanned at start-up.
  • The worked example is karyo-inventory-ext-example. Its build compiles against karyo-inventory-api and the CDI API with compileOnly. HeldLotStockFilter is active: @Alternative @Priority(1000) switches the CDI alternative on, and priority() = 500 places it in the filter chain - two numbers doing two different jobs. HazmatStockFilter is deliberately inactive: an @Alternative with no @Priority. The module is always compiled and tested, and it is included in the application only when the build is run with -PkaryoInventoryExample=true.
  • The running application reports its seams, and says which are for implementation. GET /api/v1/admin/extensions (ADMIN) lists every interface declared in a *.spi package and the beans that implement each; a seam whose module is not on the classpath is dropped from the response. Each row carries a kind: STRATEGY_SEAM (an extension may implement it), LOOKUP (a read-only in-process contract) or PORT (an in-process command or orchestration contract). A lookup or a port is implemented by Karyo's own modules and is not for implementation.
  • The registry is the only list. The console reads it for the Extensions page, the navigation badge and the sidebar footer, and keeps no catalogue of its own. When the registry cannot answer, the page shows the standard error state and the shell shows no count.
  • Compatibility is not unconditional. Additive, defaulted members aim to keep extensions working, but an extension must be recompiled and tested against each release. No -api artefact is published to a Maven repository; an extension builds against this repository's module graph.
  • The engine modules plug into their seams the same way, as build-time modules (ADR 0029).

Consequences

  • An installation runs exactly the code that was built and tested into its image, and the image is the unit of deployment and rollback.
  • Anyone can build their own extended image, with no involvement from the vendor.
  • Changing an extension is a rebuild and a redeploy.
  • Extension code must preserve Karyo's invariants itself - stock arithmetic, owner isolation, the transaction it runs in. A bean is trusted in-process code.
  • A row's kind is set by hand in the registry list, from the interface's own KDoc and from how its consumer finds it. AdminExtensionsResourceSeamListTest fails when a row has no kind, and when a *Lookup, a *Port or a *Strategy carries the wrong one. Presence in the list is still not a promise that a second implementation of a STRATEGY_SEAM will be called by every consumer.
  • An administrator who cannot read the registry sees no seam count, not a bundled one.

Alternatives considered

  • Drop-in JARs loaded by the running application. Rejected. Quarkus resolves CDI beans at build-time augmentation, so a JAR added after the build is never discovered; supporting it would mean giving up the build-time model the application is packaged on.
  • Forking the source per client. Not a supported route. The supported routes are configuration (ADR 0018), integration through the API and webhooks, and a build-time extension of a published contract. Why forks are excluded is not recorded beyond that preference.
  • Publishing the -api modules to a Maven repository so an extension can build outside this repository. Not done: it would add a distribution channel and a versioning surface to own.

Evidence

  • settings.gradle.kts, include(":services:inventory-service:karyo-inventory-ext-example") - the example module is always part of the build
  • services/karyo-app/build.gradle.kts, providers.gradleProperty("karyoInventoryExample") - included in the application only on request, "never a runtime JAR upload"
  • services/inventory-service/karyo-inventory-ext-example/build.gradle.kts, dependencies.compileOnly - compiled against the API module and CDI only
  • services/inventory-service/karyo-inventory-ext-example/src/main/resources/META-INF/beans.xml - bean discovery for the extension module
  • services/inventory-service/karyo-inventory-ext-example/src/main/kotlin/com/karyo/inventory/ext/example/HeldLotStockFilter.kt, HeldLotStockFilter - activation priority and chain priority
  • services/inventory-service/karyo-inventory-ext-example/src/main/kotlin/com/karyo/inventory/ext/example/HazmatStockFilter.kt, HazmatStockFilter - an alternative that is never activated
  • services/karyo-app/src/main/kotlin/com/karyo/app/admin/AdminExtensionsResource.kt, AdminExtensionsResource.listExtensions, AdminExtensionsResource.resolve, ExtensionKind - the live registry, the rule that makes it complete and the kind of every row
  • services/inventory-service/karyo-inventory-api/src/main/kotlin/com/karyo/inventory/api/spi/StockSelectionFilter.kt, StockSelectionFilter and services/warehouse-layout-service/karyo-layout-api/src/main/kotlin/com/karyo/layout/spi/LocationFilter.kt, LocationFilter - the discovery descriptions, which say a bean is compiled into the build
  • frontend/web/src/pages/admin/admin-strategies-page.tsx, AdminStrategiesPage, frontend/web/src/config/admin-navigation.ts, adminNavItems, visibleAdminNavItems and frontend/web/src/components/layout/admin-shell.tsx, AdminShell - the only readers of the registry; none keeps a list of seams