SlideShare a Scribd company logo
HEXAGONAL ARCHITECTURE
Message oriented software design
By Matthias Noback
ARCHITECTURE
What's the problem?
Nice app
Sad app
Your brain can't handle it
M V C ?
Coupling to frameworks
and libraries
How do you start a new
project?
Pick a framework

Install a skeleton project

Remove demo stuff

Auto-generate entities

Auto-generate CRUD controllers

Done
"It's a Symfony project!"
That's actually outside in
The boring stuff
The interesting stuff
Symfony
Doctrine
RabbitMQ
Redis
Angular
Slow tests
DB
Browser
Message
queue
Key-
value
Filesystem
Why do frameworks not solve this for us?
Because they can't ;)
Frameworks are about
encapsulation
Low-level API
$requestContent = file_get_contents('php://input');
$contentType = $_SERVER['CONTENT_TYPE'];
if ($contentType === 'application/json') {
$data = json_decode($requestContent, true);
} elseif ($contentType === 'application/xml') {
$xml = simplexml_load_string($requestContent);
...
}
Nicely hides the details
$data = $serializer->deserialize(
$request->getContent(),
$request->getContentType()
);
Low-level API
$stmt = $db->prepare(
'SELECT * FROM Patient p WHERE p.anonymous = ?'
);
$stmt->bindValue(1, true);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$patient = Patient::reconstituteFromArray($result);
Hides a lot of details
$patient = $repository->createQueryBuilder('p')
->where('p.anonymous = true')
->getQuery()
->getResult();
What about abstraction?
$patient = $repository->createQueryBuilder('p')
->where('p.anonymous = true')
->getQuery()
->getResult();
Concrete
Concrete
Concrete
$patients = $repository->anonymousPatients();
Abstract
Nice
DIY
Coupling to the delivery
mechanism
public function registerPatientAction(Request $request)
{
$patient = new Patient();
$form = $this->createForm(new RegisterPatientForm(), $patient);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($patient);
$em->flush();
return $this->redirect($this->generateUrl('patient_list'));
}
return array(
'form' => $form->createView()
);
}
Request and Form are web-specific
EntityManager is ORM, i.e.
relational DB-specific
Reusability: impossible
Some
functionality
The web
The CLI
Some
functionalityRun
it
Lack of intention-revealing code
data
data
data
public function updateAction(Request $request)
{
$patient = new Patient();
$form = $this->createForm(new PatientType(), $patient);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($patient);
$em->flush();
return $this->redirect($this->generateUrl('patient_list'));
}
return array(
'form' => $form->createView()
);
}
from the HTTP request
copied into an entity
then stored in the database
What exactly
changed?!
And... why?
R.A.D.
Rapid Application Development
B.A.D.
B.A.D. Application Development
In summary
Coupling to a framework

Coupling to a delivery mechanism (e.g. the web)

Slow tests

Lack of intention in the code
THE ESSENCE
of your application
The essence
Other things
The "heart"?
"The heart of software is its ability to solve
domain-related problems for its users.
–Eric Evans, Domain Driven Design
All other features, vital though they may be,
support this basic purpose."
What's essential?
Domain model
Interaction with it
Use cases
What's not essential?
“The database is an implementation detail”
–Cool software architect
The core doesn't need to
know about it
What about interaction?
The core doesn't need to
know about it
Infrastructure
The world outside
Web browser
Terminal
Database
Messaging
Filesystem
(E)mail
Mmm... layers Layers
allow you to
separate
Layers
allow you to
allocate
Layers
have
boundaries
Rules
for crossing
Rules about
communication
Actually: rules about dependencies
The dependency rule
–Robert Martin, Screaming Architecture
What crosses layer
boundaries?
Message
Messages
someFunctionCall(
$arguments,
$prepared,
$for,
$the,
$receiver
);
$message = new TypeOfMessage(
$some,
$relevant,
$arguments
);
handle($message);
What about the application
boundary?
The app
Message
The world outside
How does an app allow
incoming messages at all?
By exposing input ports
Routes
Console commands
A WSDL file for a SOAP API
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Ports use protocols for
communication
Each port has a language of its own
Web (HTTP)
Messaging (AMQP)
HTTP
Request
Form
Request
Controller
Entity
Value object
W
eb
port
Translate
the
request
Repository
Adapters
The translators are called: adapters
"Ports and adapters"
Ports: allow for communication to happen

