SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
Hexagonal Architecture: Why Architecture
Hexagonal architecture is a specific instance of an architecture
pattern. Why do we need one at all?
Make software easier to change
Make software easier to test
Make software easier to reason about
Make software easier to write with fewer bugs
Reduce the future cost of changing your mind later, about
nearly anything
Michael Nash Hexagonal Architecture
Hexagonal Architecture: Definition
What is Hexagonal Architecture?
An alternative to the “standard layered model”
Developed by Alistair Cockburn
Later called Ports and Adapters
Also called the Onion Architecture
Involves application of the Dependency Inversion Principle
Michael Nash Hexagonal Architecture
Hexagonal Architecture: Contrast
What is the Standard Layered Model?
UI
Application
Domain
Network and database
Hexagonal architecture rejects the notion that any of these layers
except the domain are different from one another. E.g. a user
sitting at a UI is not much different than a flat file full of test
cases, or a network and a database.
Michael Nash Hexagonal Architecture
Layered Architecture: Diagram
Michael Nash Hexagonal Architecture
Hexagonal Architecture: Diagram
Domain on the inside, infrastructure (ports and adapters) on the
outside
Michael Nash Hexagonal Architecture
Hexagonal Architecture: Value
Why Hexagonal Architecture?
What does this architecture buy us?
Symmetrical
Verifiable – you can tell when you’ve got it by inspection
Decouple core logic (the domain) from infrastructure
Always possible to test everything easily
Infrastructure changes are not relevant to the domain logic
Makes package and module structure consistent and easy to
navigate
Natural fit with DDD and EDA
Language and framework agnostic
Excellent fit with functional programming
Michael Nash Hexagonal Architecture
Hexagonal Architecture: Ports and Adapters
Infrastructure services can easily be replaced with others
Michael Nash Hexagonal Architecture
Dependency Inversion Principle
To apply Hexagonal architecture, we use the dependency inversion
principle
Specific top-level package structure
Careful management of imports and dependency management
Common classes depend on nothing (no IO, utilities only)
Domain classes depend only on common classes and each
other
Services classes depend on domain, adapt to infrastructure
Infrastructure classes depend on services and domain
Michael Nash Hexagonal Architecture
Dependency Inversion Principle: Diagram
Michael Nash Hexagonal Architecture
Dependency Inversion Principle: Common
The Common package contains only shared utility classes
No I/O!
String utilities
Date utilities
Random numbers
Data structures
NOT what we currently call “common”
Michael Nash Hexagonal Architecture
Dependency Inversion Principle: Domain
The Domain package contains only business domain classes and
functions
Depends ONLY on other domain classes and common classes
Can use abstractions like logging (traits only)
Contains domain logic – avoid anemic domain!
No I/O
Can contain DDD services for operations that span aggregates
No DTOs
No annotations
Use types, not primitives wherever possible
Michael Nash Hexagonal Architecture
Dependency Inversion Principle: Services
The Services package contains the service classes used by the ports
and adapters to interact with the domain
Depends ONLY on domain and common
Expose operations needed by the adapters
No I/O
Could contain Repositories
No event handlers (these are infrastructure)
No REST routing (again, infrastructure)
No DTOs
No annotations
Michael Nash Hexagonal Architecture
Dependency Inversion Principle: Infrastructure
The Infrastructure package contains the adapters that connect the
services and the domain to the outside world
Can depend on any other package as required
Contains sub-packages for specific adapters (e.g. http,
eventbus, mongo)
I/O goes here – all of it
Calls services and domain
REST routing goes here
Implementations of repositories go here
DTOs go here
Guice module, dependency injection goes here
Michael Nash Hexagonal Architecture
Hexagonal Architecture: Action Plan
How do we get there? What’s the plan?
Review Hierarchy (now), make sure we all understand the
desired outcome
In other modules, create top-level packages domain, common,
services and infrastructure
Refactor into proper package structure, decoupling as required
Decouple from deprecated common modules
Refactor spray-service-common and submodules into re-usable
infrastructure modules
Use Crucible to review and discuss refactors
Specific stories to refactor each module
Decouple EventBus from our domain (make domain-agnostic)
Adopt single-source tree view to facilitate refactorings
Michael Nash Hexagonal Architecture
Hexagonal Architecture: Single Sourcetree View
A single bounded context should be visible as a single logical
source tree
No more p2build plugin
Refactoring greatly simplified
No more versions of common
Executable artifacts become a deploy-time question: can
change as needed
Acheivable “virtually” right away with git sub-modules
(ListingDistributionContext)
Adding new Event types (for example) becomes trivial
One git repo (logically, if not physically at first)
Decouple EventBus from our domain (make domain-agnostic)
Integration tests become trivial (no need to launch multiple
jars)
Michael Nash Hexagonal Architecture
Hexagonal Architecture: Conclusion
We want the benefits of hexagonal architecture, hence the
refactors
Questions?
Michael Nash Hexagonal Architecture

Contenu connexe

Tendances

Tendances (20)

Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
 
The Quest for Global Design Principles
The Quest for Global Design PrinciplesThe Quest for Global Design Principles
The Quest for Global Design Principles
 
Arquitectura hexagonal
Arquitectura hexagonalArquitectura hexagonal
Arquitectura hexagonal
 
Hexagonal architecture in PHP
Hexagonal architecture in PHPHexagonal architecture in PHP
Hexagonal architecture in PHP
 
The quest for global design principles - PHP Benelux 2016
The quest for global design principles - PHP Benelux 2016The quest for global design principles - PHP Benelux 2016
The quest for global design principles - PHP Benelux 2016
 
Clean architecture with ddd layering in php
Clean architecture with ddd layering in phpClean architecture with ddd layering in php
Clean architecture with ddd layering in php
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVC
 
Distributed Computing
Distributed ComputingDistributed Computing
Distributed Computing
 
Hexagonal architecture for the web
Hexagonal architecture for the webHexagonal architecture for the web
Hexagonal architecture for the web
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
 
Actor model in F# and Akka.NET
Actor model in F# and Akka.NETActor model in F# and Akka.NET
Actor model in F# and Akka.NET
 
Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHP
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean Architecture
 
The framework as an implementation detail
The framework as an implementation detailThe framework as an implementation detail
The framework as an implementation detail
 
How to Implement Domain Driven Design in Real Life SDLC
How to Implement Domain Driven Design  in Real Life SDLCHow to Implement Domain Driven Design  in Real Life SDLC
How to Implement Domain Driven Design in Real Life SDLC
 
Application architecture
Application architectureApplication architecture
Application architecture
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)
 

Similaire à Hexagonal

17 applied architectures
17 applied architectures17 applied architectures
17 applied architectures
Majong DevJfu
 
Sodius cassidian mdday2010
Sodius cassidian mdday2010Sodius cassidian mdday2010
Sodius cassidian mdday2010
MD DAY
 

Similaire à Hexagonal (20)

Onion (clean) architecture
Onion (clean) architectureOnion (clean) architecture
Onion (clean) architecture
 
[WSO2Con USA 2018] Deep-dive into Agile Architecture and Methodology
[WSO2Con USA 2018] Deep-dive into Agile Architecture and Methodology[WSO2Con USA 2018] Deep-dive into Agile Architecture and Methodology
[WSO2Con USA 2018] Deep-dive into Agile Architecture and Methodology
 
Webinar - Mobile Apps: Monolithic to Serverless
Webinar - Mobile Apps: Monolithic to ServerlessWebinar - Mobile Apps: Monolithic to Serverless
Webinar - Mobile Apps: Monolithic to Serverless
 
SodiusCassidianmdday2010 101129081449-phpapp02
SodiusCassidianmdday2010 101129081449-phpapp02SodiusCassidianmdday2010 101129081449-phpapp02
SodiusCassidianmdday2010 101129081449-phpapp02
 
Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"
 
Building modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf FildebrandtBuilding modular software with OSGi - Ulf Fildebrandt
Building modular software with OSGi - Ulf Fildebrandt
 
How to Think Multi-Cloud
How to Think Multi-CloudHow to Think Multi-Cloud
How to Think Multi-Cloud
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
Productionizing Predictive Analytics using the Rendezvous Architecture - for ...
Productionizing Predictive Analytics using the Rendezvous Architecture - for ...Productionizing Predictive Analytics using the Rendezvous Architecture - for ...
Productionizing Predictive Analytics using the Rendezvous Architecture - for ...
 
HCE project brief
HCE project briefHCE project brief
HCE project brief
 
Full lifecycle of a microservice
Full lifecycle of a microserviceFull lifecycle of a microservice
Full lifecycle of a microservice
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Oo Design And Patterns
Oo Design And PatternsOo Design And Patterns
Oo Design And Patterns
 
17 applied architectures
17 applied architectures17 applied architectures
17 applied architectures
 
Sca
ScaSca
Sca
 
L02 Architecture
L02 ArchitectureL02 Architecture
L02 Architecture
 
Advanced application architecture
Advanced application architectureAdvanced application architecture
Advanced application architecture
 
Advanced Application Architecture (workshop slides)
Advanced Application Architecture (workshop slides)Advanced Application Architecture (workshop slides)
Advanced Application Architecture (workshop slides)
 
An agile approach to cloud infrastructure
An agile approach to cloud infrastructureAn agile approach to cloud infrastructure
An agile approach to cloud infrastructure
 
