A coroutine-first Mediator library for Kotlin. Implements the CQRS and Vertical Slice patterns — requests go to exactly one handler, notifications fan out to many, and a pipeline of behaviors sits in between.
dependencies {
implementation("io.github.fajrbahr:mediatork:0.6.3")
}For KMP, Maven, and other project types — see Installation.
data class CreateOrderCommand(val id: String, val amount: Double) : Request<Order>class CreateOrderHandler(private val db: OrderRepository) : RequestHandler<CreateOrderCommand, Order> {
override suspend fun handle(
mediator: Mediator,
requestContext: RequestContext,
request: CreateOrderCommand,
): Order {
val order = Order(request.id, request.amount)
db.save(order)
mediator.publish(OrderCreatedEvent(order.id))
return order
}
}data class OrderCreatedEvent(val orderId: String) : Notificationclass SendConfirmationEmailHandler : NotificationHandler<OrderCreatedEvent> {
override suspend fun handle(notification: OrderCreatedEvent) {
emailService.send(notification.orderId)
}
}class OrderRegistrar(private val db: OrderRepository) : MediatorRegistrar {
override fun register(registry: HandlerRegistry) {
registry.scope {
+CreateOrderHandler(db)
+SendConfirmationEmailHandler()
}
}
}val mediator = MediatorFactory.create(
registrars = listOf(OrderRegistrar(db)),
)val order = mediator.send(CreateOrderCommand("ORD-1", 150.0))First and above all — الحمد لله (Alhamdulillah). This library was built during a hard time, and every line was written with Allah's help and guidance.
Jimmy Bogard — for his talks on Vertical Slice Architecture and MediatR (.NET), which were the direct inspiration for bringing this pattern to Kotlin.
beno.com — the production environment that shaped this library. Real-world usage at scale drove every design decision here.
Ahmed Akilan, Jacqueline Lim, and Jaewoong Eum (skydoves) — Ahmed, our CTO, whose technical mentorship and trust made it possible to grow as an engineer and ship something worth sharing. Jacqueline, whose support and collaboration were invaluable throughout this journey. And Jaewoong — a one-man engineering force whose open-source contributions to the Android community are worth a team of 100 engineers.
Philipp Lackner — for his Android and Kotlin content on YouTube, which has been an invaluable learning resource.
Dr. Venkat Subramaniam — for his exceptional teaching of Kotlin, functional programming, and software design. His talks and courses shaped the way this library thinks about clean code.
droidcon — for the talks, conferences, and community that keep Android and Kotlin engineering moving forward.
Released under CC0 1.0 Universal — public domain. No attribution required.