java icon indicating copy to clipboard operation
java copied to clipboard

Implement support for `relationship!=` expressions

Open mwz opened this issue 10 months ago • 2 comments

Hello,

This is my first contribution to Structurizr, and I’d like to take a moment to thank you for building this project. We use it extensively for representing our architecture, and it has been incredibly useful.

We’ve found that some of our system context diagrams can become quite large. To create smaller, more focused views, we’ve been using the following script to remove relationships that are not directly connected to the target system:

!script groovy {
  element = view.getSoftwareSystem();
  view.removeRelationshipsNotConnectedToElement(element);
}

It would be better to achieve this directly using view expressions, so I implemented support for relationship not equals expressions.

This PR introduces: • relationship.source!=relationship.destination!=relationship!=

With these expressions, for example:

systemContext mySystem "MySystemContext" {
  include *
  exclude "relationship.source!=mySystem && relationship.destination!=mySystem"
}

one can simplify a complex diagram, such as:

Screenshot-2025-02-18-12 45 00

or

Screenshot-2025-02-18-13 49 44

into a cleaner version that only includes direct relationships to the system, removing relationships between other systems, if not relevant for the view:

Screenshot-2025-02-18-12 45 17

or

Screenshot-2025-02-18-13 48 52

This significantly improves readability and makes it easier to understand direct dependencies for the system in question.

I hope this change can be helpful to others in improving their diagrams. I’m not very familiar with the codebase, so please let me know if I’ve missed anything. Looking forward to your feedback!

mwz avatar Feb 18 '25 13:02 mwz

Thanks for this. I need to get my head around whether this will work for all view types - specifically deployment views where either the software system/container or software system instance/container instance could be specified as the relationship source/destination.

In the meantime, can I offer this as a simpler alternative? (this is available now if you build from source)

include * (greedy)

greedy

include *? (reluctant)

reluctant

simonbrowndotje avatar Feb 19 '25 09:02 simonbrowndotje

Hi Simon,

Thanks so much—this is definitely a simpler way to achieve what I was aiming for!

I still think “relationship not equals” expressions could be useful beyond my specific use case. If you agree, I’d be more than happy to make any changes needed to include this functionality.

Really appreciate the quick response and the effort you put into implementing this.

Thanks again!

mwz avatar Feb 19 '25 12:02 mwz