Menu

Diagrams as code

A .skemo file is a few lines of text. It lives in the repository next to what it describes, changes in pull requests like the code, and renders to the same image on every machine.

{"skemo":1,"name":"docs-as-code.skemo","source":"//- A diagram that lives with the code: checked and rendered on every push\ndiagram(dir=\"right\")\n\n card#file.src(icon=\"file-code\") architecture.skemo\n | in the repository, reviewed in pull requests\n to(check)\n\n zone#ci.ci CI job\n card#check.step skemo lint\n | --deny-warnings\n to(render)\n card#render.step skemo render\n | same image on every machine\n to(png svg html)\n\n zone#out.out Published\n card#png.img architecture.png\n | README, wiki\n card#svg.img architecture.svg\n | docs site\n card#html.img architecture.html\n | slides, steps\n","css":[{"name":"docs-as-code.css","content":".src { --c: #7048E8; --label: \"Source\"; }\n.step { --c: #2F9E44; --label: \"Command\"; }\n.img { --c: #3E6FC4; --label: \"Output\"; }\n"}],"theme":"light"}SOURCEarchitecture.skemoin the repository, reviewed in pullrequestsCI JOBCOMMANDskemo lint--deny-warningsCOMMANDskemo rendersame image on every machinePUBLISHEDOUTPUTarchitecture.pngREADME, wikiOUTPUTarchitecture.svgdocs siteOUTPUTarchitecture.htmlslides, steps
{"skemo":1,"name":"docs-as-code.skemo","source":"//- A diagram that lives with the code: checked and rendered on every push\ndiagram(dir=\"right\")\n\n card#file.src(icon=\"file-code\") architecture.skemo\n | in the repository, reviewed in pull requests\n to(check)\n\n zone#ci.ci CI job\n card#check.step skemo lint\n | --deny-warnings\n to(render)\n card#render.step skemo render\n | same image on every machine\n to(png svg html)\n\n zone#out.out Published\n card#png.img architecture.png\n | README, wiki\n card#svg.img architecture.svg\n | docs site\n card#html.img architecture.html\n | slides, steps\n","css":[{"name":"docs-as-code.css","content":".src { --c: #7048E8; --label: \"Source\"; }\n.step { --c: #2F9E44; --label: \"Command\"; }\n.img { --c: #3E6FC4; --label: \"Output\"; }\n"}],"theme":"dark"}SOURCEarchitecture.skemoin the repository, reviewed in pullrequestsCI JOBCOMMANDskemo lint--deny-warningsCOMMANDskemo rendersame image on every machinePUBLISHEDOUTPUTarchitecture.pngREADME, wikiOUTPUTarchitecture.svgdocs siteOUTPUTarchitecture.htmlslides, steps
docs-as-code.skemo
//- A diagram that lives with the code: checked and rendered on every push
diagram(dir="right")

  card#file.src(icon="file-code") architecture.skemo
    | in the repository, reviewed in pull requests
    to(check)

  zone#ci.ci CI job
    card#check.step skemo lint
      | --deny-warnings
      to(render)
    card#render.step skemo render
      | same image on every machine
      to(png svg html)

  zone#out.out Published
    card#png.img architecture.png
      | README, wiki
    card#svg.img architecture.svg
      | docs site
    card#html.img architecture.html
      | slides, steps
docs-as-code.css
.src  { --c: #7048E8; --label: "Source"; }
.step { --c: #2F9E44; --label: "Command"; }
.img  { --c: #3E6FC4; --label: "Output"; }

Why text

  • Reviewable. Adding a service is one line in the diff, not a binary image to compare by eye.
  • Deterministic. Fonts and theme are built into the binary: the same file gives the same pixels everywhere, so rendered images can be committed and compared.
  • Stable when edited. A change only moves the arrows attached to what changed; pin a card with at="x,y" to keep it in place.
  • Offline. One executable, no browser, no Node, no network: the diagram of a private system never leaves your machine.

Check and render in CI

skemo lint docs/*.skemo --deny-warnings          # exit code 1 on any problem
skemo render docs/architecture.skemo -o docs/architecture.svg --deny-warnings

A GitHub Actions step, for instance:

- run: curl -fsSL https://skemo.net/install.sh | sh
- run: ~/.local/bin/skemo lint docs/*.skemo --deny-warnings

Outputs

FormatUse
PNG, WebPREADMEs, wikis, chat, slides (--scale 2 for sharp screens, --transparent)
SVGdocumentation sites: sharp at any size, text selectable and indexed by search engines
HTMLa standalone page with light and dark themes, step-by-step reader and animated arrows
GIF, APNG, animated WebPanimations where no script runs

Images that reopen

Every image skemo renders carries its source and stylesheets in metadata that viewers ignore. Share the PNG alone; later, skemo extract diagram.png gives the text back, and any command accepts the image in place of the source. Render with --no-source when the source must not travel with the image.

Live preview while you write

skemo docs/architecture.skemo --watch --css docs/architecture.css   # http://127.0.0.1:8710

The page reloads on every save. skemo lint --fix keeps files in one canonical form, so diffs stay small.

See also