Hexagonal architecture for java applications

Fabricio Epaminondas
Fabricio EpaminondasProject Leader / Software Engineer at Virtus, UFCG
Java Development
HEXAGONAL
ARCHITECTURE
for Java Applications
01 Concepts
Software Architecture
01 What drives the software architecture?
• High Maintainability
• Low Technical Debt: The cost payed by bad decisions
• Lack of understanding
• Lack of tests
• Lack of documentation
• Lack of collaboration
• Lack of process
01 Common multi-layer architecture
!
"
#
"
! UI Layer
" Application Layer
# Data
" Crosscutting
Dependency
01 Multi-tier architecture
Web Application Tier
! !
" "
"
# # #
" "
"
!
"
Client Tier
Browsers, Frontend App
Mobile devices, PC$Q
%
!
+
Data / Integration Tier
Database, File Storage,
External Systems, Cloud
&

ERP
CRM
DOCs
Dependency
01 Dependency inversion principle
Reference: http://blog.ploeh.dk/2013/12/03/layers-onions-ports-adapters-its-all-the-same
Dependency
DANGER -
Possible business
logic leaks
02 Hexagonal
Architecture
The Pattern
02 Intent
• Alternative names
• Ports & Adapters
• Onion Architecture / Onion Layers
“Allow an application to equally be driven by users,
programs, automated test or batch scripts, and to be
developed and tested in isolation from its eventual run-
time devices and databases.”
Alistair Cockburn
02 Key Concepts
Ports are interfaces
Adapters are implementations
The big picture: Ports & Adapters02
"Application
Port Port
Port
Mock
DB
DB
Integration
Test
Agent
UI
Adapter
Adapter
Adapter
Adapter
Use Case
Boundary
‘’driven’’ adapters
‘’driver’’ adapters
Overview02

In-Memory
"Application
# Database
( Web Services
)
) Enterprise Integration
*

SQL Server
REST
Adapter
* Configuration
+
Test Agent
!
HTML5 App
Environment
Adapter
File Source
Adapter
,
SQL
Adapter
#
NoSQL
Adapter
- MQ Service
MQ
Adapter
.
. Messaging Queue
&ERP
CRM
DOCs
EI
Adapter
(SOAP
Adapter
TEST
Adapter
03 Application
Keeping it simple
03
• Organizing Concerns and Code with Domains
• Well defined boundaries between domains
• Simple event-driven components
• Life Preserver diagram
Life preserver approach by Russ Miles
Life Preserver diagram03
Integration
Core
Domain Event
Service
Domain
Boundary
Notes03
• Core
• Single purpose
• Focus on unit testing
• No side-effects
• Integration
• Side effects
04 Practice
Ticket System
Kick-off04
github.com/fabricioepa/lab-
springboot-rest-sample
Lets start from the sample project and
then create the ports and adapters
05 Core
Use Case as service
Implementing the Use Case as Service05
• Domain model
• Entities
• Repositories
• Well defined interface
• Input/Output Events
• Event Handlers & Translators
• Service composition
• Unit Testing
Life Preserver
Services
Domain
Event
Repository
D
atabase
Test
UnitTest
Framework
0405
06 Controllers
Implementing passive controllers
• Dummy service invokers
• Do not perform multiple service calls
• It does not make any workflow decision
• REST Domain translator
0305
• UC
• Service
• Services
• Domain
• Controller
REST
Domain
06
Life Preserver
Services
Domain
Event
Repository
D
atabase
Test
UnitTest
Framework
Domain
Controller
R
EST
030506
07
Configuration
Externalized configuration
• External files
• Environment variables
• Configuration profiles
• Services
030507
MySQL
Life Preserver
Services
Domain
Event
Repository
D
atabase
Test
UnitTest
Framework
Domain
Controller
R
EST
C
onfiguration
App
Settings
Test
Client
H2
in-memory
Environment
030507
Comments
• How many ports?
• The hexagon is a metaphor
• Abstractions
• Use Case as port
• Module as port: Notification, Administration,
Public API, Database
0303
• Services
See more…
• RESTful API with Spring Boot
• Securing REST APIs
• References:
[1] alistair.cockburn.us/Hexagonal+architecture
[2] www.infoq.com/news/2013/08/hexagonal-lifepreserver-spring
[3] github.com/russmiles/life-preserver-introductory-article-developer-magazine/
blob/master/README.md
[4] github.com/spring-guides/deprecate-tut-rest
[5] blog.ploeh.dk/2013/12/03/layers-onions-ports-adapters-its-all-the-same
/ fabricioepa.wordpress.com
Contact
FABRICIO EPAMINONDAS
0 linkedin.com/in/fabricioepa
/ fabricioepa.wordpress.com
1 @fabricioepa
1 of 29

Recommended

Hexagonal architecture: how, why and when by
Hexagonal architecture: how, why and whenHexagonal architecture: how, why and when
Hexagonal architecture: how, why and whenXoubaman
976 views53 slides
Hexagonal Architecture by
Hexagonal ArchitectureHexagonal Architecture
Hexagonal ArchitectureMarcelo Cure
1.2K views11 slides
Hexagonal architecture by
Hexagonal architectureHexagonal architecture
Hexagonal architectureNicolas Guignard
140 views27 slides
Hexagonal architecture with Spring Boot by
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootMikalai Alimenkou
8.8K views23 slides
Domain Driven Design by
Domain Driven DesignDomain Driven Design
Domain Driven DesignAraf Karsh Hamid
3.6K views45 slides
Kata: Hexagonal Architecture / Ports and Adapters by
Kata: Hexagonal Architecture / Ports and AdaptersKata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and Adaptersholsky
2.1K views7 slides

More Related Content

What's hot

Introduction to Microservices Patterns by
Introduction to Microservices PatternsIntroduction to Microservices Patterns
Introduction to Microservices PatternsDimosthenis Botsaris
343 views35 slides
Domain Driven Design by
Domain Driven DesignDomain Driven Design
Domain Driven DesignYoung-Ho Cho
8.3K views64 slides
Domain Driven Design (DDD) by
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)Tom Kocjan
13.2K views41 slides
Domain Driven Design(DDD) Presentation by
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationOğuzhan Soykan
5.9K views34 slides
Domain Driven Design by
Domain Driven DesignDomain Driven Design
Domain Driven DesignNader Albert
4.4K views68 slides
Hexagonal architecture in PHP by
Hexagonal architecture in PHPHexagonal architecture in PHP
Hexagonal architecture in PHPPaulo Victor Gomes
11.1K views37 slides

