-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modularise mermaid to have diagram specific code not spread across the mermaid code base #3061
Comments
In that matter, having a look across the theme artefacts I stumbled over the following thing:
And, how could a diagram provide it's own scss at run-time and not at compile-time? (is there a solution for that?) |
One other finding is: On second thought there should be no need for a diagram to extend the "defaultConfig" object... If the parser/db/renderer of a diagram needs to access it's config it should be able to import it directly. Or am I missing something? |
@financelurker No there are artifacts from organic growth in the code. It is high time for some refactoring. I am looking forward to start with that. The first step will be to create the abstract diagram which opens things up. I think we need to code cleaning to happen as well. 😊 We have some commented out code thats should be removed, etc. The sass stuff should also be removed as it is not used anymore (#3093 3093). Regarding config it has to do with the directives where you can change some of the configuration options from the diagram code. You don't want the directives changes to the configuration to pollute the global configuration. It is surprisingly complicated. |
Good points regarding with gathering everything you need to be a diagram into each diagram. |
@knsv Ad "example implementation": Is there a compatibility reason to not use ES6 features? Because I'd like to see JavaScript classes that provide a kind of standardised interface for "diagrams", so it's easier for developers to know what a custom diagram has to provide to the orchestrating logic. Ad "configuration": Okay, so there's three layers of configuration: the "mermaid default config", the "diagram default config" and on top of that the configuration provided via directives? I think this complexity should be hidden within the configAPI somehow - which could be also orchestrated within the mermaidAPI, since it's providing the |
Yes, the extension of the default config is used in order to have a whitelist of configuration options so what the directives can not add anything else. This caused security issues. Using es6 for the standardised diagram is my though as well. The interface should have a way of registering valid configuration options. |
So, I have some assumptions about the current config-code, which tackles these security issues:
Are there other aspects of security for now, which I haven't found by now? Which makes me wonder, in a scenario where diagrams can be loaded as dedicated npm packages into the using-app-runtime: What strategies would mermaid need to implement, to protect a consuming app if they load "unknown" or "unverified" diagram-packages, which injects malicious code? That would be a new attack vector for mermaid users... Ad "monorepo": This would fit the development of default diagrams for mermaid, I guess... Custom diagrams, which companies will develop for themselves or their customers will stay in their code repositories and will then be bundled in their apps. (or other wild thought: they'll have dedicated own GitHub-/*-repositories until they get incorporated into mermaid) |
I think The general security question is important. In the end we cant get away from that the final responsibility will land on the "integrator" that integrated mermaid in an app or on a site. All that said, we should have solid foundation for the security, can we help in that effort we should though. I think a monorepo is that way to go for the diagrams that mermaid develops as it, in my experience, greatly reduces the administration and development speed. Another aspect that very important that need to be considered is backwards compatibility. It is unfortunate if changes in the API renders lots of custom diagrams defunct. Before external v1 on the API, open for external use we should be confident that API is solid. |
Just a suggestion: This thread is an excellent candidate to move to 'Discussions' since it cuts across so many things. Speaking as someone coming in to the project and trying to figure out what is being worked on, etc. :-) I also recognize that it causes a disruption to do so (people involved in this thread are already used to watching and participating in it; PRs/commits can easily point here). Maybe just a single mention of it in a Discussion to point to this thread would be worthwhile. |
Is your feature request related to a problem? Please describe.
When developing a new diagram type for mermaid it is a huge change to the complete mermaid code. Currently there is the diagram code in the diagrams folder itself, and other necessary changes: defaultConfig.js, Diagram.js, mermaidAPI.js, styles.js, utils.js and several locations in the files contained in the themes folder (did I miss something?).
Describe the solution you'd like
The ideal solution - imho - would be that the mermaid project is split up into:
In the end the base code of mermaid should be free of any diagram information, can focus on orchestration and must only consume the mermaid API - no hard-coded imports of diagrams and neither should the diagram packages import anything from the mermaid logic package.
Then an using app could "simply" import the mermaid logic package and the supported diagrams (or a diagram-bundle-package).
Describe alternatives you've considered
The currently available alternative is to add new diagram types and have a huge junk of the mermaid code base also changed.
Additional context
Implementation proposal
@financelurker thats a good idea. I think that we are reaching a point where the base package of mermaid needs to be split up. If you don't care about gantt charts why include and load them? I have been thinking about a lazy loading. This could be another way or even better a part of that setup.
There are some refactoring activities that need to happen first though. The code that initially handled two diagrams is not as clean when handling 10+ diagrams after"organic growth". We need to define what a diagram is so that mermaid can treat them all diagrams in the same way with a basic interface. This is high up on my prioritisation list and diagram organisation is a part of that.
Originally posted by @knsv in #2456 (comment)
The text was updated successfully, but these errors were encountered: