agentleFS
BK202503BK202503/open-claude-all/skills/nestjs-provider-review/SKILL.md

nestjs-provider-review

Skill7 starsChanged 4 months agoMITView on GitHub

Review NestJS module / provider / dependency-injection code before you PR for common regressions. Injection scope misuse (DEFAULT vs REQUEST vs TRANSIENT), circular module dependencies masked by `forwardRef`, missing `exports` in module definitions, exception filter / interceptor / pipe / guard ordering, and async-provider typing gaps. Triggers include "review this NestJS code", "check my module wiring", "why is my provider undefined", "nest DI review".

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Default scope is singleton.

    line 17
  2. Very specific:

    Every forwardRef is a smell.

    line 22
  3. Distinctive:

    Use it only for cross-cutting infra (config, logging, tracing).

    line 31
  4. Distinctive:

    Always annotate the factory return type explicitly.

    line 43
  5. Very specific:

    If you swap adapters mid-project, re-audit every filter, interceptor, and manual response.

    line 47

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

nestjs-provider-review

Catches regressions in the DI graph and request-lifecycle layer of a NestJS app. These bugs pass unit tests (which build their own module) and fail only in the full app boot. Runs before you PR.

What to check

1. Injection scope

  • Default scope is singleton. A REQUEST-scoped provider injected into a DEFAULT-scoped provider silently upgrades the whole graph to request-scoped, degrading throughput.
  • TRANSIENT-scoped providers create a new instance per consumer. If the provider holds a connection or timer, you leak one per consumer.
  • Grep for scope: Scope.REQUEST and confirm every consumer up the chain understands the cost.

2. Circular deps and forwardRef

  • Every forwardRef is a smell. It usually means the two modules should be one, or one dependency should be inverted.
  • A cycle that "works" today can fail at boot after a refactor because the eager-init order changed. Prefer restructuring the graph.

3. Module exports

  • A provider works in providers for internal use but is invisible to importing modules until it is in exports.
  • Common failure: fixed a service in tests (module has its own providers), broke in prod (importing module has no access).

4. Global module overuse

  • @Global() hides the dep graph and makes module refactoring painful.
  • Use it only for cross-cutting infra (config, logging, tracing). Not for business services.

5. Exception filter chain

  • Filters registered globally, at controller level, and at method level all apply. The most specific wins for the same error type. Confirm the intended catch order.
  • A filter that returns without calling response.send (or without returning a value under the fastify adapter) hangs the request.

6. Pipe / Guard / Interceptor order

  • Runtime order: middleware, then guards, then interceptors (pre), then pipes, then handler, then interceptors (post), then filters.
  • A DTO transformation done in a pipe is not visible to a guard. If a guard needs the transformed value, move that logic into the guard or into an interceptor.

7. Async providers

  • useFactory with an async function returns a Promise. TypeScript infers the token as the awaited type, but if the inject: array is wrong, the factory receives undefined at boot and Nest throws only when the first consumer resolves.
  • Always annotate the factory return type explicitly.

8. Fastify vs Express adapter differences

  • Return value semantics differ. A handler returning a plain object works in both, but streaming, cookies, and header manipulation differ.
  • If you swap adapters mid-project, re-audit every filter, interceptor, and manual response. call.

Common failure patterns to grep for

  • forwardRef(() => appearing in imports across more than two modules.
  • scope: Scope.REQUEST on a provider whose consumers are DEFAULT-scoped controllers.
  • useFactory: async (...) with no explicit return type annotation.
  • Providers listed in providers: but missing from exports: in the same module.

When to invoke

Trigger when the user asks for a NestJS review, mentions DI confusion, or opens a PR touching *.module.ts, *.service.ts, or the app bootstrap file.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.