Hexagonal Architecture Kotlin Template

Overview

Hexagonal Architecture Kotlin Template

The purpose of this template is to avoid repeating, over and over again, the same basic packages structure, gradle and configurations. Note: this is just a skeleton with a silly example. Is good to start a project with it, but if you want to see a production ready and fully tested project with a lot of examples, please visit my friend Albert Llousas Team Management repository.

The current packages structure has been popularized by Vaughn Vernon, the author of Implementing Domain-Driven Design and Domain-Driven Design Distilled and you can see an example in his Github Repository. The structure is a mix of Alistair Cockburn's Ports & Adapters Pattern and DDD concepts. In fact, if you know the original Hexagonal Architecture article, you will see that the packages structure is not familiar to you, but you may recognize the concepts embedded (Ports & Adapters). In the src directory you will see the following packages:

.
├── application
├── domain
└── infrastructure

The application package is the place where we will put all the Application Services (aka Use Cases) classes.

The domain package will host all the pure Domain classes, such as Aggregates, Value Objects, Entities, Domain Events, Repositories etc. Usually this package also hosts PORTS (CustomerRepository is an example of a Port).

The infrastructure package instead, is the place were we put all the infrastructure concerns, such as framework, configurations and concrete implementations. You will see an adapters package that contains Inbound and Outbound Adapters, that are concrete implementations of Ports, defined in the domain package.

Short introduction to Testing

The silly example provided is, of course, tested (using Outside-In TDD). This project is following the typical Testing Pyramid, but adapted to (Micro)services. testing-pyramid

You will see that there are three different types of tests and each one of them has a concrete scope.

  • End-To-End Tests have been excluded on purpose, since their scope is broader than a single service.

  • Component Tests: this is a kind of test that have been popularized in Microservices Patterns (See Service Component Tests), but at the end is just another name for the well known Acceptance Tests. The scope is to test the service itself, in isolation, "mocking" external dependencies such as database (using TestContainers for instance) and external services (using Wiremock for instance).

  • Integration Tests: this kind of tests are run in isolation, there is no real call to an external service or a real database. Here we include repositories, clients, controllers, consumers, producers tests etc. We can also include Contract Tests (extending Controller tests, for instance, to check contract with Consumers using some kind of tool like Pact.io).

  • Unit Tests: and finally we "unit test" what's the most important part of the service: the Domain. Here we include all the tests for Aggregates, Value Objects, Entities, Domain Events, Application Services (aka Use Cases), Domain Services etc.

How to run

First you will need to install Copier on your local machine. This is an open-source tool to copy directories and files from one place to another also using templates. To install it, run in your console: pip install copier Then to copy this template, run the following command:

copier https://github.com/Hyunk3l/hexagonal-architecture-kotlin-template.git put-your-directory-here

you will be asked about a few configurations (name of the package, project etc.). Once done, open your put-your-directory-here.

How to run tests

As you already know, there are three type of tests. You can run them separately or together:

  • Component: ./gradlew componentTest
  • Integration: ./gradlew integrationTest
  • Unit: ./gradlew unitTest

To run them together: ./gradlew test

Caveats

  • Domain is anemic: just a silly example :)
  • Not publishing Domain Events: maybe in the future I will.
  • In memory repository has not been tested (on purpose). Maybe in the future I'll add a real db repository implementation.
You might also like...
An Android template you can use to build your project with gradle kotlin dsl

Android Gradle KTS An Android template you can use to build your project with gradle kotlin dsl Build.gradle.kts You can use your project's build.grad

Minecraft Forge Kotlin Template

Minecraft Forge Kotlin Template Minecraft 1.12.2 で Forge と Kotlin を用いた Mod のテンプレートです。 Minecraft 1.12.2 Mod template using Forge and Kotlin. Getting St

Kotlin async server template with coroutines and zero deps

kotlin-server At attempt to very light-weight non-blocking http app template with support for Kotlin coroutines. Zero dependencies - Java built-in jdk

A Simple Task Template With Kotlin