Adapters: translate messages from the world outside
== Hexagonal architecture
Alistair Cockburn
An example
Plain HTTP
message
$_POST,
$_GET,
$_SERVER,
Request
POST /patients/ HTTP/1.1
Host: hospital.com
name=Matthias&email=matthiasn
oback@gmail.com
Command
$command = new RegisterPatient(
$request->get('name'),
$request->get('email')
);
Command
$command = new RegisterPatient(
$request->get('name'),
$request->get('email')
);
Expresses
intention
Implies
change
Independent
of delivery
mechanism
Only the
message
class RegisterPatientHandler
{
public function handle(RegisterPatient $command)
{
$patient = Patient::register(
$command->name(),
$command->email()
);
$this->patientRepository->add($patient);
}
}
Command
Command
handler
Command
Command
handler A
Command
bus
Command
handler B
Command
handler C
HTTP
Request
Form
Request
Controller
Patient
(entity)
W
eb
port
PatientRepository
RegisterPatient-
Handler
RegisterPatient
(command)
Infrastructure
Application
Dom
ain
Change
New entity
(Patient)
Entity-
Manager
UnitOf-
Work
$patient = Patient::register(
$command->name(),
$command->email()
);
$this->patientRepository
->add($patient);
Insert
query (SQL)
INSERT INTO patients SET
name='Matthias',
email='matthiasnoback@gmai
l.com';
SQL query
EntityManager
UnitOfWork
QueryBuilder
Persistence
port
Prepare
for
persistence
PatientRepository
C
ore
Infrastructure
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Messaging (AMQP)
Persistence
(MySQL)
What often goes wrong:
we violate boundary rules...
EntityManager
UnitOfWork
QueryBuilder
PatientRepository
C
ore
Infrastructure
RegisterPatient-
Handler
Domain
Infrastructure
Application
Domain
PatientRepository
(uses MySQL)
EntityManager
UnitOfWork
QueryBuilder
PatientRepository
(uses MySQL)
Domain
Infrastructure
Application
Domain
RegisterPatient-
Handler
Domain
PatientRepository
(interface)
Dependency
inversion
PatientRepository
(uses MySQL)
RegisterPatient-
Handler
Domain
InMemory-
PatientRepository
Speedy
alternative
RegisterPatient-
Handler
PatientRepository
(uses MySQL)
PatientRepository
(interface)
"A good software architecture allows decisions [...]
to be deferred and delayed."
–Robert Martin, Screaming Architecture
IN CONCLUSION
what did we get from all of this?
Separation of concerns
Core
Infrastructure
Command
Command
Command
handler
Command
handler
Stand-alone use cases
Command
Command
handler
Intention-
revealing
Reusable
Infrastructure stand-ins
Regular
implementation
Interface
Stand-in, fast
implementation
This is all very much
supportive of...
See also: Modelling by Example
DDD
TDD
BDD
CQRS
QUESTIONS?
joind.in/talk/32a42
FEEDBACK?

More Related Content

