Skip to content

analyze

Scan a legacy codebase and generate suggested bounded contexts, complexity tiers, and hotspot identification.

Terminal window
npx modernizespec analyze [options]
  1. Scans the project directory for source files
  2. Analyzes module boundaries (directory structure, import patterns, naming conventions)
  3. Computes file-level metrics (LOC, function count, import count)
  4. Identifies God-classes and complexity hotspots
  5. Suggests bounded context groupings
  6. Outputs updated domains.json and complexity.json
FlagDescriptionDefault
--dir <path>Directory to analyzeCurrent directory
--language <lang>Source languageAuto-detected
--framework <name>Framework (affects analysis heuristics)Auto-detected
--output <format>Output format: files, json, stdoutfiles
--dry-runShow suggestions without writing filesWrite to disk
--god-class-threshold <n>LOC threshold for God-class detection2000
Terminal window
npx modernizespec analyze
Terminal window
npx modernizespec analyze --dry-run
Terminal window
npx modernizespec analyze --god-class-threshold 1500
Terminal window
npx modernizespec analyze --dir /path/to/legacy-project --language python

When --output files (default), the command updates:

  • .agents/modernization/domains.json — Suggested bounded contexts
  • .agents/modernization/complexity.json — Hotspots and tiers

When --output json, the analysis is printed to stdout as JSON for piping.

The analyzer looks for:

  • Top-level directories as potential bounded contexts
  • modules.txt or equivalent framework manifests
  • Package/namespace boundaries
  • Import clustering (files that import each other tend to belong together)
MetricCalculation
LOCLine count (excluding blanks and comments)
Function countAST or regex-based function/method detection
Import countDirect import statements per file
Cyclomatic complexityBranch count approximation

Modules are assigned to tiers based on:

FactorTier 1 (Extract Now)Tier 2 (Extract With Care)Tier 3 (Defer)
External couplingLow (< 0.2)Medium (0.2 - 0.5)High (> 0.5)
God-classesNoneSome (decomposable)Central (blocking)
Framework couplingLowModerateDeep
  • Analysis is heuristic-based, not semantically precise
  • Framework-specific patterns may not be detected without the --framework flag
  • Cross-file dependency analysis is approximate (based on imports, not runtime calls)
  • Results should be reviewed and adjusted by someone with domain knowledge