ADR 0002: The backend is Kotlin on Quarkus
Status: Accepted
Context
The backend carries dense business rules - stock selection, location finding, order and pick state machines, replenishment - where a null reference or an unhandled case can send stock to the wrong place. It is written against the Jakarta programming model that the rest of the architecture relies on: CDI beans and SPIs injected across modules (ADR 0006), CDI events with transaction phases (ADR 0008), JAX-RS resources, JPA entities and JTA transactions.
It runs self-hosted, one host per company, beside PostgreSQL and nginx, with optional managed
Keycloak or an external OIDC provider, and a default
memory limit of 1.5 GB for the application container
(infrastructure/docker/docker-compose.prod.yml, services.karyo-app.mem_limit). It needs OIDC, health checks, metrics,
scheduling, fault tolerance, schema migration, a workable local-development loop and an LLM
integration, without bespoke glue for each.
Decision
- The backend is Kotlin on a Java 21 toolchain, running on Quarkus. Both versions are
pinned in the version catalog (
gradle/libs.versions.toml,versions.kotlin, versions.quarkus) and applied through the build conventions (ADR 0003). - All main source is Kotlin. There is no Java source under any
src/main. - The Quarkus platform BOM is applied as an enforced platform
(
services/karyo-app/build.gradle.kts,enforcedPlatform(libs.quarkus.bom)), and the backend uses Quarkus extensions for REST, Hibernate ORM with Panache for Kotlin, PostgreSQL, Flyway, caching, fault tolerance, health, Micrometer, OpenTelemetry, JSON logging, OIDC, validation and scheduling (gradle/libs.versions.toml,libraries.quarkus-bom and libraries.quarkus-*). - The Kotlin
allopenandjpacompiler plugins apply everywhere:allopenopens classes that carry the annotations Quarkus proxies,jpagenerates the no-argument constructors Hibernate needs, and Java nullability annotations are read strictly (buildSrc/src/main/kotlin/karyo.kotlin-conventions.gradle.kts,plugins, kotlin.jvmToolchain, allOpen, KotlinCompile.compilerOptions). - JPA entities are ordinary mutable classes (
OutboxEvent); DTOs and event payloads are data classes (WavePickActivityEvent). - The application runs on the JVM as a Quarkus fast-jar (
.github/workflows/ci.yml,jobs.package.steps: Build karyo-app (Quarkus fast-jar)). Native compilation is not used.
Consequences
- Nullability is checked by the compiler. Sealed result types and data classes keep the domain types short and exhaustively handled.
- Every Java library in the stack - Hibernate and Jackson - is used directly from Kotlin.
- Quarkus resolves CDI at build time, so an unsatisfied injection point fails the build rather than a request.
- Quarkus Dev Services start PostgreSQL for tests and for local work, and Keycloak for tests, with nothing installed on the machine (ADR 0028).
- The
allopenannotation list is maintained by hand. A class whose only proxy-relevant annotation is missing from it stays final and cannot be proxied. - JPA entities cannot be data classes, and their properties stay mutable.
- Quarkus releases often, so the platform needs regular upgrades. Because its BOM is an enforced
platform, a plain dependency constraint cannot raise a version the BOM manages; security floors
for those coordinates go through the root build's
securityFloorinstead (build.gradle.kts,securityFloor).
Alternatives considered
- Spring Boot. Rejected for a larger memory footprint and slower startup than Quarkus in JVM mode, and for having no equivalent of Dev Services.
- Micronaut. Rejected: no Dev Services equivalent and a smaller extension ecosystem, which would have meant more custom integration work.
- Helidon. Rejected: the smallest community of the candidates and no dedicated Kotlin support.
- Java alone. Rejected: no compile-time null safety, which matters most in a system where a null location or lot can misroute stock, and noticeably more code for the same domain model - records have no copy, no defaults and no mutable fields.
- Scala. Rejected: a steeper learning curve and a much smaller hiring pool for a domain that is mostly imperative state machines, and little Quarkus support.
Evidence
gradle/libs.versions.toml,versions.kotlin, versions.quarkus- the Kotlin and Quarkus versionsgradle/libs.versions.toml,libraries.quarkus-bom and libraries.quarkus-*- the platform BOM and the extensions in usebuildSrc/src/main/kotlin/karyo.kotlin-conventions.gradle.kts,plugins, kotlin.jvmToolchain, allOpen, KotlinCompile.compilerOptions- Kotlin plugins, toolchain,allopenlist, strict nullabilitybuildSrc/src/main/kotlin/karyo.quarkus-service.gradle.kts,plugins- the Quarkus plugin on every moduleservices/karyo-app/build.gradle.kts,enforcedPlatform(libs.quarkus.bom)- the BOM as an enforced platformbuild.gradle.kts,securityFloor- why version floors bypass plain constraints.github/workflows/ci.yml,jobs.package.steps: Build karyo-app (Quarkus fast-jar)- the fast-jar build