umlgraphvizdotpackage-diagram

Create a complex package diagram with GraphViz


I want to create a package diagram using the dot language, similar to the one below. I know it is possible to nest elements using "clusters" but unsure if it is possible to put labels in the tab area of the outer packages. Let me know if it is possible.

UML package diagram


Solution

  • Unfortunately the tab shape (the one with the ear in top left corner) doesn't support specifying a label there.

    If you are willing to sacrifice that, you can use a regular rectangle or record shape

    digraph diagram {
        compound=true;
        ranksep=1
        node[shape=record]
    
        subgraph cluster_all {
            label="Multi-Layered Application"
            Users [shape=tab]
    
            subgraph cluster_presentation {
                label="Presentation Layer"
                "User Interface" [shape=tab]
                "Presentation Logic" [shape=tab]
            }
    
            Users -> "User Interface" [lhead=cluster_presentation]
    
            subgraph cluster_business {
                label="Business Layer"
                node[shape=tab]
                "Application Facade"
            }
    
            "User Interface" -> "Application Facade" [lhead=cluster_business,ltail=cluster_presentation,style=dashed]
        }
    
    }
    

    enter image description here

    But as you can see, graphviz isn't exactly well-suited for this as you need to do a lot of low-level fiddling.

    Alternatively, if the objective is to describe the diagram with a text, I highly recommend plantuml.com, which has much saner syntax for this kind of task.

    @startuml
    package "<<model>> Multi-Layered Application <<model>>" as app {
      package Users { }
    
      package "Presentation Layer" as presentation {
        package "User Interface" { }
        package "Presentation Logic" { }
      }
    
      Users ..> presentation
    
      package "Business Layer" {
        package "Application Facade" { }
      }
    
      presentation ..> "Business Layer"
    
    }
    @enduml
    

    enter image description here