circular-deps

Diagnose and break circular dependencies between NestJS modules without forwardRef.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/aymansalkhatib/medledger --skill circular-deps-aymansalkhatib
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: circular-deps
Source: https://github.com/aymansalkhatib/medledger/tree/main/.claude/skills/circular-deps
Command: npx skills add https://github.com/aymansalkhatib/medledger --skill circular-deps-aymansalkhatib

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? NestJS applications fail at startup with "circular dependency" or "can't resolve dependencies" errors when modules import each other in a cycle. This Skill diagnoses the offending edge in the module graph and re-cuts the layering so the dependency graph stays a DAG, instead of papering over the cycle with forwardRef. ## Core Features & Use Cases - Cycle diagnosis: Distinguishes module-level cycles ("ModuleA -> ModuleB -> ModuleA") from provider-level cycles ("Nest can't resolve dependencies of the X (?)"), and greps for existing forwardRef usage as a smell. - Prioritized fix ladder: Applies five escalating strategies — re-check method ownership, pass data as arguments instead of importing modules, extract shared code downward into shared/ or infrastructure/, orchestrate cooperating leaves one level up, and only as a last resort use forwardRef on both sides with a documented justification. - Architecture enforcement: Verifies leaf modules (holdings, ledger, audit-events) never import operation modules (transfers, administrations, waste-records), keeping the dependency direction strictly downward. - Use Case: You add a cross-module service injection and the app fails to boot with a circular dependency error. Run the skill with the two module names to identify the backward edge and apply the correct restructuring. ## Quick Start Ask the AI to run the circular-deps check mode to scan the NestJS codebase for forwardRef usage and any leaf module importing an operation module.

Frequently Asked Questions about circular-deps

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a NestJS circular dependency error?▼

Identify the backward edge by reading both modules' imports arrays, then remove it by moving the method to the correct owner service, passing data as arguments instead of importing the module, or extracting shared code into a shared or infrastructure layer that neither side imports.

How to resolve "Nest can't resolve dependencies of the X (?)" error?▼

The question mark marks the provider caught in a dependency cycle. Trace which providers inject each other, then break the cycle by re-checking method ownership or orchestrating the two services from a higher-level module that imports both.

When should I use forwardRef in NestJS?▼

Use forwardRef only as a last resort for genuinely mutually-recursive providers when restructuring options do not apply. It must appear on both sides of the relationship and include a comment naming the rejected alternative, otherwise it hides a layering problem.

Why does a NestJS circular dependency only fail at startup and not compile time?▼

TypeScript compiles the imports fine because the cycle is in the runtime dependency-injection graph, not the type graph. Nest resolves providers at bootstrap, so a surviving cycle throws during application startup even when the build is green.

Is importing another module's repository a valid way to break a cycle?▼

No. Importing the other module's repository trades a circular dependency for a boundary violation, letting one module mutate another's rows. Give each piece of state a single owner and pass data across the boundary as arguments instead.