feat: Add Mermaid namespace clustering support - #480
Merged
Conversation
Add `cluster: true` support for Mermaid `classDiagram` output, grouping
entities by their Ruby namespace into Mermaid `namespace { }` blocks.
This brings Mermaid to parity with the existing Graphviz clustering feature.
When clustering is enabled, models like `Admin::User` and `Admin::Role`
are grouped together in a namespace block, making large diagrams with many
namespaced models easier to understand.
Features:
- Entities grouped by namespace into Mermaid namespace blocks
- Nested namespaces converted to dot notation (Admin::Users -> Admin.Users)
- Entities without namespace appear outside any namespace block
- Relationships render outside namespace blocks (Mermaid requirement)
- Warning emitted when cluster: true used with erDiagram (not supported)
Implementation uses a two-phase approach: collect entities by namespace
during each_entity, then emit namespace blocks before relationships and
specializations are rendered.
Closes #479
The test was setting RailsERD.options.warn but the Diagram#warn method checks options.warn (the diagram's own options hash). This meant the warning was never actually being captured during the test. Fixed by: - Passing :warn => true directly to the Diagram constructor - Creating the diagram explicitly instead of using the memoized helper - Capturing the warning output during diagram generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
cluster: truesupport for MermaidclassDiagramoutput, grouping entities by their Ruby namespace into Mermaidnamespace { }blocks.This brings Mermaid to parity with the existing Graphviz clustering feature.
Closes #479
Motivation
When working with large schemas that include multiple namespaces (e.g.,
Admin::,Billing::,SolidQueue::), it's helpful to visually group related models together. The Graphviz generator already supports this via theclusteroption, but Mermaid output ignored it.Changes
lib/rails_erd/diagram/mermaid.rbnamespace { }blocksAdmin::Users→Admin.Users)cluster: trueused witherDiagram(not supported)clusteroption in README.mdExample Output
Produces:
classDiagram namespace Admin { class User class Role } namespace Billing { class Invoice class Payment } User --> Role Invoice --> PaymentLimitations
Clustering is not supported with Mermaid's default
erDiagramstyle (ER diagrams don't have a namespace concept). A warning is emitted ifcluster: trueis used witherDiagram.Testing