divizu diagram compiler
v0.1.0

Reference manual / rev. 0.1

The whole
contract.

divizu draws dependency-injection wiring as hardware: sockets, plugs and cables. The renderer keeps no explanatory text inside the drawing. This page is the legend.

Document
divizu / reference
Issue
0.1.0
Status
stable
Updated
2026-10
License
MIT
01

Overview

/overview

A divizu document is a list of blocks. Each block has one of four roles: root, component, boundary or value. Blocks declare needs for service keys and, optionally, provides for the keys they supply. A need may name the block that provides it.

The default layout reads bottom-up as a forest of slot trees: each provider sits directly above its socket, with its tab plugged into the notch. The optional layers layout draws a layered DAG instead, where shared providers appear once with a cable to each socket.

For coding agents. Start with the machine-readable context in llms.txt and the divizu skill. The skill contains the workflow, DSL cheat sheet, and render commands.
No runtime measurement. Character widths are estimated from a monospace grid. The same DSL produces byte-identical SVG on every machine, without a browser engine.
Property Value
InputA plain-text DSL, one block list
OutputDeterministic, self-contained SVG
RuntimeZero dependencies, no DOM, no canvas
DirectionBottom-up; root at the bottom
GeometryInteger-safe floats, monospace text grid

Open the playground to edit the canonical example, or continue to the role legend.

02

Roles & colors

renderer.ts / palette

Role colors are applied to the block outline. The palette adapts to light and dark themes; the swatches below show the dark defaults used by the site.

root The program or composition root. Sits at the bottom, owns needs, and cannot be used as a provider.
component Internal code that gets wired in. The default building block: services, handlers, layers, repositories.
boundary Code that itself crosses the process boundary: database, network, queue, filesystem, vendor SDK.
value Injected data with no behaviour: config, constants, feature flags. Values cannot declare needs.
Role Dark stroke Light stroke Typical use
root#f1602f#c2410cProgram / entry point
component#6f9fce#2b5e98Internal service, handler or layer
boundary#d7a24a#9a6b12Database, network, queue, vendor adapter
value#2dd4bf#0f766eConfig or injected data, no methods

Every block must start with its role. There is no inference and no role: directive, so an agent cannot quietly turn a service into an adapter. tag: carries open-vocabulary language details such as closer, scoped or singleton without changing the drawing.

03

Sockets & plugs

layout / envelope

A socket is a U-shaped notch cut into the top edge of a block. Its width comes from the requirement key. The key pill sits on the floor of the notch.

  • needs PaymentPort <- StripePayment is a bound socket: a solid pill names the service key, and StripePayment declares provides: PaymentPort.
  • The provider’s bottom edge grows a plug tab. In the default slot layout the tab descends into the socket; in the layers layout an orthogonal cable connects it to the socket instead.
  • Slot mode is a forest: each provider is placed directly above its socket, and wide subtrees push neighbouring sockets outward. Layers mode is a DAG: a provider sits above every consumer that needs it and shared providers are drawn once.
  • Every block perimeter — top notches, body, bottom tab — is one clockwise polygon rounded with a single quadratic-curve pass. Cables are separate paths in layers mode.

A block may have several needs. They are ordered left-to-right inside the block. In slot mode a provider referenced twice is slotted twice, once per consumer. In layers mode it is drawn once and wired to each consumer. Write needs K <- fresh Provider in layers mode when a consumer must get its own instance.

FIG. 01 examples/checkout.svg 1347 × 652
Rendered checkout diagram with socket notches, interface pills and slot-connected adapters
The canonical checkout plate. The two dashed pills — ShippingPort and ReportPort — are unbound needs flanking the bound OrderUseCase.
Slots are the default; sharing is a deliberate view. Switch the playground to Layers or pass --layout layers when a DbLive needed by twenty components should be one database node with twenty cables instead of twenty slots. Use fresh only when the runtime really creates a separate instance.
04

Unbound ports

socket / dashed

Write a need without a provider to leave it unbound:

unbound.di DSL
root CheckoutApi {
  needs ShippingPort
  needs OrderUseCase <- OrderService
}

An unbound need has no provider. Its key pill is drawn with a dashed outline and a muted amber fill. It still carves a real notch, so it participates in layout exactly like a bound socket.

Use unbound sockets for dependencies that live outside the diagram, ports that cross a bounded context, or to deliberately stop a graph at an interface boundary.

05

Internal modules

modules / rows