What's hot(20)

Domain Driven Design by Young-Ho Cho
Domain Driven DesignDomain Driven Design
Domain Driven Design
Young-Ho Cho8.3K views
Domain Driven Design (DDD) by Tom Kocjan
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
Tom Kocjan13.2K views
Domain Driven Design(DDD) Presentation by Oğuzhan Soykan
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
Oğuzhan Soykan5.9K views
Domain Driven Design by Nader Albert
Domain Driven DesignDomain Driven Design
Domain Driven Design
Nader Albert4.4K views
Clean architecture by .NET Crowd
Clean architectureClean architecture
Clean architecture
.NET Crowd3.5K views
Design patterns for microservice architecture by The Software House
Design patterns for microservice architectureDesign patterns for microservice architecture
Design patterns for microservice architecture
The Software House21.9K views
Designing APIs and Microservices Using Domain-Driven Design by LaunchAny
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven Design
LaunchAny15.1K views
Domain-Driven Design by Andriy Buday
Domain-Driven DesignDomain-Driven Design
Domain-Driven Design
Andriy Buday1.8K views
Clean architecture - Protecting the Domain by Victor Rentea
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
Victor Rentea652 views
Introducing Clean Architecture by Roc Boronat
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
Roc Boronat3K views
Domain Driven Design by Ryan Riley
Domain Driven DesignDomain Driven Design
Domain Driven Design
Ryan Riley9.8K views

Similar to Hexagonal architecture for java applications

Pros & Cons of Microservices Architecture by
Pros & Cons of Microservices ArchitecturePros & Cons of Microservices Architecture
Pros & Cons of Microservices ArchitectureAshwini Kuntamukkala
2.8K views31 slides
Stay productive_while_slicing_up_the_monolith by
Stay productive_while_slicing_up_the_monolithStay productive_while_slicing_up_the_monolith
Stay productive_while_slicing_up_the_monolithMarkus Eisele
592 views38 slides
Tokyo Azure Meetup #5 - Microservices and Azure Service Fabric by
Tokyo Azure Meetup #5 - Microservices and Azure Service FabricTokyo Azure Meetup #5 - Microservices and Azure Service Fabric
Tokyo Azure Meetup #5 - Microservices and Azure Service FabricTokyo Azure Meetup
517 views52 slides
Software Architecture and Architectors: useless VS valuable by
Software Architecture and Architectors: useless VS valuableSoftware Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuableComsysto Reply GmbH
93 views79 slides
Cloud-native Data: Every Microservice Needs a Cache by
Cloud-native Data: Every Microservice Needs a CacheCloud-native Data: Every Microservice Needs a Cache
Cloud-native Data: Every Microservice Needs a Cachecornelia davis
4.4K views48 slides
Stay productive while slicing up the monolith by
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Markus Eisele
438 views42 slides

Similar to Hexagonal architecture for java applications(20)

