agentleFS
aliefauzanaliefauzan/Orthogram/skills/drawing-data-models/SKILL.md

drawing-data-models

Skill2 starsChanged 2 months agoMITView on GitHub

Use when drawing a data model or entity-relationship diagram — tables, columns, primary and foreign keys, and the cardinality between them — as a .drawio / draw.io file. Also called an ERD, schema diagram or database diagram, and for fixing one whose relationships are unlabelled or whose lines do not meet the key they are about

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use the folder the user names.

    line 27
  2. Very specific:

    Never leave a build script, a .drawio or a preview in the project root, and never write outside the project you were pointed at.

    line 34

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Drawing data models

A .drawio entity-relationship diagram in the same visual language as the other drawing-* skills: light page, white tables with hairline borders, Google's palette on the relationships.

Build it with erd_drawio.py (this directory). Check it with check_routing.py. Look at it with preview.py.

Where the files go

Everything this skill produces lives in one folder, never loose in the project root:

docs/diagrams/
  billing-schema.py             # the script that builds it
  billing-schema.drawio         # the diagram
  billing-schema.preview.svg    # what you looked at

Use the folder the user names. Otherwise put it under docs/diagrams/ when the project has a docs/ directory, and diagrams/ at the project root when it does not — the build script, the .drawio, and any preview or PNG together. write() creates the folder if it is missing, so f.write("docs/diagrams/billing-schema.drawio") is all it takes, and preview.py writes the SVG beside its input.

Never leave a build script, a .drawio or a preview in the project root, and never write outside the project you were pointed at. One folder, named files — a diagram whose script sits next to it can be regenerated; one scattered across a repository root cannot be found again.

The output contract

  1. Every relationship carries its cardinality. rel() requires it. A line between two tables that does not say one-to-many or many-to-many states that the rows are related without saying how, which is the only thing the reader came for.
  2. Every connector routed — direct=, corridor= or points=. No default.
  3. check_routing.py reporting 0 FAIL.
  4. A foreign key's line meets the key. orders.at("user_id", "L") is a face fraction level with that field, so the line lands on the row it is about instead of the middle of the table.

The pieces

from erd_drawio import Model, L, R, T, B, WEAK

m = Model("Orders", "postgres · public schema")
users  = m.table("users",  ["id PK", "email UNIQUE", "created_at"], col=0, row=0)
orders = m.table("orders", ["id PK", "user_id FK", "status", "total_cents"],
                 col=1, row=0)

m.rel(users, orders, "one-to-many",
      exit=users.at("id"), entry=orders.at("user_id", "L"), direct=True)

Columns are plain strings. A trailing PK, FK, UNIQUE, NULL or INDEX is read off the end and set in blue on the right of the row, so the source stays a list of columns rather than a table of markup.

kindwhat it draws
one-to-oneone bar each end
one-to-manya bar and a crow's foot
many-to-onethe other way round
many-to-manya crow's foot each end — usually a join table you have not drawn yet
zero-or-onea circle and a bar
zero-or-manya circle and a crow's foot

colour=WEAK, dashed=True is for a link the database does not enforce — a column joined by convention, an id stored in JSON. Saying so on the picture is cheaper than finding out later.

Geometry

table240 wide; 32 header + 22 per field
column pitch420 (table 240, gutter 180)
row pitch300

The page measures itself from the tables. width=/height= are a floor.

Before handing it over

S=~/.claude/skills/drawing-data-models
python3 "$S/check_routing.py" docs/diagrams/model.drawio        # must report 0 FAIL
python3 "$S/preview.py" docs/diagrams/model.drawio              # writes docs/diagrams/model.preview.svg
rsvg-convert -w 1400 -o docs/diagrams/model.png docs/diagrams/model.preview.svg

The preview draws plain arrowheads rather than crow's feet — draw.io renders the real ER ends from the same file. That is why the cardinality is also written on the line: the words survive both renderers, and a screenshot in a document.

Common mistakes

A line with no cardinalityRefused. Say one-to-many, or say many-to-many and then draw the join table.
Lines into the middle of a tableUse t.at("user_id", "L") so the line meets the key it is about.
Every column listedA model with forty columns per table is a schema dump. Show the keys and what the reader needs to follow the joins.
many-to-many left as a lineIn a relational database that is a join table. Draw it, or say why it is missing.
An unenforced link drawn solidIf the database will not stop you breaking it, dash it and colour it WEAK.
Reporting done without the checkerThe routing failure is invisible until it renders.

preview.py writes a plain SVG — open it in any browser if you have no rsvg-convert. The PNG step is for pasting into a document, not for looking at it.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.