Visualising Software Architecture With The c4 Model Full Day
Visualising Software Architecture With The c4 Model Full Day
software architecture
with the C4 model
@simonbrown
https://leanpub.com/visualising-software-architecture/c/…
What is software
architecture?
Structure
The definition of software in terms
of its building blocks and their interactions
Vision
The process of architecting;
making decisions based upon business goals,
requirements and constraints,
plus being able to communicate this to a team
Enterprise Architecture
Structure and strategy across people, process and technology
System Architecture
High-level structure of a software system
(software and infrastructure)
Application Architecture
The internal structure of an application
“ ”
As a noun, design is the named
structure or behaviour of a system whose
presence resolves ... a force on that
system. A design thus represents one
point in a potential decision space.
Grady Booch
“ ”
All architecture is design, but
not all design is architecture.
Grady Booch
“ ”
Architecture represents the
significant decisions, where significance
is measured by cost of change.
Grady Booch
Draw one or more software
architecture diagrams to describe
the system/project you
are currently working on
60 minutes
Design a software solution for
the ”Financial Risk System”, and
draw one or more architecture
diagrams to describe your solution
90 minutes
Did you find anything
about this exercise
challenging?
Swap and review your diagrams
Focus on the diagrams rather than the solution itself;
do you understand the notation, colour coding, symbols, etc?
15 minutes
The perfection game
We rate the diagrams… (1-10)
We liked…
To make the diagrams perfect…
15 minutes
1 1 1 2 2 2
Information is likely
still stuck in your heads
“ ”
This doesn’t make sense,
but we’ll explain it.
• What is this shape/symbol?
• What is this line/arrow?
• What do the colours mean?
• What level of abstraction is shown?
• Which diagram do we read first?
Moving fast in the same direction
as a team requires
good communication
I’ve run diagramming workshops
in 30+ countries
for 10,000+ people
Software architects
struggle to communicate
software architecture
Do you use UML?
In my experience, optimistically,
Web
Application
Logging
Component
Relational
Database
Ubiquitous
language
Abstractions
Would you code it that way?
(ensure that your diagrams reflect
your implementation intent)
When drawing software
architecture diagrams,
think like a software developer
A common set of abstractions
is more important
than a common notation
Software System
Overview first
2. Containers
The overall shape of the architecture and technology choices.
A model of the
Static
Data
(entity relationship
model etc…
static structure
forms the basis
diagrams) (software systems,
containers, components
and classes)
Infrastructure
for other views
Deployment
(physical, virtual,
(mapping of containers
containerised hardware;
to infrastructure)
firewalls, routers, etc)
Example
(techtribes.je)
techtribes.je
A simple content aggregator for
the local tech and digital industry
Notation
Titles
Short and meaningful, include the diagram type,
numbered if diagram order is important; for example:
[Person]
techtribes.je is the only way to keep up
to date with the IT, tech and digital
Anybody on the web.
sector in Jersey and Guernsey, Channel
Islands.
30 minutes
Designing software is where
the complexity should be,
not communicating it!
Richer diagrams lead to
richer design discussions
The perfection game
We rate the diagrams… (1-10)
We liked…
To make the diagrams perfect…
15 minutes
Similar levels of abstraction provide
a way to easily compare solutions
C4 and UML
Spring PetClinic
A sample application that illustrates how to build Java web applications using the Spring MVC framework
https://github.com/spring-projects/spring-petclinic/
JSP-with--
Views custom-tags-
|| Thymeleaf-
Spring-@MVC-annotaGons-
Controller
Bean-ValidaGon-
@Cacheable-
Service
@TransacGonal-
Spring-Data-JPA-
Repository 3-profiles- default-(JPA)-
jdbc-
https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application
System landscape diagrams
Runtime/behavioural diagrams
Static structure diagrams
are very useful, but they
don’t tell the whole story
JSP-with--
Views custom-tags-
|| Thymeleaf-
Spring-@MVC-annotaGons-
Controller
Bean-ValidaGon-
@Cacheable-
Service
@TransacGonal-
Spring-Data-JPA-
Repository 3-profiles- default-(JPA)-
jdbc-
Use dynamic diagrams to describe
patterns or complex interactions
Deployment diagrams
Deployment is about the mapping
of containers to infrastructure
Deployment Node
Physical infrastructure (a physical server or device),
virtualised infrastructure (IaaS, PaaS, a virtual machine),
containerised infrastructure (a Docker container),
database server, Java EE web/application server,
Microsoft IIS, etc
A deployment node can contain
other deployment nodes
or container instances
Frequently asked questions
What's the inspiration
behind the C4 model?
Why "container"?
Can we change the terminology?
How do you model microservices
and serverless?
How do you diagram large and
complex software systems?
Option 1: Introduce additional abstractions
(nested components, sub-components, layers, etc)
Web controllers
Business components
Option 2: Partition the diagrams
(one diagram per business concept, feature set,
bounded context, aggregate root, vertical slice, etc)
Will the diagrams become
outdated quickly?
Why doesn't the C4 model cover
business processes, workflows,
state machines, domain models,
data models, etc?
The C4 model vs UML,
ArchiMate and SysML?
Can we combine C4 and arc42?
Does the C4 model imply a
design process or team structure?
Draw a System Context diagram
to describe your software system
(people and software systems)
30 minutes
Draw a Container diagram
to describe your software system
(deployable/runnable units within the software system in scope)
30 minutes
Draw System Context and
Container diagrams to describe
your software system
60 minutes
Tooling
“ ”
What tools do you
recommend?
Whiteboards and paper
for up front design
General purpose diagramming tools
allow you to draw anything
Microsoft Visio, OmniGraffle, Gliffy,
Lucidchart, draw.io, Creately, …
Static diagrams need to be
kept up to date individually
Diagrams vs models
Text-based tools allow you to
create diagrams using text
PlantUML, WebSequenceDiagrams, yUML, nomnoml, …
Text-based diagrams
can be version controlled,
generated from build scripts, etc
Text-based diagrams
can’t be queried
Architecture description languages
provide a way to describe
architecture as text
Darwin, ACME, Koala, Wright, …
Modelling tools allow you to create
a model of your software system
Sparx Enterprise Architect, IBM Rational Software Architect,
StarUML, GenMyModel, Visual Paradigm, …
Static analysis and dependency
management tools can help
understand code structure
Structure101, Lattix, JArchitect, NDepend,
JDepend, jQAssistant, Degraph, …
Modelling tools
Sophisticated and often complex tooling to create rich models using
UML, ArchiMate, SysML, etc; either by “drag & drop” or reverse-engineering code.
Richness of model
Ease of use
Virtual Panel on
Software
Architecture
Documentation
(2009)
http://www.infoq.com/articles/virtual-panel-arch-documentation
Do structural engineers and building architects
use general purpose drawing tools?
Diagrams are not useful for
architectural improvement if they
are not connected to the code
Reverse-engineer
code to diagrams?
Spring PetClinic
A sample application that illustrates how to build Java web applications using the Spring MVC framework
https://github.com/spring-projects/spring-petclinic/
JSP-with--
Views custom-tags-
|| Thymeleaf-
Spring-@MVC-annotaGons-
Controller
Bean-ValidaGon-
@Cacheable-
Service
@TransacGonal-
Spring-Data-JPA-
Repository 3-profiles- default-(JPA)-
jdbc-
https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application
Most tools see code,
not components
Information about
software architecture
doesn’t exist in the code
“architecturally-evident coding style”
Examples of architecturally-evident
coding styles
Annotations/attributes (@Component, [Component], etc)
Naming conventions (*Service)
Namespacing/packaging (com.mycompany.system.components.*)
Maven & Gradle modules, OSGi & Java 9 modules
JavaScript module patterns, ECMAScript 6 modules,
microservices, etc
Extract as much of the
software architecture from the code
as possible, and supplement
the model where necessary
Executable architecture
description language
Structurizr for Java and .NET
Modelling tools
Sophisticated and often complex tooling to create rich models using
UML, ArchiMate, SysML, etc; either by “drag & drop” or reverse-engineering code.
Ease of use
public static void main(String[] args) throws Exception {
Workspace workspace = new Workspace(
"Spring PetClinic",
"This is a C4 representation of the Spring PetClinic sample app
(https://github.com/spring-projects/spring-petclinic/)");
}
// software systems and people
SoftwareSystem springPetClinic = model.addSoftwareSystem(
"Spring PetClinic",
"Allows employees to view and manage information regarding the
veterinarians, the clients, and their pets.");
clinicEmployee.uses(springPetClinic, "Uses");
// containers
Container webApplication = springPetClinic.addContainer(
"Web Application",
"Allows employees to view and manage information regarding the
veterinarians, the clients, and their pets.",
"Apache Tomcat 7.x");
clinicEmployee.uses(webApplication,
"Uses", “HTTP");
webApplication.uses(relationalDatabase,
"Reads from and writes to", "JDBC, port 9001");
// components
ComponentFinder componentFinder = new ComponentFinder(
webApplication,
"org.springframework.samples.petclinic",
new SpringComponentFinderStrategy(
new ReferencedTypesSupportingTypesStrategy()
),
new SourceCodeComponentFinderStrategy(
new File(sourceRoot, "/src/main/java/"), 150));
componentFinder.findComponents();
// connect components with other model elements
webApplication.getComponents().stream()
.filter(c -> c.getTechnology().equals(SpringComponentFinderStrategy.SPRING_MVC_CONTROLLER))
.forEach(c -> clinicEmployee.uses(c, "Uses", "HTTP"));
webApplication.getComponents().stream()
.filter(c -> c.getTechnology().equals(SpringComponentFinderStrategy.SPRING_REPOSITORY))
.forEach(c -> c.uses(relationalDatabase, "Reads from and writes to", "JDBC"));
// system context, container and component views
ViewSet viewSet = workspace.getViews();