SlideShare a Scribd company logo
Hexagonal architecture: how, why and when
Hexagonal
architecture: how,
why and when
Hexagonal Architecture: how, why and when - 11/2019 3
About meAbout me
Carlos Gándara
software developer at
@xoubaman
Hexagonal Architecture: how, why and when - 11/2019 4
Why?
Hexagonal Architecture: how, why and when - 11/2019 5
A journey through
architectural patterns
Hexagonal Architecture: how, why and when - 11/2019 6
Hexagonal Architecture: how, why and when - 11/2019 7
Spaghetti
Hexagonal Architecture: how, why and when - 11/2019 8
Spaghetti architecture
✅ Fun to revisit after some years...
✅ Valid for small proof of concept scripts
with a 10 minutes life expectancy
...although that means you have it on production
Hexagonal Architecture: how, why and when - 11/2019 9
Hexagonal Architecture: how, why and when - 11/2019 10
MVC
Hexagonal Architecture: how, why and when - 11/2019 11
HTTP
language
Database
language
Business
rules
Data
centric
MVC architecture
Hexagonal Architecture: how, why and when - 11/2019 12
Ctrl+C
Ctrl+V
We want to add
products from the
console
MVC architecture
Hexagonal Architecture: how, why and when - 11/2019 13
I just realized
products have also
a max price
WET code
(makes you sweat)
MVC architecture
Hexagonal Architecture: how, why and when - 11/2019 14
Controllers go fat
MVC architecture
Hexagonal Architecture: how, why and when - 11/2019 15
MVC architecture
❌ No isolation of business logic
✅ Valid for prototyping and purely CRUD applications
❌ Data centric
❌ Hard to test, infrastructure everywhere
Hexagonal Architecture: how, why and when - 11/2019 16
Hexagonal Architecture: how, why and when - 11/2019 17
Layered architecture
Hexagonal Architecture: how, why and when - 11/2019 18
Layered architecture
HTTP & CLI
Same application
service
Diagram from book DDD in PHP
Hexagonal Architecture: how, why and when - 11/2019 19
Layered architecture (the wrong way)
Now need to read
products from this
random API
And we should
notify warehouse
guys
Database
language
Outside
world
Outside
world
Our thing
Hexagonal Architecture: how, why and when - 11/2019 20
Layered architecture (the wrong way)
Hey, plz generate a
RSS feed with
products we read
from this weird
machine
And did I
mentioned we
are migrating to
Mongo?
Combinatorial explosion
Infrastructure coupling
Hexagonal Architecture: how, why and when - 11/2019 21
Layered architecture (the wrong way)
Hey, plz generate a
RSS feed with
products we read
from this weird
machine
And did I
mentioned we
are migrating to
Mongo?
Combinatorial explosion
Infrastructure coupling
Aren’t tests
taking too much
time?
Testability
Hexagonal Architecture: how, why and when - 11/2019 22
Layered architecture
❌ Data persistence is in the core*
✅ Separation of concerns
✅ Application layer encapsulating use cases
❌ Potential infrastructure leaks in other layers*
✅ You can build good stuff
❌ Lasagna antipattern
* if you do it wrong
Hexagonal Architecture: how, why and when - 11/2019 23
Hexagonal Architecture: how, why and when - 11/2019 24
Hexagonal architecture
Hexagonal Architecture: how, why and when - 11/2019 25
Aka Ports and Adapters
Coined by Alistair Cockburn in 2005
Hexagonal architecture
Check out Alistair in the "Hexagone" in Youtube
Hexagonal Architecture: how, why and when - 11/2019 26
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.
Hexagonal architecture
Hexagonal Architecture: how, why and when - 11/2019 27
Outside the application
A boundary
Application
Hexagonal architecture
Hexagonal Architecture: how, why and when - 11/2019 28
Port:
● Outside element
communicating with the
application
● Defined by an interface*
Application
Adapter:
● Implementation of a port
interface into what
application understands
*Not a code interface, although
sometimes represented by one
Ports and adapters
Hexagonal Architecture: how, why and when - 11/2019 29
Primary ports
Drivers
Secondary ports
Repositories and
recipients
Ports and adapters
Hexagonal Architecture: how, why and when - 11/2019 30
Test driver
User interface
Router + HTTP Controller
Ports and adapters
CLI
Console component
REST API
External application
Other adapter
Other adapter
Hexagonal Architecture: how, why and when - 11/2019 31
Ports and adapters
REST API adapter with Symfony:
● Routing component
● HTTP Kernel and Controller
● HTTP component Request
Hexagonal Architecture: how, why and when - 11/2019 32
Ports and adapters
Persistence
Queue
Feed
Interface implementation
Interface implementation
Interfaces
defined by the
application
Hexagonal Architecture: how, why and when - 11/2019 33
Ports and adapters
Persistence adapter with Doctrine ORM
Application defines the contract in its
own language
We don’t care about using database
or library language in the adapter
Hexagonal Architecture: how, why and when - 11/2019 34
Ports and adapters
Persistence adapter with Doctrine ORM
No infrastructure leaks
Testability improved!
Hexagonal Architecture: how, why and when - 11/2019 35
How?
Hexagonal Architecture: how, why and when - 11/2019 36
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.
Hexagonal architecture
No mention to
layers...
Hexagonal Architecture: how, why and when - 11/2019 37
Hexagonal architecture
You can put whatever you want inside the hexagon
Hexagonal Architecture: how, why and when - 11/2019 38
Hexagonal + Layered
Hexagonal Architecture: how, why and when - 11/2019 39
Hexagonal + Layered
Hexagonal Architecture: how, why and when - 11/2019 40
User Interface and Infrastructure layer:
● UI for primary ports adapters
● Infrastructure for secondary ports implementations
Application layer:
● Defines the system use cases
● Orchestrates the domain logic
● Command + Command Handler pattern
Domain layer:
● Holds all the business logic and invariants
● Defines the contracts implemented in infrastructure
Hexagonal + Layered: a proposal
Hexagonal Architecture: how, why and when - 11/2019 41
Hexagonal + Layered
Domain
Application
UI
Infrastructure
Hexagonal Architecture: how, why and when - 11/2019 42
Hexagonal + Layered: Domain layer
Domain
Application
UI
Infrastructure
Don’t leak
infrastructure in
your domain
Hexagonal Architecture: how, why and when - 11/2019 43
Hexagonal + Layered: Application layer
Domain
Application
UI
Infrastructure
More logic
than this is
suspicious
Hexagonal Architecture: how, why and when - 11/2019 44
Hexagonal + Layered: Driver port
Domain
Application
UI
Infrastructure
Hexagonal Architecture: how, why and when - 11/2019 45
Hexagonal + Layered: Repository port
Domain
Application
UI
Infrastructure
Dependency inversion
Hexagonal Architecture: how, why and when - 11/2019 46
When?
Hexagonal Architecture: how, why and when - 11/2019 47
When to apply hexagonal architecture?
ALWAYS*
Hexagonal Architecture: how, why and when - 11/2019 48
When to apply hexagonal architecture?
Pros
● Testability
● Promotes separation of
concerns
● Pushes accidental complexity
out of the domain
● Open/Closed
● Handy base for DDD
● Handy base for CQRS and ES
Cons
● Indirection
● Amount of boilerplate code
Hexagonal Architecture: how, why and when - 11/2019 49
When to apply hexagonal architecture?
Makes no sense for
● Scripting
● Prototyping
● Tooling
● Frameworks
Makes sense for
● Applications relying on external technologies
● CRUD applications
● Anything more complex than that
Hexagonal Architecture: how, why and when - 11/2019 50
When to apply hexagonal architecture?
Take decisions based on the context and needs
Keep in mind the reasons and the consequences
ALWAYS
Hexagonal Architecture: how, why and when - 11/2019 51
Questions?
Hexagonal Architecture: how, why and when - 11/2019
● Slides of this presentation anytime soon in @xoubaman
● Article: Hexagonal Architecture by Alistair Cockburn
● Article: Hexagonal Architecture by Fideloper
● Article: DDD, Hexagonal, Onion, Clean, CQRS, … How I put it all together by Hebert Graca
● Video: Introducción Arquitectura Hexagonal (Spanish) by CodelyTV
● Video: Hexagonal Architecture - Message-Oriented Software Design by Matthias Noback
● Video: Alistair in the “Hexagone” by DDD FR
● Book: DDD in PHP by Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary
● Book: Implementing Domain Driven Design by Vaughn Vernon
● Code samples glittered with Carbon
52
Some resources to follow up
Thank you!

More Related Content

What's hot (20)

PDF
The Secrets of Hexagonal Architecture
Nicolas Carlo
 
PDF
Observability at Scale
Knoldus Inc.
 
PPTX
Hexagonal architecture with Spring Boot
Mikalai Alimenkou
 
PPSX
Microservices, Containers, Kubernetes, Kafka, Kanban
Araf Karsh Hamid
 
PDF
Service Mesh on Kubernetes with Istio
Michelle Holley
 
PPTX
Docker Kubernetes Istio
Araf Karsh Hamid
 
PDF
Understanding MicroSERVICE Architecture with Java & Spring Boot
Kashif Ali Siddiqui
 
PPTX
Event-driven microservices
Andrew Schofield
 
PDF
Istio : Service Mesh
Knoldus Inc.
 
PDF
The Complete Guide to Service Mesh
Aspen Mesh
 
PDF
Kubernetes Networking
CJ Cullen
 
PDF
What are Microservices | Microservices Architecture Training | Microservices ...
Edureka!
 
PPSX
Event Sourcing & CQRS, Kafka, Rabbit MQ
Araf Karsh Hamid
 
PDF
Domain Driven Design (Ultra) Distilled
Nicola Costantino
 
PDF
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
PPTX
What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...
Simplilearn
 
PPTX
Domain Driven Design
Araf Karsh Hamid
 
