This GitHub repository is a .NET library to create software architecture models that are compatible with Structurizr, a SaaS to create web-based software architecture diagrams. In summary:
- Create a software architecture model using .NET 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).
Here is a quick overview of how to get started with "Structurizr for .NET" so that you can create a software architecture model as code. You can find the code here. For more examples, please see the Examples project.
The "Structurizr for .NET" assemblies are available on NuGet as follows:
Name | Description |
---|---|
Structurizr.Core | The core library that can used to create and upload software architecture models to Structurizr. |
To install Structurizr.Core, use the following command in the NuGet Package Manager Console:
Install-Package Structurizr.Core
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 model = workspace.Model;
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.Views;
SystemContextView contextView = viewSet.CreateSystemContextView(softwareSystem, "context", "A simple example of a System Context diagram.");
contextView.AddAllSoftwareSystems();
contextView.AddAllPeople();
Elements and relationships can be styled by specifying colours, sizes and shapes.
Styles styles = viewSet.Configuration.Styles;
styles.Add(new ElementStyle(Tags.SoftwareSystem) { Background = "#1168bd", Color = "#ffffff" });
styles.Add(new ElementStyle(Tags.Person) { Background = "#08427b", 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 and create your own workspace. 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).
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.