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
| Format | Primary use |
|---|---|
| JSON | Automation and stable structured interchange. |
| Graphviz DOT | General graph tooling and rendered images. |
| PlantUML | Documentation repositories that already use PlantUML. |
| Mermaid | Markdown-oriented documentation surfaces. |
| Dependency Cruiser JSON | Interop with dependency visualization tooling. |
| HTML | A 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.