npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nonsoo/prisma-mermaid

v0.2.0

Published

A Prisma generator that generates Mermaid Class or ER diagrams from your Prisma schema.

Readme

Prisma to Mermaid Generator

Generate Mermaid class diagrams and Mermaid ERD diagrams directly from your Prisma schema. This package exposes a Prisma generator that runs during prisma generate as well as two helpers functions -- generateMermaidClass and generateMermaidERD.

Installation

npm i --save-dev @nonsoo/prisma-mermaid @mermaid-js/mermaid-cli

Usage (Prisma Generator)

Add the following generator to your prisma schema and run npx prisma generate in your terminal.

generator diagram {
  provider = "prisma-mermaid"
  output   = "../src/generated/diagrams"
  format   = "mermaid-erd"
}

Once Mermaid files .mmd are generated you can use the mermaid cli to render the file as an SVG, PNG, embed it in Markdown, etc.

Run the the following command to generate SVG

npx mmdc -i <path/input-file>.mmd -o <path/output-file>.svg

Format options

| Format Value | Description | | ------------- | --------------------------------- | | mermaid-erd | Generates a Mermaid ERD diagram | | mermaid-class | Generates a Mermaid class diagram |

Disabling the Diagram Generator (Useful for CI)

Set the following environment variable in your .env:

PRISMA_DIAGRAM_GENERATOR_DISABLE=true

Usage (Internal Functions)

You can also call the underlying functions directly if you want to generate diagrams outside of the Prisma CLI.

import {
  generateMermaidClass,
  generateMermaidERD,
} from "@nonsoo/prisma-mermaid";

await generateMermaidClass({
  schemaPath: "./prisma/schema.prisma",
  output: "./diagrams/classDiagram.mmd",
});

await generateMermaidERD({
  schemaPath: "./prisma/schema.prisma",
  output: "./diagrams/erdDiagram.mmd",
});

Styling Diagrams

This library ships with sensible default styles for Mermaid ERD and Class diagrams. However, if you need more control, both generateMermaidClass and generateMermaidERD accept a configuration object that lets you customize the final diagram output.

The configuration type is exported as MermaidDiagramConfig. You can import it directly and pass the config object to the generator functions.

import {
  type MermaidDiagramConfig,
  generateMermaidERD,
} from "@nonsoo/prisma-mermaid";

const config = {
  type: "mermaid-erd",
  config: {
    layout: "elk",
  },
} satisfies MermaidDiagramConfig;

await generateMermaidERD({
  schemaPath: "./prisma/schema.prisma",
  output: "./diagrams/erdDiagram.mmd",
  config,
});

Purpose

Documentation should evolve alongside the code it describes. Diagrams-as-code tools such as Mermaid make it easier for teams to maintain clear, accurate diagrams as their systems grow and change. However, creating these diagrams manually — especially for database schemas — still introduces friction and the risk of diagrams falling out of sync with the system.

Prisma already provides a single source of truth for your data model through the Prisma schema. Therefore, by generating diagrams directly from the schema, we can ensure documentation stays automatically aligned with the current state of the database models.

This library bridges that gap. It transforms your Prisma schema into a Mermaid ERD or class diagrams, combining code generation with diagrams-as-code. Once generated, these diagrams can be used to create Markdown files, SVGs, PDFs, or any other Mermaid-supported output — always consistent, always up to date.