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.
| Property | Value |
|---|---|
| Input | A plain-text DSL, one block list |
| Output | Deterministic, self-contained SVG |
| Runtime | Zero dependencies, no DOM, no canvas |
| Direction | Bottom-up; root at the bottom |
| Geometry | Integer-safe floats, monospace text grid |
Open the playground to edit the canonical example, or continue to the role legend.
Roles & colors
renderer.ts / paletteRole 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.
| Role | Dark stroke | Light stroke | Typical use |
|---|---|---|---|
root | #f1602f | #c2410c | Program / entry point |
component | #6f9fce | #2b5e98 | Internal service, handler or layer |
boundary | #d7a24a | #9a6b12 | Database, network, queue, vendor adapter |
value | #2dd4bf | #0f766e | Config 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.
Sockets & plugs
layout / envelopeA 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 <- StripePaymentis a bound socket: a solid pill names the service key, andStripePaymentdeclaresprovides: 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.
ShippingPort and ReportPort — are
unbound needs flanking the bound OrderUseCase.
--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.
Unbound ports
socket / dashedWrite a need without a provider to leave it unbound:
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.
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.
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.
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”.
component PreviewGeneratorFactory "factory" {
provides: PreviewGenerator
needs ImageScaler <- SharpImageScaler
candidates: DocumentPreview, ImagePreview(ImageScaler), VideoPreview
}
Namerenders 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.
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.
DSL reference
parser / grammarThe complete grammar:
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, soC#Parserandfoo//barare 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.
Scaling a large codebase
layout / forestLarge 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.
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.
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
CLI & API
src/cli.tsRender a file to SVG, or read the DSL from stdin:
divizu <input.di> [options]
cat graph.di | divizu [options]
divizu architecture.di --check --json
divizu architecture.di --check --verify-src
| Option | Description |
|---|---|
-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) |
--responsive | Emit width="100%" height="100%" |
--title <text> | Accessible SVG title |
--check | Validate without rendering |
--json | Layout JSON; with --check, a validation report |
--verify-src | With --check, verify src: paths exist |
-w, --watch | Re-render when the input file changes |
Use it as a library:
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.
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.
.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.
Deliberate limits
/limits-
Sharing is layout-dependent. Slot mode
duplicates a provider per consumer. Layers mode draws it once;
freshopts 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
rootblocks 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-srcchecks thatsrc:files exist; it does not type-check the code in them.