Hexagonal Architecture Demo Project about Ticketing and Payment

Overview

Modular Architecture - Hexagonal Demo Project

This project is a sample production-ready implementation for demonstrating the power of Hexagonal Architecture (aka Ports And Adapters Pattern) written in Java.

Build Ticket API Build Payment API

Lines of Code Coverage Technical Debt Code Smells Maintainability Rating


Table of Contents

Wiki

Reports


Hexagonal Architecture Flow Diagram (click to enlarge)

Hexagonal Architecture Flow Diagram

Motivation

We want to write clean, maintainable, well-defined boundary context, well-tested domain code and isolate business logic from outside concern.

What is the Hexagonal Architecture

The hexagonal architecture was invented by Alistair Cockburn in an attempt to avoid known structural pitfalls in object-oriented software design, such as undesired dependencies between layers and contamination of user interface code with business logic, and published in 2005.

A timeless goal of software engineering has been to separate code that changes frequently from code that is stable.

~ James Coplien / Lean Architecture

We recommend Hexagonal Architecture for those who want to write clean, maintainable, well-defined boundary context, well-tested domain, and decoupling business logic from technical code.

Technologies Used

You can use any programming language for implementing Hexagonal Architecture. Here is the list of technologies we used for the demo application;

  • Spring Boot 2
  • Java 11
  • Gradle 7
  • Mono Repo
  • Docker
  • Mysql
  • Redis
  • Kafka
  • Groovy 3
  • Cucumber
  • GitHub Actions

It's so easy to reach 100% code coverage if you design by tests wisely via TDD. There are the types of tests written:

  • Unit tests
  • Dockerized integration tests
  • Consumer-driven contract tests
  • External verifier contract tests
  • Acceptance tests

What You Will Learn

  • Implementing two microservices with spring boot
  • Designing the APIs with hexagonal architecture
  • Packaging by functions and screaming architecture
  • How Ports and adapters separate business from integration points
  • Writing behavior focused unit tests at domain module
  • Writing integration tests isolated from the business at infra module
  • Using Gradle to configure microservices and modules
  • Using mono-repo to handle all APIs in a single git repository
  • Implementing consumer-driven contract tests
  • Creating different testing styles for validating data adapters, event consumers/publishers, controllers

Useful Links From Authors

  • Modular Architecture for Pragmatic Developers - Slides - Youtube
  • Growing Hexagonal Microservices With TDD - Slides, Youtube
  • It's Not Solid Anymore: Rethinking Software Design and Modularity - Slides, Youtube

Useful Links about Hexagonal Architecture

  • ITT 2018 - Jakub Nabrdalik - Hexagonal Architecture in practice - Youtube
  • Ian Cooper on Hexagonal Architectures at Agile Yorkshire - Youtube
  • Ports and Adapters Pattern, by Juan Manuel Garrido de Paz - Blog
  • DDD, Hexagonal, Onion, Clean, CQRS, … How I put it all together, by Herberto Graca - Blog
  • Hexagonal Architecture: three principles and an implementation example, by Erwan Alliaume, Sébastien Roccaserra - Blog

History

This repository is a side project developed while preparing the conference talk "Growing Hexagonal Microservices With TDD" at Java Day Istanbul 2020. As the authors of this repository, we've been using hexagonal architecture in all microservices (i.e. more than 50+ microservices) running in production since 2017. We believe modularity is the key to building maintainable and high-quality software. That's why we shared our demo project with the community to attract their interest in the topic.

Contributing

Please feel free to open tickets to suggest new features and improvement points. Please feel free to contribute.

Code of Conduct

Please take a look at code of conduct before opening issues or creating pull requests.

Authors

License

Distributed under the MIT License. See LICENSE for more information.

Comments
  • Create stand alone common module

    Create stand alone common module

    It's neither bug nor feature but would definitely eliminate code duplication

    In each services there're common sub-modules for both domain and infra. Certain classes, interfaces and enums such as Event, Status, UseCase, UseCaseHandler are repeatedly created. Considering addition of several other microservices to the project, it'll definitely increase the code repetition.

    It'd be a better implementation to separate common module to an individual one. Such as

    
    \common
          \ domain 
                 \ commandhandler
                        CommandHandler
          \ infra
                 \ entity
                        AbstractEntity
    \payment-api
    \ticket-api
    ...
    

    P.s I'm planning to make a PR for this matter if the issue is also okay with you guys.

    wontfix 
    opened by elshanakberov 3
  • some ducks don't wanna fly and some want

    some ducks don't wanna fly and some want

    How can code duplication be prevented when useCase handlers consist of the same business logic? Multiple inheritance is not permitted just because of ObservableUseCasePublisher class. How is a structure made that resembles the template method approach?

    opened by atakanburakgungor 0
  • Remove spring dependency from domain module

    Remove spring dependency from domain module

    hell yeah, why do we need spring dependency at domain module? for transactional and dependency injection purposes, right? All these can be done without spring at all. Let's do that and show the world we need no spring dependency at domain module.

    opened by lemiorhan 0
  • Added No Use Case Handler

    Added No Use Case Handler

    it's been added the no param use case handler to be able to handle without any use case and return a response model

    By the way, Thanks a lot for this great boilerplate project which you have been released with @lemiorhan. We also have got a production-ready project that this project's help us, it will be released in the near future 🙂

    We needed to return static content to our mobile clients without depending on any request model, that's why we added up the NoUseCaseHandler

    opened by yusufcakal 0
  • Use Java9 modules to protect the modules from unnecessary access

    Use Java9 modules to protect the modules from unnecessary access

    From infra point of view, there is no need to access a jpa repository of domain module. So it will be a great refactoring to adapt with java9 modules and handle access.

    opened by lemiorhan 0
  • Write contract tests for event consumer and producers

    Write contract tests for event consumer and producers

    Kafka event consumers and producers need to have contract tests to validate. That requires additional dependencies to add. Embedded kafka could be used.

    opened by lemiorhan 0
  • Auto trigger acceptance tests when both apis build successfully

    Auto trigger acceptance tests when both apis build successfully

    Since acceptance test workflow is triggered after push, it cannot get the latest codebase from the latest docker image. Build workflows for both apis should complete successfully before acceptance test workflow.

    Github started to support dependencies between workflow very lately. However all solutions have some drawbacks. We should check workflow_run and workflow_dispatch commands at GitHub Actions.

    Reference: https://github.com/marketplace/actions/workflow-run-conclusion-dispatch-action

    opened by lemiorhan 0
  • Upgrade Spring Boot to 2.5 to support Groovy 3 and Gradle 7

    Upgrade Spring Boot to 2.5 to support Groovy 3 and Gradle 7

    https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes

    We need to upgrade to the latest 2.5 version of Spring boot to officially support Java 16, Groovy 3, and Gradle 7.

    opened by lemiorhan 0
Owner
Alican Akkuş
Passionate engineer, Agile and Lean practitioner, Pair programming lover
Alican Akkuş
An estate management api based on the hexagonal architecture, built on top of Quarkus

An estate management api based on the hexagonal architecture, built on top of Quarkus

Mudi Lukman 2 Mar 30, 2022
Clean-architecture-guide - Guia sobre Clean Architecture criado a partir dos meus estudos sobre o tema.

Clean Architecture Guide Arquitetura são as práticas e fundamentos de como organizamos um sistema. Tem relação e como os componentes estão relacionado

Jean Jacques Nascimento Barros 3 Apr 23, 2022
Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

spring-microservice Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker. Arc

null 4 Sep 13, 2022
A simple live streaming mobile app with cool functionalities and time extension, and live chat. With a payment system integrated. Server is designed with socket.io to give you full flexibility.

Video Live Streaming Platform Android A simple live streaming mobile app with cool functionalities and time extension, and live chat. With a payment s

Dev-Geek 2 Dec 16, 2022
Arquitetura Hexagonal utilizando Spring

