software architecture as code

127
Simon Brown @simonbrown Software Architecture as Code

Upload: others

Post on 11-Sep-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Software Architecture as Code

Simon Brown @simonbrown

Software Architecture

as Code

Page 2: Software Architecture as Code
Page 3: Software Architecture as Code

Jersey

Page 4: Software Architecture as Code

Jersey

Page 5: Software Architecture as Code

Jersey

Page 6: Software Architecture as Code
Page 7: Software Architecture as Code

I help software teams understand

software architecture,

technical leadership and

the balance with agility

Page 8: Software Architecture as Code

Software architecture needs to be more

accessible

Page 9: Software Architecture as Code

A developer-friendly guide to software architecture, technical leadership and the balance with agility

Page 10: Software Architecture as Code

I code too⇧ ; - ⇧ 0

Page 11: Software Architecture as Code

The intersection between

software architecture

and

code

Page 12: Software Architecture as Code

How do we

communicate software architecture?

Page 13: Software Architecture as Code

The tension between software architecture

and code

Page 14: Software Architecture as Code

It’s usually difficult to show the entire design on

a single diagram

Different views of the design can be used to manage complexity and

highlight different aspects of the solution

Page 15: Software Architecture as Code

Software architecture deals with abstraction, with decomposition and

composition, with style and esthetics.

To describe a software architecture, we use a

model composed of multiple views or perspectives.

Architectural Blueprints—The “4+1” View Model of Software Architecture by Philippe Kruchten

Page 16: Software Architecture as Code
Page 17: Software Architecture as Code

Do the names of those views make sense?

Development vs PhysicalProcess vs FunctionalConceptual vs Logical

Development vs ImplementationPhysical vs Implementation

Physical vs Deployment

Page 18: Software Architecture as Code

Logical and

development views are often

separated

Page 19: Software Architecture as Code

Brain freeze!

Page 20: Software Architecture as Code
Page 21: Software Architecture as Code

9 out of 10 people

don’t use UML (in my experience)

Page 22: Software Architecture as Code
Page 23: Software Architecture as Code

In my experience, software teams aren’t able to

effectively communicate the software architecture

of their systems

Page 24: Software Architecture as Code

The Airline Route Map

Page 25: Software Architecture as Code

Generically True

Page 26: Software Architecture as Code

Homeless Old C# Object (HOCO)

Page 27: Software Architecture as Code

Choose your own adventure

Page 28: Software Architecture as Code

Would we

code it that way?

Page 29: Software Architecture as Code

Did we

code it that way?

Page 30: Software Architecture as Code

Abstraction is about reducing detail rather than creating a different representation

Page 31: Software Architecture as Code

Abstractions help us

reason about a big and/or complex

software system

Page 32: Software Architecture as Code

Does your code reflect the

abstractions that you think about?

Page 33: Software Architecture as Code

We often think

in components

but write classes (usually in layers)

Page 34: Software Architecture as Code

Package by layer (horizontal slicing)

Presentation layer

Business layer

Data layer

Controller BController A

Data Access A

Data Access B

Service BService A

Page 35: Software Architecture as Code
Page 36: Software Architecture as Code
Page 37: Software Architecture as Code
Page 38: Software Architecture as Code
Page 39: Software Architecture as Code
Page 40: Software Architecture as Code

Package by layer (horizontal slicing)

Presentation layer

Business layer

Data layer

Controller BController A

Data Access A

Data Access B

Service BService A

Controller C

Service C

Data Access C

Page 41: Software Architecture as Code

Hexagons and onions

Page 42: Software Architecture as Code

Should layers be

considered harmful?

Page 43: Software Architecture as Code

Are layers significant

structural elements

or just an

implementation detail?

Page 44: Software Architecture as Code

Package by feature (vertical slicing)

Feature Set B Feature Set A

Controller BController A

Data Access A

Data Access B

Service BService A

Page 45: Software Architecture as Code

Organisation of code

vs the architectural views

Page 46: Software Architecture as Code

“the model-code gap”

Page 47: Software Architecture as Code

Sketches get out of date, so why not

auto-generate the diagrams?

Page 48: Software Architecture as Code

Diagramming tools see

packages and classes

rather than components

Page 49: Software Architecture as Code
Page 50: Software Architecture as Code

Describing software

architecture

Page 51: Software Architecture as Code

“Modules, components and connectors”

Is this vocabulary in common use?

Page 52: Software Architecture as Code

A common set of abstractions

is more important than a common notation

Page 53: Software Architecture as Code

Agree on a simple set of abstractions that the whole team can use to communicate

Class Class Class

Component Component Component

Container (e.g. web application, application server, standalone application,

browser, database, file system, etc)

Container (e.g. web application

browser, database, file system, etc)

Container (e.g. web application

browser, database, file system, etc)

Software System

Page 54: Software Architecture as Code

The C4 model

Classes Component or pattern implementation details

System Context The system plus users and system dependencies

Containers The overall shape of the architecture and technology choices

Components Logical components and their interactions within a container

Page 55: Software Architecture as Code

Context •What are we building?

•Who is using it? (users, actors, roles, personas, etc)

•How does it fit into the existing IT environment? (systems, services, etc)

Page 56: Software Architecture as Code

Containers •What are the high-level technology decisions? (including responsibilities)

•How do containers communicate with one another?

•As a developer, where do I need to write code?

Page 57: Software Architecture as Code

Components •What components/services is the container made up of?

•Are the technology choices and responsibilities clear?

Page 58: Software Architecture as Code

A notationless notation (whiteboard and sticky note friendly, supplemented with colour coding)

My Web Application [Container: Apache Tomcat 7.x]

Here is a list of the key responsibilities for my

web application.

Page 59: Software Architecture as Code

Classes Component or pattern implementation details

System Context The system plus users

and system dependencies

Containers The overall shape of the architecture

and technology choices

Components Logical components and their

interactions within a container

Overview first

Zoom and filter

Details on demand

Shneiderman’s mantra

Page 60: Software Architecture as Code

Diagrams are maps that help a team navigate a complex codebase

Page 61: Software Architecture as Code

Think about the

target audience

Non-technical Semi-technical Very technical

Page 62: Software Architecture as Code

C4++ Enterprise context

User interface mockups and wireframes Domain model

Sequence and collaboration diagrams Business process and workflow models

Infrastructure model Deployment model

...

Page 63: Software Architecture as Code

4+1 architectural view model

Philippe Kruchten

Software Systems Architecture Working with Stakeholders Using

Viewpoints and Perspectives (2nd Edition)

Nick Rozanski and Eoin Woods

Page 64: Software Architecture as Code

Static Model

(at different levels of abstraction)

Runtime/Behavioural

Deployment

InfrastructureOperation & Support

Data

Page 65: Software Architecture as Code

C4 is about the

static structure of software, which is ultimately about

code

Page 66: Software Architecture as Code

Software developers are the most important

stakeholders of software architecture

Page 67: Software Architecture as Code

Components?

Page 68: Software Architecture as Code

What is a

“component”?

Page 69: Software Architecture as Code

Spring PetClinic https://github.com/spring-projects/spring-petclinic/

3-profiles-jdbc-

default-(JPA)-Spring-Data-JPA-

Repository

Service @Cacheable-@TransacGonal-

Controller Bean-ValidaGon-

Spring-@MVC-annotaGons-

Views

Bootstrap-(CSS)-

JSP-with--custom-tags- Thymeleaf-

Dandelion-webjars-

| |

&& && +

https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application

Page 70: Software Architecture as Code

An auto-generated UML class diagram

Page 71: Software Architecture as Code

What are the architecturally

significant elements?

Page 72: Software Architecture as Code

A UML class diagram showing architecturally significant elements

Page 73: Software Architecture as Code

A component diagram,

based upon the code

Page 74: Software Architecture as Code

The intersection of

software architecture and code

Page 75: Software Architecture as Code

Merge the code

and the model?

Page 76: Software Architecture as Code

Abstractions on diagrams

should reflect the

code

Page 77: Software Architecture as Code

“architecturally-evident coding style”

(subclassing, naming conventions, module dependencies, package structure, …)

Page 78: Software Architecture as Code
Page 79: Software Architecture as Code

What’s a “component”?

Page 80: Software Architecture as Code

Package by component

Component B

Feature Set BFeature Set A

Component A

Controller BController A

Data Access A

Data Access B

Service BService A

Page 81: Software Architecture as Code

What’s a “component”?

Page 82: Software Architecture as Code
Page 83: Software Architecture as Code

Architecturally-evident coding styles include:

Annotations/attributes (@Component, [Component], etc)

Naming conventions (*Service)

Namespacing/packaging (com.mycompany.system.components.*)

Maven modules, OSGi modules, microservices, etc

Page 84: Software Architecture as Code

Modularity as a principle

Page 85: Software Architecture as Code

Software architecture

vs testing (a quick aside)

Page 86: Software Architecture as Code

“In the early days of computing when computers were slow, unit tests gave the developer more immediate feedback about whether a change

broke the code instead of waiting for system tests to run. Today, with cheaper and more powerful computers, that argument is less persuasive.”

Page 87: Software Architecture as Code

“do not let your tests drive your design”

Page 88: Software Architecture as Code

What’s a “component”?

Page 89: Software Architecture as Code