Stay productive_while_slicing_up_the_monolith by Markus Eisele
Stay productive_while_slicing_up_the_monolithStay productive_while_slicing_up_the_monolith
Stay productive_while_slicing_up_the_monolith
Markus Eisele592 views
Tokyo Azure Meetup #5 - Microservices and Azure Service Fabric by Tokyo Azure Meetup
Tokyo Azure Meetup #5 - Microservices and Azure Service FabricTokyo Azure Meetup #5 - Microservices and Azure Service Fabric
Tokyo Azure Meetup #5 - Microservices and Azure Service Fabric
Tokyo Azure Meetup517 views
Software Architecture and Architectors: useless VS valuable by Comsysto Reply GmbH
Software Architecture and Architectors: useless VS valuableSoftware Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuable
Cloud-native Data: Every Microservice Needs a Cache by cornelia davis
Cloud-native Data: Every Microservice Needs a CacheCloud-native Data: Every Microservice Needs a Cache
Cloud-native Data: Every Microservice Needs a Cache
cornelia davis4.4K views
Stay productive while slicing up the monolith by Markus Eisele
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith
Markus Eisele438 views
What serverless means for enterprise apps by Sumit Sarkar
What serverless means for enterprise appsWhat serverless means for enterprise apps
What serverless means for enterprise apps
Sumit Sarkar353 views
12 Factor App Methodology by laeshin park
12 Factor App Methodology12 Factor App Methodology
12 Factor App Methodology
laeshin park2.3K views
.NET microservices with Azure Service Fabric by Davide Benvegnù
.NET microservices with Azure Service Fabric.NET microservices with Azure Service Fabric
.NET microservices with Azure Service Fabric
Davide Benvegnù494 views
12-factor-jruby by Joe Kutner
12-factor-jruby12-factor-jruby
12-factor-jruby
Joe Kutner818 views
AzureSQL Managed Instance (SQLKonferenz 2018) by Jovan Popovic
AzureSQL Managed Instance (SQLKonferenz 2018)AzureSQL Managed Instance (SQLKonferenz 2018)
AzureSQL Managed Instance (SQLKonferenz 2018)
Jovan Popovic958 views
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk by Amazon Web Services
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
Amazon Web Services11.3K views
12 Factor Scala by Joe Kutner
12 Factor Scala12 Factor Scala
12 Factor Scala
Joe Kutner1.1K views
Ask The Architect: RightScale & AWS Dive Deep into Hybrid IT by RightScale
Ask The Architect: RightScale & AWS Dive Deep into Hybrid ITAsk The Architect: RightScale & AWS Dive Deep into Hybrid IT
Ask The Architect: RightScale & AWS Dive Deep into Hybrid IT
RightScale1.5K views
DockerCon 2016 - Structured Container Delivery by Oscar Renalias
DockerCon 2016 - Structured Container DeliveryDockerCon 2016 - Structured Container Delivery
DockerCon 2016 - Structured Container Delivery
Oscar Renalias661 views
Building a highly scalable and available cloud application by Noam Sheffer
Building a highly scalable and available cloud applicationBuilding a highly scalable and available cloud application
Building a highly scalable and available cloud application
Noam Sheffer415 views
AWS Dev Lounge: Applying the Twelve-Factor Application Manifesto to Developin... by Amazon Web Services
AWS Dev Lounge: Applying the Twelve-Factor Application Manifesto to Developin...AWS Dev Lounge: Applying the Twelve-Factor Application Manifesto to Developin...
AWS Dev Lounge: Applying the Twelve-Factor Application Manifesto to Developin...
Amazon Web Services2.8K views
Voxxed Athens 2018 - Eventing, Serverless, and the Extensible Enterprise by Voxxed Athens
Voxxed Athens 2018 - Eventing, Serverless, and the Extensible EnterpriseVoxxed Athens 2018 - Eventing, Serverless, and the Extensible Enterprise
Voxxed Athens 2018 - Eventing, Serverless, and the Extensible Enterprise
Voxxed Athens447 views

More from Fabricio Epaminondas

Understanding Web services by
Understanding Web servicesUnderstanding Web services
Understanding Web servicesFabricio Epaminondas
1.8K views28 slides
Designing Scalable Applications by
Designing Scalable ApplicationsDesigning Scalable Applications
Designing Scalable ApplicationsFabricio Epaminondas
2.7K views33 slides
Continuous testing in agile projects 2015 by
Continuous testing in agile projects 2015Continuous testing in agile projects 2015
Continuous testing in agile projects 2015Fabricio Epaminondas
3.5K views46 slides
Info Card - Techical Debt Management by
Info Card  - Techical Debt ManagementInfo Card  - Techical Debt Management
Info Card - Techical Debt ManagementFabricio Epaminondas
2.9K views14 slides
Software quality - Round table discussion by
Software quality - Round table discussionSoftware quality - Round table discussion
Software quality - Round table discussionFabricio Epaminondas
584 views6 slides
Continuous integration practices to improve the software quality by
Continuous integration practices to improve the software qualityContinuous integration practices to improve the software quality
Continuous integration practices to improve the software qualityFabricio Epaminondas
2.6K views18 slides

Recently uploaded

FIMA 2023 Neo4j & FS - Entity Resolution.pptx by
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptxNeo4j
6 views26 slides
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsRa'Fat Al-Msie'deen
5 views49 slides
Keep by
KeepKeep
KeepGeniusee
75 views10 slides
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h... by
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...Deltares
5 views31 slides
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... by
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Lisi Hocke
28 views124 slides
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Marc Müller
37 views83 slides

Recently uploaded(20)

FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j6 views
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h... by Deltares
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
Deltares5 views
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... by Lisi Hocke
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke28 views
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller37 views
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Generic or specific? Making sensible software design decisions by Bert Jan Schrijver
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta5 views
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm14 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares8 views
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by Deltares
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
Deltares5 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares10 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares17 views

Hexagonal architecture for java applications