structurizr / dsl

Structurizr DSL
https://docs.structurizr.com/dsl
Apache License 2.0
1.41k stars 266 forks source link

"AND" logic for expressions #355

Closed ghost closed 10 months ago

ghost commented 10 months ago

Description

This follows on from #348, I believe the feature I'm requesting will solve their problem as well as mine. In my case I have a container representing a DB with components representing tables, and in a separate container there are several different components that interact with particular tables. I wish there was a simple way to express "include all components with direct relationships to the components within this container".

My use case is that I'm trying to model some legacy software that is really poorly organised so we can assess and plan our upgrades. The example in the cookbook that was mentioned in #348 as a solution has two major drawbacks for me:

  1. I can use include element.parent==Container2 but then I have many additional components included that do not interact with this particular DB (like I said, it's legacy software), too many to manually list and exclude.
  2. I can use include component1 component2 component3 ... but this requires me to keep careful track of exactly which components are interacting with the DB and list them manually, which is not very convenient but the better of the two approaches.
  3. There is also potentially a third way of doing it by tagging the specific components that interact with the DB, but this is not really any better than option 2 above so I haven't even tried it.

Being able to use an "AND" statement between "include" expressions would be very powerful and solve this problem with a straightforward expression like the following:

views {
    component DBcontainer {
        include ->(element.parent==DBcontainer)-> AND element.type==Component
    }
}

Such that only elements that satisfy both expressions are included. The way it currently works (where you just leave a space between each expression) is effectively like having "OR" between each expression.

Priority

Low

Resolution

I have no budget and there's no rush, please add this feature for free

More information

No response

ghost commented 10 months ago

Funny how I spent half an hour writing this, but it only took 10 minutes of going over the source code to realise this feature already exists, it just has to be in quote marks and use && instead of AND:

views {
    component DBcontainer {
        include "->element.parent==DBcontainer-> && element.type==Component"
    }
}

This feature should definitely be explained more clearly in the language reference, the cookbook, and elsewhere in the documentation

shahabganji commented 10 months ago

For Containers, it works if:

container CONTAINER_NAME "DIAGRAM_KEY" "DIAGRAM_DESCRIPTION" {
    include "->element.parent==CONTAINER_NAME-> && element.type==container"
}
ghost commented 10 months ago

Good spot @shahabganji! Just a typo on my part, the parentheses don't work and shouldn't have been there, I've edited my comment to avoid confusion.