How Do I Generate an ER Diagram From My Prisma Schema?

2026-10-08

Short answer: to generate an ER diagram from your Prisma schema, install prisma-erd-generator and it redraws the diagram every time you run prisma generate. If you want one file you can open offline or hand to a teammate, use vibeX. If you want to click around a huge schema, use Liam ERD. I ran all three on the same schemas, and every one of them drew at least one relationship that does not exist in the real database.

Same Prisma schema drawn as an ER diagram by vibeX, prisma-erd-generator and Liam ERD

You open a Prisma project you haven’t touched in months. Or a new teammate asks, “how do orders connect to users again?” You scroll through a 600-line schema.prisma file and try to hold it all in your head.

That scrolling is the problem. A picture would fix it in seconds. That’s what an ER diagram is for, and three open-source tools will draw one straight from your schema file.

But I found a catch while testing them. A diagram you can’t trust is worse than no diagram. You stop checking. So this post compares the three tools on speed, size and setup, and then on the thing nobody checks: did the picture tell the truth?

What is an ER diagram, and why make one from Prisma?

Mind map: generate an ER diagram from a Prisma schema, covering ER basics, three tools, the test, speed and size, self-relation bugs, the join-table check, and which tool to pick

An ER diagram is a map of your database: boxes for tables, lines for how they connect.

So start with the base. A database stores data in tables, like sheets in a spreadsheet. A User table holds users, an Order table holds orders.

Tables point at each other with a foreign key (a column that stores the ID of a row in another table). An order has a userId column, so every order knows which user placed it.

ER diagram basics, User to Order with crow's foot notation

Now the new word. ER stands for entity-relationship. An ER diagram draws each table as a box and each foreign key as a line between boxes.

The line ends tell you how many. A fork at one end (called crow’s foot notation, because it looks like a bird’s foot) means “many”. A single bar means “exactly one”. So one user, many orders.

And that’s where Prisma comes in. Prisma is a popular database toolkit for Node.js and TypeScript. You describe your tables in one file, schema.prisma, and Prisma builds the real database from it. That file is already a complete description of your data, which is why tools can turn it into a diagram with no database connection at all.

Which tools generate an ER diagram from a Prisma schema?

Three open-source tools do it, and each one works in a different way.

Three pipelines that turn schema.prisma into an ER diagram

prisma-erd-generator plugs into Prisma itself. Prisma has generators (small add-ons that run every time you type npx prisma generate). This one draws an SVG image or writes a Mermaid file (Mermaid is a text format for diagrams that GitHub renders as a picture). Your diagram updates itself every time your schema changes.

Liam ERD is a command-line tool that builds a small web app from your schema. You get a folder with an interactive diagram you can pan, zoom and search. It also has a hosted version for public GitHub repos.

vibeX is the newest. It turns your schema into a JSON spec (a plain data file describing every box and line), then renders that spec into one HTML file. It has zero dependencies and also installs as a skill (a set of instructions an AI coding agent loads) for Claude Code and Codex, so you can just ask “show me the data model”.

And all three are free. prisma-erd-generator and vibeX use the MIT license, and Liam ERD uses Apache 2.0.

How I tested them

Same schemas, same machine, every output checked against the SQL Prisma would actually create.

I wrote a small shop schema with nine models (Prisma’s word for tables) and two enums (fixed lists of allowed values, like PAID or SHIPPED). I packed it with the shapes that trip tools up.

So there is a one-to-one link (each user has at most one profile). There is a many-to-many link (products and tags), which Prisma stores in a hidden join table (an extra table that holds pairs of IDs). There is a composite key (a row identified by two columns together, here user plus team).

And there is a self-relation (a table that points at itself). Each user can have an invitedBy user, and each user can see the people they invited. That is one inviter to many invitees, a plain one-to-many link.

Test Prisma schema with one-to-one, many-to-many, composite key and self-relation

Then I needed the truth to grade against. Prisma can print the exact SQL it would run to create your database, without touching any database. That SQL is the real answer: which tables exist and which foreign keys exist.

After the small test, I ran all three on a real production schema: the open-source cal.com scheduling app, with 100 models, 2 views and 46 enums.

How fast is each tool, and how big is the setup?

vibeX is the lightest by far. prisma-erd-generator gets heavy the moment you want an image.

vibeXprisma-erd-generatorLiam ERD
Install size2.2 MB, no dependencies75 MB for text output, about 550 MB for images (before a browser)158 MB download on first run
Small schema run0.25 s for all three steps2.4 s for the SVG19 s first run, about 2 s after
Outputone 134 KB HTML fileone 145 KB SVG imagea 3.2 MB folder
Opens from disk?yesyesno, needs a local web server
Updates on prisma generate?no, you rerun ityesno, you rerun it

That image size surprised me. Mermaid needs a real browser to measure text before it can lay out boxes, so the image route pulls in a headless browser (a browser that runs with no window) through Puppeteer.

Install size of vibeX, prisma-erd-generator and Liam ERD

So if you only need the diagram on GitHub, ask the generator for a .md file instead of an .svg. It skips the browser entirely, and GitHub draws the Mermaid diagram for you. There is also a Graphviz renderer that makes SVGs without a browser (77 MB in my install), but it drops the crow’s feet and shows how-many in arrowheads and labels instead.

And Liam’s folder has its own catch. The page won’t load if you double-click index.html. The CLI tells you to serve the folder first, with npx serve dist/ or similar.

Did the diagrams match the real database?

Every tool got the plain links right. Every tool got the self-relation wrong, in a different way.

