This GitHub repository is a Java library to create software architecture models that are compatible with Structurizr, a SaaS to create web-based software architecture diagrams. It's an implementation of the "C4 software architecture model", as described in Simon Brown's FREE The Art of Visualising Software Architecture book. In a nutshell:
- Create a software architecture model using Java code, either manually or by extracting information from an existing codebase.
- Upload the model (as a JSON document) to Structurizr using the web API.
- Visualise and share the resulting software architecture diagrams (example).
- Building from source
- Binaries
- Getting started
- API Client
- Styling elements
- Styling relationships
- Hiding relationships
- Extracting components from your codebase
- The Spring PetClinic example
- Client-side encryption
- Graphviz and DOT
To build "Structurizr for Java" from the sources (you'll need Java 8)...
git clone https://github.com/structurizr/java.git
cd java
./gradlew build
Note: For now, if you want to build the structurizr-dot library you'll also need to clone and install dot-diagram into your local Maven repository:
git clone https://github.com/cyriux/dot-diagram.git
cd dot-diagram/dot-diagram/
mvn install -DskipTests=true
The -DskipTests=true
is needed as the unit test are failing in the dot-diagram
project.
If necessary, after building, you can install "Structurizr for Java" into your local Maven repo using:
./gradlew publishToMavenLocal
The "Structurizr for Java" binaries are hosted on Bintray and the JCenter repository. The dependencies for use with Maven, Ivy, Gradle, etc are as follows.
Name | Description |
---|---|
com.structurizr:structurizr-core:0.7.0 | The core library that can used to create and upload models to Structurizr. |
com.structurizr:structurizr-spring:0.7.0 | The Spring integration to extract classes annotated @Controller, @Service and @Repository for identification as components. |
com.structurizr:structurizr-annotations:0.7.0 | Annotations to add software architecture hints into your own code. |
Here is a quick overview of how to get started with Structurizr for Java so that you can create a software architecture model as code. You can find the code here. For more examples, please see structurizr-examples.
If you want a quick start, simply clone the Structurizr for Java starter project.
The Structurizr for Java binaries are hosted on Bintray and the JCenter repository. The dependencies for use with Maven, Ivy, Gradle, etc are as follows.
Name | Description |
---|---|
com.structurizr:structurizr-core:0.7.0 | The core library that can used to create models and upload models to Structurizr. |
com.structurizr:structurizr-client:0.7.0 | The structurizr.com API client for Java for uploading models. |
Please note that you will need to add "http://jcenter.bintray.com" as an additional repository to your build configuration.
The first step is to create a workspace in which the software architecture model will reside.
Workspace workspace = new Workspace("My model", "This is a model of my software system.");
Model model = workspace.getModel();
Now let's add some elements to the model.
Person user = model.addPerson("User", "A user of my software system.");
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "My software system.");
user.uses(softwareSystem, "Uses");
With the model created, we need to create some views with which to visualise it.
ViewSet viewSet = workspace.getViews();
SystemContextView contextView = viewSet.createContextView(softwareSystem);
contextView.addAllSoftwareSystems();
contextView.addAllPeople();
Elements and relationships can be styled by specifying colours, sizes and shapes.
Styles styles = viewSet.getConfiguration().getStyles();
styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#a4b7c9").color("#000000");
styles.addElementStyle(Tags.PERSON).background("#728da5").color("#ffffff");
structurizr.com provides an API to get and put workspaces directly from/to your Structurizr account as follows.
StructurizrClient structurizrClient = new StructurizrClient("key", "secret");
structurizrClient.putWorkspace(1234, workspace);
In order to upload your model to Structurizr using the web API, you'll need to sign up to get your own API key and secret.
The result is a diagram like this (once you've dragged the boxes around).
Once you have uploaded your model to Structurizr and organised the boxes on the diagrams, you'll probably want to retain the diagram layout next time you upload the model. To do this, you can use the mergeWorkspace
helper method on the StructurizrClient
.
structurizrClient.mergeWorkspace(1234, workspace);
This will get the current version of the workspace via the API, merge the diagram layout information, and then upload the new version via the API. See API Client for more details.