Search in sources :

Example 6 with ComponentView

use of com.structurizr.view.ComponentView in project tutorials by eugenp.

the class StructurizrSimple method addSpringComponents.

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();
}
Also used : Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView)

Example 7 with ComponentView

use of com.structurizr.view.ComponentView in project tutorials by eugenp.

the class StructurizrSimple method addComponents.

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();
}
Also used : Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) Component(com.structurizr.model.Component)

Example 8 with ComponentView

use of com.structurizr.view.ComponentView in project agile-architecture-documentation-system by Riduidel.

the class Architecture method describeArchitecture.

/**
 * Creates the workspace object and add in it both the architecture components
 * AND the views used to display it
 *
 * @return
 */
public Workspace describeArchitecture() {
    // tag::structurizr-example-context[]
    String name = "agile-architecture-documentation-system";
    Workspace workspace = new Workspace(name, "This is the model of the agile architecture documentation system.");
    Model model = workspace.getModel();
    Person architect = model.addPerson("Architect", "The architect as team scribe is the writer of this kind of documentation.");
    Person stakeholder = model.addPerson("Stakeholder", "All project stakeholders are readers of this kind of documentation.");
    SoftwareSystem agileArchitecture = model.addSoftwareSystem(AGILE_ARCHITECTURE_DOCUMENTATION, "This software system generates the documentation.");
    agileArchitecture.addProperty(ModelElementKeys.ISSUE_MANAGER, "https://github.com/Riduidel/agile-architecture-documentation-system");
    agileArchitecture.addProperty(ADRExtractor.AGILE_ARCHITECTURE_TICKETS_PROJECT, name);
    agileArchitecture.addProperty(ADRExtractor.AGILE_ARCHITECTURE_TICKETS_ADR_LABEL, "decision");
    architect.uses(agileArchitecture, "Writes");
    stakeholder.uses(agileArchitecture, "Read");
    // end::structurizr-example-context[]
    // ///////////////////////////////////////////////////////////////////////////////////////
    // tag::structurizr-example-containers[]
    Container archetype = agileArchitecture.addContainer(CONTAINERS_ARCHETYPE, "Archetype generating a valid build", "maven archetype");
    archetype.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("archetype/pom.xml"));
    architect.uses(archetype, "Bootstrap a valid project");
    Container maven = agileArchitecture.addContainer(CONTAINERS_MAVEN, "Maven build tool", "Maven build tool");
    architect.uses(maven, "Generates documentation");
    Container base = agileArchitecture.addContainer(CONTAINERS_BASE, "Architecture base", "Java executable");
    base.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("base/pom.xml"));
    base.addProperty(ModelElementKeys.SCM_PATH, base.getName());
    // end::structurizr-example-containers[]
    // tag::structurizr-example-components[]
    ComponentFinder componentFinder = new ComponentFinder(base, // new SourceCodeComponentFinderStrategy(new File("../base/src/main/java")),
    ArchitectureModelProvider.class.getPackageName(), new StructurizrAnnotationsComponentFinderStrategy());
    // end::structurizr-example-components[]
    if (getClass().getClassLoader() instanceof URLClassLoader) {
        componentFinder.setUrlClassLoader((URLClassLoader) getClass().getClassLoader());
    }
    try {
        componentFinder.findComponents();
    } catch (Exception e) {
        throw new RuntimeException("Unable to locate components in ", e);
    }
    // model.addImplicitRelationships();
    // Damn, structurizr-annotations doesn't understand CDI. Let's supplement it!
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("DocumentsCollector"), "Collects documents in source folder");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("SCMLinkGenerator"), "Generates links to SCM sources");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("SCMReadmeReader"), "Includes elements readme when they exist");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("ImplicitIncludeManager"), "Generates includes for all enhancers");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("GraphEmitter"), "Generates diagrams in PlantUML format");
    maven.uses(base.getComponentWithName("ArchitectureDocumentationBuilder"), "Invokes that Java executable during maven build");
    Component gitHub = base.addComponent("github-scm-handler", "GitHub SCM Handler", "java");
    gitHub.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("github-scm-handler/pom.xml"));
    gitHub.addProperty(ModelElementKeys.SCM_PATH, gitHub.getName());
    base.getComponentWithName("SCMLinkGenerator").uses(gitHub, "Get project source link");
    base.getComponentWithName("SCMReadmeReader").uses(gitHub, "Get project readme");
    Component gitLab = base.addComponent("gitlab-scm-handler", "GitLab SCM Handler", "java");
    gitLab.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("gitlab-scm-handler/pom.xml"));
    gitLab.addProperty(ModelElementKeys.SCM_PATH, gitLab.getName());
    base.getComponentWithName("SCMLinkGenerator").uses(gitLab, "Get project source link");
    base.getComponentWithName("SCMReadmeReader").uses(gitLab, "Get project readme");
    Component adrTicketsExtractor = base.addComponent("adr-tickets-extractor", "enhanced by maven");
    adrTicketsExtractor.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("adr-tickets-extractor/pom.xml"));
    adrTicketsExtractor.addProperty(ModelElementKeys.SCM_PATH, adrTicketsExtractor.getName());
    adrTicketsExtractor.uses(gitLab, "Read tickets from Gitlab if configured so");
    adrTicketsExtractor.uses(gitHub, "Read tickets from GitHub if configured so");
    base.getComponentWithName("ArchitectureEnhancer").uses(adrTicketsExtractor, "Produces ADR reporting");
    Component cdiConfigExtension = base.addComponent("cdi-config-extension", "CDI Config extensions", "java");
    cdiConfigExtension.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("cdi-config-extension/pom.xml"));
    cdiConfigExtension.addProperty(ModelElementKeys.SCM_PATH, cdiConfigExtension.getName());
    base.getComponentWithName("ArchitectureDocumentationBuilder").uses(cdiConfigExtension, "Eases out some CDI code");
    Component mavenEnhancer = base.addComponent("maven-metadata-inferer", "Enhanced by Maven");
    cdiConfigExtension.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("maven-metadata-inferer/pom.xml"));
    cdiConfigExtension.addProperty(ModelElementKeys.SCM_PATH, mavenEnhancer.getName());
    base.getComponentWithName("ArchitectureDocumentationBuilder").uses(mavenEnhancer, "Infer most of element details from Maven infos");
    Container asciidoc = agileArchitecture.addContainer("asciidoc", "Asciidoc tooling", "Maven plugin");
    maven.uses(base, "Generates diagrams and asciidoc includes");
    maven.uses(asciidoc, "Generates documentation as usable text in HTML/PDF/...");
    // ///////////////////////////////////////////////////////////////////////////////////////
    // tag::structurizr-example-views[]
    ViewSet views = workspace.getViews();
    SystemContextView contextView = views.createSystemContextView(agileArchitecture, "SystemContext", "Illustration of agile-architecture-documentation usage");
    contextView.addAllSoftwareSystems();
    contextView.addAllPeople();
    ContainerView agileArchitectureContainers = views.createContainerView(agileArchitecture, "agile.architecture.containers", "Agile architecture containers");
    agileArchitectureContainers.addAllContainersAndInfluencers();
    ComponentView agileArchitectureBaseComponents = views.createComponentView(base, "agile.architecture.base.components", "Agile architecture base components view");
    agileArchitectureBaseComponents.addAllComponents();
    // styles.addElementStyle(Tags.PERSON).background("#08427b").color("#ffffff").shape(Shape.Person);
    return workspace;
}
Also used : ArchitectureModelProvider(org.ndx.agile.architecture.base.ArchitectureModelProvider) ComponentFinder(com.structurizr.analysis.ComponentFinder) StructurizrAnnotationsComponentFinderStrategy(com.structurizr.analysis.StructurizrAnnotationsComponentFinderStrategy) Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) ViewSet(com.structurizr.view.ViewSet) SystemContextView(com.structurizr.view.SystemContextView) URLClassLoader(java.net.URLClassLoader) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) ContainerView(com.structurizr.view.ContainerView) Component(com.structurizr.model.Component) Person(com.structurizr.model.Person) Workspace(com.structurizr.Workspace)

