DevTools Logo

Monorepo Dependency Graph Viewer

Monorepo Dependency Graph Viewer

Build a deterministic workspace package graph from pnpm, npm or yarn workspaces, detect cycles and version drift, and export Mermaid.

Runs in your browser
Try an example

Workspace inputs

30 lines · 548 chars

2 globs read from pnpm-workspace.yaml.

An array of path plus content (object or JSON string), or an object mapping each path to its content.

Dependency graph

3 packages · 2 internal edges
Topological: @acme/utils → @acme/core → @acme/uiLayers: 3

No dependency cycles detected.

Visualization

@acme/utils@acme/core@acme/ui
@acme/core1.0.0layer 1

internal: @acme/utils

@acme/ui1.0.0layer 2

internal: @acme/core · external: react

@acme/utils1.0.0layer 0

internal: none

Examples

Internal vs external split

Input
@demo/core depends on @demo/utils: workspace:* and react: ^19
Output
internalDependencies: ["@demo/utils"], externalDependencies: ["react"], topologicalOrder: ["@demo/utils", "@demo/core"], layers: { "@demo/utils": 0, "@demo/core": 1 }

The workspace: spec creates an edge and layer 1; the npm range stays external and out of the graph.

Two-package cycle plus isolated node

Input
a ↔ z via workspace:*, plus isolated with no deps
Output
cycles: [["a","z","a"]], topologicalOrder: ["isolated", "a", "z"]

DFS reports the a→z→a loop while the isolated package orders first at layer 0.

About this tool

Monorepo Dep Graph Viewer builds a workspace graph with buildDependencyGraph(workspaceYaml, inputs): parseWorkspaceGlobs reads the packages: list (block dash items and inline [..] forms, # comments stripped, ! negations dropped, duplicates deduped), inputs outside every glob are excluded, malformed package.json entries land in errors, and packages sort alphabetically by name for deterministic output.

Each package splits its combined dependencies/devDependencies/peerDependencies/optionalDependencies into internalDependencies (spec starts with workspace: OR the name exists in the workspace) versus externalDependencies (everything else, e.g. react: ^19). Internal links become sorted edges with their raw spec, cycles are found by depth-first search (a↔z yields [["a", "z", "a"]] with cyclicPackages ["a", "z"]), and topologicalOrder emits dependencies-first with alphabetical tie-breaking — cyclic leftovers append alphabetically after the acyclic nodes.

Layers derive from the order (layer = max(dep layer) + 1, so isolated packages sit at 0), and mermaid renders a flowchart TD with one pkg_<sanitized>[<label>] node per package plus pkg_from -->|<spec>| pkg_to lines for every internal edge — non-alphanumeric name characters collapse to _ in IDs.

How to use this tool

  1. Describe the workspace

    Paste pnpm-workspace-style YAML (packages: globs) and the package.json inputs; only glob-matched packages enter the graph.

  2. Read internal vs external

    workspace:* specs (or any dep name present in the workspace) count as internal edges; bare npm ranges like react ^19 stay external.

  3. Break the cycles

    Check cycles/cyclicPackages — a two-package loop reports [["a","z","a"]] — and remove or invert one edge before relying on the order.

Use cases

Sequencing workspace builds

Read topologicalOrder and layers to build leaf packages (layer 0) before their dependents.

Finding accidental cycles

Surface a↔z workspace loops that block topological builds and decide which direction to cut.

Embedding the graph in docs

Paste the Mermaid flowchart TD block — containing every internal edge — into Markdown or a wiki page.

Common mistakes

Mistake:Assuming every listed dependency is internal.

Fix:Only workspace:-prefixed specs or names present in the workspace are internal; plain npm ranges are external even when a workspace package shares the name pattern.

Mistake:Treating topologicalOrder as cycle-free proof.

Fix:Cyclic packages are appended alphabetically after the acyclic order — always check cycles/cyclicPackages alongside the order.

Frequently asked questions

What does this tool do?

It builds a workspace graph with buildDependencyGraph(workspaceYaml, inputs): glob-matched packages sort alphabetically, deps split into internal vs external, cycles are DFS-detected, and the result carries topologicalOrder, layers, and a flowchart TD Mermaid block.

What counts as internal, and what do cycles and layers look like?

A dep is internal when its spec starts with workspace: or its name exists in the workspace (react ^19 stays external); a↔z yields cycles [["a","z","a"]] with cyclicPackages ["a","z"]; and an isolated package sits at layer 0 and orders first.

Is my package data uploaded or stored?

No. Glob matching, edge building, cycle search, and Mermaid rendering are pure client-side computation — manifests never leave your browser.

Does the Mermaid output cover every edge?

Yes. Each internal edge renders one pkg_from -->|<spec>| pkg_to line (names sanitized to pkg_<A-Za-z0-9_>), so every entry in edges appears verbatim in the mermaid string.

References & standards