Exemplo de arquitetura Hexagonal feita em Spring Esse projeto foi feito para explicar melhor sobre a arquitetura Hexagonal, podendo ter sido feito com

Nataniel Paiva 45 Jan 3, 2023
Kryptokrona Java SDK for building decentralized private communication and payment systems.

Kryptokrona Java SDK Kryptokrona is a decentralized blockchain from the Nordic based on CryptoNote, which forms the basis for Monero, among others. Cr

null 22 Oct 31, 2022
Saga pattern with Java => order -> payment -> stock microservices are ready to use

Order_Payment_Stock_Saga_Pattern Saga pattern with Java => order -> payment -> stock microservices are ready to use Docker-compose.yaml You can see th

Gurkan İlleez 5 Dec 27, 2022
Integrates with XRPLedger to send token payment to trustline addresses

strategyengine token distribution rest service This service also runs here -- https://fsedistributionservice-56gpv2b23a-uc.a.run.app/ #How to run loca

strategyengine 8 Dec 14, 2022
A React Native project starter with Typescript, a theme provider with hook to easy styling component, a folder architecture ready and some configs to keep a codebase clean.

React Native Boilerplate Folder structure : src ├── assets │   ├── audios │   ├── fonts │   ├── icons │   └── images ├── components │   ├── Layout.tsx

LazyRabbit 23 Sep 1, 2022
N-Layer Architecture human resource management system project with Java.

HRMS Project Backend N-Layer Architecture human resource management system project with Java. Report Bug · Request Feature About The Project Built Wit

Ahmet Çetinkaya 78 Dec 26, 2022
Restaurant Management Project with Microservice Architecture by Evren Tan

Restaurant Management Restaurant Management Project with Microservice Architecture is developed by Evren Tan. Table of Contents Modules Cloud Config S

Evren Tan 26 Dec 11, 2022
This project illustrates TDD & Clean Architecture implementation in Java

Banking Kata - Java Overview This project illustrates TDD & Clean Architecture implementation in Java, showing the Use Case Driven Development Approac

Valentina Cupać 191 Dec 28, 2022
Microservices with Spring Boot and Kafka Demo Project

Example microservices showing how to use Kafka and Kafka Streams with Spring Boot on the example of distributed transactions implementations with the SAGA pattern

Piotr Mińkowski 98 Jan 7, 2023
Geektime Todo is a demo todo project for Geektime column.

Geektime Todo 简介 这是《极客时间》专栏的 Todo 项目示例。 基本用法 生成 IDEA 工程 ./gradlew idea 检查 ./gradlew check 数据库迁移 ./gradlew flywayMigrate 生成构建产物 ./gradlew build 生成发布包 对

Zheng Ye 53 Oct 20, 2022
The project is a simple vulnerability Demo environment written by SpringBoot

The project is a simple vulnerability Demo environment written by SpringBoot. Here, I deliberately wrote a vulnerability environment where there are arbitrary file uploads, and then use the `scan` attribute in the loghack configuration file to cooperate with the logback vulnerability to implement RCE.

Panda 76 Dec 14, 2022
Spring for GraphQL demo project with a Vue frontend.

Spring Books - Hello GraphQL This is a demo project that will introduce you to [https://spring.io/projects/spring-graphql](Spring for GraphQL). The Sp

Dan Vega 11 Dec 2, 2022
Practice and testing with Java 11, Prometheus, and Spring-boot with MicroService Architecture. Designed to run on Kubernetes in minikube.

This application was written by Andrew Aslakson Built to run on minikube using kubernetes General race tracking system? Secure with Firebase Authentic

null 1 Feb 5, 2022
An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or to turn an existing project into a devops project using open source software (Git, Docker, Jenkins..)

DevOpsify Description An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or t

obaydah bouifadene 14 Nov 8, 2022
Microservice Architecture with Spring Boot, Spring Cloud and Docker

Piggy Metrics Piggy Metrics is a simple financial advisor app built to demonstrate the Microservice Architecture Pattern using Spring Boot, Spring Clo

Alexander Lukyanchikov 12.1k Jan 1, 2023