structurizr / dsl

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

Add support for `!ref` inside softwareSystems, components and containers #334

Closed faustool closed 11 months ago

faustool commented 1 year ago

Description

I am adopting a docs coding style where I separate the element definition and their relationships in different sections. First the elements, their tags, descriptions, technologies, etc., then the relationships follow bellow them.

For instance:

workspace {

    !identifiers hierarchical

    model {
        /*
        * Elements
        */
        user = person "User"

        softwareSystem = softwareSystem "Software System" {
            container1 = container "Container 1" {
                component1 = component "Component 1"
            }

            container2 = container "Container 2" {
                component2 = component "Component 2"
            }
        }

        /*
        * Relationships
        */
        !ref softwareSystem {
            container2.component2 -> container1.component1 "Calls"
        }

        user -> softwareSystem "Uses"
    }
}

I'm also using !identifiers hierarchical to avoid name clashes.

I am also documenting my containers (frontend, backend) in separate files. I document the internal relationships (e.g.: between components) of these containers inside their files, alongside the component definitions.

The problem I am facing now is that I cannot use !ref inside those containers, components, or even softwareSystem. That means I have to repeat the full qualified name of the elements every time.

For instance, I have this database component:

database = container "Database" {
    technology "SQL Server"
    tags Database

    group "schema: myschema" {
        table1 = component "table1 " {
            tags Table
            description "Store some data"
        }

        table2 = component "table2" {
            tags Table
            description "Store some data"
        }

        table3 = component "table3" {
            tags Table
            description "Store some data"
        }

        table4 = component "table4" {
            tags Table
            description "Store some data"
        }

        table5 = component "table5" {
            tags Table
            description "Store some data"
        }
    }
}

After I defined the structure, now I want to describe the relationship between these elements next:

!ref database {
    table1 -> table2 "Has many"
    table2 -> table3 "Has many"
    table3 -> table4 "Has many"
    table4 -> table5 "Has many"
}

Except this will not work because I cannot use !ref inside the softwareSystem definition where this example would be placed.

Instead, this is what I have to write:

    database.table1 -> database.table2 "Has many"
    database.table2 -> database.table3 "Has many"
    database.table3 -> database.table4 "Has many"
    database.table4 -> database.table5 "Has many"

Perhaps this was never intended to be used like this, but I think it can be very useful.

Priority

Medium

Resolution

I have no budget, please add this feature for free

More information

No response

simonbrowndotje commented 11 months ago

I think allowing !ref to be used as a nested keyword will potentially cause confusion, with people asking why things like this don't work:

        softwareSystem = softwareSystem "Software System" {
            container1 = container "Container 1" {
                loggingComponent = component "Logging Component"
            }

            container2 = container "Container 2" {
                !ref container1.loggingComponent
            }
        }

Thanks for the suggestion, but it's not something I want to implement at this time.