plantuml-stdlib / C4-PlantUML

C4-PlantUML combines the benefits of PlantUML and the C4 model for providing a simple way of describing and communicate software architectures
MIT License
6.44k stars 1.1k forks source link

Descriptions for boundaries #350

Closed NathanDotTo closed 6 months ago

NathanDotTo commented 7 months ago

Hi

It seems to me that adding a description to a boundary would be a good thing. That way we could describe what the boundary contains in a general sense. This also seems like an obvious idea, so I am wondering why it is not already possible.

To explore whether boundary descriptions might be possible, I am looking at the Enterprise_Boundary, System_Boundary, and Container_Boundary procedures. For example:

!unquoted procedure Enterprise_Boundary($alias, $label, $tags="", $link="")
  !if ($tags != "")
    !$allTags = $tags + '+enterprise'
  !else
    !$allTags = 'enterprise'
  !endif
  ' $type defined via $tag style
  Boundary($alias, $label, "", $allTags, $link)
!endprocedure

Which leads to, in C4.puml:

!unquoted procedure Boundary($alias, $label, $type="", $tags="", $link="")
!$boundaryTags = $addBoundaryPostfix($tags)
' nodes $type reuses $techn definition of $boundaryTags
!$type=$toElementArg($type, $boundaryTags, "ElementTagTechn", "boundary")
rectangle "$getBoundary($label, $type)" $toStereos("boundary", $boundaryTags) as $alias $getLink($link)
!endprocedure

Which leads to:

!function $getBoundary($label, $type)
  !if ($type == "")
    !return '== ' + $breakLabel($label)
  !endif
  !if (type != "")
    !return '== ' + $breakLabel($label) + '\n<size:' + $TECHN_FONT_SIZE + '>[' + $type + ']</size>'
  !endif
!endfunction

Does anyone reading this know whether/how a rectangle can have a description?

Am I thinking about this in the right way please?

Thanks

Nathan

kirchsth commented 7 months ago

HI @NathanDotTo,

I will try to implement it in one of the next weekends. But in the meantime you could use following workaround for e.g. System_Boundary:

like (follow the image link then you see the code)

BR Helmut

NathanDotTo commented 7 months ago

Cool, that worked, thanks! :-)

NathanDotTo commented 7 months ago

I have also had cause to use the type too, like this:

System(a_system, "A Cloud Platform", "X-as-a-Service (XaaS) ", $type="GCP", $tags="system_boundary") {
  Container ...
}
kirchsth commented 7 months ago

Update: correct solution see next comment

If you want a different type, then I would directly use a boundary and define its own $type like

Boundary(anotherBoundary, "Another Boundary", $type="BOUNDARY TYPE", $tags="v1") {

details see https://github.com/plantuml-stdlib/C4-PlantUML?tab=readme-ov-file#sample-with-different-boundary-tag-combinations

BR Helmut

kirchsth commented 7 months ago

Hi @NathanDotTo,

sorry, I forgot my implementation (indention) related to the $type support of a (System/Container/...)Boundary. You can define it via the tags AddBoundaryTag(tagName, ..., $type="NewType", ...) and then e.g. all (Systems) boundaries which uses the $tag displays the updated $type automatically too. Sample see below (follow the image link then you see the code):

BR Helmut

kirchsth commented 7 months ago

Hi @NathanDotTo,

I implemented a version in my extended branch (details see #352) can you please check it via my branch? (the only difference is that you have to use my extended branch !include https://raw.githubusercontent.com/kirchsth/C4-PlantUML/extended/...

@startuml
!include https://raw.githubusercontent.com/kirchsth/C4-PlantUML/extended/C4_Container.puml

AddBoundaryTag("chatGPT", $type="ChatGPT", $bgColor="red", $fontColor="white", $borderColor="darkred", $sprite="robot2")

Person(admin, "Administrator",$sprite="person2")
System_Boundary(c1, "Sample System", $descr="ChatGPT with model gpt-3.5-turbo. It has been updated to feature higher accuracy", $tags="chatGPT") {
    Container(web_app, "Web Application", "C#, ASP.NET Core 2.1 MVC", "Allows users to compare multiple Twitter timelines")
}
System(twitter, "Twitter")

Rel(admin, web_app, "Uses", "HTTPS")
Rel(web_app, twitter, "Gets tweets from", "HTTPS")

SHOW_LEGEND()
@enduml

Thank you and best regards Helmut

NathanDotTo commented 7 months ago

Thank you for this. I will be able to test this next week.

NathanDotTo commented 6 months ago

I have tested this, and it works, thank you :-)