SlideShare a Scribd company logo
Principles & Advantages
of Hexagonal Architecture
on Magento
June 10/11 2021  Virtual Conference
Alessandro Ronchi
COO  Bitbull
Principles & Advantages of Hexagonal Architecture on Magento
Testing is hard
it is even harder on Magento
Principles & Advantages of Hexagonal Architecture on Magento
There must be a way
to simplify testing
Principles & Advantages of Hexagonal Architecture on Magento
to the rescue
Hexagonal architecture
Principles & Advantages of Hexagonal Architecture on Magento
Decoupling
Focus on the domain
Focus on testability
Advantages
Principles & Advantages of Hexagonal Architecture on Magento
Team mentor at Bitbull
Passionate about Software Design
Magento Master & Maintainer
About me
@aleron75
Principles & Advantages of Hexagonal Architecture on Magento
a different way of layering components
Hexagonal architecture
Principles & Advantages of Hexagonal Architecture on Magento
Decoupling
Core vs Infrastructure
CORE
CODE
DOES NOT DEPEND ON
EXTERNAL SYSTEMS
INFRASTRUCTURE
CODE
DEPENDS ON
EXTERNAL SYSTEMS
INFRASTRUCTURE
CORE
R/W
MODEL
WEB
CONTROLLER
USES
R/W
CORE
CODE
DEFINES & DEPENDS ON
ABSTRACTIONS
INFRASTRUCTURE
CODE
IMPLEMENTS
ABSTRACTIONS
CORE
CODE
DEFINES & DEPENDS ON
ABSTRACTIONS
INFRASTRUCTURE
CODE
IMPLEMENTS
ABSTRACTIONS
MYSQL REPOSITORY
<REPOSITORY>
IMPLEMENTED BY
CORE
CODE
DOES NOT DEPEND ON
CONTEXT
INFRASTRUCTURE
CODE
DEPENDS ON
CONTEXT
WEB CONTROLLER
SERVICE
USED BY
CORE
CODE
DOES NOT DEPEND ON
CONTEXT
INFRASTRUCTURE
CODE
DEPENDS ON
CONTEXT
CLI COMMAND
SERVICE
USED BY
INFRASTRUCTURE
CORE
SERVICE
MYSQL
REPOSITORY
<REPOSITORY>
WEB
CONTROLLER
USES
IMPLEMENTED BY
USES
USES
R/W
CLI
COMMAND
USES
Meet Magento IT 2021 - Principles & Advantages of Hexagonal Architecture on Magento
APPLICATION
CARD REPOSITORY
CARD
CONTROLLER
USES
USES
R/W
class Save extends Action implements HttpPostActionInterface
{
// ...
public function execute()
{
$redirectResult =
$this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$cardNumber = $this->getRequest()->getParam('card_number');
$customerId = (int)$this->currentCustomer->getCustomerId();
// validation and error handling...
$card = $this->cardFactory->create();
$card->setData([
‘card_number’ => $cardNumber,
‘customer_id’ => $customerId,
]);
$this->cardRepository->save($card);
return $redirectResult->setPath('loyalty/card/index');
}
}
class Save extends Action implements HttpPostActionInterface
{
// ...
public function execute()
{
$redirectResult =
$this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$cardNumber = $this->getRequest()->getParam('card_number');
$customerId = (int)$this->currentCustomer->getCustomerId();
// validation and error handling...
$command = new RegisterCardCommand($customerId, $cardNumber);
$this->application->registerCard($command);
return $redirectResult->setPath('loyalty/card/index');
}
}
class Save extends Action implements HttpPostActionInterface
{
// ...
public function execute() {
// ...
$this->application->registerCard($command); // framework-agnostic
// ...
}
}
class Save extends Action implements HttpPostActionInterface
{
// ...
public function execute() {
// ...
$this->cardRepository->save($card); // framework-coupled
// ...
}
}
vs
CORE
CODE
- FRAMEWORK: AGNOSTIC
- CHANGES: MANAGED
INFRASTRUCTURE
CODE
- FRAMEWORK: BASED ON IT
- CHANGES: UNPREDICTABLE
Principles & Advantages of Hexagonal Architecture on Magento
a better name: Ports & Adapters
Hexagonal architecture
PORT
- WHAT OUR CORE CAN DO
- INTENT OF COMMUNICATION
ADAPTER
...
INFRASTRUCTURE
CORE
SERVICE
MYSQL
REPOSITORY
<REPOSITORY>
WEB
CONTROLLER
USES
IMPLEMENTED BY
USES
USES
R/W
INFRASTRUCTURE
CORE
PORT
MYSQL
REPOSITORY
<PORT>
WEB
CONTROLLER
USES
IMPLEMENTED BY
USES
USES
R/W
PORT
- INCOMING COMMUNICATION
- OUTGOING COMMUNICATION
ADAPTER
...
INFRASTRUCTURE
CORE
INCOMING PORT
MYSQL
REPOSITORY
<OUTGOING PORT>
WEB
CONTROLLER
USES
IMPLEMENTED BY
USES
USES
R/W
PORT
...
ADAPTER
- USES INCOMING PORTS
- IMPLEMENTS OUTGOING PORTS
INFRASTRUCTURE
CORE
INCOMING PORT
MYSQL
REPOSITORY
<OUTGOING PORT>
WEB
CONTROLLER
USES
IMPLEMENTED BY
USES
USES
R/W
INFRASTRUCTURE
CORE
INCOMING PORT
OUTGOING
ADAPTER
<OUTGOING PORT>
INCOMING
ADAPTER
USES
IMPLEMENTED BY
USES
USES
R/W
Principles & Advantages of Hexagonal Architecture on Magento
Focus on the domain
the CORE of our application
INFRASTRUCTURE
CORE
Meet Magento IT 2021 - Principles & Advantages of Hexagonal Architecture on Magento
Meet Magento IT 2021 - Principles & Advantages of Hexagonal Architecture on Magento
YOU NAME IT
Principles & Advantages of Hexagonal Architecture on Magento
Focus on testability
with framework-agnostic tests
Meet Magento IT 2021 - Principles & Advantages of Hexagonal Architecture on Magento
USE-CASE TESTS
UNIT TESTS
USE-CASE TESTS
UNIT TESTS
Registration
✔ The customer can register an unregistered card
✔ The customer can’t register already registered card
✔ The customer can’t register more than one card
✔ The customer can delete a registered card
OK (4 tests)
USE-CASE TESTS
UNIT TESTS
IN-MEMORY
REPOSITORY
FAKE OBJECT USED
JUST FOR TESTING
USE-CASE TESTS
UNIT TESTS
Card Number
✔ It accepts ten digits
✔ It accepts all zeroes
✔ It doesn’t accept an empty string
✔ It doesn’t accept less than ten digits
✔ It doesn’t accept more than ten digits
✔ It doesn’t accept invalid chars
OK (6 tests)
USE-CASE TESTS
UNIT TESTS
NO EXTERNAL
DEPENDENCIES
NO NEED TO USE
MOCK OBJECTS
Principles & Advantages of Hexagonal Architecture on Magento
Test Infrastructure
with integration adapter tests
USE-CASE TESTS
UNIT TESTS
USE-CASE TESTS
UNIT TESTS
MYSQL
REPOSITORY
WEB
CONTROLLER
ADAPTER TESTS
ADAPTER TESTS
Card Controller
✔ It calls Application service getCardByCustomer()
✔ It calls Application service registerCard()
✔ It calls Application service deleteCardByCustomer()
OK (3 tests)
INCOMING TESTS
OUTGOING TESTS
INCOMING TESTS
OUTGOING TESTS
JUST VERIFY THAT AN INCOMING
ADAPTER CALLS THE PROPER SERVICE
CORE
USE APPLICATION
MOCK
Card Repository
✔ It can save a card and load it by its number
✔ It can save a card and load it by its customer
✔ It can delete a card by its customer
OK (3 tests)
INCOMING TESTS
OUTGOING TESTS
INCOMING TESTS
OUTGOING TESTS
JUST VERIFY THAT AN OUTGOING
ADAPTER PROPERLY HANDLES I/O
Principles & Advantages of Hexagonal Architecture on Magento
Increase confidence
with functional end-to-end tests
END-TO-END TESTS
UNIT TESTS
ADAPTER TESTS
E2E TESTS
USE-CASE TESTS
MFTF
Codeception
cypress.io
DOMAIN
LOGIC
I/O
APPLICATION
ddd/
└─ loyalty/
├─ src/
│ ├─ Application/
│ ├─ Controller/
│ ├─ Domain/
│ ├─ etc/
│ ├─ Model/
│ ├─ view/
│ └─ ViewModel/
├─ test/
│ ├─ Adapter/
│ ├─ Unit/
│ └─ UseCase/
├─ composer.json
└─ registration.php
CORE
Principles & Advantages of Hexagonal Architecture on Magento
Complex logic
Long-lasting code
Multi-platform code
When it is worth
Principles & Advantages of Hexagonal Architecture on Magento
Core hacks or fixes
Short-term code
Platform-specific code
When it is not worth
Principles & Advantages of Hexagonal Architecture on Magento
Split Core/Infrastructure
Use own abstractions
Apply a Testing Strategy
Takeaways
Principles & Advantages of Hexagonal Architecture on Magento
http://bit.ly/ddd-loyalty
The project
Principles & Advantages of Hexagonal Architecture on Magento
Inspired by
Principles & Advantages of Hexagonal Architecture on Magento
With a special discount
https://bit.ly/mn-awaa
The book
Principles & Advantages of Hexagonal Architecture on Magento
Thank you!
Questions: @aleron75
June 10/11 2021  Virtual Conference

More Related Content

PDF
Software Composition Analysis in PHP
PDF
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
PDF
What Can Reverse Engineering Do For You?
PDF
Software, Over the Air (SOTA) for Automotive Grade Linux (AGL)
PDF
Latency tracing in distributed Java applications
PDF
GBDC 勉強会 #6 Java イベントレポート 2016
PPTX
Do's and Do not's about p2
PPT
Managing Change
Software Composition Analysis in PHP
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
What Can Reverse Engineering Do For You?
Software, Over the Air (SOTA) for Automotive Grade Linux (AGL)
Latency tracing in distributed Java applications
GBDC 勉強会 #6 Java イベントレポート 2016
Do's and Do not's about p2
Managing Change

What's hot (20)

PPTX
Node.js wrapper for mbed Device Connector REST calls
PDF
Identifying Hotspots in the PostgreSQL Build Process
PDF
Who Needs Thumbs? Reverse Engineering Scramble with Friends v1.1
PDF
Hacking ios-on-the-run-using-cycript-viaforensics-rsa-conference-2014
PDF
Criando aplicações RestFul com Zend Framework 2
PDF
Docker In the Bank
PDF
Lecture1: NGS Analysis on Beocat and an introduction to Perl programming for ...
PDF
Devoxx17 - Préparez-vous à la modularité selon Java 9
PDF
10thMeetup-20190420-REST API Design Principles 되새기기
PDF
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
PDF
Service Discovery. Spring Cloud Internals
PPTX
Essential Tools for Modern PHP
PDF
Identifying Hotspots in Software Build Processes
PDF
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
PDF
Create a PHP Library the right way
PDF
invokedynamic for Mere Mortals [Code One 2019]
PDF
Dessi docker kubernetes paas cloud
PPT
Introdot Netc Sharp En
Node.js wrapper for mbed Device Connector REST calls
Identifying Hotspots in the PostgreSQL Build Process
Who Needs Thumbs? Reverse Engineering Scramble with Friends v1.1
Hacking ios-on-the-run-using-cycript-viaforensics-rsa-conference-2014
Criando aplicações RestFul com Zend Framework 2
Docker In the Bank
Lecture1: NGS Analysis on Beocat and an introduction to Perl programming for ...
Devoxx17 - Préparez-vous à la modularité selon Java 9
10thMeetup-20190420-REST API Design Principles 되새기기
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
Service Discovery. Spring Cloud Internals
Essential Tools for Modern PHP
Identifying Hotspots in Software Build Processes
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Create a PHP Library the right way
invokedynamic for Mere Mortals [Code One 2019]
Dessi docker kubernetes paas cloud
Introdot Netc Sharp En
Ad