Here is the small schema result, line by line against Prisma’s own SQL.

Link in the schemaWhat really existsvibeXprisma-erd-generatorLiam ERD
Order to User (one-to-many)1 foreign keycorrectcorrectcorrect
Product to Tag (many-to-many)1 join tablecorrectcorrectcorrect
Membership (two-column key)2 key columnscorrectcorrect after one settingcorrect
User invited by User (one-to-many)1 foreign key, no join tableright line plus an extra many-to-many linedrawn as one-to-oneright key plus a fake join table
How each Prisma ERD tool drew a one-to-many self-relation

Look at that last row, because it is the one that would mislead you. Prisma’s SQL has no join table for invites. Just one invitedById column.

But vibeX drew a second line labeled “implicit m:n”, and Liam drew a whole table called _UserToUser that does not exist. Both read the invitees list (the back side of the same link) as a separate many-to-many link. prisma-erd-generator skipped the fake table, but drew the link as one-to-one, so it says each user can invite one person at most.

That wasn’t the only miss. There was one smaller one too. By default, prisma-erd-generator hides foreign key columns, so the Membership box showed only role and looked like a table with one column. Add includeRelationFromFields = true to the generator block and both key columns come back.

What happens on a big real schema?

On cal.com‘s 100 models, the same bugs showed up, plus one worse one.

ER diagram accuracy on the 100-model cal.com Prisma schema
vibeXprisma-erd-generatorLiam ERD
Run time0.35 s9.2 sabout 3 s
Output971 KB HTML4.2 MB SVG, 36,597 px wide3.7 MB folder
Real many-to-many links (2)both foundboth foundboth missing
Fake links added403 fake join tables
Self-relations (3, all one-to-many)extra fake line on eachall drawn one-to-onefake join table on each

That missing pair is the one that worries me most. An extra line makes you double-check. A missing table just quietly isn’t there, and you never think to look.

And vibeX added a fourth fake link on this schema. It paired two different relations between teams and OAuth clients into one many-to-many line. It also warned that it could not map one two-column foreign key, and it told me 146 boxes in one diagram is hard to read. That’s fair. It is.

And the generator’s 36,597-pixel image is technically correct and practically unusable. For a schema this size, an image you can’t search is a poster, not a tool.

How do you check any diagram in 10 seconds?

Ask Prisma for the SQL and look for the join tables. That’s where the tools get it wrong.

Every bug in my tests involved join tables or self-relations. So you don’t need to audit every line. You need one list: the join tables that really exist.

So on Prisma 6, run this from your project:

npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script | grep 'CREATE TABLE "_'

On Prisma 7, the flag is --to-schema instead of --to-schema-datamodel. On Prisma 6 it ran with no database at all. It prints every hidden join table, and Prisma names those tables with a leading underscore.

prisma migrate diff listing the real join tables

On my small schema, it printed exactly one: _ProductToTag. So any diagram showing a _UserToUser table is wrong. If you already use Prisma Migrate, you can skip the command and search your prisma/migrations folder for CREATE TABLE "_ instead.

Then look at each self-relation in your schema (a model with a field pointing at its own type) and check its line by eye. Those were the other weak spot, in every tool.

Which Prisma ERD generator should you use?

For most projects, prisma-erd-generator writing a Markdown file. It was the most accurate and never needs a browser.

Which Prisma ERD tool to use by job

Still, to be fair to vibeX, it is the nicest to use. One 2 MB install, one HTML file in under a second, and it opens anywhere, even offline. Its spec is plain JSON, so I deleted the fake line from the file, re-rendered, and the diagram was correct. If you work in Claude Code, the skill lets you ask for the diagram in plain English.

And Liam ERD wins on one job: exploring a giant schema. Search, zoom and a table-names-only view make 100 models usable. Just don’t trust it to show every many-to-many link.

Here is the setup I’d use on a real Prisma project:

  1. npm i -D prisma-erd-generator
  2. Add a generator block with provider = "prisma-erd-generator", output = "../ERD.md" and includeRelationFromFields = true.
  3. Run npx prisma generate and commit ERD.md. GitHub draws it.
  4. Run the join-table check once, and fix any self-relation you care about by eye.

If you want a file to send a teammate, add vibeX: npx @vibex/vibex import prisma prisma/schema.prisma db.erd.json, then npx @vibex/vibex render db.erd.json.

But there is one honest limit to all this. I tested two schemas, not every shape Prisma allows. Views, multi-file schemas and MongoDB projects may break these tools in other ways. Run the check on yours.

So pick any of the three. Then spend ten seconds making sure the picture is true.

Common questions about Prisma ER diagrams

Can Prisma generate an ER diagram by itself?

No. The Prisma CLI has no command that draws an ER diagram. You add a generator like prisma-erd-generator, or run a separate tool like Liam ERD or vibeX on your schema.prisma file.

Do I need a running database to make the diagram?

No. All three tools read only the schema.prisma file. The 10-second check also ran without a database in my test.

Why does my ER diagram show a table that isn’t in my database?

It is usually a self-relation read as a many-to-many link, which makes the tool invent a join table. Run prisma migrate diff and compare the join tables it prints with the diagram.

Is there a free Prisma schema visualizer I can open offline?

Yes. vibeX writes a single HTML file that opens from disk with no server, and prisma-erd-generator writes an SVG or Markdown file you can keep in your repo.

JOIN OUR NEWSLETTER
Be the first to know. Get fresh AI/Tech updates instantly, no spam, unsubscribe anytime

2 comments

Leave a comment