SlideShare a Scribd company logo
Hexagonal
Architecture 

in Elixir
Buzzwords
🐝
Hexagonal
Architecture
Domain-Driven Design
Clean Architecture
Ports & Adapters
Lots of
Buzzwords
This is not about them…
Separate Domain
& Infrastructure
= maintainable software
@nicoespeon
Domain 

vs
Infrastructure
Domain
Business Logic
Infra.
Technical Details
Software is 

a mean 

to a 

Business end
Infrastructure is
a detail
Business 

doesn't care!
Infrastructure can change
shouldn't
Can your PM 

🌟 understand 🌟 

the source code?
Problems mixing
Domain & Infra.
def prs_open_time_until_today() do
today = Date.utc_today() !|> Date.to_iso8601()
{200, prs, _} =
Tentacat.Client.new(%{access_token: @access_token})
!|> Tentacat.Pulls.list("nicoespeon", "my-repo")
prs
!|> Enum.map(fn pr !-> pr["created_at"] end)
!|> Enum.flat_map(fn created_at !->
case DaysDiff.between(today, created_at) do
{:ok, open_time} !-> [open_time]
{:error, _} !-> []
end
end)
end
def prs_open_time_until_today() do
today = Date.utc_today() !|> Date.to_iso8601()
{200, prs, _} =
Tentacat.Client.new(%{access_token: @access_token})
!|> Tentacat.Pulls.list("nicoespeon", "my-repo")
prs
!|> Enum.map(fn pr !-> pr["created_at"] end)
!|> Enum.flat_map(fn created_at !->
case DaysDiff.between(today, created_at) do
{:ok, open_time} !-> [open_time]
{:error, _} !-> []
end
end)
end
Hard to 

see

the Business
Hard to 

test

the Business
Hard to 

change

the Business
Hard to change the Infra.
without breaking the Business
Is your Business
easy to read?
📖
Is your Business
easy to test?
🚦
Hexagonal
Architecture
The simplest way to



Separate Domain 

& Infrastructure
Infra.
Domain
The outside depends
on the inside.


Never the opposite.
Rule
Infra.
Domain
Dependency
Infra.
Domain
Dependency
Interface
Adapter
use
implement
Port
Adapter
use
implement
Ports & Adapters
Architecture
Inside the Hexagon
Business language 

only
%
Left-side Right-side
⚙
W
eb
UI
REST
API
Database
Send
event
'(Benefits
Flexibility
REST API CLI CRON
FTP File System HTTP
Console Sentry Postgres
…
You can plug another
Infra. to the Domain
🔌
A good software
architect defers
technical decisions
You can start with
something simple✨
In Elixir
Interfaces in Elixir


But we have
Behaviours
# i_read_prs.ex (Behavior)

defmodule IReadPrs do
@callback opened_prs() !:: [OpenTime.pr()]
end
# i_give_dates.ex (Behavior)

defmodule IGiveDates do
@callback today() !:: String.t()
end
defmodule OpenTime do
@type pr !:: %{created_at: String.t()}
def prs_open_time_until_today() do
end
end
defmodule OpenTime do
@type pr !:: %{created_at: String.t()}
@dates_giver Application.get_env(:pr_metrics, :dates_giver)
def prs_open_time_until_today() do
today = @dates_giver.today()
end
end
defmodule OpenTime do
@type pr !:: %{created_at: String.t()}
@dates_giver Application.get_env(:pr_metrics, :dates_giver)
@prs_reader Application.get_env(:pr_metrics, :prs_reader)
def prs_open_time_until_today() do
today = @dates_giver.today()
prs = @prs_reader.opened_prs()
end
end
defmodule OpenTime do
@type pr !:: %{created_at: String.t()}
@dates_giver Application.get_env(:pr_metrics, :dates_giver)
@prs_reader Application.get_env(:pr_metrics, :prs_reader)
def prs_open_time_until_today() do
today = @dates_giver.today()
prs = @prs_reader.opened_prs()
prs
!|> Enum.map(fn pr !-> pr.created_at end)
!|> Enum.flat_map(fn created_at !->
case DaysDiff.between(today, created_at) do
{:ok, open_time} !-> [open_time]
{:error, _} !-> []
end
end)
end
end
# dates_giver.system.ex (Adapter)
defmodule DatesGiver.System do
@behaviour IGiveDates
end
# prs_reader.github.ex (Adapter)
defmodule PrsReader.GitHub do
@behaviour IReadPrs
end
# dates_giver.system.ex (Adapter)
defmodule DatesGiver.System do
@behaviour IGiveDates
def today, do: Date.utc_today() !|> Date.to_iso8601()
end
# prs_reader.github.ex (Adapter)
defmodule PrsReader.GitHub do
@behaviour IReadPrs
end
# dates_giver.system.ex (Adapter)
defmodule DatesGiver.System do
@behaviour IGiveDates
def today, do: Date.utc_today() !|> Date.to_iso8601()
end
# prs_reader.github.ex (Adapter)
defmodule PrsReader.GitHub do
@behaviour IReadPrs
@access_token Application.get_env(:pr_metrics, :github_access_token)
def opened_prs do
{200, prs, _} =
Tentacat.Client.new(%{access_token: @access_token})
!|> Tentacat.Pulls.list("nicoespeon", "my-repo")
prs
!|> Enum.map(fn pr !-> %{created_at: pr["created_at"]} end)
end
end
# config/config.exs
use Mix.Config
config :pr_metrics,
dates_giver: DatesGiver.System,
prs_reader: PrsReader.GitHub
# config/config.test.exs
use Mix.Config
config :pr_metrics,
dates_giver: Mock.DatesGiver,
prs_reader: Mock.PrsReader
defmodule OpenTimeTest do
use ExUnit.Case
import Mox
end
defmodule OpenTimeTest do
use ExUnit.Case
import Mox
test "returns an empty array if there is no opened PR" do
open_times = OpenTime.prs_open_time_until_today()
assert open_times !== []
end
end
defmodule OpenTimeTest do
use ExUnit.Case
import Mox
@today "2011-01-10"
test "returns an empty array if there is no opened PR" do
Mock.DatesGiver
!|> stub(:today, fn !-> @today end)
open_times = OpenTime.prs_open_time_until_today()
assert open_times !== []
end
end
defmodule OpenTimeTest do
use ExUnit.Case
import Mox
@today "2011-01-10"
test "returns an empty array if there is no opened PR" do
Mock.DatesGiver
!|> stub(:today, fn !-> @today end)
Mock.PrsReader
!|> stub(:opened_prs, fn !-> [] end)
open_times = OpenTime.prs_open_time_until_today()
assert open_times !== []
end
end
"Program to a
behaviour"
Elixir
Use 

