Class diagrams: packages and namespaces

Class diagrams: packages and namespaces

puml.online

简介 / Introduction

Class diagrams don’t just show relationships — they also use packages or namespaces to organize model elements into a hierarchical structure. This article uses the same scenario to compare PlantUML and Mermaid’s package/namespace syntax, highlighting similarities and differences.

PlantUML 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package "com.example.app" {
class MyClass
class Helper
}

package "com.example.lib" {
class Service
class Dao
}

MyClass --> Service : uses
MyClass --> Dao : queries
Helper --> Service

package "com.example.util" {
class StringUtils
}

Service ..> StringUtils : imports

PlantUML uses package "name" { ... } to group classes, supports nesting and colors/icons, and expresses dependencies with arrows.

Mermaid 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
classDiagram
namespace com.example.app {
class MyClass {
+void doWork()
}
class Helper {
+void assist()
}
}

namespace com.example.lib {
class Service {
+void process()
}
class Dao {
+void fetch()
}
}

namespace com.example.util {
class StringUtils {
+static String format()
}
}

MyClass --> Service : uses
MyClass --> Dao : queries
Helper --> Service
Service ..> StringUtils : imports

Mermaid uses namespace 名称 { ... } to separate classes under the same namespace. Class bodies can optionally declare member methods, and dependency arrows work the same way.

对比 / Side-by-side

Feature PlantUML Mermaid
Package/namespace keyword package "name" { } namespace name { }
Class member syntax Just class ClassName in block Requires +method() inside class body
Nested packages Supported, multi-level package nesting Not directly supported; simulate with namespace hierarchy
Dependency arrows --> / ..> / `< –`
Colors / icons Supported via package "name" #Pink Not supported

小结 / Wrap-up

PlantUML’s package syntax is richer — it supports nesting, colors, and icons, making it better suited for formal modeling. Mermaid’s namespace is lighter and more readable, ideal for documentation and quick diagrams. Dependency arrow syntax is nearly identical between the two, keeping the learning curve low.

  • Title: Class diagrams: packages and namespaces
  • Author: puml.online
  • Created at : 2026-09-03 09:00:00
  • Updated at : 2026-09-03 01:06:42
  • Link: https://puml.online/blog/class-diagram-packages-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Class diagrams: packages and namespaces