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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How Spring and Hibernate Simplify Web and Database Management
  • Functional Endpoints: Alternative to Controllers in WebFlux
  • Graceful Shutdown: Spring Framework vs Golang Web Services
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4

Trending

  • A Developer's Guide to Mastering Agentic AI: From Theory to Practice
  • Integrating Security as Code: A Necessity for DevSecOps
  • Unlocking AI Coding Assistants Part 2: Generating Code
  • Top Book Picks for Site Reliability Engineers
  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.4K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How Spring and Hibernate Simplify Web and Database Management
  • Functional Endpoints: Alternative to Controllers in WebFlux
  • Graceful Shutdown: Spring Framework vs Golang Web Services
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!