Flowchart Generator
Generate architecture diagrams from any context the user provides. Two output formats:
- HTML (default) — interactive single-file viewer, open in browser
- Markdown + ASCII — text-based diagrams with box-drawing characters, embeddable in docs/READMEs
Use Markdown when the user asks for "ASCII", "text diagram", "markdown diagram", or when the output goes into a .md file, PR description, or doc. Use HTML for everything else.
What you produce
HTML output
A single .html file containing:
- The ArchitectureViewer engine (from the engine template)
- A
createArchitectureViewer() call with extracted architecture data
The viewer provides: interactive node boxes, animated edge routing, API endpoint cards with I/O data, detail panels, centered modal popovers, search (Cmd+K), tab/scene navigation, hover path highlighting, and URL hash state.
Markdown + ASCII output
A .md file containing:
- One ASCII box diagram per scene, using box-drawing characters (
┌─┐│└─┘, arrows ──▶, ──▷, │, ▼)
- Each diagram is a fenced code block (
```text)
- Below each diagram, a Reference section with linked details for every node
- File paths as markdown links:
[path/to/file.go](https://github.com/org/repo/blob/main/path/to/file.go)
- Function signatures, descriptions, and notes as bullet points under each node heading
ASCII layout rules
- Nodes are boxes:
┌──────────────┐│ Node Title ││ subtitle │└──────────────┘
- Box width: longest line + 4 padding. Minimum 16 chars.
- Horizontal edges:
───▶ or ◀─── between boxes on the same row, with label centered above the arrow
- Vertical edges:
│ with ▼ or ▲ arrow, label to the right of the line
- Grid layout: same column/row structure as the HTML scene positions
- Keep the same visual topology as the HTML version — same rows, columns, connections
Markdown reference structure
After each ASCII diagram:
### Scene: Overview
(ascii diagram here)
#### Node: API Server
- **File:** [api/main.go](https://github.com/org/repo/blob/main/api/main.go)
- **Description:** REST API handling business logic.
- **Functions:**
- `HandleRequest(w, r)` — Routes incoming HTTP requests
- **Notes:** Uses middleware chain for auth + logging
Workflow
1. Gather context
Read whatever the user points you at — source code, design docs, API specs, conversations, README files, OpenAPI specs, Slack threads, etc. If the user gives a vague request like "diagram this repo", explore the codebase to understand the architecture before generating.
2. Extract architecture
From the context, identify:
- Components — services, modules, packages, classes, CLI commands, databases, queues, external APIs
- Relationships — which component calls/depends on/sends data to which other
- API endpoints — HTTP methods, paths, request/response fields
- Data flows — what data moves between components and how
- Groupings — logical layers (frontend, backend, storage, external), lifecycle phases, deployment stages
- Issues/status — if the context mentions tickets, PRs, or status, capture them
3. Design scenes
Organize the architecture into scenes (views):
- Overview — all major components and their connections
- Focused views — zoom into specific flows (e.g., "Auth Flow", "Order Pipeline", "Deploy Process")
- Before/After — if the context describes a migration or change, show both states plus a diff view
Group scenes into tabs. Common patterns:
- Single system: tabs = ["Overview"], scenes = overview + focused flows
- Migration: tabs = ["Current", "Target", "Changes"]
- Multi-environment: tabs = ["Dev", "Staging", "Prod"]
4. Generate the config
Read references/config-schema.md for the full schema. Key rules:
Node positioning:
- Use a grid layout: columns at x = 10, 310, 610, 910 (310px apart)
- Rows at y = 10, 140, 270, 400 (130px apart)
- The engine auto-adjusts for endpoint cards, so don't worry about exact spacing
- Place related nodes in the same column or row
Edge labels:
- Keep labels short (1-3 words): function names, protocols, or action verbs
- Labels are centered on the edge line automatically
- The
desc field has the full explanation (shown in modal on click)
Endpoint cards:
- Add
endpoints to edges that represent API calls
- Use abbreviated paths:
/v1/.../users not /api/v1/projects/{projectId}/users/{userId}
in and out are comma-separated field names (compact)
Node detail:
description should be 1-2 sentences explaining the component's role
files[] links to source code (if applicable)
endpoints[] on nodes have full schema (headers, request/response body, status codes)
notes[] for important context that doesn't fit elsewhere
functions[] — every function entry should include a file field with the exact file path and line number (e.g. "pkg/server.go:42"). Use grep -n "^func " on the source to find real line numbers. This makes each function name a clickable link to the source in the detail panel.
File links and line numbers:
- The
links.files[].baseUrl is prepended to every path in files[] and functions[].file. The engine appends #L<line> for path:line references.
- When diagramming code on a specific git branch (not
main), set baseUrl to include the branch: "https://github.com/org/repo/blob/<branch>/", and use relative paths from the repo root in files[] and functions[].file.
- When diagramming code across multiple branches, set
baseUrl to "https://github.com/org/repo/blob/" and prefix every path with the branch name: "my-branch/pkg/server.go:42". This produces correct per-branch links.
- Always find real line numbers from the source (
grep -n). Never guess or use placeholder line numbers.
5. Build the HTML file
Read the engine template from references/engine-template.html. This contains:
- The full HTML/CSS
- 15 built-in themes (popular vim/neovim colorschemes) with a runtime theme picker
- The viewer engine JS (layout, routing, components)
- A placeholder where your data goes
To produce the output file:
- Copy the engine template
- Replace the placeholder section with your generated
NODE_DATA and SCENES constants
- Add the
createArchitectureViewer() call at the bottom with title, tabs, nodes, scenes, links, and optionally a default theme
- Write to the user's specified path (default:
architecture.html in the current directory)
The structure of the output file:
[HTML head + CSS from template]
<script type="text/babel">
[Engine JS from template — themes, hooks, components, createArchitectureViewer]
// ═══ GENERATED DATA ═══
const NODE_DATA = { ... };
const SCENES = { ... };
createArchitectureViewer({
title: "...",
tabs: [...],
nodes: NODE_DATA,
scenes: SCENES,
links: { files: [...], issues: [...] },
theme: "catppuccin-mocha" // optional — sets the default theme
});
</script>
</body></html>
Themes:
The engine includes 34 themes from popular vim/neovim colorschemes, grouped into Dark and Light in the dropdown. Users can switch at any time via the picker in the top-right of the tab bar. The choice persists in localStorage.
Available theme IDs:
- Dark (23):
catppuccin-mocha, catppuccin-frappe, catppuccin-macchiato, tokyo-night, tokyo-night-storm, tokyonight-moon, gruvbox-dark, nord, dracula, one-dark, solarized-dark, rose-pine, rose-pine-moon, kanagawa, everforest-dark, nightfox, carbonfox, github-dark, ayu-dark, ayu-mirage, monokai-pro, material-deep-ocean, palenight
- Light (11):
catppuccin-latte, tokyo-night-light, gruvbox-light, solarized-light, rose-pine-dawn, everforest-light, one-light, github-light, ayu-light, dayfox, kanagawa-lotus
To set a default, pass theme: "<id>" in the createArchitectureViewer() config. If omitted, the viewer uses its built-in dark style unless the user has previously picked a theme (saved in localStorage). If the user asks for a specific theme or light/dark preference, set the matching theme ID.
6a. HTML: Open in browser
After writing the .html file, open it with agent-browser or tell the user where to find it.
6b. Markdown: Write the .md file
For each scene, render an ASCII box diagram inside a fenced code block, then add a Reference section below with markdown-linked details for every node. Use the same data extracted in steps 1-3. The reference section should link source files to the repo URL so readers can click through.
Quality checklist
Before outputting, verify:
- Every node referenced in a scene has an entry in NODE_DATA
- Every edge's
from and to reference nodes that exist in that scene
- No two nodes in the same scene have the same position
- Edge labels are short enough to fit between nodes (~15 chars max)
- At least one scene per tab
- The first scene in each tab is a good overview
- Names come from the actual code. Node titles, edge labels, function names, and file paths must match what exists in the codebase. Never invent names like "CacheManager" when the code calls it
cache.go with a func EnsureDocs(). Read the source to find the real names — types, functions, packages, filenames. If there's no obvious name, use the filename or package name, not a made-up CamelCase noun.
- Every function has a source link. Every entry in
functions[] must include a file field with path:line pointing to the actual definition. Run grep -n "^func " (or equivalent) on each source file to collect line numbers. Do not omit the file field or use approximate line numbers.
- File links resolve correctly for the branch. If diagramming code on non-default branches, verify that
links.files[].baseUrl combined with the paths in files[] and functions[].file produces working URLs. Test by constructing one full URL mentally before generating.
Example: minimal config
For a simple 3-service system:
const NODE_DATA = {
"client": {
title: "Web Client", sub: "React SPA",
category: "Frontend",
description: "Single-page app served from CDN."
},
"api": {
title: "API Server", sub: "api/main.go",
category: "Backend",
description: "REST API handling business logic.",
files: ["api/main.go"],
functions: [
{ name: "HandleRequest", sig: "(w http.ResponseWriter, r *http.Request)", desc: "Routes incoming HTTP requests", file: "api/main.go:42" },
{ name: "CreateUser", sig: "(ctx context.Context, email string) (int, error)", desc: "Creates a new user", file: "api/main.go:87" }
],
endpoints: [
{ method: "POST", path: "/api/users", requestBody: [{ name: "email", type: "string", desc: "User email" }], responseBody: [{ name: "id", type: "int", desc: "Created user ID" }], statusCodes: [{ code: "201", desc: "Created" }] }
]
},
"db": {
title: "PostgreSQL", sub: "users, orders",
category: "Storage",
description: "Primary data store."
}
};
const SCENES = {
"overview": {
tab: "system", label: "Overview", width: 700, height: 200,
nodes: [
{ id: "client", x: 10, y: 60 },
{ id: "api", x: 310, y: 60 },
{ id: "db", x: 610, y: 60 }
],
edges: [
{ from: "client", to: "api", label: "REST", desc: "Client calls API over HTTPS.",
endpoints: [{ method: "POST", path: "/api/users", in: "email", out: "id" }] },
{ from: "api", to: "db", label: "SQL", desc: "API queries PostgreSQL." }
]
}
};
createArchitectureViewer({
title: "My System",
tabs: [{ id: "system", label: "System" }],
nodes: NODE_DATA,
scenes: SCENES,
links: { files: [{ baseUrl: "https://github.com/myorg/myrepo/blob/main/" }], issues: [] },
theme: "catppuccin-mocha" // optional: default theme (user can switch via dropdown)
});
Example: Markdown + ASCII output
For the same 3-service system:
# My System Architecture
## Overview
```text
┌──────────────┐ REST ┌──────────────┐ SQL ┌──────────────┐
│ Web Client │ ─────────────────────▶ │ API Server │ ─────────────────────▶ │ PostgreSQL │
│ React SPA │ │ api/main.go │ │ users,orders│
└──────────────┘ └──────────────┘ └──────────────┘
```
### Web Client
- **Category:** Frontend
- **Description:** Single-page app served from CDN.
### API Server
- **File:** [api/main.go](https://github.com/myorg/myrepo/blob/main/api/main.go)
- **Category:** Backend
- **Description:** REST API handling business logic.
- **Endpoints:**
- `POST /api/users` — in: `email` → out: `id` (201 Created)
### PostgreSQL
- **Category:** Storage
- **Description:** Primary data store for users and orders.
1---2name: flowchart3description: Generate flowcharts and architecture diagrams as interactive HTML or Markdown+ASCII. Use when asked to visualize, diagram, or map out any system, flow, or structure.4---56# Flowchart Generator78Generate architecture diagrams from any context the user provides. Two output formats:9101. **HTML** (default) — interactive single-file viewer, open in browser112. **Markdown + ASCII** — text-based diagrams with box-drawing characters, embeddable in docs/READMEs1213Use Markdown when the user asks for "ASCII", "text diagram", "markdown diagram", or when the output goes into a `.md` file, PR description, or doc. Use HTML for everything else.1415## What you produce1617### HTML output18A single `.html` file containing:19- The ArchitectureViewer engine (from the engine template)20- A `createArchitectureViewer()` call with extracted architecture data2122The viewer provides: interactive node boxes, animated edge routing, API endpoint cards with I/O data, detail panels, centered modal popovers, search (Cmd+K), tab/scene navigation, hover path highlighting, and URL hash state.2324### Markdown + ASCII output25A `.md` file containing:26- One ASCII box diagram per scene, using box-drawing characters (`┌─┐│└─┘`, arrows `──▶`, `──▷`, `│`, `▼`)27- Each diagram is a fenced code block (` ```text `)28- Below each diagram, a **Reference** section with linked details for every node29- File paths as markdown links: `[path/to/file.go](https://github.com/org/repo/blob/main/path/to/file.go)`30- Function signatures, descriptions, and notes as bullet points under each node heading3132#### ASCII layout rules33- Nodes are boxes: `┌──────────────┐│ Node Title ││ subtitle │└──────────────┘`34- Box width: longest line + 4 padding. Minimum 16 chars.35- Horizontal edges: `───▶` or `◀───` between boxes on the same row, with label centered above the arrow36- Vertical edges: `│` with `▼` or `▲` arrow, label to the right of the line37- Grid layout: same column/row structure as the HTML scene positions38- Keep the same visual topology as the HTML version — same rows, columns, connections3940#### Markdown reference structure41After each ASCII diagram:4243```markdown44### Scene: Overview4546(ascii diagram here)4748#### Node: API Server49- **File:** [api/main.go](https://github.com/org/repo/blob/main/api/main.go)50- **Description:** REST API handling business logic.51- **Functions:**52 - `HandleRequest(w, r)` — Routes incoming HTTP requests53- **Notes:** Uses middleware chain for auth + logging54```5556## Workflow5758### 1. Gather context5960Read whatever the user points you at — source code, design docs, API specs, conversations, README files, OpenAPI specs, Slack threads, etc. If the user gives a vague request like "diagram this repo", explore the codebase to understand the architecture before generating.6162### 2. Extract architecture6364From the context, identify:6566- **Components** — services, modules, packages, classes, CLI commands, databases, queues, external APIs67- **Relationships** — which component calls/depends on/sends data to which other68- **API endpoints** — HTTP methods, paths, request/response fields69- **Data flows** — what data moves between components and how70- **Groupings** — logical layers (frontend, backend, storage, external), lifecycle phases, deployment stages71- **Issues/status** — if the context mentions tickets, PRs, or status, capture them7273### 3. Design scenes7475Organize the architecture into scenes (views):7677- **Overview** — all major components and their connections78- **Focused views** — zoom into specific flows (e.g., "Auth Flow", "Order Pipeline", "Deploy Process")79- **Before/After** — if the context describes a migration or change, show both states plus a diff view8081Group scenes into tabs. Common patterns:82- Single system: tabs = ["Overview"], scenes = overview + focused flows83- Migration: tabs = ["Current", "Target", "Changes"]84- Multi-environment: tabs = ["Dev", "Staging", "Prod"]8586### 4. Generate the config8788Read `references/config-schema.md` for the full schema. Key rules:8990**Node positioning:**91- Use a grid layout: columns at x = 10, 310, 610, 910 (310px apart)92- Rows at y = 10, 140, 270, 400 (130px apart)93- The engine auto-adjusts for endpoint cards, so don't worry about exact spacing94- Place related nodes in the same column or row9596**Edge labels:**97- Keep labels short (1-3 words): function names, protocols, or action verbs98- Labels are centered on the edge line automatically99- The `desc` field has the full explanation (shown in modal on click)100101**Endpoint cards:**102- Add `endpoints` to edges that represent API calls103- Use abbreviated paths: `/v1/.../users` not `/api/v1/projects/{projectId}/users/{userId}`104- `in` and `out` are comma-separated field names (compact)105106**Node detail:**107- `description` should be 1-2 sentences explaining the component's role108- `files[]` links to source code (if applicable)109- `endpoints[]` on nodes have full schema (headers, request/response body, status codes)110- `notes[]` for important context that doesn't fit elsewhere111- `functions[]` — every function entry should include a `file` field with the exact file path and line number (e.g. `"pkg/server.go:42"`). Use `grep -n "^func "` on the source to find real line numbers. This makes each function name a clickable link to the source in the detail panel.112113**File links and line numbers:**114- The `links.files[].baseUrl` is prepended to every path in `files[]` and `functions[].file`. The engine appends `#L<line>` for `path:line` references.115- When diagramming code on a specific git branch (not `main`), set `baseUrl` to include the branch: `"https://github.com/org/repo/blob/<branch>/"`, and use relative paths from the repo root in `files[]` and `functions[].file`.116- When diagramming code across multiple branches, set `baseUrl` to `"https://github.com/org/repo/blob/"` and prefix every path with the branch name: `"my-branch/pkg/server.go:42"`. This produces correct per-branch links.117- Always find real line numbers from the source (`grep -n`). Never guess or use placeholder line numbers.118119### 5. Build the HTML file120121Read the engine template from `references/engine-template.html`. This contains:122- The full HTML/CSS123- 15 built-in themes (popular vim/neovim colorschemes) with a runtime theme picker124- The viewer engine JS (layout, routing, components)125- A placeholder where your data goes126127To produce the output file:1281. Copy the engine template1292. Replace the placeholder section with your generated `NODE_DATA` and `SCENES` constants1303. Add the `createArchitectureViewer()` call at the bottom with title, tabs, nodes, scenes, links, and optionally a default `theme`1314. Write to the user's specified path (default: `architecture.html` in the current directory)132133The structure of the output file:134```135[HTML head + CSS from template]136<script type="text/babel">137[Engine JS from template — themes, hooks, components, createArchitectureViewer]138139// ═══ GENERATED DATA ═══140const NODE_DATA = { ... };141const SCENES = { ... };142143createArchitectureViewer({144 title: "...",145 tabs: [...],146 nodes: NODE_DATA,147 scenes: SCENES,148 links: { files: [...], issues: [...] },149 theme: "catppuccin-mocha" // optional — sets the default theme150});151</script>152</body></html>153```154155**Themes:**156157The engine includes 34 themes from popular vim/neovim colorschemes, grouped into Dark and Light in the dropdown. Users can switch at any time via the picker in the top-right of the tab bar. The choice persists in localStorage.158159Available theme IDs:160- **Dark (23):** `catppuccin-mocha`, `catppuccin-frappe`, `catppuccin-macchiato`, `tokyo-night`, `tokyo-night-storm`, `tokyonight-moon`, `gruvbox-dark`, `nord`, `dracula`, `one-dark`, `solarized-dark`, `rose-pine`, `rose-pine-moon`, `kanagawa`, `everforest-dark`, `nightfox`, `carbonfox`, `github-dark`, `ayu-dark`, `ayu-mirage`, `monokai-pro`, `material-deep-ocean`, `palenight`161- **Light (11):** `catppuccin-latte`, `tokyo-night-light`, `gruvbox-light`, `solarized-light`, `rose-pine-dawn`, `everforest-light`, `one-light`, `github-light`, `ayu-light`, `dayfox`, `kanagawa-lotus`162163To set a default, pass `theme: "<id>"` in the `createArchitectureViewer()` config. If omitted, the viewer uses its built-in dark style unless the user has previously picked a theme (saved in localStorage). If the user asks for a specific theme or light/dark preference, set the matching `theme` ID.164165### 6a. HTML: Open in browser166167After writing the `.html` file, open it with `agent-browser` or tell the user where to find it.168169### 6b. Markdown: Write the `.md` file170171For each scene, render an ASCII box diagram inside a fenced code block, then add a **Reference** section below with markdown-linked details for every node. Use the same data extracted in steps 1-3. The reference section should link source files to the repo URL so readers can click through.172173## Quality checklist174175Before outputting, verify:176- Every node referenced in a scene has an entry in NODE_DATA177- Every edge's `from` and `to` reference nodes that exist in that scene178- No two nodes in the same scene have the same position179- Edge labels are short enough to fit between nodes (~15 chars max)180- At least one scene per tab181- The first scene in each tab is a good overview182- **Names come from the actual code.** Node titles, edge labels, function names, and file paths must match what exists in the codebase. Never invent names like "CacheManager" when the code calls it `cache.go` with a `func EnsureDocs()`. Read the source to find the real names — types, functions, packages, filenames. If there's no obvious name, use the filename or package name, not a made-up CamelCase noun.183- **Every function has a source link.** Every entry in `functions[]` must include a `file` field with `path:line` pointing to the actual definition. Run `grep -n "^func "` (or equivalent) on each source file to collect line numbers. Do not omit the `file` field or use approximate line numbers.184- **File links resolve correctly for the branch.** If diagramming code on non-default branches, verify that `links.files[].baseUrl` combined with the paths in `files[]` and `functions[].file` produces working URLs. Test by constructing one full URL mentally before generating.185186## Example: minimal config187188For a simple 3-service system:189190```js191const NODE_DATA = {192 "client": {193 title: "Web Client", sub: "React SPA",194 category: "Frontend",195 description: "Single-page app served from CDN."196 },197 "api": {198 title: "API Server", sub: "api/main.go",199 category: "Backend",200 description: "REST API handling business logic.",201 files: ["api/main.go"],202 functions: [203 { name: "HandleRequest", sig: "(w http.ResponseWriter, r *http.Request)", desc: "Routes incoming HTTP requests", file: "api/main.go:42" },204 { name: "CreateUser", sig: "(ctx context.Context, email string) (int, error)", desc: "Creates a new user", file: "api/main.go:87" }205 ],206 endpoints: [207 { method: "POST", path: "/api/users", requestBody: [{ name: "email", type: "string", desc: "User email" }], responseBody: [{ name: "id", type: "int", desc: "Created user ID" }], statusCodes: [{ code: "201", desc: "Created" }] }208 ]209 },210 "db": {211 title: "PostgreSQL", sub: "users, orders",212 category: "Storage",213 description: "Primary data store."214 }215};216217const SCENES = {218 "overview": {219 tab: "system", label: "Overview", width: 700, height: 200,220 nodes: [221 { id: "client", x: 10, y: 60 },222 { id: "api", x: 310, y: 60 },223 { id: "db", x: 610, y: 60 }224 ],225 edges: [226 { from: "client", to: "api", label: "REST", desc: "Client calls API over HTTPS.",227 endpoints: [{ method: "POST", path: "/api/users", in: "email", out: "id" }] },228 { from: "api", to: "db", label: "SQL", desc: "API queries PostgreSQL." }229 ]230 }231};232233createArchitectureViewer({234 title: "My System",235 tabs: [{ id: "system", label: "System" }],236 nodes: NODE_DATA,237 scenes: SCENES,238 links: { files: [{ baseUrl: "https://github.com/myorg/myrepo/blob/main/" }], issues: [] },239 theme: "catppuccin-mocha" // optional: default theme (user can switch via dropdown)240});241```242243## Example: Markdown + ASCII output244245For the same 3-service system:246247````markdown248# My System Architecture249250## Overview251252```text253┌──────────────┐ REST ┌──────────────┐ SQL ┌──────────────┐254│ Web Client │ ─────────────────────▶ │ API Server │ ─────────────────────▶ │ PostgreSQL │255│ React SPA │ │ api/main.go │ │ users,orders│256└──────────────┘ └──────────────┘ └──────────────┘257```258259### Web Client260- **Category:** Frontend261- **Description:** Single-page app served from CDN.262263### API Server264- **File:** [api/main.go](https://github.com/myorg/myrepo/blob/main/api/main.go)265- **Category:** Backend266- **Description:** REST API handling business logic.267- **Endpoints:**268 - `POST /api/users` — in: `email` → out: `id` (201 Created)269270### PostgreSQL271- **Category:** Storage272- **Description:** Primary data store for users and orders.273````