Skip to content

Commit bf9502f

Browse files
committed
docs: add nested namespace documentation and changeset
Co-Authored-By: Claude Opus 4.6 (prompted with care by @M-a-c)
1 parent 6335421 commit bf9502f

3 files changed

Lines changed: 157 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mermaid': minor
3+
---
4+
5+
feat: add nested namespace support for class diagrams via dot notation and syntactic nesting

docs/syntax/classDiagram.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,104 @@ namespace BaseShapes {
498498
}
499499
```
500500

501+
### Nested Namespaces (v\<MERMAID_RELEASE_VERSION>+)
502+
503+
Namespaces can be nested to represent hierarchical groupings. There are two ways to define nested namespaces:
504+
505+
**Dot notation** creates intermediate namespaces automatically:
506+
507+
```mermaid-example
508+
classDiagram
509+
namespace Company.Engineering.Backend {
510+
class Developer {
511+
+writeCode()
512+
}
513+
}
514+
namespace Company.Engineering.Frontend {
515+
class Designer {
516+
+createMockup()
517+
}
518+
}
519+
namespace Company.Engineering {
520+
class TechLead {
521+
+planSprint()
522+
}
523+
}
524+
TechLead --> Developer : leads
525+
TechLead --> Designer : leads
526+
```
527+
528+
```mermaid
529+
classDiagram
530+
namespace Company.Engineering.Backend {
531+
class Developer {
532+
+writeCode()
533+
}
534+
}
535+
namespace Company.Engineering.Frontend {
536+
class Designer {
537+
+createMockup()
538+
}
539+
}
540+
namespace Company.Engineering {
541+
class TechLead {
542+
+planSprint()
543+
}
544+
}
545+
TechLead --> Developer : leads
546+
TechLead --> Designer : leads
547+
```
548+
549+
**Syntactic nesting** places namespace blocks inside other namespace blocks:
550+
551+
```mermaid-example
552+
classDiagram
553+
namespace Platform {
554+
namespace Auth {
555+
class UserService {
556+
+login()
557+
+logout()
558+
}
559+
}
560+
namespace Data {
561+
class Repository {
562+
+find()
563+
+save()
564+
}
565+
}
566+
class Gateway {
567+
+route()
568+
}
569+
}
570+
Gateway --> UserService : delegates
571+
Gateway --> Repository : delegates
572+
```
573+
574+
```mermaid
575+
classDiagram
576+
namespace Platform {
577+
namespace Auth {
578+
class UserService {
579+
+login()
580+
+logout()
581+
}
582+
}
583+
namespace Data {
584+
class Repository {
585+
+find()
586+
+save()
587+
}
588+
}
589+
class Gateway {
590+
+route()
591+
}
592+
}
593+
Gateway --> UserService : delegates
594+
Gateway --> Repository : delegates
595+
```
596+
597+
Both approaches can be combined. Dot notation like `namespace A.B.C` will automatically create namespaces `A` and `A.B` as parents if they don't already exist.
598+
501599
## Cardinality / Multiplicity on relations
502600

503601
Multiplicity or cardinality in class diagrams indicates the number of instances of one class that can be linked to an instance of the other class. For example, each company will have one or more employees (not zero), and each employee currently works for zero or one companies.

packages/mermaid/src/docs/syntax/classDiagram.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,60 @@ namespace BaseShapes {
320320
}
321321
```
322322

323+
### Nested Namespaces (v<MERMAID_RELEASE_VERSION>+)
324+
325+
Namespaces can be nested to represent hierarchical groupings. There are two ways to define nested namespaces:
326+
327+
**Dot notation** creates intermediate namespaces automatically:
328+
329+
```mermaid-example
330+
classDiagram
331+
namespace Company.Engineering.Backend {
332+
class Developer {
333+
+writeCode()
334+
}
335+
}
336+
namespace Company.Engineering.Frontend {
337+
class Designer {
338+
+createMockup()
339+
}
340+
}
341+
namespace Company.Engineering {
342+
class TechLead {
343+
+planSprint()
344+
}
345+
}
346+
TechLead --> Developer : leads
347+
TechLead --> Designer : leads
348+
```
349+
350+
**Syntactic nesting** places namespace blocks inside other namespace blocks:
351+
352+
```mermaid-example
353+
classDiagram
354+
namespace Platform {
355+
namespace Auth {
356+
class UserService {
357+
+login()
358+
+logout()
359+
}
360+
}
361+
namespace Data {
362+
class Repository {
363+
+find()
364+
+save()
365+
}
366+
}
367+
class Gateway {
368+
+route()
369+
}
370+
}
371+
Gateway --> UserService : delegates
372+
Gateway --> Repository : delegates
373+
```
374+
375+
Both approaches can be combined. Dot notation like `namespace A.B.C` will automatically create namespaces `A` and `A.B` as parents if they don't already exist.
376+
323377
## Cardinality / Multiplicity on relations
324378

325379
Multiplicity or cardinality in class diagrams indicates the number of instances of one class that can be linked to an instance of the other class. For example, each company will have one or more employees (not zero), and each employee currently works for zero or one companies.

0 commit comments

Comments
 (0)