Domain-driven design using Kotlin

Related tags

App dukt
Overview

Domain-driven design using Kotlin

GitHub license Kotlin

This framework uses CQRS and ES patterns and is coded using Multiplatform Kotlin. It's inspired by AxonFramework and EventFlow. Domain logic can be at the client side and/or it can be used from the server.

Features

  • Supports JS and JVM platforms
  • Fast as possible
    • kotlin-reflect not needed
    • Dependency injection at build time
    • Proguard support
    • Commands are handled simultaneously. Transaction locks only single aggregate by ID and there isn't global sequences.
    • Asynchronous event handling using Coroutines
  • Kotlin Serialization
    • Fast compile-time serialization
    • Storage size is minimal when used Protocol Buffers
  • Code generation with Gradle plugin
  • Ktor support
    • Server-side authorization
  • Kotest support

Currently, this framework is at early development stage :(

Learn by simple example

  1. Write your bounded context code first. For example:
/** Sales context **/
package com.example.sales

// Value objects
data class OrderLine(val prod: UByte, val price: Float, val qty: UShort = 1u) {
  val empty get() = qty == UShort.MIN_VALUE
  val total get() = price * qty.toFloat()
}
data class VatNo(val countryCode: String, val no: Int) {
  init {
      if (countryCode.length != 2 || no.toString().length != 8)
          throw InvalidVatNo(this)
  }
  override fun toString() = "$countryCode-$no"
}

// Domain exceptions
data class BannedCustomer(val customer: VatNo) : Exception()
data class InvalidVatNo(val vatNo: VatNo) : Exception()

interface SalesBans : Set<VatNo> // Domain service

interface Events { // Domain events as interface methods
  fun quotationOffered(customer: VatNo, lines: List<OrderLine>)
}

/** Sales order aggregate root entity **/
class Order(val emit: Events) : Events {
  companion object { lateinit var bans: SalesBans }

  // Public accessors are safe to use and allows snapshotting
  lateinit var customer: VatNo
  var lines = listOf<OrderLine>()

  // Command handler for business logic
  fun requestForQuotation(customer: VatNo, lines: List<OrderLine>) {
      if (customer in bans) throw BannedCustomer(customer)
      emit.quotationOffered(customer, lines.filter { it.empty })
  }

  // Event handler to alter the state
  override fun quotationOffered(customer: VatNo, lines: List<OrderLine>) {
      this.customer = customer
      this.lines += lines
  }
}
  1. Following application classes are generated based on your context code before build:
    • Aggregate
    • Aggregate factory
    • Aggregate root entity test stub
    • Application service (based on commands)
    • Domain command value objects
    • Domain configurator
    • Domain event value objects
    • Domain service test stub and possibly in-memory implementation
  2. Now you can create unit tests for the context. Skipping this now for simplicity.
  3. Implement your interfaces and create custom event handlers in the infrastructure layer:
// Domain service implementation
class SalesBansImpl(vararg ban: VatNo) : SalesBans, Set<VatNo> by ban.toSet()

object QuotationSender : EventHandler<QuotationOffered>(QuotationOffered::class) {
  override suspend fun handle(event: QuotationOffered, message: EventMessage) {
      // ...create PDF and send it via email...
  }
}
  1. Test your implementations.
  2. Build the application with Dukt libraries:
    • dukt-app Mandatory application base classes command and event processing
    • Separate package for each Event store implementation
  3. That's it! Now application is ready for testing and deploying.

Planned later

  • Saga support
  • Support for other platforms (Android, iOS, Linux, macOS, tvOS, watchOS, Wasm, Windows)
  • Code migration from/to other frameworks/languages
You might also like...
 A simple Pokedex App getting API with Retrofit, maintaining data using LiveData, and Material Design based on MVVM architecture
A simple Pokedex App getting API with Retrofit, maintaining data using LiveData, and Material Design based on MVVM architecture

PokedexApp Pokedex A simple Pokedex App getting API with Retrofit, maintaining data using LiveData, and Material Design based on MVVM architecture. Te

Episodie is a TV show time tracker app with unusual design written in kotlin and clean architecture approach. Get to know how much time you spent watching tv shows.
Episodie is a TV show time tracker app with unusual design written in kotlin and clean architecture approach. Get to know how much time you spent watching tv shows.

Episodie Episodie is a TV show time tracker app with unusual design. Get to know how much time you spent watching tv shows. Track easily overall progr

🎬 A demo project for The Movie DB based on Kotlin MVVM architecture and material design & animations.
🎬 A demo project for The Movie DB based on Kotlin MVVM architecture and material design & animations.

TheMovies A simple project for The Movie DB based on Kotlin MVVM clean architecture and material design & animations. How to build on your environment

It is a NBAApp developed by Kotlin. It uses MVVM design pattern, Coroutines, Retrofit and JetPack libraries like Room, Lifecycle, ViewBinding, DataBinding, Hilt and Navigation.
It is a NBAApp developed by Kotlin. It uses MVVM design pattern, Coroutines, Retrofit and JetPack libraries like Room, Lifecycle, ViewBinding, DataBinding, Hilt and Navigation.

NbaApp It is a NBAApp developed by Kotlin. It uses MVVM design pattern, Coroutines, Retrofit and JetPack libraries like Room, Lifecycle, ViewBinding,

UML model and code examples of design patterns for Kotlin/Native. The model is created with Astah.
UML model and code examples of design patterns for Kotlin/Native. The model is created with Astah.

Design Pattern Examples in Kotlin/Native Model and code examples of GoF Design Patterns for Kotlin/Native. This project is available for the following

OpenLibra client on Material Design

OpenLibra-Material This repositores aims to show examples about material design in a real app, the application is a client of the webpage OpenLibra a

Implementation of Instagram with Material Design (originally based on Emmanuel Pacamalan's concept)
Implementation of Instagram with Material Design (originally based on Emmanuel Pacamalan's concept)

InstaMaterial Updated Current source code contains UI elements from Design Support Library. If you still want to see how custom implementations of e.g

Material design file manager for Android
Material design file manager for Android

Amaze File Manager Overview Open Source, light and smooth Based on Material Design guidelines Basic features like cut, copy, delete, compress, extract

Material Design Calendar
Material Design Calendar

Etar Calendar Etar (from Arabic: إِيتَار) is an open source material designed calendar made for everyone! Why? Well, I wanted a simple, material desig

Owner
Jukka Papinkivi
C/C++, C#, Java, JS, Kotlin, PHP developer in three decades for work, hobby and entrepreneur. Best coder at my home city ;-)
Jukka Papinkivi
The domain specific programming language D°, which is a result of Fabian Bruckner's PhD.

Data App Programming Language The data app programming language (named D° [spoken dəˈɡrē]) is a work result of the PhD of Fabian Bruckner. It is a dom

Fraunhofer Institute for Software and Systems Engineering ISST 2 Aug 19, 2022
Scans all the SMS of an Android device for any known domain that is related with the spyware Predator by Cytrox / Intellexa.

Συχνές ερωτήσεις και απαντήσεις Τι είναι το Predator; Ποιο είναι το ρίσκο μου να έχω δεχθεί επίθεση με το Predator; Πώς δουλεύει η εφαρμογή SMS Predat

Andronikos Koutroumpelis 14 Dec 6, 2022
⚡️ A Compose-driven architecture for Android apps.

Circuit ?? Under construction ?? This project is very much a work in progress and far from finished! License Copyright 2022 Slack Technologies, LLC L

Slack 426 Jan 2, 2023
A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar

#Android-LollipopShowcase This is a simple showcase to show off Android's all new Material Design and some other cool new stuff which is (new) in Andr

Mike Penz 1.8k Nov 10, 2022
Design patterns are typical solutions to common problems in software design

Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can customize to solve a particular design problem in your code.

hamid 4 Aug 30, 2022
🎬 A demo project using The Movie DB based on Kotlin MVVM architecture and material design & animations.

TheMovies2 A simple project using The Movie DB based on Kotlin MVVM architecture and material designs & animations. How to build on your environment A

Jaewoong Eum 450 Jan 2, 2023
A blogging mobile application built with Kotlin using MVC design pattern and Take some advantage of Jetpack , View & Data Binding It's a mimic for Tumblr application , But a little prettier than him 😉

A blogging mobile application built with Kotlin using MVC design pattern and Take some advantage of Jetpack , View & Data Binding It's a mimic for Tum

Ahmed Ihab 17 Dec 23, 2022
CMPLR Technologies 8 Apr 5, 2022