mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
68.75k stars 6.08k forks source link

Add support for nested namespaces #5487

Open skillmaker-dev opened 2 months ago

skillmaker-dev commented 2 months ago

Proposal

I think it would be a great feature to have, nested namespaces make it easier to represent packages or namespaces in which classes reside, and it should be possible either by creating a namespace inside another namespace or by separating namespaces with a dot like this namespace example1.example2.example3 {}

Example

for example in PlantUML, nested packages or namespaces can be represented like this package foo1.foo2.foo3 { class Object }

Screenshots

The previous example will be represented in this way in plantUML: image

Khar-Ma2 commented 1 month ago

Hi, I just encountered the same problem. I also think that this item should be documented.

However, I have found a solution, although this behavior is unpredictable and not obvious to me.

So, I created 2 namespaces at the same level, and then I put the "children" as a class in the "main" one. It looks something like this:

classDiagram

namespace presentation{
    class auth
    class main
}
namespace auth{
    class AuthScreen
    class AuthViewModel
}
namespace main{
    class MainScreen
    class MainViewModel
}
classDiagram

namespace presentation{
    class auth
    class main
}
namespace auth{
    class AuthScreen
    class AuthViewModel
}
namespace main{
    class MainScreen
    class MainViewModel
}
skillmaker-dev commented 1 month ago

Hi, I just encountered the same problem. I also think that this item should be documented.

However, I have found a solution, although this behavior is unpredictable and not obvious to me.

So, I created 2 namespaces at the same level, and then I put the "children" as a class in the "main" one. It looks something like this:

classDiagram

namespace presentation{
    class auth
    class main
}
namespace auth{
    class AuthScreen
    class AuthViewModel
}
namespace main{
    class MainScreen
    class MainViewModel
}
classDiagram

namespace presentation{
    class auth
    class main
}
namespace auth{
    class AuthScreen
    class AuthViewModel
}
namespace main{
    class MainScreen
    class MainViewModel
}

That's a nice workaround, the namespace is behaving like a class and therefore it is being surrounded by the box and then you change it to be a namespace, I hope they create this feature, No one replied to this issue so far apart from you :(

nirname commented 2 weeks ago

Hello! Thanks for the suggestion. Is this workaround enough so we can close the issue, or you are still interested in something like

classDiagram

namespace presentation{
    namespace auth {
        class AuthScreen
        class AuthViewModel
    }
    namespace main{
        class MainScreen
        class MainViewModel
    }
}
skillmaker-dev commented 2 weeks ago

I think

classDiagram

namespace presentation{
    namespace auth {
        class AuthScreen
        class AuthViewModel
    }
    namespace main{
        class MainScreen
        class MainViewModel
    }
}

or this are better than the workaround because it is somehow confusing when working with a large codebase.

namespace example1.example2.example3 
{
    class class1
}
nirname commented 2 weeks ago

@skillmaker-dev would you like to make a contribution?

skillmaker-dev commented 1 week ago

@nirname I will try my best after taking a look at the codebase.