DDeps

February 11, 2026 ยท View on GitHub

Source review support tool

A tool to create a module dependency graph for the D language. The feature is that you can record snapshots in two versions and compare them to visualize the differences.

Screenshot (Example)

basic

rx

no core, no std

rx-nostd

exclude rx.subject

rx-nosubject

Requirements

  1. dub
  2. Graphviz (for DOT/SVG output)
  3. Mermaid-capable viewer/editor (only when using --format=mermaid)

Settings

For library (example)

	"configurations": [
		{
			"name": "default"
		},
		{
			"name": "diff",
			"postGenerateCommands": [
				"dub build -c makedeps",
				"dub fetch ddeps",
				"dub run ddeps -- --focus=rx -o deps.dot",
				"dot -Tsvg -odeps.svg deps.dot"
			]
		},
		{
			"name": "diff-update",
			"postGenerateCommands": [
				"dub fetch ddeps",
				"dub run ddeps -- --update"
			]
		},
		{
			"name": "makedeps",
			"dflags": ["-deps=deps.txt"]
		}
  ]

For executable

	"configurations": [
		{
			"name": "default"
		},
		{
			"name": "diff",
			"postGenerateCommands": [
				"dub build -c makedeps",
				"dub fetch ddeps",
				"dub run ddeps -- -o deps.dot",
				"dot -Tsvg -odeps.svg deps.dot"
			]
		},
		{
			"name": "diff-update",
			"postGenerateCommands": [
				"dub fetch ddeps",
				"dub run ddeps -- --update"
			]
		},
		{
			"name": "makedeps",
			"dflags": ["-deps=deps.txt"]
		}
  ]

For Mermaid output (example)

Use the same configurations but swap the post command to emit Mermaid instead of DOT/SVG:

{
	"name": "diff-mermaid",
	"postGenerateCommands": [
		"dub build -c makedeps",
		"dub fetch ddeps",
		"dub run ddeps -- --format=mermaid --output=deps.mmd"
	]
}

Usage

At first

create lock file

dub build -c makedeps
dub build -c diff-update

Basic

  1. Modify source
  2. Update diff
    • dub build -c diff
  3. Do review with the dependency graph diff
    • Open the deps.svg in browser, or generate Mermaid with dub run ddeps -- --format=mermaid --output=deps.mmd and view it in a Mermaid-enabled editor.

Compare 2 versions

  1. checkout a target version
    • git reset --hard XXX or git checkout XXXXX
  2. reset to source version
    • git reset --hard HEAD~10 (e.g. 10 versions ago)
  3. create deps-lock.txt
    • dub build -c makedeps
    • dub build -c diff-update
    • if dub.json / dub.sdl has not configure then add these.
  4. reset to target version
    • git reset --hard ORIG_HEAD
  5. make diff
    • dub build -c diff
  6. open deps.svg (or produce Mermaid: dub run ddeps -- --format=mermaid --output=deps.mmd)

Arguments

nameUsagedescriptiondefault
input-i XXX or --input=XXXdeps file namedeps.txt
output-o XXX or --output=XXXdestination file namewrite to stdout
update-u or --updateupdate lock filefalse
lock-l XXX or --lock=XXXlock file namedeps-lock.txt
focus-f XXX or --focus=XXXfiltering target by nameapp
depth-d N or --depth=Nsearch depth1
exclude-e XXX [-e YYY] or --exclude=XXX [--exclude=YYY]exclude module namesobject
format`--format=dotmermaid`output format
allow-rule--allow-rule=A->B where A/B are module names or group:nameallow-list per source; other targets from that source warn
group-g NAME=mod1,mod2 or -g modgroup nodes; short form includes submodules; multiple -g allowed
help--helpshow help

Mermaid output

You can render the diff as a Mermaid graph (useful in Markdown viewers that support Mermaid):

dub run ddeps -- --format=mermaid --output=deps.mmd

Open deps.mmd in a Mermaid-capable viewer/editor to inspect the graph. Added nodes/edges are green, removed are red, kept are neutral. Graphviz is not required for Mermaid output.

Grouping example

dub run ddeps -- --group util --group UI=app.ui,app.ui.widgets --format=dot -o deps.dot

--group util creates a group for util and its submodules (e.g., util.log). --group UI=... groups the exact modules listed. Groups are rendered as clusters in DOT and subgraphs in Mermaid.

Wildcard helper: suffix .* inside --group targets the module and all submodules even in long form, e.g. --group external=mir.*,numir or short form --group mir.*.

Integration / sample outputs script

Run once to clone sample repos and emit DOT/Mermaid (and SVG if dot exists):

rdmd ./scripts/sample_outputs.d

Artifacts live under ./tmp/test-<repo>/ and include grouping/exclude variants. For md, both with/without -e core -e std are generated.

Rx diff example is built in: the script checks out rx tag v0.7.0 as the old reference, compares against current HEAD, and writes grouped color-diff graphs (deps-diff-full.dot/.mmd/.svg) showing red/green changes.

Dependency direction warnings

Use --allow-rule to allow specific downward directions between layers (e.g., --allow-rule=group:ui->group:app, --allow-rule=group:app->group:infra). For any source that has allow-rules, edges to non-allowed targets are warned: rendered bold/dashed (kept edges also red) with a warning message on stdout. Sources without rules are ignored. This helps enforce layered architectures where modules only depend in approved directions.