Midnighter / structurizr-python

A Python 3 port of Simon Brown's Structurizr diagrams-as-code architecture description tool.
https://structurizr.com/
Apache License 2.0
65 stars 16 forks source link

Shouldn't it be possible to add a relationship with source == destination in a dynamic view ? #84

Closed skeptic-monkey closed 3 years ago

skeptic-monkey commented 3 years ago

Checklist

Question

Currently if I try to run the following code, it fails per design:

view = views.create_dynamic_view(element=element1, key="my_dynamic_view", description="description")
view.add(element1, element2, "calls Foo()")
view.add(element2, element2, "calls Bar()")

It fails because A relationship between element2 and element2 does not exist in the model. In a way, there is an obvious relationship between an element and itself.

Could we implement such behavior ? or is against some logic related to C4 model ?

Midnighter commented 3 years ago

Thanks for trying out the dynamic views @skeptic-monkey 🙂

You can definitely add a self-relationship but you need to first add it on the model, too. Basically, everything that you add to a dynamic view must first exist on the model.

from structurizr import Workspace

workspace = Workspace(
    name="Getting Started",
    description="This is a model of my software system.",
)

model = workspace.model

user = model.add_person(name="User", description="A user of my software system.")
software_system = model.add_software_system(
    name="Software System", description="My software system."
)
software_system.uses(software_system)

dyn_view = workspace.views.create_dynamic_view(element=user, key="my_dynamic_view", description="something")
dyn_view.add(software_system, software_system, "calls Bar()")
skeptic-monkey commented 3 years ago

Ok, I see. I thought it was "implied" that an element uses itself. But I guess I can live with that solution :)

@Midnighter thanks for the python port of structurizr ! loving it (I hated so much drawing diagrams ...)

Midnighter commented 3 years ago

Ok, I see. I thought it was "implied" that an element uses itself. But I guess I can live with that solution :)

I can understand that point of view. On the other hand, I think it's good to be explicit about those relationships that are shown in a diagram.