simon brown: software architecture as code at i t.a.k.e. unconference 2015

129
Simon Brown @simonbrown Software Architecture as Code

Upload: mozaic-works

Post on 28-Jul-2015

115 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Simon Brown @simonbrown

Software Architecture

as Code

Page 2: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 3: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Jersey

Page 4: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Jersey

Page 5: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Jersey

Page 6: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 7: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

I help software teams understand

software architecture,

technical leadership and

the balance with agility

Page 8: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Software architecture needs to be more

accessible

Page 9: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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

Page 10: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

I code too⇧ ; - ⇧ 0

Page 11: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

The intersection between

software architecture

and

code

Page 12: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

How do we

communicate software architecture?

Page 13: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

The tension between software architecture

and code

Page 14: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 17: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Logical and

development views are often

separated

Page 19: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Brain freeze!

Page 20: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 21: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

9 out of 10 people

don’t use UML (in my experience)

Page 22: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 23: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

In my experience, software teams aren’t able to

effectively communicate the software architecture

of their systems

Page 24: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

The Airline Route Map

Page 25: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Generically True

Page 26: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Homeless Old C# Object (HOCO)

Page 27: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Choose your own adventure

Page 28: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Would we

code it that way?

Page 29: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Did we

code it that way?

Page 30: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Abstraction is about reducing detail rather than creating a different representation

Page 31: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Abstractions help us

reason about a big and/or complex

software system

Page 32: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Does your code reflect the

abstractions that you think about?

Page 33: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

We often think

in components

but write classes (usually in layers)

Page 34: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 36: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 37: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 38: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 39: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 40: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Hexagons and onions

Page 42: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Should layers be

considered harmful?

Page 43: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Are layers significant

structural elements

or just an

implementation detail?

Page 44: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Organisation of code

vs the architectural views

Page 46: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

“the model-code gap”

Page 47: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Sketches get out of date, so why not

auto-generate the diagrams?

Page 48: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Diagramming tools see

packages and classes

rather than components

Page 49: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 50: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Describing software

architecture

Page 51: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

“Modules, components and connectors”

Is this vocabulary in common use?

Page 52: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

“This is a component of our system” says one developer to another, pointing to a box on a diagram

labelled “Web Application”

Page 53: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

A common set of abstractions

is more important than a common notation

Page 54: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 55: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 56: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 57: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 58: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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

•Are the technology choices and responsibilities clear?

Page 59: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 60: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 61: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Diagrams are maps that help a team navigate a complex codebase

Page 62: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Think about the

target audience

Non-technical Semi-technical Very technical

Page 63: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

C4++ Enterprise context

User interface mockups and wireframes Domain model

Sequence and collaboration diagrams Business process and workflow models

Infrastructure model Deployment model

...

Page 64: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 65: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Static Model

(at different levels of abstraction)

Runtime/Behavioural

Deployment

InfrastructureOperation & Support

Data

Page 66: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

C4 is about the

static structure of software, which is ultimately about

code

Page 67: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Software developers are the most important

stakeholders of software architecture

Page 68: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Components?

Page 69: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

What is a

“component”?

Page 70: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 71: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

An auto-generated UML class diagram

Page 72: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

What are the architecturally

significant elements?

Page 73: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

A UML class diagram showing architecturally significant elements

Page 74: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

A component diagram,

based upon the code

Page 75: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

How do we do this?

Can we extract the software architecture model

from the code?

How do we create living documentation?

What is the relationship between architecture,

coding and testing?

Will I talk about microservices?

Why is this important?

Page 76: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

The intersection of

software architecture and code

Page 77: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Merge the code

and the model?

Page 78: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Abstractions on diagrams

should reflect the

code

Page 79: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

“architecturally-evident coding style”

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

Page 80: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 81: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

What’s a “component”?

Page 82: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 83: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

What’s a “component”?

Page 84: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 85: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 86: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Modularity as a principle

Page 87: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Software architecture

vs testing (a quick aside)

Page 88: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

“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 89: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

“do not let your tests drive your design”

Page 90: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

What’s a “component”?

Page 91: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Instead of blindly unit testing everything, what about

testing your significant structural elements

as black boxes?

Page 92: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Do we need to rethink the testing pyramid?

UI and functional

Integration

Unit

Page 93: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 94: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Software architecture as code

Page 95: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

The code is the

embodiment of the architecture

Page 96: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Is the architecture in the code?

Page 97: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 98: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 99: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 100: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 101: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Extract as much of the software

architecture from the code as possible,

and supplement where necessary

Page 102: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Create an architecture description language

using code

Page 103: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 104: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 105: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 106: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Structurizr for Java

(open source on GitHub)

Page 107: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Structurizr Simple, versionable,

up-to-date and scalable software architecture

models from code

Page 108: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Spring PetClinic - System Context

Page 109: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Spring PetClinic - Containers

Page 110: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Spring PetClinic - Web Application

- Components

Page 111: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

A model as code provides opportunities…

Page 112: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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

Page 113: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Software architecture

really is

for developers

:-)

Page 114: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

The point of this?

Page 115: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Maintainability is inversely proportional

to the number of

public classes dependencies microservices[ ]

Page 116: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

A good architecture

enables agility

Page 117: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Monolithic architecture

Service-based architecture

(SOA, micro-services, etc)

Something in between (components)

Page 118: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Agility is a

quality attribute

Page 119: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

If you can’t build a

structured monolith,

what makes you think microservices is the answer!?

Page 120: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 121: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

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 122: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Page 123: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Choose microservices for

the benefits, not because your monolithic

codebase is a mess :-)

Page 124: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

If your software system is hard to work with,

change it!

Page 125: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Think about how to align the

software architecture

and the

code

Page 126: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Be conscious of the software

architecture model … adopt an architecturally-evident

coding style

Page 127: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

Stop making every class

public

Page 128: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

1 RON charity donation every time you type

without thinking :-)

public class

Page 129: Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015

[email protected]

@simonbrown on Twitter

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

from the code