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

@ga-ut/mermaid-spec

v1.1.0

Published

A CLI to compile Mermaid contracts and trace changes to code and tests.

Readme

mermaid-spec

CI Release npm License

Turn Mermaid diagrams into contracts that code and tests can follow.

mermaid-spec is a command-line tool for people and coding agents. It compiles a strict Mermaid-compatible subset into TypeScript, JSON Schema, PostgreSQL DDL, OpenAPI, validated HTTP routing, and executable state machines. It also records the links from each contract to the code, tests, UI consumers, and documentation that realize it.

The compiler is deterministic: the same version and source produce the same artifacts. Unsupported or ambiguous syntax stops the build instead of being interpreted by a human or AI.

flowchart LR
  Spec[Mermaid spec] --> Compile[compile]
  Compile --> Contracts[types · schema · API · state]
  Contracts --> App[application code]
  Contracts --> Tests[conformance tests]
  App --> Links[explicit trace links]
  Tests --> Links
  Links --> Change[impact · compatibility · migration]

Run the CLI

Install Bun 1.3.14 or newer first. Bun is the runtime; npm is the distribution registry. Node.js is not a supported runtime, and you do not need the npm CLI to use this tool.

Run it without adding a dependency to your project:

bunx @ga-ut/mermaid-spec --help
bunx @ga-ut/mermaid-spec --version

bunx downloads the CLI to a shared cache when it is not already installed locally. It does not add it to your package.json.

For a command available across projects:

bun add --global @ga-ut/mermaid-spec
mermaid-spec --help

If the command is not found, run bun pm bin -g and add the printed directory to your shell's PATH, or use bunx.

First specification

Save this as task.md in any working directory:

```mermaid
stateDiagram-v2
  [*] --> Todo
  Todo --> Done : complete
  Done --> [*]

  %% @test Todo --complete--> Done
  %% @test Done --complete--> !invalid
```

Then run:

bunx @ga-ut/mermaid-spec check ./task.md
bunx @ga-ut/mermaid-spec test ./task.md
bunx @ga-ut/mermaid-spec build ./task.md --out ./generated
bunx @ga-ut/mermaid-spec verify ./task.md --out ./generated

You should see a valid state machine, two passing examples, and verified generated files. Change complete to finish without updating the examples: test fails, and verify detects that the specification and generated files no longer match. Update the examples and rebuild to accept the change. These examples validate declared transitions, not application behavior; use scenarios with application handlers for that.

Pin a version for a team or CI

You can pin the CLI without changing project dependencies:

bunx @ga-ut/[email protected] build ./specs --out ./generated

Alternatively, keep it as a development tool in your lockfile:

bun add --dev --exact @ga-ut/[email protected]
bunx --no-install @ga-ut/mermaid-spec build ./specs --out ./generated

This development dependency is optional for CLI use. Install it in the application if it uses generated JavaScript or imports @ga-ut/mermaid-spec, @ga-ut/mermaid-spec/runtime, or @ga-ut/mermaid-spec/http. Generated JavaScript depends on the package's runtime exports.

What v1 owns

  • Data contracts with separate table, schema, and reusable value roles; optional and nullable fields, arrays, nested references, enums, defaults, and common constraints.
  • HTTP contracts with typed path, query, header, and cookie inputs; structured errors; pagination; security metadata; OpenAPI; and a validating Fetch router.
  • State contracts bound to model fields, generated transition helpers, and scenarios that execute application-owned guards and effects.
  • A contract graph with stable IDs, source locations, explicit implementation and test links, bounded context retrieval, change impact, compatibility, and migration-safety reports.

Application code still owns business decisions, identity and authorization, database connections and migration execution, framework UI, deployment, and operations. The compiler makes those boundaries visible; it does not generate an application whose behavior was never specified.

Contract loop

For a project with specifications, scenario handlers, and trace links, use:

bunx @ga-ut/mermaid-spec build ./specs --out ./generated
bunx @ga-ut/mermaid-spec test ./specs --handlers ./scenario-handlers.js
bunx @ga-ut/mermaid-spec verify ./specs --out ./generated \
  --links ./mermaid-spec.links.json

Before accepting a spec change, inspect what it affects:

bunx @ga-ut/mermaid-spec impact ./specs \
  --baseline ./baseline/contract-graph.generated.json \
  --links ./mermaid-spec.links.json

bunx @ga-ut/mermaid-spec compatibility ./specs \
  --baseline ./baseline/contract-graph.generated.json

bunx @ga-ut/mermaid-spec migration ./specs \
  --baseline ./baseline/contract-graph.generated.json

compatibility fails for breaking contract changes. migration emits SQL only for changes it can classify safely; destructive or context-dependent changes stay in the report for application review. Neither command changes a database.

For one work item, context returns the selected contract, dependencies, dependents, and linked files so a person or coding agent receives bounded, explicit context:

bunx @ga-ut/mermaid-spec context ./specs \
  --id operation:createTask \
  --links ./mermaid-spec.links.json \
  --include-files --json

New contracts can be bootstrapped before their implementation exists. impact and context return missing required roles as coverageGaps, while verify remains strict and fails until the implementation, tests, and any required consumers are explicitly linked.

Full-stack proof

examples/full-stack is a persistent task service and responsive browser UI built around the generated contracts. It includes:

  • versioned Bun SQLite migration and restart recovery;
  • app-owned access policy and optimistic version checks;
  • generated request/response validation, routing, and lifecycle transitions;
  • a browser consumer linked to the API operations;
  • invalid-input, access-denial, state-rejection, pagination, UI, migration, and recovery tests.

To run the example, clone the source repository (the CLI alone does not create an application):

git clone --branch v1.1.0 https://github.com/ga-ut/mermaid-spec.git
cd mermaid-spec
bun ci
bun run example:full-stack:serve

The smaller examples/product and examples/issue-tracker isolate individual compiler capabilities.

Supported syntax and boundaries

The accepted grammar and directives are documented in docs/syntax.md. The traceability workflow is in docs/harness.md, and the evidence-based production fit is in docs/product-readiness.md.

Version 1 is suited to bounded CRUD and lifecycle-heavy vertical slices whose contracts fit the supported grammar. It does not yet cover multipart or streaming HTTP, general unions, generated browser clients, composite workflows, timers, retries, arbitrary indexes, transaction policy, or distributed-system recovery. High-risk systems such as payments still require their own domain, security, idempotency, audit, and operational controls.

Development

bun ci
bun run verify

The verification gate runs unit and integration tests with coverage thresholds, all executable examples and scenarios, generated-file and trace-link checks, compatibility and migration checks, generated TypeScript compilation, OpenAPI validation, and an installed-package smoke test. Generated example files are committed and must not be edited by hand.

See CONTRIBUTING.md and docs/versioning.md before changing public syntax or generated output. Maintainers publish with the checklist in docs/releasing.md.

Relationship to Mermaid

This is an independent project that consumes Mermaid-compatible source text. It is not affiliated with or endorsed by the Mermaid project, and it does not change Mermaid's renderer or core grammar.

License

MIT