PDF
All the cool kids....
PDF
Hexagonal Architecture - message-oriented software design (PHPCon Poland 2015)
PDF
Hexagonal
PDF
Hexagonal architecture - message-oriented software design (Symfony Live Berli...
PDF
Hexagonal architecture message-oriented software design
PDF
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
PDF
Hexagonal symfony
PDF
Hexagonal architecture - message-oriented software design
All the cool kids....
Hexagonal Architecture - message-oriented software design (PHPCon Poland 2015)
Hexagonal
Hexagonal architecture - message-oriented software design (Symfony Live Berli...
Hexagonal architecture message-oriented software design
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
Hexagonal symfony
Hexagonal architecture - message-oriented software design

What's hot (20)

PDF
The Quest for Global Design Principles
PDF
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
PDF
Arquitectura hexagonal
PDF
The quest for global design principles - PHP Benelux 2016
PDF
Hexagonal architecture in PHP
PDF
Clean architecture with ddd layering in php
PDF
Hexagonal architecture for the web
PDF
Actor model in F# and Akka.NET
PDF
Distributed Computing
PDF
Elements of DDD with ASP.NET MVC & Entity Framework Code First
PDF
Application architecture
PDF
F# and SignalR for a FastWeb
PPTX
.NET Architecture for Enterprises
PDF
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
PPTX
Implementing DDD with C#
PPTX
How to Implement Domain Driven Design in Real Life SDLC
PDF
Add Some DDD to Your ASP.NET MVC, OK?
PPT
Web UI migration
PPTX
Software Define Network, a new security paradigm ?
PDF
Domain-Driven Design (Artur Trosin Product Stream)
The Quest for Global Design Principles
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Arquitectura hexagonal
The quest for global design principles - PHP Benelux 2016
Hexagonal architecture in PHP
Clean architecture with ddd layering in php
Hexagonal architecture for the web
Actor model in F# and Akka.NET
Distributed Computing
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Application architecture
F# and SignalR for a FastWeb
.NET Architecture for Enterprises
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Implementing DDD with C#
How to Implement Domain Driven Design in Real Life SDLC
Add Some DDD to Your ASP.NET MVC, OK?
Web UI migration
Software Define Network, a new security paradigm ?
Domain-Driven Design (Artur Trosin Product Stream)
Ad

Similar to Hexagonal architecture - message-oriented software design (PHP Benelux 2016) (20)

PPTX
How to double .net code value
PPS
dot NET Framework
PPTX
Framework engineering JCO 2011
PDF
Bn1001 demo ppt advance dot net
PPT
Web Development Environments: Choose the best or go with the rest
PPT
Intro dotnet
PPT
Intro dotnet
PPT
Intro dotnet
PPT
Intro dotnet
PPT
Visual studio.net
PDF
Dot Net Fundamentals
PPTX
Unit - 1: ASP.NET Basic
PPT
PowerPoint
PDF
tybsc it asp.net full unit 1,2,3,4,5,6 notes
PPT
Dev381.Pp
PDF
Beginning MEAN Stack
PPT
Node js
PPT
Visual studio.net
PPT
Visual Studio.NET
PPTX
Getting started with dotnet core Web APIs
How to double .net code value
dot NET Framework
Framework engineering JCO 2011
Bn1001 demo ppt advance dot net
Web Development Environments: Choose the best or go with the rest
Intro dotnet
Intro dotnet
Intro dotnet
Intro dotnet
Visual studio.net
Dot Net Fundamentals
Unit - 1: ASP.NET Basic
PowerPoint
tybsc it asp.net full unit 1,2,3,4,5,6 notes
Dev381.Pp
Beginning MEAN Stack
Node js
Visual studio.net
Visual Studio.NET
Getting started with dotnet core Web APIs
Ad

More from Matthias Noback (20)

PDF
Rector fireside chat - PHPMiNDS meetup
PDF
Service abstractions - Part 1: Queries
PDF
Hexagonal Symfony - SymfonyCon Amsterdam 2019
PDF
Advanced web application architecture - PHP Barcelona
PDF
A testing strategy for hexagonal applications
PDF
Advanced web application architecture - Talk
PDF
DPC 2019, Amsterdam: Beyond design patterns and principles - writing good OO ...
PDF
Layers, ports and adapters
PDF
Beyond design principles and patterns (muCon 2019 edition)
PDF
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
PDF
Advanced web application architecture Way2Web
PDF
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
PDF
Beyond Design Principles and Patterns
PDF
Building Autonomous Services
PDF
Advanced Application Architecture Symfony Live Berlin 2018
PDF
Designing for Autonomy
PDF
Docker workshop
PDF
Docker swarm workshop
PDF
Docker compose workshop
PDF
Building autonomous services
Rector fireside chat - PHPMiNDS meetup
Service abstractions - Part 1: Queries
Hexagonal Symfony - SymfonyCon Amsterdam 2019
Advanced web application architecture - PHP Barcelona
A testing strategy for hexagonal applications
Advanced web application architecture - Talk
DPC 2019, Amsterdam: Beyond design patterns and principles - writing good OO ...
Layers, ports and adapters
Beyond design principles and patterns (muCon 2019 edition)
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Advanced web application architecture Way2Web
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Beyond Design Principles and Patterns
Building Autonomous Services
Advanced Application Architecture Symfony Live Berlin 2018
Designing for Autonomy
Docker workshop
Docker swarm workshop
Docker compose workshop
Building autonomous services

Recently uploaded (20)

PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
ai tools demonstartion for schools and inter college
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
System and Network Administration Chapter 2
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Digital Strategies for Manufacturing Companies
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
AI in Product Development-omnex systems
Odoo Companies in India – Driving Business Transformation.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
ai tools demonstartion for schools and inter college
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
System and Network Administration Chapter 2
VVF-Customer-Presentation2025-Ver1.9.pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How to Choose the Right IT Partner for Your Business in Malaysia
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
CHAPTER 2 - PM Management and IT Context
Digital Strategies for Manufacturing Companies
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Essential Infomation Tech presentation.pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
wealthsignaloriginal-com-DS-text-... (1).pdf
Wondershare Filmora 15 Crack With Activation Key [2025
AI in Product Development-omnex systems

Hexagonal architecture - message-oriented software design (PHP Benelux 2016)