Skip to content

Commit 98e768c

Browse files
dkornishevzhendrikse
authored andcommitted
Structurizr (eugenp#1927)
* Structurizr * Structurizr
1 parent fb3c480 commit 98e768c

5 files changed

Lines changed: 237 additions & 0 deletions

File tree

‎structurizr/pom.xml‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.baeldung</groupId>
8+
<artifactId>structurizr</artifactId>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>parent-modules</artifactId>
13+
<version>1.0.0-SNAPSHOT</version>
14+
</parent>
15+
16+
<properties>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.structurizr</groupId>
24+
<artifactId>structurizr-core</artifactId>
25+
<version>1.0.0-RC3</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.structurizr</groupId>
29+
<artifactId>structurizr-spring</artifactId>
30+
<version>1.0.0-RC3</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.structurizr</groupId>
34+
<artifactId>structurizr-client</artifactId>
35+
<version>0.6.0</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-context</artifactId>
40+
<version>4.3.8.RELEASE</version>
41+
</dependency>
42+
</dependencies>
43+
44+
<repositories>
45+
<repository>
46+
<snapshots>
47+
<enabled>false</enabled>
48+
</snapshots>
49+
<id>central</id>
50+
<name>bintray</name>
51+
<url>http://jcenter.bintray.com</url>
52+
</repository>
53+
</repositories>
54+
</project>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package com.baeldung.structurizr;
2+
3+
import java.io.File;
4+
import java.io.StringWriter;
5+
6+
import com.structurizr.Workspace;
7+
import com.structurizr.api.StructurizrClient;
8+
import com.structurizr.api.StructurizrClientException;
9+
import com.structurizr.componentfinder.ComponentFinder;
10+
import com.structurizr.componentfinder.ReferencedTypesSupportingTypesStrategy;
11+
import com.structurizr.componentfinder.SourceCodeComponentFinderStrategy;
12+
import com.structurizr.componentfinder.SpringComponentFinderStrategy;
13+
import com.structurizr.io.WorkspaceWriterException;
14+
import com.structurizr.io.plantuml.PlantUMLWriter;
15+
import com.structurizr.model.Component;
16+
import com.structurizr.model.Container;
17+
import com.structurizr.model.Model;
18+
import com.structurizr.model.Person;
19+
import com.structurizr.model.SoftwareSystem;
20+
import com.structurizr.model.Tags;
21+
import com.structurizr.view.ComponentView;
22+
import com.structurizr.view.ContainerView;
23+
import com.structurizr.view.Routing;
24+
import com.structurizr.view.Shape;
25+
import com.structurizr.view.Styles;
26+
import com.structurizr.view.SystemContextView;
27+
import com.structurizr.view.View;
28+
import com.structurizr.view.ViewSet;
29+
30+
public class StructurizrSimple {
31+
32+
public static final String PAYMENT_TERMINAL = "Payment Terminal";
33+
public static final String FRAUD_DETECTOR = "Fraud Detector";
34+
public static final String SOFTWARE_SYSTEM_VIEW = "SoftwareSystemView";
35+
public static final String CONTAINER_VIEW = "ContainerView";
36+
public static final String COMPONENT_VIEW = "ComponentView";
37+
public static final String JVM2_COMPONENT_VIEW = "JVM2ComponentView";
38+
39+
public static void main(String[] args) throws Exception {
40+
Workspace workspace = getSoftwareSystem();
41+
42+
addContainers(workspace);
43+
addComponents(workspace);
44+
addSpringComponents(workspace);
45+
exportToPlantUml(workspace.getViews().getViewWithKey(SOFTWARE_SYSTEM_VIEW));
46+
exportToPlantUml(workspace.getViews().getViewWithKey(CONTAINER_VIEW));
47+
exportToPlantUml(workspace.getViews().getViewWithKey(COMPONENT_VIEW));
48+
49+
exportToPlantUml(workspace.getViews().getViewWithKey(JVM2_COMPONENT_VIEW));
50+
51+
addStyles(workspace.getViews());
52+
//uploadToExternal(workspace);
53+
}
54+
55+
private static void addSpringComponents(Workspace workspace) throws Exception {
56+
Container jvm2 = workspace.getModel().getSoftwareSystemWithName(PAYMENT_TERMINAL).getContainerWithName("JVM-2");
57+
findComponents(jvm2);
58+
59+
ComponentView view = workspace.getViews().createComponentView(jvm2, JVM2_COMPONENT_VIEW, "JVM2ComponentView");
60+
view.addAllComponents();
61+
62+
}
63+
64+
private static void findComponents(Container jvm) throws Exception {
65+
ComponentFinder componentFinder = new ComponentFinder(
66+
jvm,
67+
"com.baeldung.structurizr",
68+
new SpringComponentFinderStrategy(
69+
new ReferencedTypesSupportingTypesStrategy()
70+
),
71+
new SourceCodeComponentFinderStrategy(new File("."), 150));
72+
73+
componentFinder.findComponents();
74+
}
75+
76+
private static void addComponents(Workspace workspace) {
77+
Model model = workspace.getModel();
78+
79+
SoftwareSystem paymentTerminal = model.getSoftwareSystemWithName(PAYMENT_TERMINAL);
80+
Container jvm1 = paymentTerminal.getContainerWithName("JVM-1");
81+
82+
Component jaxrs = jvm1.addComponent("jaxrs-jersey", "restful webservice implementation", "rest");
83+
Component gemfire = jvm1.addComponent("gemfire", "Clustered Cache Gemfire", "cache");
84+
Component hibernate = jvm1.addComponent("hibernate", "Data Access Layer", "jpa");
85+
86+
jaxrs.uses(gemfire, "");
87+
gemfire.uses(hibernate, "");
88+
89+
ComponentView componentView = workspace.getViews().createComponentView(jvm1, COMPONENT_VIEW, "JVM Components");
90+
componentView.addAllComponents();
91+
}
92+
93+
private static void addContainers(Workspace workspace) {
94+
Model model = workspace.getModel();
95+
96+
SoftwareSystem paymentTerminal = model.getSoftwareSystemWithName(PAYMENT_TERMINAL);
97+
Container f5 = paymentTerminal.addContainer("Payment Load Balancer", "Payment Load Balancer", "F5");
98+
Container jvm1 = paymentTerminal.addContainer("JVM-1", "JVM-1", "Java Virtual Machine");
99+
Container jvm2 = paymentTerminal.addContainer("JVM-2", "JVM-2", "Java Virtual Machine");
100+
Container jvm3 = paymentTerminal.addContainer("JVM-3", "JVM-3", "Java Virtual Machine");
101+
Container oracle = paymentTerminal.addContainer("oracleDB", "Oracle Database", "RDBMS");
102+
103+
f5.uses(jvm1, "route");
104+
f5.uses(jvm2, "route");
105+
f5.uses(jvm3, "route");
106+
107+
jvm1.uses(oracle, "storage");
108+
jvm2.uses(oracle, "storage");
109+
jvm3.uses(oracle, "storage");
110+
111+
ContainerView view = workspace.getViews().createContainerView(paymentTerminal, CONTAINER_VIEW, "Container View");
112+
view.addAllContainers();
113+
}
114+
115+
private static void uploadToExternal(Workspace workspace) throws StructurizrClientException {
116+
StructurizrClient client = new StructurizrClient("e94bc0c9-76ef-41b0-8de7-82afc1010d04", "78d555dd-2a31-487c-952c-50508f1da495");
117+
client.putWorkspace(32961L, workspace);
118+
}
119+
120+
private static void exportToPlantUml(View view) throws WorkspaceWriterException {
121+
StringWriter stringWriter = new StringWriter();
122+
PlantUMLWriter plantUMLWriter = new PlantUMLWriter();
123+
plantUMLWriter.write(view, stringWriter);
124+
System.out.println(stringWriter.toString());
125+
}
126+
127+
private static Workspace getSoftwareSystem() {
128+
Workspace workspace = new Workspace("Payment Gateway", "Payment Gateway");
129+
Model model = workspace.getModel();
130+
131+
Person user = model.addPerson("Merchant", "Merchant");
132+
SoftwareSystem paymentTerminal = model.addSoftwareSystem(PAYMENT_TERMINAL, "Payment Terminal");
133+
user.uses(paymentTerminal, "Makes payment");
134+
SoftwareSystem fraudDetector = model.addSoftwareSystem(FRAUD_DETECTOR, "Fraud Detector");
135+
paymentTerminal.uses(fraudDetector, "Obtains fraud score");
136+
137+
ViewSet viewSet = workspace.getViews();
138+
139+
SystemContextView contextView = viewSet.createSystemContextView(workspace.getModel().getSoftwareSystemWithName(PAYMENT_TERMINAL), SOFTWARE_SYSTEM_VIEW, "Payment Gateway Diagram");
140+
contextView.addAllElements();
141+
142+
return workspace;
143+
}
144+
145+
private static void addStyles(ViewSet viewSet) {
146+
Styles styles = viewSet.getConfiguration().getStyles();
147+
styles.addElementStyle(Tags.ELEMENT).color("#000000");
148+
styles.addElementStyle(Tags.PERSON).background("#ffbf00").shape(Shape.Person);
149+
styles.addElementStyle(Tags.CONTAINER).background("#facc2E");
150+
styles.addRelationshipStyle(Tags.RELATIONSHIP).routing(Routing.Orthogonal);
151+
152+
styles.addRelationshipStyle(Tags.ASYNCHRONOUS).dashed(true);
153+
styles.addRelationshipStyle(Tags.SYNCHRONOUS).dashed(false);
154+
}
155+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.structurizr.spring;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
@Component
6+
public class GenericComponent {
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.structurizr.spring;
2+
3+
import org.springframework.stereotype.Controller;
4+
5+
import javax.annotation.Resource;
6+
7+
@Controller
8+
public class PaymentController {
9+
@Resource
10+
private PaymentRepository repository;
11+
12+
@Resource
13+
private GenericComponent component;
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.structurizr.spring;
2+
3+
import org.springframework.stereotype.Repository;
4+
5+
@Repository
6+
public class PaymentRepository {
7+
}

0 commit comments

Comments
 (0)