Skip to main content

Introduction

MediatorK is a coroutine-first Mediator library for Kotlin and Kotlin Multiplatform.

It implements the CQRS and Vertical Slice patterns:

  • Every request is routed to exactly one handler
  • Every notification fans out to many handlers
  • A pipeline of behaviors sits in between (logging, caching, timeout, validation…)

No kotlin-reflect. No annotation processing. No framework required.


Why MediatorK?

FeatureDescription
Coroutine-nativesuspend all the way down — no callbacks, no blocking
🧩 KMP readyWorks on JVM, Android, iOS, Linux, Windows, WASM, and more from one codebase
🌊 StreamingStreamRequest<T> returns a cold Flow<T> — lazy, incremental, cancellable
🔌 Framework-agnosticWorks with Spring Boot, Ktor, KMP, or plain Kotlin
🪶 Zero magicNo kotlin-reflect, no code generation, no annotation processors
🛡️ Built-in validationLightweight RequestValidator DSL with rules { } and rulesFailFast { } — no annotation processing
🔧 Batteries included6 built-in pipeline behaviors: caching, logging, timeout, timing, error tracking, and more
🧪 Testable by designbuildHandlerTestHarness, FakeMediator, MediatorSpy — no mocking library needed

Quick Example

// 1. Define a request
data class GetUserQuery(val id: String) : Request<User>

// 2. Implement a handler
class GetUserHandler(private val db: UserRepository) : RequestHandler<GetUserQuery, User> {
override suspend fun handle(
mediator: Mediator,
requestContext: RequestContext,
request: GetUserQuery
): User = db.findById(request.id) ?: error("User not found")
}

// 3. Wire it up
val mediator = MediatorFactory.create(
registrars = listOf(object : MediatorRegistrar {
override fun register(registry: HandlerRegistry) {
registry register GetUserHandler(db)
}
})
)

// 4. Use it
val user = mediator.send(GetUserQuery("user-1"))

Supported Targets

PlatformTargets
JVMjvm
AndroidandroidTarget · androidNativeArm32 · androidNativeArm64 · androidNativeX64 · androidNativeX86
iOSiosArm64 · iosSimulatorArm64 · iosX64
macOSmacosArm64 · macosX64
tvOStvosArm64 · tvosSimulatorArm64 · tvosX64
watchOSwatchosArm32 · watchosArm64 · watchosDeviceArm64 · watchosSimulatorArm64 · watchosX64
LinuxlinuxArm64 · linuxX64
WindowsmingwX64
Web / Wasmjs · wasmJs · wasmWasi

Ready to start? See the promise MediatorK makes →