
Facilitates domain-driven design with features like Command and Query Responsibility Segregation, Event Sourcing, and test-driven development. Generates application layer code, supports coroutines, and offers compile-time serialization.
This framework lets you start your coding from domain layer with pure Common Kotlin. Test-driven development is also supported via generated unit test stubs.
The Dokt plugin generates application layer, which follows Command and Query Responsibility Segregation (CQRS) and Event Sourcing (ES) patterns. It can't generate infrastructure layer :) but you can code it to any platform.
plugins {
id("app.dokt") version "0.2.0"
}import app.dokt.Root
import kotlinx.serialization.Serializable
/** Events that Greeter emits */
interface Events {
fun greeted(greeting: String)
}
/** Greeter aggregate root. Identified by UUID (default). */
@Serializable // For unit testing
class Greeter : Root<Events>(), Events {
val greetings = mutableListOf<String>()
/** Greet command handler */
fun greet(who: String) {
if (who.isBlank()) throw IllegalArgumentException("Missing 'who'!")
emit.greeted("Hello, $who!")
}
/** Greeted event handler */
override fun greeted(greeting: String) {
greetings.add(greeting)
}
}generateCode task./** Greeter unit tests */
class GreeterTest : GreeterSpec({ // GreeterSpec is generated in previous step.
greet { // Command handler is a generated test context
test("World") { // "World" test case
greeter // Greeter is arranged with a random UUID.
.act { greet("World") } // The command act
.emits(Greeted("Hello, World!")) // Asserts the emitted DTO.
}
}
})allTests and you should pass your test.Check more examples.
Following frameworks have inspired this project a lot:
This framework lets you start your coding from domain layer with pure Common Kotlin. Test-driven development is also supported via generated unit test stubs.
The Dokt plugin generates application layer, which follows Command and Query Responsibility Segregation (CQRS) and Event Sourcing (ES) patterns. It can't generate infrastructure layer :) but you can code it to any platform.
plugins {
id("app.dokt") version "0.2.0"
}import app.dokt.Root
import kotlinx.serialization.Serializable
/** Events that Greeter emits */
interface Events {
fun greeted(greeting: String)
}
/** Greeter aggregate root. Identified by UUID (default). */
@Serializable // For unit testing
class Greeter : Root<Events>(), Events {
val greetings = mutableListOf<String>()
/** Greet command handler */
fun greet(who: String) {
if (who.isBlank()) throw IllegalArgumentException("Missing 'who'!")
emit.greeted("Hello, $who!")
}
/** Greeted event handler */
override fun greeted(greeting: String) {
greetings.add(greeting)
}
}generateCode task./** Greeter unit tests */
class GreeterTest : GreeterSpec({ // GreeterSpec is generated in previous step.
greet { // Command handler is a generated test context
test("World") { // "World" test case
greeter // Greeter is arranged with a random UUID.
.act { greet("World") } // The command act
.emits(Greeted("Hello, World!")) // Asserts the emitted DTO.
}
}
})allTests and you should pass your test.Check more examples.
Following frameworks have inspired this project a lot: