DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building a CRUD Application With Spring and SimpleJdbcMapper
  • How to Marry MDC With Spring Integration
  • How Spring and Hibernate Simplify Web and Database Management
  • Functional Endpoints: Alternative to Controllers in WebFlux

Trending

  • Why AI Forces a Rethink of Everything We Know About Software Security
  • Swift Concurrency Part 4: Actors, Executors, and Reentrancy
  • Lease Coordination Under Serializable Isolation in CockroachDB
  • The Prompt Isn't Hiding Inside the Image
  1. DZone
  2. Coding
  3. Frameworks
  4. Diagramming Spring MVC Webapps

Diagramming Spring MVC Webapps

By 
Simon Brown user avatar
Simon Brown
·
Jul. 01, 14 · Interview
Likes (0)
Comment
Save
Tweet
Share
8.7K Views

Join the DZone community and get the full member experience.

Join For Free

some diagrams for the spring petclinic application

following on from my previous post ( software architecture as code ) where i demonstrated how to create a software architecture model as code, i decided to throw together a quick implementation of a spring component finder that could be used to (mostly) automatically create a model of a spring mvc web application. spring has a bunch of annotations (e.g. @controller, @component, @service and @repository) and these are often/can be used to signify the major building blocks of a web application. to illustrate this, i took the spring petclinic application and produced some diagrams for it. first is a context diagram.

a context diagram for the spring petclinic application

next up are the containers, which in this case are just a web server (e.g. apache tomcat) and a database (hsqldb by default).

a container diagram for the spring petclinic application

and finally we have a diagram showing the components that make up the web application. these, and their dependencies, were found by scanning the compiled version of the application (i cloned the project from github and ran the maven build).

a component diagram for the spring petclinic web application

here is the code that i used to generate the model behind the diagrams.

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);
    }
}
the resulting json representing the model was then copy-pasted across into my simple (and very much in progress) diagramming tool . admittedly the diagrams are lacking on some details (i.e. component responsibilities and arrow annotations, although those can be fixed), but this approach proves you can expend very little effort to get something that is relatively useful. as i've said before, it's all about getting the abstractions right.
Spring Framework

Published at DZone with permission of Simon Brown. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Building a CRUD Application With Spring and SimpleJdbcMapper
  • How to Marry MDC With Spring Integration
  • How Spring and Hibernate Simplify Web and Database Management
  • Functional Endpoints: Alternative to Controllers in WebFlux

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook