Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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
• L...
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 device...
01 Dependency inversion principle
Reference: http://blog.ploeh.dk/2013/12/03/layers-onions-ports-adapters-its-all-the-same...
02 Hexagonal
Architecture
The Pattern
02 Intent
• Alternative names
• Ports & Adapters
• Onion Architecture / Onion Layers
“Allow an application to equally be d...
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
Adapt...
Overview02

In-Memory
"Application
# Database
( Web Services
)
) Enterprise Integration
*

SQL Server
REST
Adapter
* Con...
03 Application
Keeping it simple
03
• Organizing Concerns and Code with Domains
• Well defined boundaries between domains
• Simple event-driven components
...
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...
05 Core
Use Case as service
Implementing the Use Case as Service05
• Domain model
• Entities
• Repositories
• Well defined interface
• Input/Output Ev...
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 w...
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
onfigura...
Comments
• How many ports?
• The hexagon is a metaphor
• Abstractions
• Use Case as port
• Module as port: Notification, A...
See more…
• RESTful API with Spring Boot
• Securing REST APIs
• References:
[1] alistair.cockburn.us/Hexagonal+architectur...
Contact
FABRICIO EPAMINONDAS
0 linkedin.com/in/fabricioepa
/ fabricioepa.wordpress.com
1 @fabricioepa
Upcoming SlideShare
Loading in …5
×

Hexagonal architecture for java applications

17,615 views

Published on

Workshop Guide for Java Hexagonal Applications using Spring Boot

Published in: Software
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Hexagonal architecture for java applications

  1. 1. Java Development HEXAGONAL ARCHITECTURE for Java Applications
  2. 2. 01 Concepts Software Architecture
  3. 3. 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
  4. 4. 01 Common multi-layer architecture ! " # " ! UI Layer " Application Layer # Data " Crosscutting Dependency
  5. 5. 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
  6. 6. 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
  7. 7. 02 Hexagonal Architecture The Pattern
  8. 8. 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
  9. 9. 02 Key Concepts Ports are interfaces Adapters are implementations
  10. 10. 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
  11. 11. 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
  12. 12. 03 Application Keeping it simple
  13. 13. 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
  14. 14. Life Preserver diagram03 Integration Core Domain Event Service Domain Boundary
  15. 15. Notes03 • Core • Single purpose • Focus on unit testing • No side-effects • Integration • Side effects
  16. 16. 04 Practice Ticket System
  17. 17. Kick-off04 github.com/fabricioepa/lab- springboot-rest-sample Lets start from the sample project and then create the ports and adapters
  18. 18. 05 Core Use Case as service
  19. 19. Implementing the Use Case as Service05 • Domain model • Entities • Repositories • Well defined interface • Input/Output Events • Event Handlers & Translators • Service composition • Unit Testing
  20. 20. Life Preserver Services Domain Event Repository D atabase Test UnitTest Framework 0405
  21. 21. 06 Controllers
  22. 22. 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
  23. 23. Life Preserver Services Domain Event Repository D atabase Test UnitTest Framework Domain Controller R EST 030506
  24. 24. 07 Configuration
  25. 25. Externalized configuration • External files • Environment variables • Configuration profiles • Services 030507
  26. 26. 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
  27. 27. Comments • How many ports? • The hexagon is a metaphor • Abstractions • Use Case as port • Module as port: Notification, Administration, Public API, Database 0303 • Services
  28. 28. 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
  29. 29. Contact FABRICIO EPAMINONDAS 0 linkedin.com/in/fabricioepa / fabricioepa.wordpress.com 1 @fabricioepa

×