Skip to content

andrii2g/sln2mermaid

Repository files navigation

sln2mermaid

sln2mermaid is a minimal .NET console application that reads .sln, .slnx, and .csproj files and renders project-to-project references as a Mermaid dependency diagram.

Version 0.4 only visualizes <ProjectReference /> relationships. It does not inspect package references, infer architecture layers, group projects by folders, or evaluate MSBuild conditions.

Current Scope

  • Load one or more .sln, .slnx, and/or .csproj input files.
  • Discover .csproj projects listed in solution files.
  • Parse <ProjectReference Include="..." /> entries from project files.
  • Resolve project references transitively.
  • Deduplicate projects and edges across all inputs.
  • Print Mermaid diagram text to stdout.
  • Write Mermaid diagram text to the path provided with --out or to sln2mermaid.mmd by default.
  • Optionally export the Mermaid diagram to PNG or SVG through Docker.
  • Optionally group projects by detected project type metadata.

Build

dotnet build sln2mermaid.slnx

Usage

dotnet run --project src/Sln2Mermaid -- ./MySolution.slnx
dotnet run --project src/Sln2Mermaid -- ./MySolution.slnx --out graph.mmd
dotnet run --project src/Sln2Mermaid -- --in ./src/MyProject/MyProject.csproj --out graph.mmd
dotnet run --project src/Sln2Mermaid -- --in ./A.slnx ./B.csproj --out graph.mmd

Supported options:

  • --in <file...> reads one or more .sln, .slnx, or .csproj files. Positional input paths are also supported.
  • --out <file> writes the Mermaid source to a .mmd file. If omitted, sln2mermaid.mmd is used.
  • --group-by-type groups nodes into Mermaid subgraphs by detected project type metadata.
  • --png <file> renders a PNG file.
  • --png-scale <1-10> optionally sets the PNG render scale in case a lot of projects specified. Higher values improve sharpness but increase file size, render time, and memory use. By default, no explicit scale is passed to Mermaid CLI.
  • --svg <file> renders an SVG file.

Group By Project Type

Use --group-by-type to group projects into Mermaid subgraphs based on project metadata:

dotnet run --project src/Sln2Mermaid -- MySolution.sln --group-by-type
dotnet run --project src/Sln2Mermaid -- MySolution.sln --group-by-type --out deps.mmd
dotnet run --project src/Sln2Mermaid -- MySolution.sln --group-by-type --png deps.png

This is grouping by project metadata. It is not architectural inference and does not classify projects as Domain, Infrastructure, Application, or UI.

Buckets are rendered in this stable order when they contain projects:

  1. Web
  2. Worker
  3. Console
  4. Tests
  5. Library
  6. Unknown

Detection is deterministic and intentionally simple:

  • Tests: <IsTestProject>true</IsTestProject>, common test package references, or names containing markers such as .Tests, .UnitTests, .IntegrationTests, .FunctionalTests, or .Test.
  • Web: root project SDK contains Microsoft.NET.Sdk.Web.
  • Worker: root project SDK contains Microsoft.NET.Sdk.Worker.
  • Console: <OutputType>Exe</OutputType> after Tests/Web/Worker checks.
  • Library: SDK-style non-executable projects that are not classified above.
  • Unknown: missing or ambiguous project metadata.

The repository includes an Acme Company demo solution under samples/AcmeCompany.

Generate a flat diagram:

dotnet run --project src/Sln2Mermaid -- --in samples/AcmeCompany/AcmeCompany.slnx --out samples/AcmeCompany/diagrams/acme-default.mmd
graph TD
    N1["Acme.Application"]
    N2["Acme.Application.Tests"]
    N3["Acme.Console"]
    N4["Acme.Core"]
    N5["Acme.Infrastructure"]
    N6["Acme.WebApi"]
    N7["Acme.WebUi"]
    N8["Acme.Worker"]

    N1 --> N4
    N2 --> N1
    N3 --> N1
    N5 --> N4
    N6 --> N1
    N6 --> N5
    N7 --> N1
    N8 --> N1
    N8 --> N5
Loading

Generate a grouped-by-type diagram:

dotnet run --project src/Sln2Mermaid -- --in samples/AcmeCompany/AcmeCompany.slnx --group-by-type --out samples/AcmeCompany/diagrams/acme-grouped-by-type.mmd
graph TD

    subgraph Web
        N6["Acme.WebApi"]
        N7["Acme.WebUi"]
    end

    subgraph Worker
        N8["Acme.Worker"]
    end

    subgraph Console
        N3["Acme.Console"]
    end

    subgraph Tests
        N2["Acme.Application.Tests"]
    end

    subgraph Library
        N1["Acme.Application"]
        N4["Acme.Core"]
        N5["Acme.Infrastructure"]
    end

    N1 --> N4
    N2 --> N1
    N3 --> N1
    N5 --> N4
    N6 --> N1
    N6 --> N5
    N7 --> N1
    N8 --> N1
    N8 --> N5
Loading

Image Export

PNG and SVG export require Docker to be installed and running. Mermaid CLI must not be installed locally for this tool. The app runs Mermaid CLI only inside the minlag/mermaid-cli Docker container, and only when --png or --svg is requested.

dotnet run --project src/Sln2Mermaid -- --in ./MySolution.slnx --out deps.mmd --png deps.png
dotnet run --project src/Sln2Mermaid -- --in ./MyBigSolution.slnx --out deps.mmd --png deps.png --png-scale 4
dotnet run --project src/Sln2Mermaid -- --in ./MySolution.slnx --out deps.mmd --svg deps.svg
dotnet run --project src/Sln2Mermaid -- --in ./MySolution.slnx --out deps.mmd --png deps.png --svg deps.svg

Image export runs a temporary .mmd file through the Mermaid CLI container image:

docker run --rm -v <host_dir>:/data minlag/mermaid-cli -i /data/input.mmd -o /data/output.png

The app always writes the requested .mmd file first. For image export, it also creates a temporary directory, writes diagram.mmd, mounts that directory as /data, runs docker run --rm, copies the generated PNG/SVG to the requested output path, and removes the temporary directory. Docker is required only for PNG/SVG export.

PNG output is rasterized. Use --png-scale to trade file size and render cost for sharper PNG output. For large diagrams, SVG is usually the better format because it remains sharp at any zoom level.

Very large solutions can become hard to read as a single diagram regardless of image format. If a solution has many projects and dense dependencies, consider generating diagrams for smaller solution/project subsets instead of relying on one huge PNG.

Example Output

graph TD
    N1["Company.Core"]
    N2["Company.Core.Abstractions"]
    N3["Company.ProjectLogic"]
    N4["Company.Tasks"]

    N1 --> N2
    N3 --> N1
    N4 --> N1
    N4 --> N3
Loading

Project names are rendered as Mermaid labels. Generated node ids such as N1, N2, and N3 are used so project names with dots or other punctuation remain valid.

Tests

The repository includes a small no-package console test harness:

dotnet run --project tests/Sln2Mermaid.Tests

Limitations

  • Only .sln, .slnx, and .csproj inputs are supported.
  • Only project-to-project references are included.
  • PackageReference dependencies are used only for test project detection; package dependency edges are ignored.
  • MSBuild properties, imports, targets, and conditions are not evaluated.
  • Solution folders are ignored.
  • PNG and SVG export depend on Docker and are not rendered natively by this app.
  • --group-by-type is project metadata grouping, not architecture classification.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages