Zig 0.16 · v0.0.2 preview

Slice architecture and diagrams

Slices project file paths into repeated architectural units—features, components, bounded contexts—then enforce independence or diagram adherence over the projected graph.

A compiled example

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

test "API does not bypass service" {
    var project = try archunit.projectSlices(std.testing.allocator, .{});
    defer project.deinit();
    var slices = try project.definedByRegex("^src/([^/]+)/");
    defer slices.deinit();
    var should_not = try slices.shouldNot();
    defer should_not.deinit();
    var rule = try should_not.containDependency("api", "domain");
    defer rule.deinit(std.testing.allocator);
    try archunit.expectPasses(&rule, .init(.init(std.testing.allocator, std.testing.io)));
}

Compiled source: test/readme/slices.zig

Project paths to slice names

Define a slice projection with a glob or regular expression capture. A path may map to one slice label or be dropped. Equal label pairs merge while retaining all raw file-edge evidence, and isolated projected nodes remain visible.

Shipped slice rules

No cycles

Detect directed cycles among slice nodes and return a canonical closed slice path with the contributing file edges.

Independence

Require slices not to depend on one another, with configurable allowances for explicitly shared slices.

Diagram adherence

Compare actual projected dependencies with a supported PlantUML component diagram and report missing or forbidden relationships.

Diagram export

Render the owned slice graph as deterministic PlantUML without a network service or remote renderer.

PlantUML contract

The parser intentionally supports the component vocabulary the rule can verify. Aliases and directed component relationships become slice names and allowed edges. Unsupported syntax is a clear parse/configuration error rather than being guessed.

Exclusions happen before projection

Path exclusions remove project paths before labels and edges are projected. An external module has no project path and is not a slice node. This keeps a slice rule about the internal project topology instead of mixing dependency classification into capture semantics.

Use layers and slices for different shapes Layers name a small, ordered architecture hierarchy. Slices describe many repeated peer units with names captured from paths. A project can enforce both views over the same dependency graph.
Next: Graph reports