Coroutine che non bloccano mai, route tipizzate, kotlinx.serialization ovunque.
Constitution — Ktor service
Version 1.0.0 · Ratified 2026-11-10
These principles hold for every spec, plan and task of the project. A spec may add rules; it never weakens these.
-
Coroutines that never block. Handlers are
suspendfunctions that call only suspending clients. Blocking JDBC or file I/O runs insidewithContext(Dispatchers.IO), andrunBlockingoutsidemainand tests fails the review. -
Structured concurrency. Concurrent work is launched in the call’s scope with
coroutineScopeorasync, never inGlobalScope. Cancellation propagates andCancellationExceptionis never swallowed. -
Typed routes. Routes are declared with the Resources plugin as
@Resourceclasses, so paths and parameters are checked at compile time. Path and query values are not read by string name fromcall.parameters. -
kotlinx.serialization everywhere. Request and response bodies are
@Serializabledata classes handled by ContentNegotiation with kotlinx.serialization. No Jackson or Gson on the same paths, and unknown keys in requests are rejected unless the spec says otherwise. -
Errors through StatusPages. Domain errors are sealed classes or typed exceptions mapped to status codes and one error body in the StatusPages plugin. Handlers do not build error responses by hand.
-
Tested with testApplication. Every route has a test using
testApplicationwith the real module and fake dependencies, covering success and invalid input. Modules are installed through functions that take their dependencies, so tests can pass fakes.