PDF
DDD Tactical Design with Clean Architecture - Ivan Paulovich
Ivan Paulovich
 
PDF
Hexagonal Architecture.pdf
VladimirRadzivil
 
PDF
Introduction to Istio Service Mesh
Georgios Andrianakis
 
The Secrets of Hexagonal Architecture
Nicolas Carlo
 
Observability at Scale
Knoldus Inc.
 
Hexagonal architecture with Spring Boot
Mikalai Alimenkou
 
Microservices, Containers, Kubernetes, Kafka, Kanban
Araf Karsh Hamid
 
Service Mesh on Kubernetes with Istio
Michelle Holley
 
Docker Kubernetes Istio
Araf Karsh Hamid
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Kashif Ali Siddiqui
 
Event-driven microservices
Andrew Schofield
 
Istio : Service Mesh
Knoldus Inc.
 
The Complete Guide to Service Mesh
Aspen Mesh
 
Kubernetes Networking
CJ Cullen
 
What are Microservices | Microservices Architecture Training | Microservices ...
Edureka!
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Araf Karsh Hamid
 
Domain Driven Design (Ultra) Distilled
Nicola Costantino
 
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...
Simplilearn
 
Domain Driven Design
Araf Karsh Hamid
 
DDD Tactical Design with Clean Architecture - Ivan Paulovich
Ivan Paulovich
 
Hexagonal Architecture.pdf
VladimirRadzivil
 
Introduction to Istio Service Mesh
Georgios Andrianakis
 

Similar to Hexagonal architecture: how, why and when (20)

PDF
Hexagonal
jglobal
 