Example 9 with ComponentView

use of com.structurizr.view.ComponentView in project agile-architecture-documentation-system by Riduidel.

the class GraphEmitter method endVisit.

/**
 * At view end visit, we selectively remove the layout information if it is layout with legend
 */
@Override
public void endVisit(View diagram, OutputBuilder builder) {
    if (diagram instanceof ComponentView || diagram instanceof ContainerView) {
        Path path = new File(destination, diagram.getKey() + ".plantuml").toPath();
        try {
            String diagramText = Files.readString(path);
            if (diagramText.contains(C4PlantUMLWriter.Layout.LAYOUT_WITH_LEGEND.name())) {
                diagramText = diagramText.replace(C4PlantUMLWriter.Layout.LAYOUT_WITH_LEGEND.name() + "()", "");
                Files.writeString(path, diagramText);
            }
        } catch (IOException e) {
        // Nothing to do
        }
    }
}
Also used : Path(java.nio.file.Path) ComponentView(com.structurizr.view.ComponentView) ContainerView(com.structurizr.view.ContainerView) IOException(java.io.IOException) File(java.io.File)

Example 10 with ComponentView

use of com.structurizr.view.ComponentView in project dsl by structurizr.

the class StaticViewContentParserTests method test_parseInclude_IncludesTheMostAbstractElementWhenEfferentCouplingExpressionUsed.

