Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

astro-archify

An Astro integration for rendering Archify system diagrams — architecture, workflow, sequence, data flow, and lifecycle — from JSON IR code blocks in your markdown/MDX content. Works with standalone Astro projects and documentation frameworks like Starlight.

Live demos

Demo URL Description
Starlight astro-archify-starlight-demo.netlify.app Documentation site with Starlight
Standalone Astro astro-archify-astro-demo.netlify.app Pure Astro project template

See also starlight-demo/ and astro-demo/ in this repo.

Listed in the Astro integrations directory.

Archify turns a typed JSON intermediate representation (IR) into a fully self-contained, already-interactive HTML artifact — inline SVG plus a small pan/zoom/focus viewer, with every script and its ~4800 lines of CSS inlined (the one exception is a Google Fonts <link>, which degrades gracefully if it can't load). This integration renders that artifact at build time using Archify's own renderer — bundled into this package, see Attribution — and embeds it as a sandboxed <iframe>, so you get Archify's real viewer, not a re-implementation of it.

This is a different rendering model than diagram libraries like Mermaid: there is no client-side JS bundle to ship, because Archify does its layout work in Node during your Astro build, not in the browser.

There's no separate CLI to install — npm install astro-archify is everything you need.

Installation

npm install astro-archify

Quick Start

// astro.config.mjs
import { defineConfig } from 'astro/config';
import archify from 'astro-archify';

export default defineConfig({
  integrations: [archify()]
});

Then, in markdown or MDX:

```archify
{
  "schema_version": 1,
  "diagram_type": "architecture",
  "meta": { "title": "Sample Web App" },
  "components": [
    { "id": "api", "type": "backend", "label": "API", "pos": [40, 40], "size": [120, 60] },
    { "id": "db", "type": "database", "label": "Database", "pos": [260, 40], "size": [120, 60] }
  ],
  "connections": [
    { "from": "api", "to": "db", "label": "SQL" }
  ]
}
```

The diagram_type field in the IR (architecture, workflow, sequence, dataflow, or lifecycle) selects the renderer. You can also make the type explicit in the fence's language string instead of relying on the JSON body:

```archify:sequence
{ ... }
```

Loading a diagram from a JSON file

Instead of writing the IR inline, a fence can point at an external .json file with a file="..." attribute — handy for large diagrams, or ones generated by another tool:

```archify file="./diagrams/web-app.architecture.json"
```

The path is resolved relative to the markdown/MDX file it appears in (not the project root or the process's working directory). It works together with an explicit type in the fence's language string too:

```archify:sequence file="./diagrams/checkout.sequence.json"
```

An absolute path is also accepted and used as-is. A missing or unreadable file behaves like any other render failure: a visible inline error block by default, or a failed build with strict: true.

Integration Order (Important!)

When using with Starlight or other markdown-processing integrations, place archify first:

import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import archify from 'astro-archify';

export default defineConfig({
  integrations: [
    archify(), // ⚠️ Must come BEFORE starlight
    starlight({ title: 'My Docs' })
  ]
});

Configuration

archify({
  // Advanced: use a different Archify checkout instead of the copy bundled
  // with this package. Must be a directory laid out like Archify's own
  // package root (containing renderers/<type>/render-<type>.mjs and
  // assets/template.html). Most projects never need this.
  rendererRoot: '/path/to/a/newer/archify/checkout',

  // Archify quality profile: 'standard' | 'showcase'
  quality: 'showcase',

  // Fail the build instead of rendering a visible inline error block
  strict: false,

  // Initial iframe height in px, shown before the artifact reports its
  // real content height
  height: 480,

  // The iframe never shrinks below this height (defaults to `height`)
  minHeight: 480,

  // The iframe never grows past this height, even for a very tall diagram
  maxHeight: 4000,

  // Wrapper class name
  className: 'archify-diagram',

  // iframe sandbox attribute
  sandbox: 'allow-scripts allow-popups allow-downloads',

  // iframe `allow` (Permissions Policy) attribute — needed for the
  // viewer's clipboard-copy export and fullscreen presentation stage
  allow: 'clipboard-write; fullscreen',

  // Subdirectory diagram artifacts are served from, e.g. /_archify/<id>.html.
  // Change only if it collides with existing content.
  outDir: '_archify',

  // Render timeout, in milliseconds
  timeout: 30000
})

There is no width option. The iframe is always width: 100% and fills whatever container your layout gives it. Use height/minHeight/maxHeight to control vertical sizing; control horizontal sizing in your site CSS (see Layout and width below).

Layout and width

Diagram width is owned by your page layout, not by archify(). Each fence becomes a wrapper (.archify-diagram by default, or your custom className) containing a full-width iframe — so whatever box that wrapper sits in is the diagram's width.

In a plain Astro project, that usually means your layout's content column — e.g. a max-width on <main> in your layout component.

In Starlight, the prose column is controlled by --sl-content-width (default ~45rem). Three common approaches:

Widen all docs content — add a custom CSS file via Starlight's customCss option:

/* src/styles/custom.css */
:root {
  --sl-content-width: 60rem;
}

Widen only diagrams — leave prose at the default and target the embed wrapper:

/* src/styles/custom.css */
.archify-diagram {
  width: calc(100% + 8rem);
  max-width: 80rem;
  margin-inline: -4rem;
}

Tune the values to taste. This is useful when body text should stay narrow but architecture or workflow diagrams need more room.

Per-page width — in MDX, wrap a fence in a styled container:

<div class="diagram-wide">

```archify
{ ... }
```

</div>

Then style .diagram-wide in your custom CSS.

If you push --sl-content-width well past ~60rem, Starlight's table-of-contents layout can overflow at some viewport sizes — see Starlight issue #3513 for workarounds.

Astro Compatibility

astro-archify follows the same markdown-engine detection as astro-mermaid to work across Astro 4 through 7:

Astro version Markdown engine How Archify hooks in
7+ Sätteri (@astrojs/markdown-satteri, the new default) a Sätteri mdast plugin
6.4 – 6.x unified() processor a remark plugin via markdown.processor
< 6.4 legacy pipeline markdown.remarkPlugins

How It Works

  1. Build time: for each archify code fence, the JSON IR is written to a temp file and rendered by running Archify's own renderer script for that diagram type — node vendor/archify/renderers/<type>/render-<type>.mjs <input.json> <output.html> — as a subprocess. That's a real requirement, not just caution: Archify's renderer scripts call process.exit() directly on both success and failure, so they have to run out-of-process — importing them directly into the Astro build would let one bad diagram take down the whole build.
  2. The resulting self-contained HTML artifact is content-addressed (hashed from its diagram type, quality profile, and JSON source) and cached in memory under that id — so the same diagram appearing on multiple pages, or an unchanged diagram across incremental rebuilds, only renders once. Artifacts are also persisted under Astro's cacheDir (astro-archify/), so a repeat astro build whose pages come from Astro's content cache still writes every artifact those pages reference. If a referenced artifact can't be recovered, the build fails with a pointer to astro build --force instead of shipping dangling iframe URLs.
  3. Each artifact is served from its own real URL, /_archify/<id>.html by default — written to the final output directory on astro:build:done (which runs after Astro's own build, including copying publicDir, so this can't race or be clobbered), and served straight from memory by dev middleware in astro dev. The code fence is replaced with a sandboxed <iframe src="/_archify/<id>.html"> plus a plain "Open full view ↗" link to that same URL.
  4. Runtime: the browser loads Archify's own artifact directly from that URL, inside the iframe — including its full viewer: guide overlay, node finder, guided story/chapter navigation, semantic passport panel, presentation stage, and PNG/JPEG/SVG/WebM exports. This integration doesn't reimplement any of that, and doesn't inline or re-encode it into the page either — it's a normal, separately-cacheable HTTP response.

Archify's viewer assumes it owns the full browser viewport, so a fixed-size box would clip it badly. To avoid that, a small bridge script is appended to each artifact (the only modification this package makes to Archify's output) that reports its real content height to the parent page — on load and via ResizeObserver as the reader interacts with the viewer (opening a panel, entering presentation mode, etc.) — and the iframe grows or shrinks to match, bounded by minHeight/maxHeight.

If a diagram fails to render (invalid JSON, an unknown diagram_type, or a schema/composition error from Archify itself), a visible inline error block is rendered in its place — using Archify's own structured diagnostic message and suggested fix when it provides one — and a build warning is logged. Set strict: true to fail the build instead.

A note on SSR

Static builds (output: 'static', the default) are fully supported. Under SSR (output: 'server'/'hybrid'), astro:build:done's output directory is the client asset directory, which most adapters already serve as static files — so this should generally still work, but it's adapter-dependent and less thoroughly tested than the static case.

Attribution

Archify's own renderer and viewer are vendored into this package at vendor/archify/ — copied from tt-a1i/archify (MIT licensed) at commit 920543b, and used unmodified. See vendor/archify/NOTICE.md for exactly what was copied, why, and how to update it.

Archify's built-in brand-mark icons (Angular, Rust, Vue.js, Jenkins, Apache Kafka/Airflow, .NET, JavaScript, OpenAI, etc.) are third-party assets under their own licenses — not MIT, and in at least one case more restrictive than MIT. See vendor/archify/THIRD_PARTY_NOTICES.md before using or redistributing diagrams that include those marks.

To be clear about the boundary: everything under vendor/archify/ is Archify's own code, doing Archify's own layout, rendering, and the entire interactive viewer. Everything else in this repository — the remark/Sätteri plugin glue that finds archify code fences, spawning the renderer as a subprocess, content-addressed caching, serving artifacts from their own URLs, the iframe embedding and its auto-resize bridge, the Astro markdown-engine compatibility shim, the tests, and the demo — is original to astro-archify (the markdown-engine detection follows the same pattern used in astro-mermaid, also by this author).

Styling

Archify inlines its entire viewer stylesheet (~4800 lines) into every artifact — the only external stylesheet is a Google Fonts <link>, which degrades gracefully if it can't load. Combined with the iframe embedding, this means a diagram always renders pixel-identical to opening the artifact standalone: your site's CSS can never leak into it, and its CSS can never leak into your site.

You can still style the wrapper around the iframe from your site CSS — margins, borders, and width (see Layout and width). The className option is there if you need a project-specific hook.

Demos

Demo URL Source
Starlight astro-archify-starlight-demo.netlify.app starlight-demo/
Standalone Astro astro-archify-astro-demo.netlify.app astro-demo/

For Starlight, list archify() before starlight() in astro.config.mjs (see Integration Order).

Supported Diagram Types

  • Architecture
  • Workflow
  • Sequence
  • Data flow
  • Lifecycle

See the Archify repository for the full JSON IR schemas and authoring guide.

License

MIT © Jose Sebastian

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages