SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
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!

Weitere ähnliche Inhalte

Was ist angesagt?

Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean ArchitectureMattia Battiston
 
Node.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontendsNode.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontendsEugene Fidelin
 
Clean architecture
Clean architectureClean architecture
Clean architectureandbed
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean ArchitectureRoc Boronat
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Steve Pember
 
chaos-engineering-Knolx
chaos-engineering-Knolxchaos-engineering-Knolx
chaos-engineering-KnolxKnoldus Inc.
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices Bozhidar Bozhanov
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureBadoo
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on androidBenjamin Cheng
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practicesfloydophone
 
Hexagonal Architecture.pdf
Hexagonal Architecture.pdfHexagonal Architecture.pdf
Hexagonal Architecture.pdfVladimirRadzivil
 
Flutter vs React Native | Edureka
Flutter vs React Native | EdurekaFlutter vs React Native | Edureka
Flutter vs React Native | EdurekaEdureka!
 
MicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleMicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleSudhir Tonse
 
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices ArchitecturesUnit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices ArchitecturesNGINX, Inc.
 
Design & Prototype an API
Design & Prototype an APIDesign & Prototype an API
Design & Prototype an APIPostman
 

Was ist angesagt? (20)

Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
 
Node.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontendsNode.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontends
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
React JS
React JSReact JS
React JS
 
Hexagonal architecture in PHP
Hexagonal architecture in PHPHexagonal architecture in PHP
Hexagonal architecture in PHP
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
chaos-engineering-Knolx
chaos-engineering-Knolxchaos-engineering-Knolx
chaos-engineering-Knolx
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on android
 
Hexagonal And Beyond
Hexagonal And BeyondHexagonal And Beyond
Hexagonal And Beyond
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
 
Hexagonal Architecture.pdf
Hexagonal Architecture.pdfHexagonal Architecture.pdf
Hexagonal Architecture.pdf
 
Flutter vs React Native | Edureka
Flutter vs React Native | EdurekaFlutter vs React Native | Edureka
Flutter vs React Native | Edureka
 
C# Async Await
C# Async AwaitC# Async Await
C# Async Await
 
MicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scaleMicroServices at Netflix - challenges of scale
MicroServices at Netflix - challenges of scale
 
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices ArchitecturesUnit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
 
Design & Prototype an API
Design & Prototype an APIDesign & Prototype an API
Design & Prototype an API
 

Ähnlich wie Hexagonal architecture: how, why and when

UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...Karen Cannell
 
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, AirbusAPIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbusapidays
 
Why Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik RamasamyWhy Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik RamasamyStreamNative
 
Pulsar summit-keynote-final
Pulsar summit-keynote-finalPulsar summit-keynote-final
Pulsar summit-keynote-finalKarthik Ramasamy
 
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in..."Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...DECIDEH2020
 
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019Yenlo
 
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...Trivadis
 
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
APEX Interactive Grid API Essentials:  The Stuff You Will Really UseAPEX Interactive Grid API Essentials:  The Stuff You Will Really Use
APEX Interactive Grid API Essentials: The Stuff You Will Really UseKaren Cannell
 
2019 09-13 kubernetes is hard - k8s community days
2019 09-13 kubernetes is hard - k8s community days2019 09-13 kubernetes is hard - k8s community days
2019 09-13 kubernetes is hard - k8s community daysEldad Assis
 
Agile Mëtteg series session 7
Agile Mëtteg series session 7Agile Mëtteg series session 7
Agile Mëtteg series session 7Agile Partner S.A.
 
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approachDevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approachDevOps_Fest
 
Bring cloud on premises with a kubernetes-native infrastructure
Bring cloud on premises with a kubernetes-native infrastructureBring cloud on premises with a kubernetes-native infrastructure
Bring cloud on premises with a kubernetes-native infrastructureAbhinav Joshi
 
Serverless Kafka Patterns
Serverless Kafka PatternsServerless Kafka Patterns
Serverless Kafka PatternsTaras Slipets
 
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry DaysStock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry DaysVidyasagar Machupalli
 
Openbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar 2 - Leuven - Faros - Invisible InfrastructureOpenbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar 2 - Leuven - Faros - Invisible InfrastructureOpenbar
 
Cloud native past, present and future
Cloud native past, present and futureCloud native past, present and future
Cloud native past, present and futureCheryl Hung
 
Empowering your Process Automation with Machine Learning
Empowering your Process Automation with Machine LearningEmpowering your Process Automation with Machine Learning
Empowering your Process Automation with Machine LearningLykle Thijssen
 
Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
 Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e... Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...VMware Tanzu
 

Ähnlich wie Hexagonal architecture: how, why and when (20)

UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
 
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, AirbusAPIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
 
Why Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik RamasamyWhy Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik Ramasamy
 
Pulsar summit-keynote-final
Pulsar summit-keynote-finalPulsar summit-keynote-final
Pulsar summit-keynote-final
 
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in..."Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
 
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
 
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
 
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
APEX Interactive Grid API Essentials:  The Stuff You Will Really UseAPEX Interactive Grid API Essentials:  The Stuff You Will Really Use
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
 
2019 09-13 kubernetes is hard - k8s community days
2019 09-13 kubernetes is hard - k8s community days2019 09-13 kubernetes is hard - k8s community days
2019 09-13 kubernetes is hard - k8s community days
 
Web Development
Web DevelopmentWeb Development
Web Development
 
Agile Mëtteg series session 7
Agile Mëtteg series session 7Agile Mëtteg series session 7
Agile Mëtteg series session 7
 
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approachDevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
 
Apache Pulsar @Splunk
Apache Pulsar @SplunkApache Pulsar @Splunk
Apache Pulsar @Splunk
 
Bring cloud on premises with a kubernetes-native infrastructure
Bring cloud on premises with a kubernetes-native infrastructureBring cloud on premises with a kubernetes-native infrastructure
Bring cloud on premises with a kubernetes-native infrastructure
 
Serverless Kafka Patterns
Serverless Kafka PatternsServerless Kafka Patterns
Serverless Kafka Patterns
 
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry DaysStock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
 
Openbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar 2 - Leuven - Faros - Invisible InfrastructureOpenbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar 2 - Leuven - Faros - Invisible Infrastructure
 
Cloud native past, present and future
Cloud native past, present and futureCloud native past, present and future
Cloud native past, present and future
 
Empowering your Process Automation with Machine Learning
Empowering your Process Automation with Machine LearningEmpowering your Process Automation with Machine Learning
Empowering your Process Automation with Machine Learning
 
Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
 Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e... Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
 

Kürzlich hochgeladen

Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 

Kürzlich hochgeladen (20)

Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 

Hexagonal architecture: how, why and when

  • 1.
  • 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