Zig 0.16 · v0.0.2 preview

Query and export dependency graphs

Graph reports expose an owned, stable snapshot for automation and a renderer for human-readable offline artifacts. Querying and presentation remain separate operations.

A compiled example

const std = @import("std");
const archunit = @import("archunit");

test "render the project graph as Mermaid" {
    var graph = try archunit.projectGraph(std.testing.allocator, .{});
    defer graph.deinit();
    const mermaid = try graph.toMermaid(.init(std.testing.allocator, std.testing.io));
    defer std.testing.allocator.free(mermaid);
    try std.testing.expect(std.mem.indexOf(u8, mermaid, "src/api/root.zig") != null);
}

Compiled source: test/readme/graph.zig

Create an owned snapshot

projectGraph locates and extracts a project at its terminal. The result owns sorted nodes, edges, import-kind evidence, and a structural summary. Consumers can clone or inspect it without parsing a rendered document.

Focus, closure, and collapse

Start from filename, folder, path, or exact-file seeds. Focus-depth queries retain a bounded neighborhood; incoming and outgoing closure queries follow one dependency direction. Pattern exclusions remove seeds before traversal but do not hide nodes reached from an included seed.

Collapse rules group matching paths under an explicit label after selection. This makes a report legible without changing the extracted dependency graph or the evidence kept on a rendered edge.

Six local formats

FormatPrimary use
JSONAutomation and stable structured interchange.
Graphviz DOTGeneral graph tooling and rendered images.
PlantUMLDocumentation repositories that already use PlantUML.
MermaidMarkdown-oriented documentation surfaces.
Dependency Cruiser JSONInterop with dependency visualization tooling.
HTMLA complete offline interactive report with embedded assets.

Render or export

Rendering returns owned bytes and performs no filesystem writes. Export validates the requested filename, supplies the conventional extension when it is absent, creates parent directories, and propagates I/O failures. HTML output has no remote asset dependency.

Deterministic evidence

Nodes, edges, classification sets, and source locations are normalized and sorted before rendering. Optional generation timestamps can be disabled for golden files. Query operations clone their result so source snapshots and caller contexts may be released independently.

Reports explain; rules enforce Keep release policy in file, layer, slice, or metric rules. Use graph reports to explore a boundary, review a change, and attach concrete topology evidence.
Next: Metrics