modules: lists collaborators that are internal to a block, not separately plugged dependencies. They render as compact horizontal rows inside the block body, below the sockets.

modules.di DSL
component OrderService "application service" {
  provides: Orders
  modules: OrderValidator, PricingEngine, OrderMapper
}
  • Modules do not create nodes, needs or layout edges.
  • Root containers are intentionally empty: modules on a root are ignored.
  • Quote a name to include a comma: "conn pool, primary".
  • A module list may continue on the next line when the line ends with a comma.
06

Candidates with side notches

candidates / cards

candidates: lists alternative implementations that a factory or service can produce. Candidates share the same vertical card rendering as modules, but they mean “one of these”, not “all of these”.

candidates.di DSL
component PreviewGeneratorFactory "factory" {
  provides: PreviewGenerator
  needs ImageScaler <- SharpImageScaler
  candidates: DocumentPreview, ImagePreview(ImageScaler), VideoPreview
}
  • Name renders a plain horizontal card.
  • Name(RequiredInterface) cuts a U-shaped notch into the card’s right side and places a rotated interface pill inside it. It means the candidate itself requires that interface.
  • A candidate side notch is not a top-edge socket. It does not bind a provider, create a child node or add a layout edge.
FIG. 02 examples/candidates.svg 1455 × 746
Rendered candidates example with two factories and side notches
ImagePreview(ImageScaler) and AwsStorage(Encryption) grow U-shaped side notches with rotated interface pills.

The working source is examples/candidates.di. Open it in the playground to edit it live.

07

DSL reference

parser / grammar

The complete grammar:

grammar.txt EBNF-ish
file       = { block } ;
block      = role ident [ string ] "{" { NL | directive } "}" ;
role       = "root" | "component" | "boundary" | "value" ;
directive  =
    "provides"   ":" list
  | "needs"      key [ "<-" [ "fresh" ] ident ]
  | "modules"    ":" list
  | "candidates" ":" candidate { "," candidate }
  | "tag"        ":" list
  | "src"        ":" string
  | "label"      ":" name ;
list       = name { "," [ NL ] name } ;
candidate  = name [ "(" name ")" ] ;
(* directives end at NL or ";" ; braces are mandatory *)
Syntax Meaning
root App { ... } Declares a program/entry point. A root cannot be used as a provider.
component Orders { ... } Internal code that gets wired in.
boundary Db { ... } Code that crosses a process boundary: DB, queue, HTTP, vendor SDK.
value Config { ... } Injected data with no behaviour. Values cannot declare needs.
provides: Orders, Reports Service keys this block supplies. Checked against consuming needs.
needs Port Unbound requirement: dashed pill, no provider.
needs Port <- Provider Bound requirement: provider is shared by default.
needs Port <- fresh Provider Creates a separate provider instance for this consumer.
modules: a, b Internal collaborators rendered as compact rows.
candidates: A, B(IFace) Alternative implementations; the argument adds a side notch.
tag: closer, scoped Open-vocabulary labels with no layout or colour effect.
src: "path:line" Provenance for --check --verify-src and tooling.

Lexical rules

  • # and // start a comment only at a token boundary, so C#Parser and foo//bar are identifiers.
  • Names can be quoted for spaces and punctuation: provides: "@app/Users", label: "Repo<T>".
  • Lists continue after a comma and a newline.
  • Directives end at a newline or ;. Braces are mandatory.
  • Block ids must be unique; provider references must resolve.
  • Every block must be reachable from a root, and every root must be unreferenced.

Validation is intentionally strict. Duplicate ids, duplicate needs, ambiguous providers, mismatched provides, orphan blocks, malformed values and cycles fail with a file-relative line:column and a fix hint.

08

Scaling a large codebase

layout / forest

Large systems are not drawn as one god diagram. The unit is a plate: one readable bounded context, normally 5–25 blocks. For a whole repository, start with a system map with one root per entry point — storefront, operator console, workers, data platform — and let the renderer lay the roots side by side.

Use the default slot layout for the literal hardware view, and --layout layers when shared infrastructure should be drawn once instead of duplicated per socket. In layers mode a provider referenced by several consumers is one node with one cable per socket. Use modules: to compress internals, unbound needs to stop at external systems, and candidates: for alternatives.

The guard is not a target. The renderer accepts up to 5,000 instances, but a 200-block plate is technically valid and practically unreadable. Split by bounded context long before you reach the guard.

Atlas Commerce / 28 blocks