@Test
void test_parseInclude_IncludesTheMostAbstractElementWhenEfferentCouplingExpressionUsed() {
    SoftwareSystem ss1 = model.addSoftwareSystem("Software System 1");
    Container c1 = ss1.addContainer("Container 1");
    Component cc1 = c1.addComponent("Component 1");
    SoftwareSystem ss2 = model.addSoftwareSystem("Software System 2");
    Container c2 = ss2.addContainer("Container 2");
    Component cc2 = c2.addComponent("Component 2");
    model.setImpliedRelationshipsStrategy(new CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategy());
    cc1.uses(cc2, "Uses");
    ComponentView view = views.createComponentView(c1, "key", "Description");
    ComponentViewDslContext context = new ComponentViewDslContext(view);
    context.setWorkspace(workspace);
    IdentifiersRegister elements = new IdentifiersRegister();
    elements.register("cc1", cc1);
    context.setIdentifierRegister(elements);
    parser.parseInclude(context, tokens("include", "cc1->"));
    assertEquals(2, view.getElements().size());
    assertTrue(view.isElementInView(cc1));
    // this is the software system, not the component
    assertTrue(view.isElementInView(ss2));
}
Also used : ComponentView(com.structurizr.view.ComponentView) Test(org.junit.jupiter.api.Test)

Aggregations

ComponentView (com.structurizr.view.ComponentView)11 Container (com.structurizr.model.Container)5 SoftwareSystem (com.structurizr.model.SoftwareSystem)4 ContainerView (com.structurizr.view.ContainerView)4 Workspace (com.structurizr.Workspace)3 Component (com.structurizr.model.Component)3 Model (com.structurizr.model.Model)3 SystemContextView (com.structurizr.view.SystemContextView)3 Element (com.structurizr.model.Element)2 View (com.structurizr.view.View)2 ViewSet (com.structurizr.view.ViewSet)2 File (java.io.File)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ComponentFinder (com.structurizr.analysis.ComponentFinder)1 StructurizrAnnotationsComponentFinderStrategy (com.structurizr.analysis.StructurizrAnnotationsComponentFinderStrategy)1 StructurizrDslParser (com.structurizr.dsl.StructurizrDslParser)1 StructurizrDslParserException (com.structurizr.dsl.StructurizrDslParserException)1 Diagram (com.structurizr.export.Diagram)1 StructurizrPlantUMLExporter (com.structurizr.export.plantuml.StructurizrPlantUMLExporter)1