Similar to Meet Magento IT 2021 - Principles & Advantages of Hexagonal Architecture on Magento (20)

PDF
Hexagonal architecture
PDF
Fighting legacy with hexagonal architecture and frameworkless php
PPTX
Hexagonal_Architecture_DDD_Presentation.pptx
PPTX
Construcción de web aps- un enfoque hexagonal
PDF
Hexagonal architecture for the web
PDF
Hexagonal Symfony - SymfonyCon Amsterdam 2019
PDF
Introduction to hexagonal architecture
PDF
Hexagonal architecture
PDF
Advanced web application architecture Way2Web
PPTX
Hexagonal architecture with Spring Boot
PDF
Advanced web application architecture - PHP Barcelona
PPTX
Hexagonal architecture with Spring Boot [EPAM Java online conference]
PDF
Hexagonal architecture: how, why and when
PDF
Hexagonal Architecture.pdf
PPTX
Micro services Architecture
PPTX
Something Architecture
PDF
Hexagonal Architecture using Grails
PDF
ddd.pdf
PDF
Hexagonal architecture in PHP
PPTX
Microservices Architecture & Testing Strategies
Hexagonal architecture
Fighting legacy with hexagonal architecture and frameworkless php
Hexagonal_Architecture_DDD_Presentation.pptx
Construcción de web aps- un enfoque hexagonal
Hexagonal architecture for the web
Hexagonal Symfony - SymfonyCon Amsterdam 2019
Introduction to hexagonal architecture
Hexagonal architecture
Advanced web application architecture Way2Web
Hexagonal architecture with Spring Boot
Advanced web application architecture - PHP Barcelona
Hexagonal architecture with Spring Boot [EPAM Java online conference]
Hexagonal architecture: how, why and when
Hexagonal Architecture.pdf
Micro services Architecture
Something Architecture
Hexagonal Architecture using Grails
ddd.pdf
Hexagonal architecture in PHP
Microservices Architecture & Testing Strategies
Ad

More from Alessandro Ronchi (15)

PDF
Mage-OS - signals from the community - Magentiamo Day 2024
PDF
Mage-OS Fork it, Own it, Grow it, Better!
PDF
Awesome architectures in Magento 2.3
PDF
Some lessons learned contributing to #MagentoMSI
PDF
The lessons I learned contributing to #MagentoMSI
PDF
How I ended up contributing to Magento core
PDF
How I ended up touching Magento core
PDF
B2B & Magento: a long journey tale
PDF
Need to estimate? Let's play poker!
PDF
Why I did one step backward to go forward
PDF
A true story about Magento best practices
PDF
Magento best practices
PDF
Mageday::2014 - Workshop
PDF
Mageday::2014
PDF
Mageploy presentato al Mage::day() 2013
Mage-OS - signals from the community - Magentiamo Day 2024
Mage-OS Fork it, Own it, Grow it, Better!
Awesome architectures in Magento 2.3
Some lessons learned contributing to #MagentoMSI
The lessons I learned contributing to #MagentoMSI
How I ended up contributing to Magento core
How I ended up touching Magento core
B2B & Magento: a long journey tale
Need to estimate? Let's play poker!
Why I did one step backward to go forward
A true story about Magento best practices
Magento best practices
Mageday::2014 - Workshop
Mageday::2014
Mageploy presentato al Mage::day() 2013

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Approach and Philosophy of On baking technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
cuic standard and advanced reporting.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
sap open course for s4hana steps from ECC to s4
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding
MIND Revenue Release Quarter 2 2025 Press Release
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Approach and Philosophy of On baking technology
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
cuic standard and advanced reporting.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Meet Magento IT 2021 - Principles & Advantages of Hexagonal Architecture on Magento