Professional Documents
Culture Documents
Ports / Adaptors
Layers / Boundary
Example
Q&A - 10 min
Why Hexagonal Architecture?
Your Nice Little Application
Your Big Sad Application
Model - View - Controller
M V C
How do you start a new project?
● Pick your favorite framework
● Generate Entities
● Done
Framework coupling and lack of intention...
Request and Form objects are web specific
public function newAction(Request $request)
{
$client = new Client();
$form = $this->createForm(new RegisterClientForm, $client);
$form->handleRequest($request);
return $this->redirectToRoute('task_success');
}
B.A.D
application development
Maintainability Unmaintainable
application
test or batch scripts, and to be developed and tested in isolation from its
The inside
Use Cases
What’s not that important...
The outside
Ports
Domain
Infrastructure model
Browser
Infrastructure
Application
Domain model
Core Domain
Terminal Database
E-mail
rt
HTTP Request
b po
We Forms
Controller
e st
Request qu
e re Entity
Adaptors th
te
sla
r an Value Object
T
Validator
Repository
Layers
Message
Message Message
Messages
handle($message);
Application boundaries?
ge
Me
ssa
ssa
Me
ge
sa ge
es M
Ports and adapters
Feedback
≈ Hexagonal Architecture
by Alistair Cockburn
Product
Client
RCA
In summary: ports and adaptors
$_POST
$_GET
HTTP Message
$_SERVER
message (command)
Request (from
symfony)
Message
(command)
class RegisterClientHandler() {
}
}
Use a bus for commands
Vote
Feedback
Handler
RegisterClient Leave
Command Bus Feedback
Command
Handler
Laravel: built in
rt
HTTP Request b po
We Forms
Client Entity
uc
str
ion
ra
ain
at
Inf
lic
m
Client Repository
p
Do
Ap
re
Co
Entity
New Entity
Manager SQL INSERT
(Client)
Unit of Work
UnitOfWork
Core Domain
Entity
Manager t
por
Application nc
e
Query st e
r si
Builder
Pe
Persistence
Who noticed the mistake?
UnitOfWork
Core Domain
Entity
Manager
rt
Application po
Query nce
Builder si ste
r
Pe SQL query
Infrastructure
Entity
Manager
Core Domain
Register Client SQL query
ClientRepository
Handler
Application
Infrastructure
Client Repository Entity
Interface Manager
D
e
In pen
ve d
rs en
io cy
n
Core Domain
Register Client SQL query
ClientRepository
Handler
Application InMemoryRepository
Speedy
alternative
Infrastructure
Hexagonal architecture is also supportive of ...
DDD
Event Sourcing
BDD
TDD
CQRS
Conclusions
● Separation of concerns
● When and where you should use Hexagonal Architecture depends on the project
Thank you!
Leonard Mocanu Iulian Popa
@leonardmocanu2 @iulyanpopa
leonard.mocanu@emag.ro iulian.popa@emag.ro