A simple tool that helps you understand and visualize how modules in your D projects depend on each other.
This is an example of a dependency graph of that example project generated by Module Viz.
I also tried this in the phobos codebase, the graph looks like this. Yes, this is huge😅 -
Module Viz scans your D project, figures out how your modules are connected through imports, and creates visual diagrams that help you understand your codebase structure.
Key features:
- ✅ Creates visual dependency graphs from your D code
- ✅ Shows how modules connect to each other
- ✅ Generates both graphical and text-based visualizations
- ✅ Color-codes modules based on their role in your project
- ✅ Works on Windows, Linux, and macOS
-
Download the tool
- Go to the Releases page
- Download the zip file for your platform (e.g.,
module-viz-v1.0.0-win-x64.zip
for Windows)
-
Install it
- Extract the zip file to a folder of your choice
- For convenience, you might want to place
viz.exe
in a dedicated folder likeC:\Tools\ModuleViz
or~/tools/moduleviz
-
Add to your PATH (optional but recommended)
On Windows:
- Right-click on "This PC" or "My Computer" and select "Properties"
- Click on "Advanced system settings"
- Click on the "Environment Variables" button
- Under "System variables" (or "User variables" for just your account), find the "Path" variable and click "Edit"
- Click "New" and add the folder path where you placed viz.exe (e.g.,
C:\Tools\ModuleViz
) - Click "OK" on all dialog boxes
- Restart any open command prompts for the change to take effect
On Linux/macOS:
- Edit your
~/.bashrc
,~/.zshrc
, or equivalent shell configuration file - Add this line:
export PATH="$PATH:/path/to/folder/containing/viz"
- Save the file and run
source ~/.bashrc
(or appropriate file) or restart your terminal
If you prefer to build the tool yourself:
-
Prerequisites
- D compiler (DMD, LDC, or GDC)
- DUB package manager
-
Build steps
# Clone the repository git clone https://github.com/abulgit/module-viz.git cd module-viz # Build the project dub build # The executable will be in the bin directory
# If added to PATH:
viz --input=path/to/project
# If not added to PATH (Windows):
C:\path\to\viz.exe --input=path/to/project
# If not added to PATH (Linux/macOS):
/path/to/viz --input=path/to/project
Create a dependency graph of your project:
viz --input=path/to/project --output=graph.dot --image
See a text-based graph:
viz --input=path/to/project --text
Get help:
viz --help
--input=PATH, -i Directory containing D source files to analyze (default: current directory)
--output=FILE, -o Output .dot file (default: dependency_graph.dot)
--image, --img Automatically generate image from the dot file
--format=FORMAT, -f Image format (png, svg, pdf, etc.) when using --image (default: png)
--text, -t Display text-based visualization of the dependency graph
--help, -h Show help information
The tool color-codes modules to help you understand their role:
- Light Green: Base modules that are only imported by other modules but don't import anything
- Salmon: Entry point modules that import other modules but aren't imported by anything
- Gold: Hub modules that are heavily connected (both importing and being imported)
- Light Blue: Regular modules with balanced dependencies
To generate images, you need GraphViz installed on your system.
If you don't have GraphViz or can't install it, you can:
- Use the
--text
option to see a text representation - Upload the .dot file to an online GraphViz tool:
# Generate a PNG visualization of a project
viz --input=path/to/dproject --image
# Generate an SVG instead of PNG
viz --input=path/to/dproject --image --format=svg
# Show both text and graphical visualization
viz --input=path/to/dproject --text --image
The repository includes an example project in the example/
directory:
# Analyze the example project
viz --input=example --output=example.dot --image --text
- "Command not found": Make sure viz is in your PATH or use the full path to the executable
- Image generation fails: Install GraphViz from https://graphviz.org/download/
- No modules found: Check that you're pointing to a directory with .d files
If you encounter any issues, please open an issue on GitHub.
Proprietary
- libdparse - D language parsing library