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

ng-di-graph

v0.8.5

Published

Angular DI dependency graph CLI tool

Downloads

47

Readme

ng-di-graph

CI Version License

A command-line tool that analyzes Angular TypeScript codebases to extract dependency injection relationships.

Target Angular Versions: 17-21

Prerequisites

  • Node.js 20.x (npm 10+)
  • Angular project targeting v17-21 with a tsconfig.json to discover or reference

Installation

npm install -g ng-di-graph

Quick start

# Analyze the whole project and print text output (default)
ng-di-graph

# Generate a Mermaid diagram and save it
ng-di-graph --format mermaid --out docs/di-graph.mmd

# Target specific files via positional filePaths
ng-di-graph src/app/app.component.ts src/app/auth.service.ts --format json

# Auto-discover the nearest tsconfig.json (no --project needed)
ng-di-graph src/app --format mermaid --out docs/di-graph.mmd

# Focus on a symbol and see who depends on it
ng-di-graph --entry UserService --direction upstream

# Override auto-discovery with an explicit tsconfig
ng-di-graph --project ./tsconfig.json --format json

Features

Complete Feature Set - Production-ready dependency graph analysis for Angular applications

  • 🔍 Dependency Analysis - Extract DI relationships from @Injectable, @Component, and @Directive classes
  • 🎯 Constructor Injection - Analyze constructor parameters with type annotations and @Inject() tokens
  • Modern DI Support - Analyze dependencies from constructor injection and the inject() function
  • 🏷️ Decorator Flags - Capture @Optional, @Self, @SkipSelf, and @Host parameter decorators
  • 📊 Multiple Output Formats - Text (default), JSON (machine-readable), Mermaid (visual flowcharts)
  • 🎨 Entry Point Filtering - Generate sub-graphs from specific starting nodes
  • 🔄 Bidirectional Analysis - Explore upstream dependencies, downstream consumers, or both
  • 🔁 Circular Detection - Automatically detect and report circular dependencies
  • 🧹 Angular Core Filtering - Hide @angular/core nodes by default (--include-angular-core to show)

Common commands

  • Full project, text output (default):
    ng-di-graph
  • JSON output to stdout:
    ng-di-graph --format json
  • Mermaid diagram to file:
    ng-di-graph --format mermaid --out docs/di-graph.mmd
  • Filter to specific symbols:
    ng-di-graph --entry AppComponent
  • Upstream consumers of a service:
    ng-di-graph --entry UserService --direction upstream
  • Include decorator flags with verbose logging:
    ng-di-graph --include-decorators --verbose

CLI options at a glance

ng-di-graph [filePaths...] [options]

Option | Default | Description -- | -- | -- filePaths | none | Positional alias for --files; combines with --files when both are set. -p, --project <path> | auto-discovered | Path to the TypeScript config file to analyze (omit to auto-discover). --files <paths...> | none | Limit analysis to specific files or directories. -f, --format <format> | text | Output as text, json, or mermaid. -e, --entry <symbol...> | none | Start the graph from one or more symbols. -d, --direction <dir> | downstream | downstream, upstream, or both relative to entries. --include-decorators | false | Add @Optional, @Self, @SkipSelf, @Host flags to edges. --include-angular-core | false | Include nodes that originate from @angular/core imports. --out <file> | stdout | Write output to a file. -v, --verbose | false | Show detailed parsing and resolution logs. -h, --help | false | Display CLI help.

Output Formats

Text Format (default)

Project: ./tsconfig.json
Scope: direction=downstream, entry=all
Files: 12 (skipped: 0)

Dependencies (A depends on B):
AppComponent
└─ UserService

UserService
├─ AuthService
└─ Logger

JSON Format

{
  "nodes": [
    {
      "id": "AppComponent",
      "kind": "component",
      "source": { "filePath": "/path/to/src/app.component.ts", "line": 12, "column": 14 }
    },
    {
      "id": "UserService",
      "kind": "service",
      "source": { "filePath": "/path/to/src/user.service.ts", "line": 8, "column": 14 }
    },
    {
      "id": "AuthService",
      "kind": "service",
      "source": { "filePath": "/path/to/src/auth.service.ts", "line": 20, "column": 14 }
    },
    {
      "id": "Logger",
      "kind": "service",
      "source": { "filePath": "/path/to/src/logger.service.ts", "line": 5, "column": 14 }
    }
  ],
  "edges": [
    {
      "from": "AppComponent",
      "to": "UserService"
    },
    {
      "from": "UserService",
      "to": "AuthService",
      "flags": { "optional": true, "self": false, "skipSelf": false, "host": false }
    },
    {
      "from": "AuthService",
      "to": "Logger",
      "flags": { "optional": false, "self": false, "skipSelf": false, "host": false }
    }
  ],
  "circularDependencies": [["UserService", "AuthService", "UserService"]]
}

Node Kinds:

  • service - Classes decorated with @Injectable()
  • component - Classes decorated with @Component()
  • directive - Classes decorated with @Directive()
  • unknown - Could not determine decorator type

Node Source (when available):

  • source.filePath - Absolute file path reported by the TypeScript project
  • source.line / source.column - 1-based position of the class name token
  • source is omitted for unknown nodes created from unresolved tokens

Edge Flags (when --include-decorators is used):

  • optional - Parameter has @Optional() decorator
  • self - Parameter has @Self() decorator
  • skipSelf - Parameter has @SkipSelf() decorator
  • host - Parameter has @Host() decorator

Mermaid Format

flowchart LR
  AppComponent --> UserService
  UserService --> AuthService

Mermaid diagrams can be rendered in GitHub/GitLab markdown, viewed in the Mermaid Live Editor, or converted to images with CLI tools.

Use cases

  • Test planning: surface dependencies to decide what to mock.
  • Impact analysis: list consumers before changing a service.
  • Documentation: add Mermaid diagrams to READMEs or architecture docs.

Release workflow

Releases are automated via Release Please; tag pushes run lint → typecheck → test → build → pack → publish. Maintainer runbook: see docs/release/ci-publish.md.

Error handling

The CLI reports clear failures and continues past unparseable files; rerun with --verbose for detailed logs.

Contributing

Contributions are welcome! Please see our Contributing Guide for development setup, code quality standards, and the pull request process.

License

MIT License - See LICENSE file for details