---
name: visualize-architecture-static
description: >
  Use when a fixed PNG architecture diagram is required or editable D2 source is requested.
  Static alternative to visualize-architecture-interactive (Archify), which is the default
  for architecture visualization. Always use the current project's theme, colors and fonts.
allowed-tools: Read, Write, Edit, Bash, Glob, Grep
---

# architecture-diagram

## Selection and project theme

Use `visualize-architecture-interactive` (Archify) for ordinary architecture visualization.
Select this D2 alternative only for an explicitly required static PNG or D2 source.
Archify also exports images; PNG is not an exclusive D2 capability.

Before authoring, read the current project's CLAUDE.md / AGENTS.md and its referenced
DESIGN.md, design system, brand guidance or existing UI tokens. Apply that project's
colors, typography, surfaces, borders and light/dark mode. Agent OS uses its MAROSCH
tokens; other projects use their own design. Never carry MAROSCH or a previous project's
palette into an unrelated project. If no design source exists, resolve that gap before
claiming project-themed output. Adapt reference templates rather than treating their
sample colors or fonts as requirements.

Builds **brand-styled, agent-driven architecture diagrams** without any GUI or copy/paste.

Default engine: **D2** (Terrastruct DSL) with `simpleicons.org` CDN for branded tool logos and the **current project's design tokens** for project-consistent output.

Fallback: **mingrammer/diagrams** (Python) when the diagram is auto-generated from data (e.g. iterating a Supabase schema, a Kubernetes manifest) rather than hand-modeled.


## Logos and semantic symbols

Every architecture node needs a recognizable symbol plus its readable name. Use the
real product logo for named services and providers (for example Todoist, Grok, Claude
and OpenAI). Use the current project's icon set for generic roles; an AI agent gets
a Bot/agent symbol and an explicit Agent label, a person a person icon, a database a
database icon. Keep role and provider separate: a Claude-powered agent has an agent
symbol plus Claude identity, not a Claude logo standing for an ordinary server.

Read the installed `logo-finder/SKILL.md` for exact logo lookup and download; search
before choosing a slug, do not confuse Grok, Groq and ngrok. Reuse an exact bundled
Archify mark when available. For missing marks, obtain the exact SVG with logo-finder
or a verified official source and integrate it into the task-local render inputs or
template before delivery. Archify's stock `brand` field does not accept arbitrary local
SVG filenames, and its `icon` enum has no `agent` value: do not invent schema fields
or pretend unsupported values rendered. Use the project's named Bot icon (Lucide Bot
by default) in the task-local template/renderer adaptation, retaining semantics,
validation and readable labels. Do not patch delivered HTML after its provenance hash
is recorded; regenerate and recheck it.

Embed sanitized SVG/image bytes in the artifact; no remote logo fetch on opening.
Preserve source attribution and appropriate brand artwork, use a contrast plate when
needed, and keep the diagram's chrome in the project's theme. Do not recolor logos
arbitrarily to match the palette. Show names alongside symbols, preserve keyboard
accessibility, and verify that logos/role icons remain legible in each requested export.
If an exact logo cannot be found or safely embedded, retain a clear role icon and label
and explicitly identify the missing logo rather than drawing an invented brand mark.

## Output Contract

- Format: **PNG** (SVG fallback only on request — SVGs have rendered poorly in past tests)
- Location: `<project-root>/docs/diagrams/architecture_d2.png`
- Source file kept alongside: `architecture_d2.d2` (re-render whenever stack changes)
- Naming: `architecture_<topic>.d2` / `.png` for multiple diagrams in one project

## Dependencies

| Tool | Install | Purpose |
|---|---|---|
| `d2` | `brew install d2` | Primary renderer |
| `graphviz` | `brew install graphviz` | Mingrammer fallback only |
| `uvx` | already present | Run mingrammer without polluting envs |
| Network | — | Fetches brand logos from `cdn.simpleicons.org` at render time (cached) |

Check both: `which d2 dot uvx`. If missing, install before continuing.

## Workflow

### Step 1 — Read project context

Always do this before writing the diagram:

1. `Read <project>/CLAUDE.md` — pull stack table, services, integrations
2. `Read <project>/package.json` or equivalent — confirm versions, runtime deps
3. `Glob <project>/supabase/migrations/*.sql` etc. — sense check schema if backend involved
4. If unclear or multiple plausible interpretations, ask user once which slice to diagram (auth flow vs data flow vs deployment)

### Step 2 — Choose engine

| Use D2 when | Use mingrammer when |
|---|---|
| Hand-modeled overview | Auto-generated from data source |
| Need brand logos | Need a Python loop over DB / YAML |
| Diagram changes occasionally | Diagram regenerates on every deploy |

