DEV Community

Simon Brown
Simon Brown

Posted on

7

Scripting support added to the Structurizr DSL

The Structurizr DSL now provides a way to run scripts written in Groovy, Kotlin, Ruby, and JavaScript, via the new !script keyword. This gives you access to the underlying Structurizr for Java workspace, for when you need to do something not supported by the DSL.

For example, you could use a script to create the default set of views, without automatic layout enabled:

workspace {

    model {
        user = person "User"
        softwareSystem = softwareSystem "Software System"

        user -> softwareSystem "Uses"
    }

    !script groovy {
        workspace.views.createDefaultViews()
        workspace.views.views.each { it.disableAutomaticLayout() }
    }   

}
Enter fullscreen mode Exit fullscreen mode

You could also use a script to programmatically add elements to a view, using more complicated logic than is possible via the DSL alone.

workspace {

    model {
        group "Group 1" {
            a = softwareSystem "A" {
                tags "Tag 1"
            }
            b = softwareSystem "B" {
                tags "Tag 2"
            }
        }
        group "Group 2" {
            c = softwareSystem "C" {
                tags "Tag 1"
            }
            d = softwareSystem "D" {
                tags "Tag 2"
            }
        }
    }

    views {
        systemLandscape "key" {
            !script groovy {
                view = workspace.views.getViewWithKey("key");
                workspace.model.softwareSystems.findAll { it.group == "Group 1" && it.hasTag("Tag 1") }.each{ view.add(it); };
            }

            autolayout
        }
    }

}
Enter fullscreen mode Exit fullscreen mode

Scripting support is available now, via the open source Structurizr CLI and the free Structurizr Lite. See the Structurizr DSL language reference - Scripts and the Structurizr DSL cookbook - Scripts for more details.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay