Architecture rules for TypeScript, checked on every build

Write down rules such as "controllers don't import repositories" or "no cycles between modules". tdepend checks them against an import graph that matches the TypeScript compiler, and fails the build when an import breaks one.

Quick Installation

Needs Node 22.12 or later

npm install -D tdepend

What It Does

Rules, and the graph that makes them trustworthy

Architecture Rules

Forbid imports between files or layers, keep a component's internals private, ban npm packages from parts of the code, and stop import cycles. Every violation names the file, line and import to fix.

A Graph That Matches the Compiler

Every import is resolved by TypeScript's own resolver: tsconfig paths, package exports, project references and workspace packages, built or not. If tsc can follow an import, so can tdepend.

Runtime or Type-Only

tdepend knows which imports really load their target at runtime and which ones the compiler erases, so a cycle made only of type imports isn't reported as a runtime cycle.

Presets

NestJS, React, Express, Fastify and plain Node projects are detected per package.json. Each preset brings sensible skips, components and recommended rules, and you can write your own.

Baselines

Adopt a rule in a codebase that already breaks it. The baseline accepts today's violations with a count, so only new ones fail the build.

Cycles With Proof

Cycles are found between files, components and packages. Each one comes with its shortest loop and the exact import behind every step.

Coupling Metrics

Afferent and efferent coupling, instability, abstractness and distance from the main sequence, for every file, component and package. Metrics inform; they never fail a build.

CLI, Library and JSON

Run it from the command line or call it from Node. The JSON output is sorted and has no timestamp, so two runs on the same code are byte-identical.

Use as CLI or Library

Choose the approach that fits your workflow

CLI Usage

tdepend init        # write a starter config
tdepend analyze     # components, metrics, cycles
tdepend check       # evaluate the rules
tdepend baseline    # accept today's violations
tdepend explain src/main.ts

Library Usage

import { check } from 'tdepend';

const report = await check({ root: '.' });

for (const violation of report.actionable) {
  console.log(violation);
}
process.exitCode = report.exitCode;

Understanding Core Concepts

Learn how tdepend groups files into components, how it tells a runtime import from a type-only one, what the coupling metrics mean, how cycles are found, and how a baseline lets you adopt a rule gradually.

Ready to write your first rule?

Run tdepend init in your repository and see what it finds.