Tarefas - Kotlin Download do aplicativo Tecnologia MVVM Retrofit SQLite Navigation Fingerprint - Autenticação biométrica Tela de Login Tela de cadastr

My personal template for a Spring Boot REST reactive webapp

My personal spring boot kotlin reactive template Features Spring Security implementation with JWT access and refresh token MongoDB database Project Co

Here is a ready to use JAICF bot template that utilises

JAICF Spring Bot template Here is a ready to use JAICF bot template that utilises Spring MongoDB Docker Prometheus Grafana Graylog How to use Please r

Used to generate the template code of GetX framework
Used to generate the template code of GetX framework

Language: English | 中文简体 statement some fast code snippet prompt come from getx-snippets-intelliJ Description install Plugin effect Take a look at the

A basic template ecommerce application with payment integration made using Android Architechture componets
A basic template ecommerce application with payment integration made using Android Architechture componets

ShopIt ShopIt is a basic template ecommerce application with payment integration(RazorPay), made using Android Architechture componets and Material Co

Team management service is a production ready and fully tested service that can be used as a template for a microservices development.
Team management service is a production ready and fully tested service that can be used as a template for a microservices development.

team-mgmt-service Description Team management service is a production ready and fully tested service that can be used as a template for a microservice

Releases(v3.0.1)
Owner
Fabri Di Napoli
Tech Lead
Fabri Di Napoli
Hexagonal Architecture Java Example

Hexagonal Architecture Dev.to Hexagonal Architecture Article I have been working on many projects that claim to be using the Hexagonal Architecture St

null 17 Dec 21, 2022
Aplicação Micronaut GRPC utilizando Kotlin e arquitetura Hexagonal

micronaut-grpc-demo Aplicação Micronaut GRPC utilizando Kotlin e arquitetura Hexagonal #Baixando e configurando um container Postgres: Postgres: docke

Paulo César de Souza 0 Nov 15, 2021
Exemplo de microsserviço em koltin e spring boot usando a arquitetura hexagonal/ports&adapters como base de estrutura

Microservice boilerplate Exemplo de microsserviço em koltin e spring boot usando a arquitetura hexagonal como base de estrutura Executando Localmente

Odilio 6 Dec 7, 2022
Kotlin multi platform project template and sample app with everything shared except the UI. Built with clean architecture + MVI

KMMNewsAPP There are two branches Main News App Main The main branch is a complete template that you can clone and use to build the awesome app that y

Kashif Mehmood 188 Dec 30, 2022
This is an example of a simple application with layered software base on clean-architecture as application architecture and mvvm as presentation architecture

This is an example of a simple application with layered software base on clean-architecture as application architecture and mvvm as presentation archi

null 3 Jul 2, 2021
Learning Project (Story App) For Applying Android Architecture Components And Clean Architecture Using MVVM With Kotlin

Learning Project (Story App) For Applying Android Architecture Components And Clean Architecture Using MVVM With Kotlin. Implemented by Clean Architecture, Hilt, MVVM, LiveData, Coroutines, Retrofit2, Glide

Samad Talukder 4 Sep 27, 2022
This is a template to help you get started building amazing Kotlin applications and libraries.

Welcome to the Starter This is a template to help you get started building amazing Kotlin applications and libraries. Over time, examples will be comp

Backbone 8 Nov 4, 2022
KMMT : Kotlin Multiplatform Mobile Template

Kotlin Multiplatform Mobile App Template

Jitty Andiyan 206 Dec 22, 2022
Template for building CLI tool in Kotlin and producing native binary

Kotlin command-line native tool template This template allows you to quickly build command-line tool using Kotlin , Clikt and build a native binary fo

Ryszard Grodzicki 10 Dec 31, 2022
For Kotlin with SpringBoot project that have multi-module-structure template

Goals kotlin + spring-boot + gradle + multi-module building Module-Structure ---root |--- src.main.kotlin.KotlinSpringbootMultiModuleTemplateAppl

pguma 1 Jul 24, 2022