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 at GettingStarted.java and the live example workspace at https://structurizr.com/share/25441.
See the java-quickstart project for a quick and simple way to get started with Structurizr for Java.
For more examples, please see structurizr-examples.
The Structurizr for Java binaries are hosted on Maven Central and the dependencies for use with Maven, Ivy, Gradle, etc are as follows.
| Name | Description |
|---|---|
| com.structurizr:structurizr-client:1.0.0-RC5 | The Structurizr API client library. |
The first step is to create a workspace in which the software architecture model will reside.
Workspace workspace = new Workspace("Getting Started", "This is a model of my software system.");
Model model = workspace.getModel();Now let's add some elements to the model to describe a user using a software system.
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 views = workspace.getViews();
SystemContextView contextView = views.createSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram.");
contextView.addAllSoftwareSystems();
contextView.addAllPeople();Elements and relationships can be styled by specifying colours, sizes and shapes.
Styles styles = views.getConfiguration().getStyles();
styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#1168bd").color("#ffffff");
styles.addElementStyle(Tags.PERSON).background("#08427b").color("#ffffff").shape(Shape.Person);Structurizr provides a web API to get and put workspaces.
StructurizrClient structurizrClient = new StructurizrClient("key", "secret");
structurizrClient.putWorkspace(25441, workspace);In order to upload your model to Structurizr using the web API, you'll need to sign up for free to get your own API key and secret. See Workspaces for information about finding your workspace ID, API key and secret.
The result is a diagram like this (once you've dragged the boxes around).
A diagram key is automatically generated based upon the styles in the model. Click the 'i' button on the toolbar (or press the 'i' key) to display the diagram key.

