Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 747bf8b

Browse files
Added some more docs and examples.
1 parent cf3ce5e commit 747bf8b

20 files changed

+578
-5
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,6 @@ _Pvt_Extensions
238238

239239
# Rider project files
240240
.idea
241+
242+
# Structurizr JSON files
243+
Structurizr.Examples/*.json

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ You can see the live workspace at [https://structurizr.com/share/25441](https://
4343
* [Binaries](docs/binaries.md)
4444
* [API Client](docs/api-client.md)
4545
* Diagrams
46+
* [System Context diagram](docs/system-context-diagram.md)
47+
* [Container diagram](docs/container-diagram.md)
48+
* [Component diagram](docs/component-diagram.md)
49+
* [Dynamic diagram](docs/dynamic-diagram.md)
50+
* [Enterprise Context diagram](docs/enterprise-context-diagram.md)
4651
* [Styling elements](docs/styling-elements.md)
4752
* [Styling relationships](docs/styling-relationships.md)
4853
* Documentation

Structurizr.Examples/BigBankPlc.cs

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
using System.IO;
2+
using System.Linq;
3+
using Structurizr.Api;
4+
using Structurizr.Documentation;
5+
using Structurizr.Util;
6+
7+
namespace Structurizr.Examples
8+
{
9+
10+
/// <summary>
11+
/// This is an example workspace to illustrate the key features of Structurizr,
12+
/// based around a fictional Internet Banking System for Big Bank plc.
13+
///
14+
/// The live workspace is available to view at https://structurizr.com/share/36141
15+
/// </summary>
16+
public class BigBankPlc
17+
{
18+
19+
private const long WorkspaceId = 36711;
20+
private const string ApiKey = "62fd36b9-f43e-4cef-a91e-b4ac5c448d7c";
21+
private const string ApiSecret = "ac56a0ac-e289-4451-aee4-f13489b93b1e";
22+
23+
private const string DatabaseTag = "Database";
24+
25+
private static Workspace create(bool usePaidFeatures)
26+
{
27+
Workspace workspace = new Workspace("Big Bank plc", "This is an example workspace to illustrate the key features of Structurizr, based around a fictional online banking system.");
28+
Model model = workspace.Model;
29+
ViewSet views = workspace.Views;
30+
31+
model.Enterprise = new Enterprise("Big Bank plc");
32+
33+
// people and software systems
34+
Person customer = model.AddPerson(Location.External, "Customer", "A customer of the bank.");
35+
36+
SoftwareSystem internetBankingSystem = model.AddSoftwareSystem(Location.Internal, "Internet Banking System", "Allows customers to view information about their bank accounts and make payments.");
37+
customer.Uses(internetBankingSystem, "Uses");
38+
39+
SoftwareSystem mainframeBankingSystem = model.AddSoftwareSystem(Location.Internal, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.");
40+
internetBankingSystem.Uses(mainframeBankingSystem, "Uses");
41+
42+
SoftwareSystem atm = model.AddSoftwareSystem(Location.Internal, "ATM", "Allows customers to withdraw cash.");
43+
atm.Uses(mainframeBankingSystem, "Uses");
44+
customer.Uses(atm, "Withdraws cash using");
45+
46+
Person bankStaff = model.AddPerson(Location.Internal, "Bank Staff", "Staff within the bank.");
47+
bankStaff.Uses(mainframeBankingSystem, "Uses");
48+
49+
// containers
50+
Container webApplication = internetBankingSystem.AddContainer("Web Application", "Provides all of the Internet banking functionality to customers.", "Java and Spring MVC");
51+
Container database = internetBankingSystem.AddContainer("Database", "Stores interesting data.", "Relational Database Schema");
52+
database.AddTags(DatabaseTag);
53+
54+
customer.Uses(webApplication, "HTTPS");
55+
webApplication.Uses(database, "Reads from and writes to", "JDBC");
56+
webApplication.Uses(mainframeBankingSystem, "Uses", "XML/HTTPS");
57+
58+
// components
59+
// - for a real-world software system, you would probably want to extract the components using
60+
// - static analysis/reflection rather than manually specifying them all
61+
Component homePageController = webApplication.AddComponent("Home Page Controller", "Serves up the home page.", "Spring MVC Controller");
62+
Component signinController = webApplication.AddComponent("Sign In Controller", "Allows users to sign in to the Internet Banking System.", "Spring MVC Controller");
63+
Component accountsSummaryController = webApplication.AddComponent("Accounts Summary Controller", "Provides customers with an summary of their bank accounts.", "Spring MVC Controller");
64+
Component securityComponent = webApplication.AddComponent("Security Component", "Provides functionality related to signing in, changing passwords, etc.", "Spring Bean");
65+
Component mainframeBankingSystemFacade = webApplication.AddComponent("Mainframe Banking System Facade", "A facade onto the mainframe banking system.", "Spring Bean");
66+
67+
webApplication.Components.Where(c => "Spring MVC Controller".Equals(c.Technology)).ToList().ForEach(c => customer.Uses(c, "Uses", "HTTPS"));
68+
signinController.Uses(securityComponent, "Uses");
69+
accountsSummaryController.Uses(mainframeBankingSystemFacade, "Uses");
70+
securityComponent.Uses(database, "Reads from and writes to", "JDBC");
71+
mainframeBankingSystemFacade.Uses(mainframeBankingSystem, "Uses", "XML/HTTPS");
72+
73+
// deployment nodes and container instances
74+
// todo
75+
// DeploymentNode developerLaptop = model.AddDeploymentNode("Developer Laptop", "A developer laptop.", "Windows 7 or 10");
76+
// developerLaptop.AddDeploymentNode("Docker Container - Web Server", "A Docker container.", "Docker")
77+
// .AddDeploymentNode("Apache Tomcat", "An open source Java EE web server.", "Apache Tomcat 8.x", 1, MapUtils.Create("Xmx=512M", "Xms=1024M", "Java Version=8"))
78+
// .Add(webApplication);
79+
//
80+
// developerLaptop.AddDeploymentNode("Docker Container - Database Server", "A Docker container.", "Docker")
81+
// .AddDeploymentNode("Database Server", "A development database.", "Oracle 12c")
82+
// .Add(database);
83+
//
84+
// DeploymentNode liveWebServer = model.AddDeploymentNode("bigbank-web***", "A web server residing in the web server farm, accessed via F5 BIG-IP LTMs.", "Ubuntu 16.04 LTS", 8, MapUtils.Create("Location=London"));
85+
// liveWebServer.AddDeploymentNode("Apache Tomcat", "An open source Java EE web server.", "Apache Tomcat 8.x", 1, MapUtils.Create("Xmx=512M", "Xms=1024M", "Java Version=8"))
86+
// .Add(webApplication);
87+
//
88+
// DeploymentNode primaryDatabaseServer = model.AddDeploymentNode("bigbank-db01", "The primary database server.", "Ubuntu 16.04 LTS", 1, MapUtils.Create("Location=London"))
89+
// .AddDeploymentNode("Oracle - Primary", "The primary, live database server.", "Oracle 12c");
90+
// primaryDatabaseServer.Add(database);
91+
//
92+
// DeploymentNode secondaryDatabaseServer = model.AddDeploymentNode("bigbank-db02", "The secondary database server.", "Ubuntu 16.04 LTS", 1, MapUtils.Create("Location=Reading"))
93+
// .AddDeploymentNode("Oracle - Secondary", "A secondary, standby database server, used for failover purposes only.", "Oracle 12c");
94+
// ContainerInstance secondaryDatabase = secondaryDatabaseServer.Add(database);
95+
//
96+
// model.getRelationships().stream().filter(r -> r.getDestination().equals(secondaryDatabase)).forEach(r -> r.AddTags("Failover"));
97+
// Relationship dataReplicationRelationship = primaryDatabaseServer.Uses(secondaryDatabaseServer, "Replicates data to", "");
98+
// secondaryDatabase.AddTags("Failover");
99+
100+
// views/diagrams
101+
EnterpriseContextView enterpriseContextView = views.CreateEnterpriseContextView("EnterpriseContext", "The system context diagram for the Internet Banking System.");
102+
enterpriseContextView.AddAllElements();
103+
enterpriseContextView.PaperSize = PaperSize.A5_Landscape;
104+
105+
SystemContextView systemContextView = views.CreateSystemContextView(internetBankingSystem, "SystemContext", "The system context diagram for the Internet Banking System.");
106+
systemContextView.AddNearestNeighbours(internetBankingSystem);
107+
systemContextView.PaperSize = PaperSize.A5_Landscape;
108+
109+
ContainerView containerView = views.CreateContainerView(internetBankingSystem, "Containers", "The container diagram for the Internet Banking System.");
110+
containerView.Add(customer);
111+
containerView.AddAllContainers();
112+
containerView.Add(mainframeBankingSystem);
113+
containerView.PaperSize = PaperSize.A5_Landscape;
114+
115+
ComponentView componentView = views.CreateComponentView(webApplication, "Components", "The components diagram for the Web Application");
116+
componentView.AddAllContainers();
117+
componentView.AddAllComponents();
118+
componentView.Add(customer);
119+
componentView.Add(mainframeBankingSystem);
120+
componentView.PaperSize = PaperSize.A5_Landscape;
121+
122+
if (usePaidFeatures) {
123+
// dynamic diagrams, deployment diagrams and corporate branding are not available with the Free Plan
124+
DynamicView dynamicView = views.CreateDynamicView(webApplication, "SignIn", "Summarises how the sign in feature works.");
125+
dynamicView.Add(customer, "Requests /signin from", signinController);
126+
dynamicView.Add(customer, "Submits credentials to", signinController);
127+
dynamicView.Add(signinController, "Calls isAuthenticated() on", securityComponent);
128+
dynamicView.Add(securityComponent, "select * from users u where username = ?", database);
129+
dynamicView.PaperSize = PaperSize.A5_Landscape;
130+
131+
// todo
132+
// DeploymentView developmentDeploymentView = views.CreateDeploymentView(internetBankingSystem, "DevelopmentDeployment", "An example development deployment scenario for the Internet Banking System.");
133+
// developmentDeploymentView.Add(developerLaptop);
134+
// developmentDeploymentView.setPaperSize(PaperSize.A5_Landscape);
135+
//
136+
// DeploymentView liveDeploymentView = views.CreateDeploymentView(internetBankingSystem, "LiveDeployment", "An example live deployment scenario for the Internet Banking System.");
137+
// liveDeploymentView.Add(liveWebServer);
138+
// liveDeploymentView.Add(primaryDatabaseServer);
139+
// liveDeploymentView.Add(secondaryDatabaseServer);
140+
// liveDeploymentView.Add(dataReplicationRelationship);
141+
// liveDeploymentView.setPaperSize(PaperSize.A5_Landscape);
142+
143+
Branding branding = views.Configuration.Branding;
144+
branding.Logo = ImageUtils.GetImageAsDataUri(new FileInfo("structurizr-logo.png"));
145+
}
146+
147+
// colours, shapes and other diagram styling
148+
Styles styles = views.Configuration.Styles;
149+
styles.Add(new ElementStyle(Tags.Element) { Color = "#ffffff" });
150+
styles.Add(new ElementStyle(Tags.SoftwareSystem) { Background = "#1168bd" });
151+
styles.Add(new ElementStyle(Tags.Container) { Background = "#438dd5" });
152+
styles.Add(new ElementStyle(Tags.Component) { Background = "#85bbf0", Color = "#000000" });
153+
styles.Add(new ElementStyle(Tags.Person) { Background = "#08427b", Shape = Shape.Person });
154+
styles.Add(new ElementStyle(DatabaseTag) { Shape = Shape.Cylinder });
155+
styles.Add(new ElementStyle("Failover") { Opacity = 25 });
156+
styles.Add(new RelationshipStyle("Failover") {Opacity = 25, Position = 70});
157+
158+
// documentation
159+
// - usually the documentation would be included from separate Markdown/AsciiDoc files, but this is just an example
160+
StructurizrDocumentation documentation = new StructurizrDocumentation(workspace);
161+
documentation.AddContextSection(internetBankingSystem, Format.Markdown,
162+
"Here is some context about the Internet Banking System...\n" +
163+
"![](embed:EnterpriseContext)\n" +
164+
"![](embed:SystemContext)\n" +
165+
"### Internet Banking System\n...\n" +
166+
"### Mainframe Banking System\n...\n");
167+
documentation.AddContainersSection(internetBankingSystem, Format.Markdown,
168+
"Here is some information about the containers within the Internet Banking System...\n" +
169+
"![](embed:Containers)\n" +
170+
"### Web Application\n...\n" +
171+
"### Database\n...\n");
172+
documentation.AddComponentsSection(webApplication, Format.Markdown,
173+
"Here is some information about the Web Application...\n" +
174+
"![](embed:Components)\n" +
175+
"### Sign in process\n" +
176+
"Here is some information about the Sign In Controller, including how the sign in process works...\n" +
177+
"![](embed:SignIn)");
178+
documentation.AddDevelopmentEnvironmentSection(internetBankingSystem, Format.AsciiDoc,
179+
"Here is some information about how to set up a development environment for the Internet Banking System...\n" +
180+
"image::embed:DevelopmentDeployment[]");
181+
documentation.AddDeploymentSection(internetBankingSystem, Format.AsciiDoc,
182+
"Here is some information about the live deployment environment for the Internet Banking System...\n" +
183+
"image::embed:LiveDeployment[]");
184+
185+
return workspace;
186+
}
187+
188+
static void Main()
189+
{
190+
StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);
191+
structurizrClient.PutWorkspace(WorkspaceId, create(true));
192+
}
193+
194+
}
195+
196+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using Structurizr.Api;
2+
3+
namespace Structurizr.Examples
4+
{
5+
6+
/// <summary>
7+
/// A simple example of what a microservices architecture might look like. This workspace also
8+
/// includes a dynamic view that demonstrates parallel sequences of events.
9+
///
10+
/// The live version of the diagrams can be found at https://structurizr.com/public/4241
11+
/// </summary>
12+
public class MicroservicesExample
13+
{
14+
15+
private const long WorkspaceId = 4241;
16+
private const string ApiKey = "key";
17+
private const string ApiSecret = "secret";
18+
19+
private const string MicroserviceTag = "Microservice";
20+
private const string MessageBusTag = "Message Bus";
21+
private const string DataStoreTag = "Database";
22+
23+
static void Main()
24+
{
25+
Workspace workspace = new Workspace("Microservices example", "An example of a microservices architecture, which includes asynchronous and parallel behaviour.");
26+
Model model = workspace.Model;
27+
28+
SoftwareSystem mySoftwareSystem = model.AddSoftwareSystem("Customer Information System", "Stores information ");
29+
Person customer = model.AddPerson("Customer", "A customer");
30+
Container customerApplication = mySoftwareSystem.AddContainer("Customer Application", "Allows customers to manage their profile.", "Angular");
31+
32+
Container customerService = mySoftwareSystem.AddContainer("Customer Service", "The point of access for customer information.", "Java and Spring Boot");
33+
customerService.AddTags(MicroserviceTag);
34+
Container customerDatabase = mySoftwareSystem.AddContainer("Customer Database", "Stores customer information.", "Oracle 12c");
35+
customerDatabase.AddTags(DataStoreTag);
36+
37+
Container reportingService = mySoftwareSystem.AddContainer("Reporting Service", "Creates normalised data for reporting purposes.", "Ruby");
38+
reportingService.AddTags(MicroserviceTag);
39+
Container reportingDatabase = mySoftwareSystem.AddContainer("Reporting Database", "Stores a normalised version of all business data for ad hoc reporting purposes.", "MySQL");
40+
reportingDatabase.AddTags(DataStoreTag);
41+
42+
Container auditService = mySoftwareSystem.AddContainer("Audit Service", "Provides organisation-wide auditing facilities.", "C# .NET");
43+
auditService.AddTags(MicroserviceTag);
44+
Container auditStore = mySoftwareSystem.AddContainer("Audit Store", "Stores information about events that have happened.", "Event Store");
45+
auditStore.AddTags(DataStoreTag);
46+
47+
Container messageBus = mySoftwareSystem.AddContainer("Message Bus", "Transport for business events.", "RabbitMQ");
48+
messageBus.AddTags(MessageBusTag);
49+
50+
customer.Uses(customerApplication, "Uses");
51+
customerApplication.Uses(customerService, "Updates customer information using", "JSON/HTTPS", InteractionStyle.Synchronous);
52+
customerService.Uses(messageBus, "Sends customer update events to", "", InteractionStyle.Asynchronous);
53+
customerService.Uses(customerDatabase, "Stores data in", "JDBC", InteractionStyle.Synchronous);
54+
customerService.Uses(customerApplication, "Sends events to", "WebSocket", InteractionStyle.Asynchronous);
55+
messageBus.Uses(reportingService, "Sends customer update events to", "", InteractionStyle.Asynchronous);
56+
messageBus.Uses(auditService, "Sends customer update events to", "", InteractionStyle.Asynchronous);
57+
reportingService.Uses(reportingDatabase, "Stores data in", "", InteractionStyle.Synchronous);
58+
auditService.Uses(auditStore, "Stores events in", "", InteractionStyle.Synchronous);
59+
60+
ViewSet views = workspace.Views;
61+
62+
ContainerView containerView = views.CreateContainerView(mySoftwareSystem, "Containers", null);
63+
containerView.AddAllElements();
64+
65+
DynamicView dynamicView = views.CreateDynamicView(mySoftwareSystem, "CustomerUpdateEvent", "This diagram shows what happens when a customer updates their details.");
66+
dynamicView.Add(customer, customerApplication);
67+
dynamicView.Add(customerApplication, customerService);
68+
69+
dynamicView.Add(customerService, customerDatabase);
70+
dynamicView.Add(customerService, messageBus);
71+
72+
dynamicView.StartParallelSequence();
73+
dynamicView.Add(messageBus, reportingService);
74+
dynamicView.Add(reportingService, reportingDatabase);
75+
dynamicView.EndParallelSequence();
76+
77+
dynamicView.StartParallelSequence();
78+
dynamicView.Add(messageBus, auditService);
79+
dynamicView.Add(auditService, auditStore);
80+
dynamicView.EndParallelSequence();
81+
82+
dynamicView.Add(customerService, "Confirms update to", customerApplication);
83+
84+
Styles styles = views.Configuration.Styles;
85+
styles.Add(new ElementStyle(Tags.Element) { Color = "#000000" });
86+
styles.Add(new ElementStyle(Tags.Person) { Background = "#ffbf00", Shape = Shape.Person });
87+
styles.Add(new ElementStyle(Tags.Container) { Background = "#facc2E" });
88+
styles.Add(new ElementStyle(MessageBusTag) {Width = 1600, Shape = Shape.Pipe});
89+
styles.Add(new ElementStyle(MicroserviceTag) { Shape = Shape.Hexagon});
90+
styles.Add(new ElementStyle(DataStoreTag) { Background = "#f5da81", Shape = Shape.Cylinder });
91+
styles.Add(new RelationshipStyle(Tags.Relationship) { Routing = Routing.Orthogonal });
92+
93+
styles.Add(new RelationshipStyle(Tags.Asynchronous) { Dashed = true });
94+
styles.Add(new RelationshipStyle(Tags.Synchronous) { Dashed = false });
95+
96+
StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);
97+
structurizrClient.PutWorkspace(WorkspaceId, workspace);
98+
}
99+
100+
}
101+
102+
}

0 commit comments

Comments
 (0)