How to simplify C4 Modelling in Enterprise Architect

The C4 Model is a lean graphical notation technique for modelling the architecture of software systems.

The intention of this post is not to sell you on this approach.. or convince you that you should use EA to produce C4 Diagrams. But rather it is aimed at those Solution Architects who need to knock up C4 models quickly but also need to share and associate these models back into the Enterprise Architecture repository to support alignment, road mapping and traceability purposes.

Sparx Systems provides a free C4 MDG download which provides a C4 shape toolbox which can be used when creating Context, Container, Component and Class (Code level) diagrams.


Using EA to produce C4 Diagrams has it’s benefits.. unfortunately speed is not one of them.

For over 10 years, EA was my modelling tool of choice.. the last couple of years however has seen a shift from me doing EA styled models to doing solution oriented abstractions which live along side the code.

The diagrams, like the code, are managed under the same version control system.

Arguably, this does not obviate the need to have a solution view and a consolidated Enterprise View. But rather introduces the challenges of how can the two easily sit alongside one another.

The C4 abstractions applied at a solution level are equally applicable at an Enterprise Level. The abstractions provide context and assist in navigating the varying levels of detail needing to be communicated across a broad spectrum of stakeholders.

The 20 lines of script on the right rendered on the PlantUML Online Server as:

The same script, by following the steps below creates the C4 diagram within Enterprise Architect:

  • create a new C4 diagram in EA
  • add a note element onto the diagram and paste the desired plantUML script into it
  • right click the Note element and select Run PlantUML Script

The script does a pretty good job of adding the C4 stereotyped elements to the EA project and laying them out on to the diagram.

The script supports multi/nested boundaries and utilises a left to right layout algorithm.

Some known limitations at present..

  • placement of object based on connectors.. eg Rel_Up, Rel_Right etc
  • no dynamic stereotype creating or overriding of colours
  • stereotyped person & connectors is not picking up the UML styling
  • adding url links to objects or connectors
@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
'!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Dynamic.puml
' uncomment the following line and comment the first to use locally
' !include C4_Container.puml
'LAYOUT_TOP_DOWN()
'LAYOUT_AS_SKETCH()
'LAYOUT_WITH_LEGEND()
title C4 Container View via script
AddElementTag("Service", $shape=EightSidedShape(), $bgColor='Lightblue',$legendText='service (eight sided)')
AddRelTag(Alert, $textColor="red", $lineColor="red", $lineStyle = DashedLine(), $legendText="console triggered")
AddRelTag(Synchronous, $textColor="black", $lineColor="dimgrey",$legendText="Synchronous")
AddRelTag(Asynchronous,$textColor="black", $lineColor="dimgrey", $lineStyle = DashedLine(), $legendText="Asynchronous")
Container_Boundary(boundary, boundary){
Container(Container1, "Container one", "Application")
Container_Boundary(boundary2, boundary2){
Container(Container3, "Container three","service", $tags='Service', "description")
ContainerDb_Ext(Container4, "Container four","storage", "desc")
Container(Container5, "Container five","Application", "container 5 description")
Container(Container6, "Container six","Application", "container 6 description")
}
}
ContainerDb_Ext(Container2, "Container two","storage", "desc")
Rel(Container1,Container3,"blah","Synchronous", $tags=Synchronous)
Rel(Container1,Container5,"blah5","Synchronous", $tags=Synchronous)
Rel(Container1,Container6,"blah6","Synchronous", $tags=Synchronous)
Rel_R(Container3,Container4,"blah2","Alert", $tags=Alert)
Rel(Container3,Container2,"","Asynchronous", $tags=Asynchronous)
SHOW_LEGEND()
@enduml

The Create PlantUML script can be used to support the EA to PlantUML round trip.


Refer to https://github.com/gobravedave/Enterprise-Architect for the code and installation instructions.

Leave a comment