SlideShare a Scribd company logo
The Secrets of Hexagonal Architecture
2
Share docs with
other systems
3
Which protocol?
4
5
1 month later…
6
7
Done!
8
1 month later…
9
10
Done!
11
+
12
The secrets of
13
Hexagonal

Architecture
Separate Domain
& Infrastructure
14
Maintainable Software
=
Domain 

vs
Infrastructure
Twitter 

GitHub 

Medium
16
}@nicoespeon
Nicolas Carlo
17
80 countries
18
Seat
Stop
Departure
Roundtrip
Leg
Taxes
Discount code
Fees
Domain is our
business
19
We could do our
business without
software!
20
21
Infrastructure is
how we make it work
22
Infrastructure 

is a detail
23
Put the Domain
at the heart of
the software
24
Problems mixing
Domain & Infra.
Get a poem from a
poetry library, or return
the default one.
26
27
class PoetryReader {
giveMeSomePoetry(): string {
}
}
28
import * as fs from "fs";
import * as path from "path";
class PoetryReader {
giveMeSomePoetry(): string {
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
}
}
29
import * as fs from "fs";
import * as path from "path";
class PoetryReader {
giveMeSomePoetry(): string {
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
if (!poem) {
poem =
"If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return poem;
}
}
30
import * as fs from "fs";
import * as path from "path";
class PoetryReader {
giveMeSomePoetry(): string {
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
if (!poem) {
poem =
"If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return poem;
}
}
31
import * as fs from "fs";
import * as path from "path";
class PoetryReader {
giveMeSomePoetry(): string {
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
if (!poem) {
poem =
"If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return poem;
}
}
Domain
32
import * as fs from "fs";
import * as path from "path";
class PoetryReader {
giveMeSomePoetry(): string {
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
if (!poem) {
poem =
"If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return poem;
}
}
Infrastructure
33
import * as fs from "fs";
import * as path from "path";
class PoetryReader {
giveMeSomePoetry(): string {
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
if (!poem) {
poem =
"If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return poem;
}
}
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
Hard to 

see
the Business
34
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
Hard to 

test
the Business
35
const pathToPoem = path.join(!__dirname, "poem.txt");
let poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
Hard to 

change
the Business
36
37
import FileReader from "lib/file-reader";
class PoetryReader {
giveMeSomePoetry(): string {
let poem = FileReader.read("poem.txt");
if (!poem) {
poem =
"If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return poem;
}
}
import FileReader from "lib/file-reader";
class PoetryReader {
giveMeSomePoetry(): string {
let poem = FileReader.read("poem.txt");
if (!poem) {
poem =
"If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return poem;
}
}
Same 

problem
38
Hexagonal
Architecture
The simplest way to
40
Separate Domain 

& Infrastructure
41
Infra.
Domain
42
Infra.
Domain
dependency
43
Infra.
Domain
dependency
44
Interface
Adapter
use
implement
45
Port
Adapter
46
Port
Adapter
Ports & Adapters architecture
47
Business
language

only
48
Left-side Right-side
49
Left-side Right-side
Adapter
Adapter
50
Left-side Right-side
Adapter
Adapter
Adapter
Adapter
A concrete
example
class PoetryReader {
}
Domain
52
class PoetryReader {
poetryLibrary: ObtainPoems;
constructor(poetryLibrary!?: ObtainPoems) {
this.poetryLibrary = poetryLibrary;
}
}
Domain
53
class PoetryReader {
poetryLibrary: ObtainPoems;
constructor(poetryLibrary!?: ObtainPoems) {
this.poetryLibrary = poetryLibrary;
}
}
Domain
54
Dependency
Injection
class PoetryReader {
poetryLibrary: ObtainPoems;
constructor(poetryLibrary!?: ObtainPoems) {
this.poetryLibrary = poetryLibrary;
}
giveMeSomePoetry(): Poem {
if (!this.poetryLibrary) {
return "If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return this.poetryLibrary.getAPoem();
}
}
Domain
55
class PoetryReader {
poetryLibrary: ObtainPoems;
constructor(poetryLibrary!?: ObtainPoems) {
this.poetryLibrary = poetryLibrary;
}
giveMeSomePoetry(): Poem {
if (!this.poetryLibrary) {
return "If you could read a leaf or treernyou’d have no need of books.
rn!-- © Alistair Cockburn (1987)";
}
return this.poetryLibrary.getAPoem();
}
}
Domain
56
giveMeSomePoetry(): Poem {
if (!this.poetryLibrary) {
return "If you could read a leaf or treernyou’d have
no need of books.rn!-- © Alistair Cockburn (1987)";
}
return this.poetryLibrary.getAPoem();
}
57
giveMeSomePoetry(): string {
let poem = FileReader.read("poem.txt");
if (!poem) {
poem =
"If you could read a leaf or treernyou’d have
no need of books.rn!-- © Alistair Cockburn (1987)";
}
return poem;
}
Implementation
Intention
Domain
type Poem = string;
interface ObtainPoems {
getAPoem(): Poem
}
58
import * as fs from "fs";
import * as path from "path";
import ObtainPoems from "!../domain/obtain-poems";
class ObtainPoemsFromFS implements ObtainPoems {
getAPoem() {
const pathToPoem = path.join(!__dirname, "poem.txt");
const poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
return poem;
}
}
Infra.
59
!// 1. Instantiate the right-side adapter(s)
!// 2. Instantiate the hexagon (domain)
!// 3. Instantiate the left-side adapter(s)
60
import ObtainPoemsFromFS from "./infrastructure/obtain-poems-from-fs";
!// 1. Instantiate the right-side adapter(s)
const poetryLibrary = new ObtainPoemsFromFS();
!// 2. Instantiate the hexagon (domain)
!// 3. Instantiate the left-side adapter(s)
61
import PoetryReader from "./domain/poetry-reader";
import ObtainPoemsFromFS from "./infrastructure/obtain-poems-from-fs";
!// 1. Instantiate the right-side adapter(s)
const poetryLibrary = new ObtainPoemsFromFS();
!// 2. Instantiate the hexagon (domain)
const poetryReader = new PoetryReader(poetryLibrary);
!// 3. Instantiate the left-side adapter(s)
62
import PoetryReader from "./domain/poetry-reader";
import ObtainPoemsFromFS from "./infrastructure/obtain-poems-from-fs";
import ConsoleApi from "./infrastructure/console-api";
!// 1. Instantiate the right-side adapter(s)
const poetryLibrary = new ObtainPoemsFromFS();
!// 2. Instantiate the hexagon (domain)
const poetryReader = new PoetryReader(poetryLibrary);
!// 3. Instantiate the left-side adapter(s)
const consoleApi = new ConsoleApi(poetryReader);
63
import PoetryReader from "./domain/poetry-reader";
import ObtainPoemsFromFS from "./infrastructure/obtain-poems-from-fs";
import ConsoleApi from "./infrastructure/console-api";
!// 1. Instantiate the right-side adapter(s)
const poetryLibrary = new ObtainPoemsFromFS();
!// 2. Instantiate the hexagon (domain)
const poetryReader = new PoetryReader(poetryLibrary);
!// 3. Instantiate the left-side adapter(s)
const consoleApi = new ConsoleApi(poetryReader);
!// App logic is only using left-side adapter(s).
console.log("Here is some poetry:n");
consoleApi.ask();
64
const poetryReader = new PoetryReader();
65
const poetryReader = new PoetryReader(poetryLibrary);
66
Pros and cons
This ain't new
68
"Program to an Interface" − OOP
"Isolate side effects" − FP
The Onion Architecture
Plug different adapters
to the Domain
69
A good architect
defers decisions
70
Start with
something simple
71
But… it's only
the first step!
72
73
More layers
74
Ubiquitous Language 

Bounded Contexts

Domain modelling
Separate Domain
& Infrastructure
75
🙏
Twitter 

GitHub 

Medium
}@nicoespeon
Nicolas Carlo
@swcraftmontreal
Software Crafters Montréal
Every 1st Tuesday of the month.
Bonuses
test("give verses when asked for poetry", () !=> {
const poetryReader = new PoetryReader();
const verses = poetryReader.giveMeSomePoetry();
expect(verses).toEqual(
"If you could read a leaf or treernyou’d have no
need of books.rn!-- © Alistair Cockburn (1987)"
);
});
Tests
test("give verses from a PoetryLibrary", () !=> {
const poetryLibrary: ObtainPoems = {
getAPoem() {
return "I want to sleep…rn!-- Masaoka Shiki (1867-1902)";
}
};
const poetryReader = new PoetryReader(poetryLibrary);
const verses = poetryReader.giveMeSomePoetry();
expect(verses).toEqual(
"I want to sleep…rn!-- Masaoka Shiki (1867-1902)"
);
});
Tests

More Related Content

PPTX
Domain Driven Design(DDD) Presentation
PDF
Hexagonal architecture for java applications
PDF
Hexagonal architecture
PDF
Hexagonal architecture: how, why and when
PDF
Hexagonal architecture - message-oriented software design
PDF
Domain Driven Design and Hexagonal Architecture
PPTX
Hexagonal Architecture
PPTX
Hexagonal architecture with Spring Boot
Domain Driven Design(DDD) Presentation
Hexagonal architecture for java applications
Hexagonal architecture
Hexagonal architecture: how, why and when
Hexagonal architecture - message-oriented software design
Domain Driven Design and Hexagonal Architecture
Hexagonal Architecture
Hexagonal architecture with Spring Boot

What's hot (20)

PPTX
Domain Driven Design: Zero to Hero
PDF
Hexagonal Architecture.pdf
PPTX
Domain Driven Design 101
PDF
Clean Architecture
PDF
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
PDF
Domain Driven Design (Ultra) Distilled
PPT
Domain Driven Design (DDD)
PPTX
Introducing Domain Driven Design - codemash
PDF
Real Life Clean Architecture
PDF
Clean Architecture
PPTX
Domain-Driven Design
PDF
Introducing Clean Architecture
PDF
Clean Architecture Essentials - Stockholm Software Craftsmanship
PDF
Clean Architecture
PDF
Domain Driven Design
PPTX
Domain Driven Design Quickly
PDF
Domain Driven Design
PPTX
Domain Driven Design Introduction
PDF
Clean architecture
PPTX
The Clean Architecture
Domain Driven Design: Zero to Hero
Hexagonal Architecture.pdf
Domain Driven Design 101
Clean Architecture
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
Domain Driven Design (Ultra) Distilled
Domain Driven Design (DDD)
Introducing Domain Driven Design - codemash
Real Life Clean Architecture
Clean Architecture
Domain-Driven Design
Introducing Clean Architecture
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture
Domain Driven Design
Domain Driven Design Quickly
Domain Driven Design
Domain Driven Design Introduction
Clean architecture
The Clean Architecture
Ad

Similar to The Secrets of Hexagonal Architecture (20)

KEY
JavaScript Growing Up
PDF
Streams API (Web Engines Hackfest 2015)
KEY
Exciting JavaScript - Part I
PPTX
ES6 is Nigh
ODP
Node js lecture
PDF
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
PDF
It's the end of design patterns as we know it (and i feel fine)
PDF
FITC '14 Toronto - Technology, a means to an end
PDF
Technology: A Means to an End with Thibault Imbert
PDF
ECMAScript 6 new features
PDF
Node intro
PPTX
Mining Code Examples with Descriptive Text from Software Artifacts
PDF
JavaScript Design Patterns
PDF
Construction Techniques For Domain Specific Languages
PDF
PDF
EcmaScript 6 - The future is here
PDF
Orthogonality: A Strategy for Reusable Code
PDF
Everything is composable
PPTX
Fact, Fiction, and FP
PDF
Think Async: Asynchronous Patterns in NodeJS
JavaScript Growing Up
Streams API (Web Engines Hackfest 2015)
Exciting JavaScript - Part I
ES6 is Nigh
Node js lecture
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
It's the end of design patterns as we know it (and i feel fine)
FITC '14 Toronto - Technology, a means to an end
Technology: A Means to an End with Thibault Imbert
ECMAScript 6 new features
Node intro
Mining Code Examples with Descriptive Text from Software Artifacts
JavaScript Design Patterns
Construction Techniques For Domain Specific Languages
EcmaScript 6 - The future is here
Orthogonality: A Strategy for Reusable Code
Everything is composable
Fact, Fiction, and FP
Think Async: Asynchronous Patterns in NodeJS
Ad

More from Nicolas Carlo (11)

PDF
Hexagonal architecture & Elixir
PDF
À la découverte des Observables - HumanTalks Paris 2017
PDF
À la découverte des observables
PDF
Testing Marionette.js Behaviors
PDF
Chaining and function composition with lodash / underscore
PDF
Les générateurs de code, pour se simplifier la vie au quotidien
PDF
Kanban et Game Development avec Trello
PDF
Plop : un micro-générateur pour se simplifier la vie au quotidien
PDF
Tester ses Behaviors Marionette.js
PDF
Chaining et composition de fonctions avec lodash / underscore
PDF
Comment organiser un gros projet backbone
Hexagonal architecture & Elixir
À la découverte des Observables - HumanTalks Paris 2017
À la découverte des observables
Testing Marionette.js Behaviors
Chaining and function composition with lodash / underscore
Les générateurs de code, pour se simplifier la vie au quotidien
Kanban et Game Development avec Trello
Plop : un micro-générateur pour se simplifier la vie au quotidien
Tester ses Behaviors Marionette.js
Chaining et composition de fonctions avec lodash / underscore
Comment organiser un gros projet backbone

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Cloud computing and distributed systems.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
A Presentation on Artificial Intelligence
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
Empathic Computing: Creating Shared Understanding
Network Security Unit 5.pdf for BCA BBA.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Cloud computing and distributed systems.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 3 Spatial Domain Image Processing.pdf
NewMind AI Monthly Chronicles - July 2025
The AUB Centre for AI in Media Proposal.docx
A Presentation on Artificial Intelligence
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

The Secrets of Hexagonal Architecture