Configuration Reference
Config File Locations
| Source | Path | Priority |
|---|---|---|
| Defaults | Built-in | Lowest |
| Global | ~/.config/diagramkit/config.json5 (or config.json) |
Low |
| Environment | DIAGRAMKIT_* env vars |
Medium |
| Local | diagramkit.config.json5 or .ts (walks up) |
High |
| Explicit | --config <path> |
High (replaces local) |
| CLI/API | Flags and RenderOptions.config |
Highest |
XDG_CONFIG_HOME overrides the global config base path.
Schema
interface DiagramkitConfig { outputDir: string // Default: '.diagramkit' manifestFile: string // Default: 'manifest.json' useManifest: boolean // Default: true sameFolder: boolean // Default: false defaultFormats: OutputFormat[] // Default: ['svg'] defaultTheme: Theme // Default: 'both' outputPrefix: string // Default: '' outputSuffix: string // Default: '' extensionMap?: Record<string, DiagramType> inputDirs?: string[] overrides?: Record<string, FileOverride> mermaidLayout?: MermaidLayoutOptions optimize?: OptimizeOptions}interface MermaidLayoutOptions { mode?: 'off' | 'warn' | 'flip' | 'elk' | 'auto' // Default: 'warn' targetAspectRatio?: number // Default: 4 / 3 tolerance?: number // Default: 2.5}interface OptimizeOptions { svg?: boolean // SVGO + Mermaid CSS pruning. Default: true png?: PngEncoderOptions webp?: WebpEncoderOptions avif?: AvifEncoderOptions}Options
outputDir
| Type | string |
| Default | '.diagramkit' |
Output folder name, created next to source files. Ignored when sameFolder is true.
manifestFile
| Type | string |
| Default | 'manifest.json' |
Manifest filename inside the output folder. Stores SHA-256 hashes for incremental builds.
useManifest
| Type | boolean |
| Default | true |
When false: all diagrams re-render every run, no manifest written.
sameFolder
| Type | boolean |
| Default | false |
Place outputs alongside source files. When true, outputDir is ignored.
Default:
docs/ flow.mermaid .diagramkit/ flow-light.svgsameFolder: true:
docs/ flow.mermaid flow-light.svgdefaultFormats
| Type | OutputFormat[] |
| Default | ['svg'] |
Array of output formats. Supports multiple formats in a single render pass.
defaultTheme
| Type | 'light' | 'dark' | 'both' |
| Default | 'both' |
outputPrefix / outputSuffix
| Type | string |
| Default | '' |
Prefix and suffix for output filenames. Pattern: {prefix}{name}{suffix}-{theme}.{format}
inputDirs
| Type | string[] |
| Default | undefined (scan entire tree) |
Restrict file discovery to these directories (relative to the project root). When set, only diagrams inside the listed directories are scanned.
{ inputDirs: ['docs/diagrams', 'src/architecture'],}extensionMap
| Type | Record<string, DiagramType> |
| Default | built-in map |
Merged with built-in map (overrides take precedence). Matching is longest-first.
Built-in map:
| Extension | Type |
|---|---|
.mermaid, .mmd, .mmdc |
mermaid |
.excalidraw |
excalidraw |
.drawio, .drawio.xml, .dio |
drawio |
.dot, .gv, .graphviz |
graphviz |
overrides
| Type | Record<string, FileOverride> |
| Default | undefined |
Per-file render overrides. Keys can be exact filenames, relative paths, or glob patterns.
{ overrides: { // Exact filename "hero.mermaid": { formats: ["svg", "png"], scale: 3 }, // Glob pattern "docs/*.excalidraw": { theme: "light" }, // Relative path "src/diagrams/arch.drawio": { quality: 95 }, },}mermaidLayout
| Type | MermaidLayoutOptions |
| Default | { mode: 'warn', targetAspectRatio: 4 / 3, tolerance: 2.5 } |
Aspect-ratio rebalance options for Mermaid renders. Mermaid’s default Dagre layout has no aspect-ratio knob — a flowchart LR with many nodes produces a very wide SVG (e.g. 12:1) and a flowchart TD with many siblings produces a very tall one. When the rendered ratio falls outside [targetAspectRatio / tolerance, targetAspectRatio * tolerance], diagramkit can warn or transparently re-render the diagram with a different layout to bring it closer to the target.
Only Mermaid renders are affected. Excalidraw, draw.io, and Graphviz outputs are unchanged.
| Field | Type | Default | Notes |
|---|---|---|---|
mode |
'off' | 'warn' | 'flip' | 'elk' | 'auto' |
'warn' |
See modes below. |
targetAspectRatio |
number |
4 / 3 ≈ 1.333 |
Used as the picker target and as the elk.aspectRatio hint. |
tolerance |
number (must be > 1) |
2.5 |
Acceptable band around the target. The default accepts ratios from roughly 1:1.9 to 3.3:1. |
Modes
| Mode | Behaviour | Cost |
|---|---|---|
off |
Never measure. Identical to pre-1.x behaviour. | 0 extra renders. |
warn (default) |
Measure once and emit a warning when out of band. Keeps the original render. | 0 extra renders. |
flip |
For flowcharts (flowchart/graph), swap LR ↔ TB (and RL ↔ BT), re-render once, keep whichever ratio is closer to the target. |
1 extra render when triggered. |
elk |
Re-render with a %%{init:{"layout":"elk","elk":{"aspectRatio":target}}}%% directive. Requires the optional @mermaid-js/layout-elk plugin to be available; otherwise the attempt is caught and the original render is kept. |
1 extra render when triggered. |
auto |
Try flip first; if still outside the band, also try elk (and the combined flip + elk). Pick the closest of all attempts. |
1–3 extra renders when triggered. |
Eligibility:
- Only
flowchart/graphdiagrams are eligible forflip/elk/autorebalances. Sequence, gantt, journey, state, class, ER, pie, mindmap, sankey, and similar inherently-directional diagrams degrade towarn-only behaviour. - If the source already declares an
%%{init}%%block that setslayout,elk, orflowchart.defaultRenderer, theelkinjection is skipped — author intent always wins. - Failed rebalance attempts are caught and warned about; the original successful render is always preserved.
{ // Project-wide opt-in to automatic rebalance. mermaidLayout: { mode: 'auto', targetAspectRatio: 4 / 3, tolerance: 2.5 },}The same options can be passed per render call via RenderOptions.mermaidLayout, layered on top of the project config.
optimize
| Type | OptimizeOptions |
| Default | { svg: true } |
Output optimization: SVGO + Mermaid CSS pruning for SVG output, and sharp encoder tuning for raster output (PNG/JPEG/WebP/AVIF, converted from the optimized SVG).
interface OptimizeOptions { svg?: boolean // Default: true png?: PngEncoderOptions webp?: WebpEncoderOptions avif?: AvifEncoderOptions}interface PngEncoderOptions { compressionLevel?: number // 0–9. Default: 9 effort?: number // 1–10. Default: 10 adaptiveFiltering?: boolean palette?: boolean quality?: number // 1–100, palette quality when palette is enabled}interface WebpEncoderOptions { effort?: number // 0–6. Default: 6 quality?: number // 1–100. Defaults to the render `quality` option lossless?: boolean nearLossless?: boolean}interface AvifEncoderOptions { effort?: number // 0–9. Default: 6 quality?: number // 1–100. Defaults to the render `quality` option lossless?: boolean}| Field | Type | Default | Notes |
|---|---|---|---|
svg |
boolean |
true |
Runs a curated, accessibility-preserving SVGO pass plus reference-aware Mermaid <style> pruning on every rendered SVG before it is written to disk (and before rasterization, so PNG/WebP/AVIF derive from the same optimized source). Preserves viewBox, width/height, role/aria-*/<title>/<desc>, kept <style> rules, and every id referenced by url(#…)/CSS selectors/<use>. Deterministic — identical input yields byte-identical output. Set false to disable for hand-authored sources that need byte-exact passthrough. |
png |
PngEncoderOptions |
{ compressionLevel: 9, effort: 10 } |
Merged on top of the tuned defaults and forwarded to sharp(...).png(...). Any option sharp accepts is passed through, not just the fields above. |
webp |
WebpEncoderOptions |
{ effort: 6 } |
Merged on top of the tuned defaults; quality follows the render quality option unless overridden here. |
avif |
AvifEncoderOptions |
{ effort: 6 } |
Merged on top of the tuned defaults; quality follows the render quality option unless overridden here. |
Mermaid boilerplate pruning is conservative: a <style> rule is dropped only when every selector in it can be confidently evaluated and none matches a class/id/tag present in the rendered document; selectors with attribute selectors, functional pseudo-classes (:not(), :has(), …), or unparsable preludes are always kept, as are @media/@supports blocks. @keyframes/@font-face at-rules are kept only when referenced by a kept rule. Optimization never throws — if SVGO fails on a pathological document, the (possibly CSS-pruned) input is returned so a render is never lost to optimization.
{ optimize: { svg: true, png: { compressionLevel: 9, effort: 10 }, webp: { effort: 6 }, avif: { effort: 6 }, },}Like mermaidLayout, optimize is deep-merged across config layers — a partial override (just svg, or just png) keeps the rest of the defaults, and each sub-object is validated independently so a malformed value falls back to its default with a warning instead of dropping the whole block.
Environment Variables
| Variable | Config Equivalent | Example |
|---|---|---|
DIAGRAMKIT_FORMAT |
defaultFormats |
DIAGRAMKIT_FORMAT=png,svg |
DIAGRAMKIT_THEME |
defaultTheme |
DIAGRAMKIT_THEME=light |
DIAGRAMKIT_OUTPUT_DIR |
outputDir |
DIAGRAMKIT_OUTPUT_DIR=images |
DIAGRAMKIT_NO_MANIFEST |
useManifest: false |
DIAGRAMKIT_NO_MANIFEST=1 |
Manifest Format
{ "version": 2, "diagrams": { "flow.mermaid": { "hash": "sha256:a1b2c3d4e5f67890", "generatedAt": "2026-04-04T10:30:00.000Z", "mtimeMs": 1712226600000.123, "size": 248, "outputs": [ { "file": "flow-light.svg", "format": "svg", "theme": "light", "width": 800, "height": 600 }, { "file": "flow-dark.svg", "format": "svg", "theme": "dark", "width": 800, "height": 600 } ], "formats": ["svg"], "theme": "both" } }}| Field | Type | Description |
|---|---|---|
version |
2 |
Format version |
diagrams |
Record<string, ManifestEntry> |
Source filename to entry |
hash |
string |
SHA-256 content hash (first 16 hex chars) |
generatedAt |
string |
ISO 8601 timestamp |
mtimeMs |
number |
Last-seen source file mtime, used for cheap no-op checks before re-hashing |
size |
number |
Last-seen source file size in bytes, paired with mtimeMs for fast stale checks |
outputs |
ManifestOutput[] |
Per-output metadata |
formats |
OutputFormat[] |
All tracked formats (accumulative) |
theme |
Theme |
Theme variant used |
Examples
Default (no config needed)
{ outputDir: '.diagramkit', manifestFile: 'manifest.json', useManifest: true, sameFolder: false, defaultFormats: ['svg'], defaultTheme: 'both',}CI/CD
{ "useManifest": false }Custom extensions
{ "extensionMap": { ".flow": "mermaid", ".diagram": "drawio", ".depgraph": "graphviz" }}Per-file overrides
{ defaultFormats: ['svg'], overrides: { "hero.mermaid": { formats: ["svg", "png"], scale: 3 }, "**/*.excalidraw": { theme: "light" }, },}