What does er-diagram do?
Turns any description of a data model into a readable ERD page (HTML), optionally exported as an SVG or PNG image.
A clean diagram means three things:
- Relation lines run only horizontally and vertically, with 90° turns.
- Tables are grouped by meaning and sit next to each other inside a labelled group frame.
- Where two lines cross without connecting, one hops over the other with an arc.
You do not draw the diagram by hand and you do not write SVG yourself. Your job is to build model.json. Layout, line routing, arc jumps and the page are produced by the ready-made script scripts/erd.js in this skill's folder. Run it; do not open or read it — it is long and you need nothing from it. Mermaid is not used here: it cannot draw arc jumps at crossings.
Language
Everything this skill produces is in English by default: the page interface, the page title, the subtitle, group titles and any relation labels you write yourself.
Use another language only when the user explicitly asks for the diagram in that language. Then write titles, group names and your own labels in that language, set "lang" to its language code, and translate the interface strings through the "ui" object: read references/ui-strings.md for the keys and English defaults. Do not read that file otherwise.
In both cases, table names, field names, types, comments and relation labels that come from the source are copied exactly as they are. Do not translate or rename them unless the user asks.
Before you start: check Node.js
Run node -v. If it prints a version, continue.
If Node.js is missing:
- Tell the user that this skill needs Node.js to build the diagram and that it is not installed.
- Ask whether you should install it. Do not install anything without the user's consent.
- If the user agrees, install it with whatever the environment offers (system package manager, nvm and so on) and run
node -vagain. - If you cannot install it (no permission, no network, the install fails), ask the user to install Node.js themselves and to tell you when it is done.
If the user declines, stop and say that the diagram cannot be built without Node.js. Do not draw the diagram by hand instead.
Output format
Before building, find out which output the user wants. If the request already says it, do not ask. Otherwise ask one question with these options:
- HTML page — interactive: zoom, pan, click a table to highlight its relations.
- HTML page + images — the page plus SVG and PNG files.
- Images only — SVG and PNG files, no page.
- Something else — the user describes what they need.
If there is nobody to ask (an unattended run), produce the HTML page.
For options 2 and 3 add --svg erd.svg --png erd.png to the build command in Step 4. For "Images only" the script still writes the HTML file; do not publish or deliver it.
Step 1. Extract the model from the source
The source can be prose, SQL DDL, Mermaid erDiagram, DBML, PlantUML, an image or a PDF.
- For a vector PDF, first try extracting text with coordinates (
pdftotext -bbox-layout) instead of reading a tiny picture by eye. - Carry over tables, fields, types, keys, relation labels and cardinalities as they are in the source.
- Do not invent tables, fields or relations that are not in the source.
- If a relation is not drawn explicitly but the table has an FK field, you may derive the relation from the FK. Remember these relations: you must tell the user about them.
- If a cardinality is unreadable in the source, use
1:N(use1:1when the FK is the whole PK or is unique) and tell the user. - If more than two or three tables have no relations at all, keep them out of the diagram and list them in
notesbelow it. Do the same for enum reference lists.
Step 2. Put tables into groups
If the source already has groups, use them. Otherwise group the tables yourself:
- 3–8 groups, usually 2–6 tables each. Every table belongs to exactly one group.
- A group is one subject area (bounded context): "Org structure", "Requests", "Catalog", "Payments".
- Junction tables (M:N) and detail tables ("items", "comments", "history") live in the group of their main parent.
- Order the groups from reference and base entities to the ones that depend on them.
- Group titles are 1–4 words.
Groups you came up with yourself must be listed in your reply to the user as your proposal.
Step 3. Write model.json
{
"pageTitle": "Shop ERD",
"title": "Shop data model",
"subtitle": "Optional line under the title.",
"lang": "en",
"direction": "DOWN",
"groups": [
{ "title": "Customers", "tables": {
"customers": ["uuid id PK", "string email UK | login"],
"addresses": ["uuid id PK", "uuid customer_id FK", "string city"]
}},
{ "title": "Orders", "tables": {
"orders": ["uuid id PK", "uuid customer_id FK", "enum status | new | paid"]
}}
],
"relations": [
["customers", "addresses", "customer_id", "lives at"],
["customers", "orders", "customer_id", "places", "1:0..N"]
],
"notes": [
{ "title": "Tables without relations", "rows": [["audit_log", "Action log."]] }
]
}
Format rules:
- Field — a string
"type name [KEY] [| comment]". Type first, then name, neither contains spaces.KEYisPK,FK,UK, or several joined by a comma without a space:PK,FK. The comment is separated by|(space, bar, space) and may itself contain|. - Relation — an array
[parent, child, fk_field, label, cardinality].parentis the table on the "one" side (the one being referenced).childis the table that holds the FK.fk_fieldis the name of the FK field inchild. The label is short (1–3 words) or"". - Cardinality —
"parent_end:child_end", default"1:N". Each end is one of1,0..1,N,0..N,1..N. Examples:1:1,0..1:0..N,N:N. Use a0..or1..form only when the source shows it explicitly. - Self-relation —
parentandchildare the same table. direction:DOWN(default, right for almost everything) orRIGHT(for small diagrams up to ~8 tables).lang: language code of the page, defaulten.ui: optional translations of the interface strings, used only when the user asked for another language (seereferences/ui-strings.md).pageTitle— a short page name of 2–4 words.notes— optional cards below the diagram, rows are[name, description].
Step 4. Build the page
Node.js is required. Nothing needs to be installed: the layout engine is bundled with the script. SKILL_DIR below is the folder this SKILL.md is in.
node "$SKILL_DIR/scripts/erd.js" model.json erd.html # fragment, for publishing as an artifact
node "$SKILL_DIR/scripts/erd.js" model.json erd.html --standalone # full HTML document, for delivering as a file
Add --svg erd.svg --png erd.png to also export images. --svg writes a self-contained vector image (light theme). --png needs Playwright with Chromium; when it is not available the script prints WARNING: PNG skipped and still writes everything else.
Read the output:
ERROR: ...— fixmodel.json(typo in a table name, field format, cardinality) and run again. Do not edit the script.WARNING: ... has no field—childdoes not contain the named FK field. Check the name against the source.- The
OK ...line must end withdiagonal segments 0.
A complete worked example of model.json is in assets/example-model.json; open it only if the format above is not enough.
Step 5. Check and deliver
- If you can, look at the result once (a screenshot of the page): tables do not overlap, groups make sense. If the diagram came out too wide, change
direction; if a group is torn apart by long lines, reconsider what belongs in it. Never adjust coordinates by hand. - Deliver what the user chose in "Output format". For the page: if an artifact publishing tool is available, publish
erd.html(the build without--standalone); otherwise give the user the file built with--standalone. For images: deliver the SVG and PNG files; if PNG was skipped, deliver the SVG and tell the user. - In your reply to the user, briefly: how many tables, groups and relations; then what in the diagram is your assumption and not from the source: groups you came up with, relations derived from FKs, default cardinalities, anything you could not read.