Advanced application architecture

  • View
    1.043

  • Download
    2

  • Category

    Software

Preview:

Citation preview

ADVANCED APPLICATION

ARCHITECTUREI - Layers

Matthias Noback @matthiasnoback

matthiasnoback/ layers-ports-and-adapters-

workshopClone from GitHub

docker-compose pull

bin/composer.sh install

docker-compose up -d

ARCHITECTUREDecisions about coupling and cohesion

COUPLINGHow are things linked to each other?

COHESIONWhich things belong together?

LAYERED ARCHITECTUREAn answer to both questions

LAYERSHelp you protect what's in a deeper layer

LAYERSAllow you to define dependency rules

LAYERSDefine the right place to put things

TRADITIONAL LAYERING

view model

data

LAYERSHorizontal division (as opposed to...)

USE CASESVertical division

LAYERSRendered as circles

CLEAN ARCHITECTUREOr "union" architecture

COHESIONA basic set of layers

infrastructure application

domain

COUPLINGThe dependency rule

Layers should only depend on deeper layers

COUPLINGDependency inversion principle

Classes should always depend on things that are more abstract

COUPLINGDependency inversion principle

low-levelconcrete class specific

abstract interface generic high-level

COUPLINGDependency inversion principle

use

COUPLINGDependency inversion principle

use implement

COUPLINGIs about dependencies in code

Use Dependency Injection

LAYER CONVENTIONSDomain layer

Domain model:

➤ Entities

➤ Value objects

➤ Domain services

➤ Factories

Business logic

Decisions

Data

State

Behavior

LAYER CONVENTIONSApplication layer

➤ Find an object

➤ Change something

➤ Notify something

➤ Get some information

Use cases

Orchestration

LAYER CONVENTIONSInfrastructure layer

Communication with:

➤ HTTP client

➤ Database

➤ Filesystem

➤ Email server

➤ Message broker

Connecting the application to

the world outside

MATTHIASNOBACK/LAYERS-PORTS-AND-ADAPTERS-

WORKSHOPAssignments are on GitHub in assignments/

assignment/01.mdLayers

ADVANCED APPLICATION

ARCHITECTUREII - Ports & adapters

MESSAGING... is the big idea

PORTS (COHESION)Web, CLI, test client, messages, database queries

User interface

Persistence

PORTS... AND ADAPTERSTranslation

HTTP

SQL

HEXAGONAL ARCHITECTURESame thing!

User interface

Persistence

PORTS... AND ADAPTERS(De)serialization, translation, structural validation

HTTP

SQL

!

!

assignment/02.mdPorts

PORT ADAPTERS...in the Infrastructure layer

APPLICATION SERVICES... in the Application layer

DOMAIN MODELin the Domain layer

APPLICATION SERVICESDelivery-mechanism agnostic

assignment/03.mdInput adapters

VALIDATIONAt different levels

Structural validation of messages

User-friendly input validation

Domain invariant protection

assignment/04.mdInput validation

APPLICATION SERVICESTransactional consistency

assignment/05.mdOutput adapter

assignment/06.mdA hidden dependency on the persistence mechanism

ADVANTAGES OF USING LAYERS, PORTS & ADAPTERS

Offers insight into the application

Isolates the low-level details

Allows for alternative implementations

Helps with testing

ADVANCED APPLICATION

ARCHITECTUREIII - Testing

UNIT TESTSTesting your units of code

One class at a time

No IO

No setup required

Mocking only dependencies "you own"

INTEGRATION TESTSTesting your adapters

Maybe multiple classes

Including IO

Some setup required

Mocking no dependencies

ACCEPTANCE TESTSTesting your application services

Multiple classes

Use cases

Infrastructure stand-ins

SYSTEM TESTSTesting your application end-to-end

The real deal

TESTING PYRAMIDMake it well-balanced

Unit

Integration

System

Acceptance

assignment/07.mdDifferent types of tests

ACCEPTANCE TESTSUse infrastructure stand-ins

Acceptance testtest the

application layer

Persistence

FileBased InMemory

Port

Adapters

MeetupRepository

FileBasedMeetupRepository InMemoryMeetupRepository

Domain

Infrastructure

implements implements

assignment/08.mdA test double for the Persistence port

assignment/09.md An acceptance test for the application layer

A WELL-BALANCED TEST SUITE

Adapters can be easily replaced

Test suite is fast

Feedback is quick

Small amount of fragile tests

Enables continuous delivery

assignment/10.mdNotifications

https://training.matthiasnoback.nl/

https://joind.in/talk/b1763

Feedback?

Recommended