Sodius cassidian mdday2010
Sodius cassidian mdday2010Sodius cassidian mdday2010
Sodius cassidian mdday2010
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Hexagonal

  • 1. Hexagonal Architecture: Why Architecture Hexagonal architecture is a specific instance of an architecture pattern. Why do we need one at all? Make software easier to change Make software easier to test Make software easier to reason about Make software easier to write with fewer bugs Reduce the future cost of changing your mind later, about nearly anything Michael Nash Hexagonal Architecture
  • 2. Hexagonal Architecture: Definition What is Hexagonal Architecture? An alternative to the “standard layered model” Developed by Alistair Cockburn Later called Ports and Adapters Also called the Onion Architecture Involves application of the Dependency Inversion Principle Michael Nash Hexagonal Architecture
  • 3. Hexagonal Architecture: Contrast What is the Standard Layered Model? UI Application Domain Network and database Hexagonal architecture rejects the notion that any of these layers except the domain are different from one another. E.g. a user sitting at a UI is not much different than a flat file full of test cases, or a network and a database. Michael Nash Hexagonal Architecture
  • 4. Layered Architecture: Diagram Michael Nash Hexagonal Architecture
  • 5. Hexagonal Architecture: Diagram Domain on the inside, infrastructure (ports and adapters) on the outside Michael Nash Hexagonal Architecture
  • 6. Hexagonal Architecture: Value Why Hexagonal Architecture? What does this architecture buy us? Symmetrical Verifiable – you can tell when you’ve got it by inspection Decouple core logic (the domain) from infrastructure Always possible to test everything easily Infrastructure changes are not relevant to the domain logic Makes package and module structure consistent and easy to navigate Natural fit with DDD and EDA Language and framework agnostic Excellent fit with functional programming Michael Nash Hexagonal Architecture
  • 7. Hexagonal Architecture: Ports and Adapters Infrastructure services can easily be replaced with others Michael Nash Hexagonal Architecture
  • 8. Dependency Inversion Principle To apply Hexagonal architecture, we use the dependency inversion principle Specific top-level package structure Careful management of imports and dependency management Common classes depend on nothing (no IO, utilities only) Domain classes depend only on common classes and each other Services classes depend on domain, adapt to infrastructure Infrastructure classes depend on services and domain Michael Nash Hexagonal Architecture
  • 9. Dependency Inversion Principle: Diagram Michael Nash Hexagonal Architecture
  • 10. Dependency Inversion Principle: Common The Common package contains only shared utility classes No I/O! String utilities Date utilities Random numbers Data structures NOT what we currently call “common” Michael Nash Hexagonal Architecture
  • 11. Dependency Inversion Principle: Domain The Domain package contains only business domain classes and functions Depends ONLY on other domain classes and common classes Can use abstractions like logging (traits only) Contains domain logic – avoid anemic domain! No I/O Can contain DDD services for operations that span aggregates No DTOs No annotations Use types, not primitives wherever possible Michael Nash Hexagonal Architecture
  • 12. Dependency Inversion Principle: Services The Services package contains the service classes used by the ports and adapters to interact with the domain Depends ONLY on domain and common Expose operations needed by the adapters No I/O Could contain Repositories No event handlers (these are infrastructure) No REST routing (again, infrastructure) No DTOs No annotations Michael Nash Hexagonal Architecture
  • 13. Dependency Inversion Principle: Infrastructure The Infrastructure package contains the adapters that connect the services and the domain to the outside world Can depend on any other package as required Contains sub-packages for specific adapters (e.g. http, eventbus, mongo) I/O goes here – all of it Calls services and domain REST routing goes here Implementations of repositories go here DTOs go here Guice module, dependency injection goes here Michael Nash Hexagonal Architecture
  • 14. Hexagonal Architecture: Action Plan How do we get there? What’s the plan? Review Hierarchy (now), make sure we all understand the desired outcome In other modules, create top-level packages domain, common, services and infrastructure Refactor into proper package structure, decoupling as required Decouple from deprecated common modules Refactor spray-service-common and submodules into re-usable infrastructure modules Use Crucible to review and discuss refactors Specific stories to refactor each module Decouple EventBus from our domain (make domain-agnostic) Adopt single-source tree view to facilitate refactorings Michael Nash Hexagonal Architecture
  • 15. Hexagonal Architecture: Single Sourcetree View A single bounded context should be visible as a single logical source tree No more p2build plugin Refactoring greatly simplified No more versions of common Executable artifacts become a deploy-time question: can change as needed Acheivable “virtually” right away with git sub-modules (ListingDistributionContext) Adding new Event types (for example) becomes trivial One git repo (logically, if not physically at first) Decouple EventBus from our domain (make domain-agnostic) Integration tests become trivial (no need to launch multiple jars) Michael Nash Hexagonal Architecture
  • 16. Hexagonal Architecture: Conclusion We want the benefits of hexagonal architecture, hence the refactors Questions? Michael Nash Hexagonal Architecture