Hexagonal architecture for dummies (and spring developer) @youen-chene

@saagie_io

Why hexagonal architecture?

@youen-chene

@saagie_io

Hexagonal/DDD Speaker (Jérome)

DDD & Hexagonal will save the world. 40mn to 1h57 before showing some code. No framework. Manual Bean & IoC instanciation.

@youen-chene

@saagie_io

Java/Kotlin Developer (Pierre)

No framework? it’s not real world stuff. What’s the value versus a layer architecture? Looks complicated.

@youen-chene

@saagie_io

“Parce que quand on est grand on arrête de mettre des couches” Cédric Champeau LCC#154

@youen-chene

@saagie_io

@youen_chene CTO @saagie_io Activiste : @normandyjug @codeursenseine @devoxx4kidsfr @n_w_x

Data Fabric

Data Governance

GDPR

Container Management Spark

Datanodes

Python

Keras Spring Boot

CPU

GPU

App/Dataviz

HTML, JS, CSS

Browser Server Controller

Controller

Service

DAO

Service

DAO

Service

DAO

DAO

HTML, JS, CSS

Browser Server Controller

Controller

Service

DAO = Business Rule

Service

DAO

Service

DAO

DAO

HTML, JS, CSS

Browser Server Controller

Controller

Service

DAO = Business Rule

Service

DAO

Service

DAO

DAO

HTML, JS, CSS

Browser Server Controller

Controller

Service

DAO = Piece of Business Rule

Service

DAO

Service

DAO

DAO

HTML, JS, CSS

Browser Server Controller

Controller

Service

DAO = Piece of Business Rule

Service

DAO

Service

DAO

DAO

if ($job->getCategory() == "dataviz" || $job->getCapsuleCode() == CapsuleInstance::JUPITER_CODE) { $notebookConfig = $this->managerConfig->getCapsules()->getNotebook(); return $notebookConfig->getMesostag(); } else if ($job!=null && $job->getCapsuleCode() == CapsuleInstance::SQOOP_CODE) { return "hdfs-master"; } else { return "hdfs"; }

Tackling Complexity in the Heart of Software Eric Evans 2003

@youen-chene

@saagie_io

Sexy Allistair Schema

@youen-chene

@saagie_io

Sister’ Architecture

@youen-chene

@saagie_io

Simple Hexagonal Architecture with Spring Boot

@youen-chene

@saagie_io

Let’s start by the domain

Domain

@youen-chene

@saagie_io

Let’s start by the domain

Domain

Rule 1 : no framework or lib dependency!!!!!!! @youen-chene

@saagie_io

Let’s start by the domain

Domain

Rule 2 : external call the inside @youen-chene

@saagie_io

One simple Rule

Domain

No Infra Code in the domain @youen-chene

@saagie_io

Back the domain

Domain

@youen-chene

@saagie_io

@youen-chene

@saagie_io

@youen-chene

@saagie_io

Let’s start by the domain

@youen-chene

@saagie_io

Hexagonal I/O

@youen-chene

@saagie_io

Accessing the Domain : (1) Primary Port

Classes, Functions, Methods, Service External Infrastructure call the inside

Domain Domain

(Ex: API Controller, Batch)

@youen-chene

@saagie_io

Accessing the Domain : (1) Primary Port

Classes, Functions, Methods, Service External Infrastructure call the inside

Domain Domain

(Ex: API Controller, Batch)

@youen-chene

@saagie_io

Accessing the Infrastructure Code : (2) Secondary Port

Interface

Domain Domain

Interface Implementation

Accessing/Pushing Data

@youen-chene

DB, Kafka, Rabbit, External API

@saagie_io

Accessing the Infrastructure Code : (2) Secondary Port

Interface

Domain Domain

Interface Implementation

Accessing/Pushing Data

@youen-chene

DB, Kafka, Rabbit, External API

@saagie_io

Co

nt r Ad AP olle r I ap te r

go on M DB er t ap Ad

Bo Spr ot ing Ap p

Infrastructure Code : With Adapters

Ba

tc

h

Ex ter AP nal A I d ap ter

h tc r Ba pte a Ad

Domain Domain Domain

@youen-chene

@saagie_io

Ports

Primary Port Driving Port Input Port

@youen-chene

Secondary Port Domain Domain Domain

Driven Port Output Port

@saagie_io

C o AP Ad ntro I ap lle te r r

Dirty technical shit

go on M DB er t ap Ad

Bo Spr ot ing Ap p

Infrastructure Code : With Adapters

Domain Domain Domain

Ba

tc

h

Ex ter AP nal A I d ap ter

h tc r Ba pte a Ad

Clean rule

@youen-chene

@saagie_io

Infrastructure Code : @Repository Spring Secondary Adapter MongoDB Adapter go on M B er D t ap

Ad

Domain Domain

