nestjs-doctorGitHub

Pipeline Overview

How nestjs-doctor works from CLI invocation to final output.

Flow

Directory Map

DirectoryResponsibility
src/cli/CLI flags, entry point, output formatters
src/engine/Config loading, file collection, project detection, diagnostic filtering, AST parsing, module graph, provider resolution, rule execution, scoring
src/engine/rules/definitions/All 43 rules organized by category (security/, correctness/, architecture/, performance/, schema/)
src/report/HTML report generation (interactive dashboard, module graph, schema ER diagram)
src/common/Shared type definitions (Diagnostic, Config, Result, errors)

Steps

The pipeline has 10 stages. In a monorepo, stages 2-9 run once per sub-project.

#StageSourceScope
1Config Loadingsrc/engine/config/loader.tsOnce
2Project Detectionsrc/engine/project-detector.tsPer project
3File Collectionsrc/engine/file-collector.tsPer project
4AST Parsingsrc/engine/graph/ast-parser.tsPer project
5Module Graphsrc/engine/graph/module-graph.tsPer project
6Provider Resolutionsrc/engine/graph/type-resolver.tsPer project
7Rule Executionsrc/engine/rule-runner.tsPer project
8Diagnostic Filteringsrc/engine/filter-diagnostics.tsPer project
9Scoringsrc/engine/scorer/index.tsPer project + combined
10Outputsrc/cli/formatters/Once

Orchestrator

The autoScan() and scanMonorepo() functions in src/engine/scanner.ts wire these stages together. The CLI calls one of these, and the Node.js API (diagnose(), diagnoseMonorepo()) wraps them with path validation.

Parallel Execution

The pipeline exploits concurrency where stages are independent:

  • Single-project mode: config loading and custom rule resolution run first, then file collection and project detection run concurrently (Promise.all). The remaining stages (AST parsing → module graph → providers → rule execution → scoring) run sequentially.
  • Monorepo mode: file collection for all sub-projects runs in parallel, and then each sub-project's full analysis (AST parsing through scoring) runs concurrently via Promise.all.

HTML Report

Run npx nestjs-doctor . --report to generate an interactive HTML report. The output is a self-contained nestjs-doctor-report.html file that auto-opens in your browser. It includes five tabs: summary, diagnostics, an interactive module graph (nodes, directed edges, circular dependency highlighting), a schema ER diagram, and a custom rule lab.