iurysza / module-graph

A Gradle Plugin for visualizing your project's structure, powered by mermaidjs
https://plugins.gradle.org/plugin/dev.iurysouza.modulegraph
MIT License
345 stars 13 forks source link

If a module has the same name as the containing folder, the generated diagram doesn't work #6

Closed gdesantos closed 1 year ago

gdesantos commented 1 year ago

šŸ› Describe the bug

If you have a folder with the same name as a submodule, it will not work. For example:

feature -> ā€ƒfeature ā€ƒcore ā€ƒdomain ā€ƒui

iurysza commented 1 year ago

I attempted to group the modules into subgraphs using folders, but it seems I overlooked a potential conflict in cases like the one you mentioned. Maybe it wasn't such a great idea šŸ˜†

I'll dive deeper into this issue and explore the available options to find a solution. Thanks for the report!

iurysza commented 1 year ago

Can you provide a branch or repo where I can reproduce this? I've tried doing it on the sample project with this structure:

+--- Project ':sample:alpha'
+--- Project ':sample:beta'
+--- Project ':sample:container'
|    +--- Project ':sample:container:delta'
|    \--- Project ':sample:container:gama'
+--- Project ':sample:sample'
|    \--- Project ':sample:sample:teta'
\--- Project ':sample:zeta'

and it gave me this: image

I think we would need to get the full path of each module and give up the subgraph approach for it to work correctly. Maybe we can have the option to do that, but I'm not sure if this is such a common use case to justify it yet. They would look more like this in this case.

gdesantos commented 1 year ago
Screenshot 2023-04-04 at 13 29 16 Screenshot 2023-04-04 at 13 29 24 Screenshot 2023-04-04 at 13 29 34
iurysza commented 1 year ago

Understood! Mermaid doesn't allow subgraphs to share the same name as nodes, so one workaround is to exclude subgraphs entirely. In your scenario, the resulting graph would look like this:

graph LR  
  app --> myModule:myModule

I think we'll need to consider supporting this functionality for situations involving complex folder structures or conflicts of this kind.

I'll come back to this issue. Thanks!

gdesantos commented 1 year ago

Thank you!

ferinagy commented 1 year ago

I think I just ran into a similar issue that has same underlying cause. In our project, we have sometimes modules with a same name, under a different folder, eg. :cards:api and :main:api:

+- :app
+- :cards
|  +- :cards:api
|  \- :cards:fake
+- :main
   +- :main:api
   \- :main:fake

With the current logic, only one api node is created in the rendered graph:

graph LR

  subgraph cards
    api
    fake
  end
  subgraph main
    api
    fake
  end
  app --> cards
  cards --> api %% :cards:api
  app --> main
  main --> api  %% :main:api
graph LR

  subgraph cards
    api
    fake
  end
  subgraph main
    api
    fake
  end
  app --> cards
  cards --> api
  app --> main
  main --> api

While in the file structure, the :cards:api is contained in :cards, looking at the modules, :cards is same as other modules, so rendering it as a subgraph is IMHO confusing. Also with subgraph, the dependency :cards --> :cards:api is almost invisible.

I think we would need to get the full path of each module and give up the subgraph approach for it to work correctly.

I think this would produce more correct and clear graph.

iurysza commented 1 year ago

This is the next thing I'll work on. I'm thinking of introducing this behavior as an option, and then turning it into the default behavior when we reach 1.0.

iurysza commented 1 year ago

This new feature is available in v0.5.0