Port (Interface)

@youen-chene

@saagie_io

Infrastructure Code : @Repository Spring Secondary Adapter MongoDB Adapter

Repository Spring bean Implements Port Kmongo as DAO

Implements method with domain, DAO and DTOs. @youen-chene

@saagie_io

Infrastructure Code : Data Transfer Object (DTO)

Mongo dependency

Boring Mapping

Boring Mapping

@youen-chene

@saagie_io

Back to Spring Boot

Domain Object

Bean @Repository class FeatureRecordsMongoRepository

DTO

KMongo @youen-chene

@saagie_io

Infrastructure Code : Spring Application Primary Adapter

Co AP Ad ntro I ap lle te r r

Bo Spr ot ing Ap p

Spring Boot App

Domain Domain @youen-chene

@saagie_io

Back to Spring Boot @SpringBootApplication class FeaturebrawlApplication

Domain Object

Instanciate

Bean @Repository class FeatureRecordsMongoRepository

DTO

KMongo @youen-chene

@saagie_io

Infrastructure Code : Spring Application Primary Adapter

Spring Boot App

Co AP Ad ntro I ap lle te r r

Bo Spr ot ing Ap p

Spring API Controller Adapter

Domain Domain @youen-chene

@saagie_io

Infrastructure Code : Spring Application Primary Adapter Spring API Controller Adapter

RestController Spring bean Inject FeatureManagement Port

Use FeatureManagement Port

@youen-chene

@saagie_io

API Calls DTO

@SpringBootApplication class FeaturebrawlApplication

Instanciate

@RestController class FeatureSpringRestController

Bean

Domain Object

Instanciate

Bean @Repository class FeatureRecordsMongoRepository

DTO

KMongo @youen-chene

@saagie_io

API Calls DTO

@SpringBootApplication class FeaturebrawlApplication

Instanciate

@RestController class FeatureSpringRestController

Bean

Domain

Domain Object

Instanciate

Bean @Repository class FeatureRecordsMongoRepository

DTO

KMongo @youen-chene

@saagie_io

@youen-chene

@saagie_io

One simple Rule

Domain

No Infra Code in the domain @youen-chene

@saagie_io

Infrastructure Code : Hack all Together

@youen-chene

@saagie_io

Infrastructure Code : Hack all Together

Service Spring bean to expose the primary port as a spring bean bean

@youen-chene

@saagie_io

Infrastructure Code : Hack all Together

So it can be injected by spring here (Rest controller primary adapter)

Service Spring bean to expose the primary port as a spring bean bean

@youen-chene

@saagie_io

Infrastructure Code : Hack all Together

Inject Repository Secondary Adapter.

@youen-chene

@saagie_io

Infrastructure Code : Hack all Together

Inject Repository Secondary Adapter. So it can use the @repository spring bean (repository primary adapter)

@youen-chene

@saagie_io

API Calls DTO

@SpringBootApplication class FeaturebrawlApplication

Instanciate

@RestController class FeatureSpringRestController

Bean

Domain Object

Instanciate

Bean @Service class FeatureManagementSpringHandler Domain Domain Object

Instanciate

Bean @Repository class FeatureRecordsMongoRepository

DTO

KMongo @youen-chene

@saagie_io

It’s a little bit crappy, no?

@youen-chene

@saagie_io

Spring Boot on it’s nominal use case Hexagonal Architecture respected Domain still clean.

@youen-chene

@saagie_io

C o AP Ad ntro I ap lle te r r

Dirty technical shit

go on M DB er t ap Ad

Bo Spr ot ing Ap p

Infrastructure Code : With Adapters

Domain Domain Domain

Ba

tc

h

Ex ter AP nal A I d ap ter

h tc r Ba pte a Ad

Clean rule

@youen-chene

@saagie_io

https://github.com/youenchene/featurebrawl

@youen-chene

@saagie_io

Pros

Cons

Clean Domain/Business Rules

DTOs make it a little heavy

Fast unit test on the domain

Developer need to be trained

Better code scalability

No starter like jHipster

@youen-chene

@saagie_io

One simple Rule

Domain

No Infra Code in the domain @youen-chene

@saagie_io

C o AP Ad ntro I ap lle te r r

Dirty technical shit

go on M DB er t ap Ad

Bo Spr ot ing Ap p

Questions?

Domain Domain Domain

Ba

tc

h

Ex ter AP nal A I d ap ter

h tc r Ba pte a Ad

Clean rule

@youen-chene

@saagie_io

Hexagonal architecture for dummies-LyonJUG.pdf

world. 40mn to 1h57 before showing. some code. No framework. Manual ... Cédric Champeau LCC#154 ... Hexagonal architecture for dummies-LyonJUG.pdf.

3MB Sizes 1 Downloads 197 Views

Recommend Documents

No documents