This imagined commerce platform is one file with 28 blocks, three roots and 25 dependencies: storefront, operator console, and async workers. The plate below uses the default slot layout. The full plate is the system map — each context can be rendered separately for a closer read.

FIG. 03 examples/large.svg 3704 × 682 / 28 blocks Open SVG ↗
A 28-block Atlas Commerce system map with storefront, operator console and async worker roots
One 28-block plate across three roots. Scroll horizontally to pan the sheet; open the SVG for full resolution.

Keeping it maintainable

  • One root per entry point. Web, admin, workers and batch jobs are separate roots, not a single tree.
  • Split at boundaries. One plate per bounded context; the system map is an index, not the whole book.
  • Compress internals. Put validators, policies and repositories in modules: rather than giving every class a socket.
  • Stop at externals. Leave a need unbound when the dependency lives outside the diagram — a queue, a vendor, another team's service.
  • Pick the right layout. Slots duplicate shared providers. Layers draw them once with cables. Use layers when fan-in is the point; use slots when the physical metaphor is.

This 28-block map renders in about 1.4 ms in Node and a few milliseconds in the browser. The compiler scales; the reading limit is yours. The playground includes this plate as the Large map example, with zoom and pan.

Source: examples/large.di · Output: examples/large.svg

09

CLI & API

src/cli.ts

Render a file to SVG, or read the DSL from stdin:

Terminal Node 18+
divizu <input.di> [options]
cat graph.di | divizu [options]

divizu architecture.di --check --json
divizu architecture.di --check --verify-src
OptionDescription
-o, --out <file>Write SVG to a file (default: stdout)
-t, --theme <mode>auto, dark or light (default auto)
-p, --padding <px>Canvas padding (default 56)
--radius <px>Corner radius (default 8)
--layer-gap <px>Space between dependency layers (default 78)
--socket-gap <px>Space between sockets and nodes (default 28)
--responsiveEmit width="100%" height="100%"
--title <text>Accessible SVG title
--checkValidate without rendering
--jsonLayout JSON; with --check, a validation report
--verify-srcWith --check, verify src: paths exist
-w, --watchRe-render when the input file changes

Use it as a library:

app.ts ESM
import { render, mount, layout, validate } from "divizu";

const { svg, width, height } = render(dsl, {
  theme: "dark",
  padding: 48,
});

mount(document.querySelector("#di"), dsl, {
  theme: "light",
});

// Agent loop: validate before rendering.
const report = validate(dsl);
if (!report.ok) console.error(report.errors);

// Geometry for tests or hit testing:
const geometry = layout(dsl);
for (const node of geometry.nodes) {
  console.log(node.label, node.layer, node.x, node.y, node.width);
}

Exports: render, mount, layout, validate, parseDocument, parseDSL, themeCss and the THEME_CSS constant.

10

Theming

theme.css / vars

The SVG embeds a self-contained stylesheet and uses low-specificity :where() selectors, so host CSS can override any --di-* variable without !important.

theme.css CSS
.my-diagram .di-viz {
  --di-canvas-bg: #0b1020;
  --di-surface: #131a2b;
  --di-stroke-root: #22d3ee;
  --di-stroke-component: #93c5fd;
  --di-stroke-boundary: #fbbf24;
  --di-stroke-value: #5eead4;
  --di-wire: #64748b;
}

Colors are also emitted as concrete presentation attributes. That keeps rasterizers without CSS-variable support (librsvg, ImageMagick, some SVG-to-PNG pipelines) fully colored. In a non-CSS renderer, theme: "auto" bakes the dark palette; use --theme light for a static light SVG.

divizu/theme.css is generated at build time if you prefer an external stylesheet.

11

Deliberate limits

/limits
  • Sharing is layout-dependent. Slot mode duplicates a provider per consumer. Layers mode draws it once; fresh opts into a separate instance. Both are guarded at 5,000 instances.
  • Graphs must be acyclic. Cycles, orphan blocks and unreachable blocks are rejected with a descriptive error.
  • Roots are explicit. One or more root blocks are required. A root cannot be used as a provider.
  • Text width is heuristic. Monospace character-width estimates replace DOM measurement. CJK or emoji-heavy labels can overflow.
  • All dependency sockets are on the top edge. Candidate side notches exist, but dependency sockets do not rotate to the sides yet.
  • Tags are open vocabulary. tag: adds meaning for humans and agents, not colour or layout. Use roles for the four structural categories.
  • Source verification is path-level. --verify-src checks that src: files exist; it does not type-check the code in them.
End of reference / rev. 0.1 Continue in the playground →