Domain language 

in Behaviours
+
Limits,
It doesn't guide you

to scale 🚀
Compatible

Has more layers
Compatible

Ubiquitous Language 

Bounded Contexts

Domain modelling
Separate Domain
& Infrastructure
🙏
Twitter 

GitHub 

Medium
}@nicoespeon
Nicolas Carlo

More Related Content

PDF
Hexagonal architecture for java applications
PDF
The Play Framework at LinkedIn
PDF
SOFEA: Service Oriented Front End Architecture, Next Gen Web Architecture for...
PDF
PPTX
Express js
PPTX
Introduction to Redis
PDF
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
PDF
Introduction to elasticsearch
Hexagonal architecture for java applications
The Play Framework at LinkedIn
SOFEA: Service Oriented Front End Architecture, Next Gen Web Architecture for...
Express js
Introduction to Redis
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
Introduction to elasticsearch

What's hot (20)

PPTX
PPTX
Introduction to MongoDB
PDF
Hadoop and Spark
PDF
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
PPTX
Database Performance Tuning
PPTX
Introduction to Angularjs
PPTX
Token Authentication in ASP.NET Core
PPTX
Caching
PDF
쿠키런 1년, 서버개발 분투기
PDF
What is new in PostgreSQL 14?
PDF
Apache Spark Listeners: A Crash Course in Fast, Easy Monitoring
PDF
Apache Spark Streaming in K8s with ArgoCD & Spark Operator
PPTX
The Basics of MongoDB
PDF
Design patterns for microservice architecture
PDF
MongodB Internals
PPTX
Introduction to Storm
PDF
ClickHouse and the Magic of Materialized Views, By Robert Hodges and Altinity...
PDF
Microservices with Java, Spring Boot and Spring Cloud
PPTX
Apache Spark Architecture
PPTX
Dynamo and BigTable in light of the CAP theorem
Introduction to MongoDB
Hadoop and Spark
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
Database Performance Tuning
Introduction to Angularjs
Token Authentication in ASP.NET Core
Caching
쿠키런 1년, 서버개발 분투기
What is new in PostgreSQL 14?
Apache Spark Listeners: A Crash Course in Fast, Easy Monitoring
Apache Spark Streaming in K8s with ArgoCD & Spark Operator
The Basics of MongoDB
Design patterns for microservice architecture
MongodB Internals
Introduction to Storm
ClickHouse and the Magic of Materialized Views, By Robert Hodges and Altinity...
Microservices with Java, Spring Boot and Spring Cloud
Apache Spark Architecture
Dynamo and BigTable in light of the CAP theorem
Ad

Similar to Hexagonal architecture & Elixir (7)

PDF
Coder sans peur du changement avec la meme pas mal hexagonal architecture
PPTX
CODE-RELATED-ARTIFACTS-CPAR.powerpoint.arts
PPTX
Udi Dahan: Event Sourcing Keynote @ DDD EU
PDF
Clojure night
PDF
Polyglot and Poly-paradigm Programming for Better Agility
PPTX
Hexagonal_Architecture_DDD_Presentation.pptx
ODP
RailswayCon 2010 - Command Your Domain
Coder sans peur du changement avec la meme pas mal hexagonal architecture
CODE-RELATED-ARTIFACTS-CPAR.powerpoint.arts
Udi Dahan: Event Sourcing Keynote @ DDD EU
Clojure night
Polyglot and Poly-paradigm Programming for Better Agility
Hexagonal_Architecture_DDD_Presentation.pptx
RailswayCon 2010 - Command Your Domain
Ad

More from Nicolas Carlo (11)

PDF
The Secrets of Hexagonal Architecture
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
The Secrets of Hexagonal Architecture
À 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
Machine learning based COVID-19 study performance prediction
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Spectral efficient network and resource selection model in 5G networks
DOCX
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
sap open course for s4hana steps from ECC to s4
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Spectral efficient network and resource selection model in 5G networks
The AUB Centre for AI in Media Proposal.docx

Hexagonal architecture & Elixir