Skip to content

Instantly share code, notes, and snippets.

@simonbrowndotje
Last active August 29, 2015 14:03
Show Gist options
  • Save simonbrowndotje/aca3c0a30020edb36ed0 to your computer and use it in GitHub Desktop.
Save simonbrowndotje/aca3c0a30020edb36ed0 to your computer and use it in GitHub Desktop.
This is a C4 representation of the Spring PetClinic sample app (https://github.com/spring-projects/spring-petclinic/).
package com.structurizr.example;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.structurizr.componentfinder.ComponentFinder;
import com.structurizr.componentfinder.SpringComponentFinderStrategy;
import com.structurizr.model.*;
import com.structurizr.view.ComponentView;
import com.structurizr.view.ContainerView;
import com.structurizr.view.ContextView;
/**
* This is a C4 representation of the Spring PetClinic sample app (https://github.com/spring-projects/spring-petclinic/).
*/
public class SpringPetClinic {
public static void main(String[] args) throws Exception {
Model model = new Model();
// create the basic model (the stuff we can't get from the code)
SoftwareSystem springPetClinic = model.addSoftwareSystem(Location.Internal, "Spring PetClinic", "");
Person user = model.addPerson(Location.External, "User", "");
user.uses(springPetClinic, "Uses");
Container webApplication = springPetClinic.addContainer("Web Application", "", "Apache Tomcat 7.x");
Container relationalDatabase = springPetClinic.addContainer("Relational Database", "", "HSQLDB");
user.uses(webApplication, "Uses");
webApplication.uses(relationalDatabase, "Reads from and writes to");
// and now automatically find all Spring @Controller, @Component, @Service and @Repository components
ComponentFinder componentFinder = new ComponentFinder(webApplication, "org.springframework.samples.petclinic",
new SpringComponentFinderStrategy());
componentFinder.findComponents();
// finally create some views
ContextView contextView = model.createContextView(springPetClinic);
contextView.addAllSoftwareSystems();
contextView.addAllPeople();
ContainerView containerView = model.createContainerView(springPetClinic);
containerView.addAllPeople();
containerView.addAllSoftwareSystems();
containerView.addAllContainers();
ComponentView componentView = model.createComponentView(springPetClinic, webApplication);
componentView.addAllComponents();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
String modelAsJson = objectMapper.writeValueAsString(model);
System.out.println(modelAsJson);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment