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

@matthewlovestocode/ts-project-mapper

v0.0.6

Published

Maps a TypeScript project's imports/exports into a graph and generates AI-agent-friendly documentation.

Readme

ts-project-mapper

Maps a TypeScript project's imports and exports into a dependency graph, and generates documentation and diagrams from it — sized for either a human skimming a repo or an AI agent orienting itself before diving into source files.

Parses source with the TypeScript Compiler API, resolves relative imports and tsconfig paths aliases to real files on disk, and distinguishes runtime imports/exports from type-only ones.

Install

npm install @matthewlovestocode/ts-project-mapper

CLI

npx ts-project-mapper <dir> [mode] [--json]

| Mode | What it does | | --- | --- | | (none) | Full ProjectMap as JSON | | --markdown | Full map as markdown: external deps, entry points, every module's exports/imports/dependents | | --summary | Just the overview — module count, external deps, likely entry points. Cheap, bounded size; the right first call on an unfamiliar project | | --focus <file> | One module's own exports/imports, plus every dependent and which names each imports from it | | --graph | The internal dependency graph as a fenced ```mermaid flowchart — renders inline on GitHub, VS Code's markdown preview, etc. | | --find <name> | Where a name is defined (which module exports it) and everywhere it's imported — the starting point when you have a symbol name but not a file path | | --impact <file> | The full transitive "blast radius" of a module: everything that depends on it, directly or through a chain of dependents | | --cycles | Circular dependencies — groups of modules that (transitively) import each other | | --unused | Exports nothing in the scan imports or re-exports — a heuristic for dead code, with real caveats (see below) | | --missing-docs | Exported declarations with no JSDoc comment — a punch list for an agent to fix, not something this tool writes itself | | --complexity | Functions that are long or branchy, and files with an unusually large number of top-level declarations — a decomposition punch list |

Add --json to any of --summary, --focus, --find, --impact, --cycles, --unused, --missing-docs, or --complexity to get the underlying structured data instead of a markdown rendering — useful when the output is consumed by code rather than read directly.

# orient on an unfamiliar project
npx ts-project-mapper src --summary

# drill into one module once you know where to look
npx ts-project-mapper src --focus src/server.ts

# find a symbol you don't have a file path for yet
npx ts-project-mapper src --find handleConnection

# what would break if I change this file?
npx ts-project-mapper src --impact src/db/parcels.ts

# visualize the whole thing
npx ts-project-mapper src --graph > graph.md

Library

import {
  mapProject,
  generateSummary,
  generateFocus,
  generateDocs,
  generateGraph,
  generateFind,
  generateImpact,
  generateCycles,
  generateUnused,
  generateMissingDocs,
  generateComplexity,
} from "@matthewlovestocode/ts-project-mapper";

const projectMap = mapProject("./src");

console.log(generateSummary(projectMap));
console.log(generateFocus(projectMap, "./src/server.ts"));
console.log(generateDocs(projectMap)); // full dump
console.log(generateGraph(projectMap)); // mermaid flowchart
console.log(generateFind(projectMap, "handleConnection"));
console.log(generateImpact(projectMap, "./src/db/parcels.ts"));
console.log(generateCycles(projectMap));
console.log(generateUnused(projectMap));
console.log(generateMissingDocs(projectMap));
console.log(generateComplexity(projectMap));

Each generateX() markdown renderer has a matching buildXData() that returns the plain data object instead (buildSummaryData, buildFocusData, buildFindData, buildImpactData, buildCycleData, buildUnusedData, buildMissingDocsData, buildComplexityData) — what the CLI's --json flag uses under the hood.

mapProject(rootDir) returns a ProjectMap:

interface ProjectMap {
  rootDir: string;
  modules: ModuleNode[];
}

interface ModuleNode {
  filePath: string;
  imports: ImportInfo[];
  exports: ExportInfo[];
}

See the exported types (ImportInfo, ExportInfo) for the full shape — each carries enough detail to tell a default import from a named one, a type-only import from a runtime one, and a resolved internal path from an external package.

Path aliases

If a tsconfig.json with compilerOptions.paths exists at or above the scanned directory, bare specifiers matching an alias (e.g. "@/lib/foo") are resolved to their real file the same way tsc would — including following extends chains.

--unused is a heuristic, not a guarantee

An export counts as "used" if something in the scan imports it by name or re-exports it. That means:

  • A namespace import (import * as ns from "./x") marks the whole source module as used, since property access through ns can't be tracked — this avoids false positives at the cost of missing some real dead code.
  • Usage from outside the scanned directory is invisible. If you scan a library's src/ in isolation, its own public API will look "unused" even though real consumers import it — scan a package's actual entry point (where its own barrel file lives), not an arbitrary subdirectory, for reliable results.

--complexity's thresholds are starting points, not rules

The defaults (50 lines, cyclomatic complexity 10, 15 top-level declarations per file) are reasonable starting cutoffs, not hard rules — pass a different ComplexityThresholds to generateComplexity()/buildComplexityData() to tune them for a codebase's own style.

One thing to expect: a test file's it("...", () => { ... }) callbacks often show up as long functions even when nothing's actually wrong — a test body with a lot of setup is normal, not a sign the test needs splitting the way a long production function would be.

Development

npm install
npm run build   # compile to dist/
npm test        # run the test suite
npm run dev     # run the CLI against source directly, via tsx