D2 is the default — switch only with reason.

### Step 3 — Write the D2 file

Use the template at `~/.claude/skills/visualize-architecture-static/templates/architecture.d2.tmpl` (see below for inline reference). Key rules:

- **Direction:** `down` for tall-vertical web stacks. `right` only when reading flow truly is left-to-right (e.g. CI/CD pipeline).
- **Layout engine:** `elk` (best aesthetics, handles clusters well). `dagre` only if elk produces overlap.
- **Theme:** choose the base theme for the project's light/dark mode and override it with project tokens in inline `style:` blocks.
- **Colors:** read the project's actual palette; map background, node/cluster surfaces, text, neutral borders and primary/semantic accents. The samples in old reference diagrams are not defaults for another project.
- **Fonts:** use the project's heading/body fonts when available, with a compatible installed fallback when needed; disclose substitution.
- **Icons:** Use `cdn.simpleicons.org/<slug>/<hex>` — verified reliable (Terrastruct's own icon CDN returns 403 for most paths).
  - Brand-color the icon to match the brand: `react/61dafb`, `postgresql/4169e1`, `supabase/22c55e`, `vercel/fafafa`, `github/fafafa`, `tailwindcss/06b6d4`, `vite/646cff`, `typescript/3178c6`, `reactquery/ff4154`
  - For nodes without a brand (Auth, Edge Function, custom service), use `shape: hexagon` with surface-elevated fill and a colored stroke matching its layer.
- **Clusters:** group by ownership boundary (Browser, Hosting, Supabase, External). Each cluster gets:
  - `fill: <project surface token>`
  - `stroke: <layer accent color>`
  - `stroke-width: 2`
  - `border-radius: 16`
  - `shadow: true`
- **Title:** Markdown block at top: `# <project name>` line 1, `## <diagram topic>` line 2
- **Edges:** semantic colors (see palette above). Use `stroke-dash: 3` for async/external, solid for sync.

### Step 4 — Render

```bash
cd <project-root>
mkdir -p docs/diagrams
d2 --theme=200 --pad=60 --layout=elk docs/diagrams/architecture_d2.d2 docs/diagrams/architecture_d2.png
```

Common flags:
- `--pad=60` — example spacing; adapt to the project and medium
- `--sketch=false` — never use sketch mode for premium look
- `--center=true` — implicit via vars block

### Step 5 — Verify

`Read` the PNG yourself — it's a multimodal model, you can see the output. Check:
- ✅ All icons loaded (no broken-image placeholders)
- ✅ No text clipping (especially title)
- ✅ Aspect ratio reasonable for the medium (not 5:1 stretched)
- ✅ Colors and fonts match the current project's design source
- ✅ Edge labels readable (not overlapping)

If clipped or stretched: flip `direction`, restructure clusters, or split into multiple diagrams.

### Step 6 — Open + report

`open <path>.png` to surface to the user, then summarize in chat:
- What the diagram shows
- Where the source D2 file lives (for future edits)
- One-line re-render command

### Step 7 — Optional: write source comment

If the project has a `docs/` folder with a README, add a one-line pointer:
`See ./diagrams/architecture_d2.png for current system architecture (source: architecture_d2.d2)`

Do not invent new doc files — only add if the conventional README exists.

## Mingrammer Fallback

Only when the diagram needs to be **data-driven** (e.g., regenerate from a DB schema dump or a K8s manifest list):

```bash
uvx --from "diagrams" python <project>/docs/diagrams/architecture_mingrammer.py
```

Caveats:
- Many "tools" share the same generic server-rack icon (Auth, Edge Function, OpenRouter etc.) — visually weaker than D2 with simpleicons.
- Requires Python + Graphviz system deps.
- Better when iterating over data: `for table in supabase_tables: PostgreSQL(table)`.

## Anti-Patterns

- ❌ Asking the user to paste DSL into a web UI — defeats the headless purpose
- ❌ SVG output without explicit request — has rendered poorly in past tests
- ❌ Generic theme or another project's brand tokens — use the current project's design
- ❌ Cramming auth + data + deployment + AI-providers into one diagram — split into multiple if it exceeds a single screen
- ❌ Inventing services that aren't in CLAUDE.md / package.json — model only what's actually there

## Reference Output

Reference implementation lives at:
`<project>/docs/diagrams/`

That folder contains:
- `architecture_d2.d2` — current canonical template structure
- `architecture_d2.png` — rendered MAROSCH-brand example
- `architecture_mingrammer.py` + `marosch_crm_mingrammer.png` — fallback reference

Use those files as living examples when writing a new diagram.
