dsmsuite / dsmsuite.sourcecode

MIT License
14 stars 9 forks source link

Add C4 Analyzer #29

Open jgquiroga opened 6 months ago

jgquiroga commented 6 months ago

Hello,

I am creating an analyzer for C4 models using "json" files created by structurizr:

https://structurizr.com/

Example:

big-bank-plc

structurizr-SystemLandscape

After I finished all the development and the test units, I think it will be a good thing to have in the main repository.

Steps to generate the diagram

Preconditions

Getting the structurizr cli

docker pull structurizr/cli:latest

Executing the structurizr cli in the current folder

docker run -it --rm -v ${PWD}:/usr/local/structurizr structurizr/cli export -workspace workspace.dsl -format json
DsmSuite.Analyzer.C4.exe AnalyzerSettings.xml
<?xml version="1.0" encoding="utf-8"?>
<AnalyzerSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <LogLevel>Error</LogLevel>
  <Input>
    <Workspace>workspace.json</Workspace>
  </Input>
  <Transformation />
  <Output>
    <Filename>Output.dsi</Filename>
    <Compress>true</Compress>
  </Output>
</AnalyzerSettings>
DsmSuite.Analyzer.C4.exe AnalyzerSettings.xml

Example of Output:

output.dsi Output.zip

output

jmuijsenberg commented 6 months ago

Thanks for your interest in the tool. As I have little time to maintain the full dsmsuite, I created a new archive https://github.com/dsmviz where I will only maintain the viewer with dsi as input file. Another reason for doing so is that for code analysis better solutions are available(e.g. doxygen). My suggestion is to keep you code in a separate archive. I will be happy to provide a link to your project and another projects compatible with the dsm tooling.

jmuijsenberg commented 6 months ago

I am not ready with with dsmviz tooling. Hopefully in a few weeks. Some parts of dsmsuite like the C# parse, java and UML in will maintain in a separate archive. I plan to fully drop the C++ part. I may also may available source code to create dsi files in C# and Python.

jgquiroga commented 6 months ago

Hello! Thank you for your feedback. I’ve been using your tool for a few weeks now, and it’s been yielding great results. I’ve even created custom parsers, including this one for C4. Additionally, I developed a parser for an Azure DevOps backlog (but I am still trying to see if it can be used outside my projects).

Regarding your plans for the viewer, if it’s separate from the existing functionality, that sounds great. I’ve been considering creating the analyzers as separate repositories too, like extensions.

As for making C# code available for creating DSI files, are you also planning to create NuGet packages? Having these packages in .NET Standard 2.0, just with essential DLLs for DSI file creation, could be beneficial. It would allow analyzers to be built for both .NET 8 and .NET Framework, and they could run on Linux (via Azure pipelines or GitHub Actions).

In the meantime, I think I will try changing the analyzer to a dotnet 8 console application.

Thank you

jmuijsenberg commented 6 months ago

Thanks for you feedback. I will look into creating a nuget package. Have no experience with that, so I am not sure how hard it is.

Another argument to split off the viewer is that it can also be used for visualizing dependencies of any else than software. See book https://mitpress.mit.edu/9780262528887/design-structure-matrix-methods-and-applications/.

The reason for developing this tool is that I find many software projects poorly structured mainly to due lack of visibility. Most projects only measure code quality and not design quality. See https://www.youtube.com/watch?v=27EfUhxqpG4 video.

jgquiroga commented 6 months ago

Yes, I was watching some videos from the author of the book you mentioned. I saw that the tool has the potential to be used for many things. Thank you for the links.

I am in the process of testing some other tools like the silverthread one and another one from Lattix.

Regarding the nuget packages, I see that you only need to publish these 3 packages:

I created a new repository only for the C4 analyzer. https://github.com/jgquiroga/dsmviz.analyzer.c4

For now, It contains the source code of those 3 projects (already working in netstandard 2.0 without changes).

If you open the csproj, you will see the changes I made to prepare the nuget package generation. Visual Studio already creates the packages for you. You only need to register a nuget account and get an api key to upload them with dotnet pack.

Also, you can upload the console applications as dotnet tools.

Here, I already created the package for the C4 Analyzer in dotnet 8, for example:

https://www.nuget.org/packages/dsmviz-analyzer-c4/#readme-body-tab

It can be installed like this: dotnet tool install --global dsmviz-analyzer-c4 --version 0.1.0-alpha.1

jmuijsenberg commented 6 months ago

I have worked with Lattix. As a commercial product it has much more features. I think it is worth its money if your project has a significant scale considering the cost of needless structural complexity. Often companies are not willing to invest in this. I believe it has a Java API to programatically create models e.g. from your C4 models. It also support dependency rules to validate if code is according specified rules.

I have had contact with Silverthread, but never used their product. I feel it is mostly relevant for large scale legacy applications.