Instead of blindly unit testing everything, what about

testing your significant structural elements

as black boxes?

Page 90: Software Architecture as Code

Do we need to rethink the testing pyramid?

UI and functional

Integration

Unit

Page 91: Software Architecture as Code

Architecturally-aligned testing (and a reshaped testing pyramid)

Class Tests Tests focused on individual classes and methods, sometimes by mocking out

dependencies (typically referred to as “unit” tests)

Component and Service Tests Tests focused on components and services

through their public interface (often referred to as “integration” tests)

System Tests UI, API, functional and

acceptance tests (“end-to-end” tests)

Page 92: Software Architecture as Code

Software architecture as code

Page 93: Software Architecture as Code

The code is the

embodiment of the architecture

Page 94: Software Architecture as Code

Is the architecture in the code?

Page 95: Software Architecture as Code

In practice, architecture is

embodied and recoverable from code, and many

languages provide architecture-level views of the system.

A Survey of Architecture Description Languages by Paul C. Clements

Page 96: Software Architecture as Code

Context

Software Systems

Integration points, APIs, known libraries, credentials for inbound consumers, etc.

Containers IDE projects/modules, build

output (code and infrastructure), etc.

People Security groups/roles in configuration files, etc.

Components Extractable from the code if an architecturally-evident

coding style has been adopted.

Page 97: Software Architecture as Code

Containers

Software Systems

Integration points, APIs, known libraries, credentials for inbound consumers, etc.

Containers IDE projects/modules, build

output (code and infrastructure), etc.

People Security groups/roles in configuration files, etc.

Components Extractable from the code if an architecturally-evident

coding style has been adopted.

Page 98: Software Architecture as Code

Components

Software Systems

Integration points, APIs, known libraries, credentials for inbound consumers, etc.

Containers IDE projects/modules, build

output (code and infrastructure), etc.

People Security groups/roles in configuration files, etc.

Components Extractable from the code if an architecturally-evident

coding style has been adopted.

Page 99: Software Architecture as Code

Extract as much of the software

architecture from the code as possible,

and supplement where necessary

Page 100: Software Architecture as Code

Create an architecture description language

using code

Page 101: Software Architecture as Code
Page 102: Software Architecture as Code
Page 103: Software Architecture as Code
Page 104: Software Architecture as Code

Structurizr for Java

(open source on GitHub)

Page 105: Software Architecture as Code

structurizr.com (not open source, but there

is a fully functional free tier)

Page 106: Software Architecture as Code

Spring PetClinic - System Context

Page 107: Software Architecture as Code

Spring PetClinic - Containers

Page 108: Software Architecture as Code

Spring PetClinic - Web Application

- Components

Page 109: Software Architecture as Code

A model as code provides opportunities…

Page 110: Software Architecture as Code

…and build pipeline integration keeps software architecture models up-to-date

Page 111: Software Architecture as Code

Software architecture

really is

for developers

:-)

Page 112: Software Architecture as Code

The point of this?

Page 113: Software Architecture as Code

Maintainability is inversely proportional

to the number of

public classes dependencies microservices[ ]

Page 114: Software Architecture as Code

A good architecture

enables agility

Page 115: Software Architecture as Code

Agility is a

quality attribute

Page 116: Software Architecture as Code

Monolithic architecture

Service-based architecture

(SOA, micro-services, etc)

Something in between (components)

Page 117: Software Architecture as Code

If you can’t build a

structured monolith,

what makes you think microservices is the answer!?

Page 118: Software Architecture as Code
Page 119: Software Architecture as Code

Well-defined, in-process components is a stepping stone to out-of-process components

(i.e. microservices)

From components to microservices

High cohesion Low coupling

Focussed on a business capability Bounded context or aggregate

Encapsulated data Substitutable Composable

<- All of that plus

Individually deployable Individually upgradeable Individually replaceable

Individually scalable Heterogeneous technology stacks

Page 120: Software Architecture as Code

Choose microservices for

the benefits, not because your monolithic

codebase is a mess :-)

Page 121: Software Architecture as Code

If your software system is hard to work with,

change it!

Page 122: Software Architecture as Code

Think about how to align the

software architecture

and the

code

Page 123: Software Architecture as Code

Be conscious of the software

architecture model … adopt an architecturally-evident

coding style

Page 124: Software Architecture as Code

Stop making every class

public

Page 125: Software Architecture as Code

$1 charity donation every time you type

without thinking :-)

public class

Page 126: Software Architecture as Code

[email protected]

@simonbrown on Twitter

If the software architecture model is in the code, it can be extracted

from the code

Page 127: Software Architecture as Code

https://leanpub.com/software-architecture-for-developers

/c/saturn15

$10 until

May 7th with this code