Structurizr (#1927)

* Structurizr

* Structurizr
This commit is contained in:
Danil Kornishev 2017-05-31 13:39:35 -04:00 committed by Zeger Hendrikse
parent fb3c480fa4
commit 98e768c863
5 changed files with 237 additions and 0 deletions

54
structurizr/pom.xml Normal file
View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>structurizr</artifactId>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.structurizr</groupId>
<artifactId>structurizr-core</artifactId>
<version>1.0.0-RC3</version>
</dependency>
<dependency>
<groupId>com.structurizr</groupId>
<artifactId>structurizr-spring</artifactId>
<version>1.0.0-RC3</version>
</dependency>
<dependency>
<groupId>com.structurizr</groupId>
<artifactId>structurizr-client</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
</project>

View File

@ -0,0 +1,155 @@
package com.baeldung.structurizr;
import java.io.File;
import java.io.StringWriter;
import com.structurizr.Workspace;
import com.structurizr.api.StructurizrClient;
import com.structurizr.api.StructurizrClientException;
import com.structurizr.componentfinder.ComponentFinder;
import com.structurizr.componentfinder.ReferencedTypesSupportingTypesStrategy;
import com.structurizr.componentfinder.SourceCodeComponentFinderStrategy;
import com.structurizr.componentfinder.SpringComponentFinderStrategy;
import com.structurizr.io.WorkspaceWriterException;
import com.structurizr.io.plantuml.PlantUMLWriter;
import com.structurizr.model.Component;
import com.structurizr.model.Container;
import com.structurizr.model.Model;
import com.structurizr.model.Person;
import com.structurizr.model.SoftwareSystem;
import com.structurizr.model.Tags;
import com.structurizr.view.ComponentView;
import com.structurizr.view.ContainerView;
import com.structurizr.view.Routing;
import com.structurizr.view.Shape;
import com.structurizr.view.Styles;
import com.structurizr.view.SystemContextView;
import com.structurizr.view.View;
import com.structurizr.view.ViewSet;
public class StructurizrSimple {
public static final String PAYMENT_TERMINAL = "Payment Terminal";
public static final String FRAUD_DETECTOR = "Fraud Detector";
public static final String SOFTWARE_SYSTEM_VIEW = "SoftwareSystemView";
public static final String CONTAINER_VIEW = "ContainerView";
public static final String COMPONENT_VIEW = "ComponentView";
public static final String JVM2_COMPONENT_VIEW = "JVM2ComponentView";
public static void main(String[] args) throws Exception {
Workspace workspace = getSoftwareSystem();
addContainers(workspace);
addComponents(workspace);
addSpringComponents(workspace);
exportToPlantUml(workspace.getViews().getViewWithKey(SOFTWARE_SYSTEM_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(CONTAINER_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(COMPONENT_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(JVM2_COMPONENT_VIEW));
addStyles(workspace.getViews());
//uploadToExternal(workspace);
}
private static void addSpringComponents(Workspace workspace) throws Exception {
Container jvm2 = workspace.getModel().getSoftwareSystemWithName(PAYMENT_TERMINAL).getContainerWithName("JVM-2");
findComponents(jvm2);
ComponentView view = workspace.getViews().createComponentView(jvm2, JVM2_COMPONENT_VIEW, "JVM2ComponentView");
view.addAllComponents();
}
private static void findComponents(Container jvm) throws Exception {
ComponentFinder componentFinder = new ComponentFinder(
jvm,
"com.baeldung.structurizr",
new SpringComponentFinderStrategy(
new ReferencedTypesSupportingTypesStrategy()
),
new SourceCodeComponentFinderStrategy(new File("."), 150));
componentFinder.findComponents();
}
private static void addComponents(Workspace workspace) {
Model model = workspace.getModel();
SoftwareSystem paymentTerminal = model.getSoftwareSystemWithName(PAYMENT_TERMINAL);
Container jvm1 = paymentTerminal.getContainerWithName("JVM-1");
Component jaxrs = jvm1.addComponent("jaxrs-jersey", "restful webservice implementation", "rest");
Component gemfire = jvm1.addComponent("gemfire", "Clustered Cache Gemfire", "cache");
Component hibernate = jvm1.addComponent("hibernate", "Data Access Layer", "jpa");
jaxrs.uses(gemfire, "");
gemfire.uses(hibernate, "");
ComponentView componentView = workspace.getViews().createComponentView(jvm1, COMPONENT_VIEW, "JVM Components");
componentView.addAllComponents();
}
private static void addContainers(Workspace workspace) {
Model model = workspace.getModel();
SoftwareSystem paymentTerminal = model.getSoftwareSystemWithName(PAYMENT_TERMINAL);
Container f5 = paymentTerminal.addContainer("Payment Load Balancer", "Payment Load Balancer", "F5");
Container jvm1 = paymentTerminal.addContainer("JVM-1", "JVM-1", "Java Virtual Machine");
Container jvm2 = paymentTerminal.addContainer("JVM-2", "JVM-2", "Java Virtual Machine");
Container jvm3 = paymentTerminal.addContainer("JVM-3", "JVM-3", "Java Virtual Machine");
Container oracle = paymentTerminal.addContainer("oracleDB", "Oracle Database", "RDBMS");
f5.uses(jvm1, "route");
f5.uses(jvm2, "route");
f5.uses(jvm3, "route");
jvm1.uses(oracle, "storage");
jvm2.uses(oracle, "storage");
jvm3.uses(oracle, "storage");
ContainerView view = workspace.getViews().createContainerView(paymentTerminal, CONTAINER_VIEW, "Container View");
view.addAllContainers();
}
private static void uploadToExternal(Workspace workspace) throws StructurizrClientException {
StructurizrClient client = new StructurizrClient("e94bc0c9-76ef-41b0-8de7-82afc1010d04", "78d555dd-2a31-487c-952c-50508f1da495");
client.putWorkspace(32961L, workspace);
}
private static void exportToPlantUml(View view) throws WorkspaceWriterException {
StringWriter stringWriter = new StringWriter();
PlantUMLWriter plantUMLWriter = new PlantUMLWriter();
plantUMLWriter.write(view, stringWriter);
System.out.println(stringWriter.toString());
}
private static Workspace getSoftwareSystem() {
Workspace workspace = new Workspace("Payment Gateway", "Payment Gateway");
Model model = workspace.getModel();
Person user = model.addPerson("Merchant", "Merchant");
SoftwareSystem paymentTerminal = model.addSoftwareSystem(PAYMENT_TERMINAL, "Payment Terminal");
user.uses(paymentTerminal, "Makes payment");
SoftwareSystem fraudDetector = model.addSoftwareSystem(FRAUD_DETECTOR, "Fraud Detector");
paymentTerminal.uses(fraudDetector, "Obtains fraud score");
ViewSet viewSet = workspace.getViews();
SystemContextView contextView = viewSet.createSystemContextView(workspace.getModel().getSoftwareSystemWithName(PAYMENT_TERMINAL), SOFTWARE_SYSTEM_VIEW, "Payment Gateway Diagram");
contextView.addAllElements();
return workspace;
}
private static void addStyles(ViewSet viewSet) {
Styles styles = viewSet.getConfiguration().getStyles();
styles.addElementStyle(Tags.ELEMENT).color("#000000");
styles.addElementStyle(Tags.PERSON).background("#ffbf00").shape(Shape.Person);
styles.addElementStyle(Tags.CONTAINER).background("#facc2E");
styles.addRelationshipStyle(Tags.RELATIONSHIP).routing(Routing.Orthogonal);
styles.addRelationshipStyle(Tags.ASYNCHRONOUS).dashed(true);
styles.addRelationshipStyle(Tags.SYNCHRONOUS).dashed(false);
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.structurizr.spring;
import org.springframework.stereotype.Component;
@Component
public class GenericComponent {
}

View File

@ -0,0 +1,14 @@
package com.baeldung.structurizr.spring;
import org.springframework.stereotype.Controller;
import javax.annotation.Resource;
@Controller
public class PaymentController {
@Resource
private PaymentRepository repository;
@Resource
private GenericComponent component;
}

View File

@ -0,0 +1,7 @@
package com.baeldung.structurizr.spring;
import org.springframework.stereotype.Repository;
@Repository
public class PaymentRepository {
}