PDF
Introduction to hexagonal architecture
Manel Sellés
 
PDF
Explicit architecture
Herberto Graça
 
PDF
A very simple hexagonal architecture.pdf
Dan MAGIER
 
PDF
Hexagonal architecture
Nicolas Guignard
 
PDF
Hexagonal Architecture - message-oriented software design (PHPCon Poland 2015)
Matthias Noback
 
PDF
Hexagonal architecture message-oriented software design
Matthias Noback
 
PDF
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Matthias Noback
 
PDF
Hexagonal architecture - message-oriented software design
Matthias Noback
 
PDF
Hexagonal architecture - message-oriented software design (Symfony Live Berli...
Matthias Noback
 
PDF
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Matthias Noback
 
PDF
Hexagonal Symfony - SymfonyCon Amsterdam 2019
Matthias Noback
 
PDF
Hexagonal architecture for the web
Jesús Espejo
 
PDF
Hexagonal architecture for java applications
Fabricio Epaminondas
 
PPTX
Hexagonal_Architecture_DDD_Presentation.pptx
AslanAs2
 
PPTX
Construcción de web aps- un enfoque hexagonal
ch1l3no
 
PDF
ljug-meetup-2023-03-hexagonal-architecture.pdf
Comsysto Reply GmbH
 
PDF
A CQRS Journey
Chrysovalantis Koutsoumpos
 
PDF
Hexagonal architecture
Alessandro Minoccheri
 
PDF
Hexagonal architecture in PHP
Paulo Victor Gomes
 
Hexagonal
jglobal
 
Introduction to hexagonal architecture
Manel Sellés
 
Explicit architecture
Herberto Graça
 
A very simple hexagonal architecture.pdf
Dan MAGIER
 
Hexagonal architecture
Nicolas Guignard
 
Hexagonal Architecture - message-oriented software design (PHPCon Poland 2015)
Matthias Noback
 
Hexagonal architecture message-oriented software design
Matthias Noback
 
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Matthias Noback
 
Hexagonal architecture - message-oriented software design
Matthias Noback
 
Hexagonal architecture - message-oriented software design (Symfony Live Berli...
Matthias Noback
 
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Matthias Noback
 
Hexagonal Symfony - SymfonyCon Amsterdam 2019
Matthias Noback
 
Hexagonal architecture for the web
Jesús Espejo
 
Hexagonal architecture for java applications
Fabricio Epaminondas
 
Hexagonal_Architecture_DDD_Presentation.pptx
AslanAs2
 
Construcción de web aps- un enfoque hexagonal
ch1l3no
 
ljug-meetup-2023-03-hexagonal-architecture.pdf
Comsysto Reply GmbH
 
Hexagonal architecture
Alessandro Minoccheri
 
Hexagonal architecture in PHP
Paulo Victor Gomes
 
Ad

Recently uploaded (20)

PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Ad

Hexagonal architecture: how, why and when

  • 3. Hexagonal Architecture: how, why and when - 11/2019 3 About meAbout me Carlos Gándara software developer at @xoubaman
  • 4. Hexagonal Architecture: how, why and when - 11/2019 4 Why?
  • 5. Hexagonal Architecture: how, why and when - 11/2019 5 A journey through architectural patterns
  • 6. Hexagonal Architecture: how, why and when - 11/2019 6
  • 7. Hexagonal Architecture: how, why and when - 11/2019 7 Spaghetti
  • 8. Hexagonal Architecture: how, why and when - 11/2019 8 Spaghetti architecture ✅ Fun to revisit after some years... ✅ Valid for small proof of concept scripts with a 10 minutes life expectancy ...although that means you have it on production
  • 9. Hexagonal Architecture: how, why and when - 11/2019 9
  • 10. Hexagonal Architecture: how, why and when - 11/2019 10 MVC
  • 11. Hexagonal Architecture: how, why and when - 11/2019 11 HTTP language Database language Business rules Data centric MVC architecture
  • 12. Hexagonal Architecture: how, why and when - 11/2019 12 Ctrl+C Ctrl+V We want to add products from the console MVC architecture
  • 13. Hexagonal Architecture: how, why and when - 11/2019 13 I just realized products have also a max price WET code (makes you sweat) MVC architecture
  • 14. Hexagonal Architecture: how, why and when - 11/2019 14 Controllers go fat MVC architecture
  • 15. Hexagonal Architecture: how, why and when - 11/2019 15 MVC architecture ❌ No isolation of business logic ✅ Valid for prototyping and purely CRUD applications ❌ Data centric ❌ Hard to test, infrastructure everywhere
  • 16. Hexagonal Architecture: how, why and when - 11/2019 16
  • 17. Hexagonal Architecture: how, why and when - 11/2019 17 Layered architecture
  • 18. Hexagonal Architecture: how, why and when - 11/2019 18 Layered architecture HTTP & CLI Same application service Diagram from book DDD in PHP
  • 19. Hexagonal Architecture: how, why and when - 11/2019 19 Layered architecture (the wrong way) Now need to read products from this random API And we should notify warehouse guys Database language Outside world Outside world Our thing
  • 20. Hexagonal Architecture: how, why and when - 11/2019 20 Layered architecture (the wrong way) Hey, plz generate a RSS feed with products we read from this weird machine And did I mentioned we are migrating to Mongo? Combinatorial explosion Infrastructure coupling
  • 21. Hexagonal Architecture: how, why and when - 11/2019 21 Layered architecture (the wrong way) Hey, plz generate a RSS feed with products we read from this weird machine And did I mentioned we are migrating to Mongo? Combinatorial explosion Infrastructure coupling Aren’t tests taking too much time? Testability
  • 22. Hexagonal Architecture: how, why and when - 11/2019 22 Layered architecture ❌ Data persistence is in the core* ✅ Separation of concerns ✅ Application layer encapsulating use cases ❌ Potential infrastructure leaks in other layers* ✅ You can build good stuff ❌ Lasagna antipattern * if you do it wrong
  • 23. Hexagonal Architecture: how, why and when - 11/2019 23
  • 24. Hexagonal Architecture: how, why and when - 11/2019 24 Hexagonal architecture
  • 25. Hexagonal Architecture: how, why and when - 11/2019 25 Aka Ports and Adapters Coined by Alistair Cockburn in 2005 Hexagonal architecture Check out Alistair in the "Hexagone" in Youtube
  • 26. Hexagonal Architecture: how, why and when - 11/2019 26 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. Hexagonal architecture
  • 27. Hexagonal Architecture: how, why and when - 11/2019 27 Outside the application A boundary Application Hexagonal architecture
  • 28. Hexagonal Architecture: how, why and when - 11/2019 28 Port: ● Outside element communicating with the application ● Defined by an interface* Application Adapter: ● Implementation of a port interface into what application understands *Not a code interface, although sometimes represented by one Ports and adapters
  • 29. Hexagonal Architecture: how, why and when - 11/2019 29 Primary ports Drivers Secondary ports Repositories and recipients Ports and adapters
  • 30. Hexagonal Architecture: how, why and when - 11/2019 30 Test driver User interface Router + HTTP Controller Ports and adapters CLI Console component REST API External application Other adapter Other adapter
  • 31. Hexagonal Architecture: how, why and when - 11/2019 31 Ports and adapters REST API adapter with Symfony: ● Routing component ● HTTP Kernel and Controller ● HTTP component Request
  • 32. Hexagonal Architecture: how, why and when - 11/2019 32 Ports and adapters Persistence Queue Feed Interface implementation Interface implementation Interfaces defined by the application
  • 33. Hexagonal Architecture: how, why and when - 11/2019 33 Ports and adapters Persistence adapter with Doctrine ORM Application defines the contract in its own language We don’t care about using database or library language in the adapter
  • 34. Hexagonal Architecture: how, why and when - 11/2019 34 Ports and adapters Persistence adapter with Doctrine ORM No infrastructure leaks Testability improved!
  • 35. Hexagonal Architecture: how, why and when - 11/2019 35 How?
  • 36. Hexagonal Architecture: how, why and when - 11/2019 36 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. Hexagonal architecture No mention to layers...
  • 37. Hexagonal Architecture: how, why and when - 11/2019 37 Hexagonal architecture You can put whatever you want inside the hexagon
  • 38. Hexagonal Architecture: how, why and when - 11/2019 38 Hexagonal + Layered
  • 39. Hexagonal Architecture: how, why and when - 11/2019 39 Hexagonal + Layered
  • 40. Hexagonal Architecture: how, why and when - 11/2019 40 User Interface and Infrastructure layer: ● UI for primary ports adapters ● Infrastructure for secondary ports implementations Application layer: ● Defines the system use cases ● Orchestrates the domain logic ● Command + Command Handler pattern Domain layer: ● Holds all the business logic and invariants ● Defines the contracts implemented in infrastructure Hexagonal + Layered: a proposal
  • 41. Hexagonal Architecture: how, why and when - 11/2019 41 Hexagonal + Layered Domain Application UI Infrastructure
  • 42. Hexagonal Architecture: how, why and when - 11/2019 42 Hexagonal + Layered: Domain layer Domain Application UI Infrastructure Don’t leak infrastructure in your domain
  • 43. Hexagonal Architecture: how, why and when - 11/2019 43 Hexagonal + Layered: Application layer Domain Application UI Infrastructure More logic than this is suspicious
  • 44. Hexagonal Architecture: how, why and when - 11/2019 44 Hexagonal + Layered: Driver port Domain Application UI Infrastructure
  • 45. Hexagonal Architecture: how, why and when - 11/2019 45 Hexagonal + Layered: Repository port Domain Application UI Infrastructure Dependency inversion
  • 46. Hexagonal Architecture: how, why and when - 11/2019 46 When?
  • 47. Hexagonal Architecture: how, why and when - 11/2019 47 When to apply hexagonal architecture? ALWAYS*
  • 48. Hexagonal Architecture: how, why and when - 11/2019 48 When to apply hexagonal architecture? Pros ● Testability ● Promotes separation of concerns ● Pushes accidental complexity out of the domain ● Open/Closed ● Handy base for DDD ● Handy base for CQRS and ES Cons ● Indirection ● Amount of boilerplate code
  • 49. Hexagonal Architecture: how, why and when - 11/2019 49 When to apply hexagonal architecture? Makes no sense for ● Scripting ● Prototyping ● Tooling ● Frameworks Makes sense for ● Applications relying on external technologies ● CRUD applications ● Anything more complex than that
  • 50. Hexagonal Architecture: how, why and when - 11/2019 50 When to apply hexagonal architecture? Take decisions based on the context and needs Keep in mind the reasons and the consequences ALWAYS
  • 51. Hexagonal Architecture: how, why and when - 11/2019 51 Questions?
  • 52. Hexagonal Architecture: how, why and when - 11/2019 ● Slides of this presentation anytime soon in @xoubaman ● Article: Hexagonal Architecture by Alistair Cockburn ● Article: Hexagonal Architecture by Fideloper ● Article: DDD, Hexagonal, Onion, Clean, CQRS, … How I put it all together by Hebert Graca ● Video: Introducción Arquitectura Hexagonal (Spanish) by CodelyTV ● Video: Hexagonal Architecture - Message-Oriented Software Design by Matthias Noback ● Video: Alistair in the “Hexagone” by DDD FR ● Book: DDD in PHP by Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary ● Book: Implementing Domain Driven Design by Vaughn Vernon ● Code samples glittered with Carbon 52 Some resources to follow up