Index of every page on this site: llms.txt
All skills
amirtaherkhani avatar

/nestjs-architecture-principles

@8272374
Run it yourself

Designs and reviews NestJS application architecture using cohesive feature modules, modular monoliths, layered or hexagonal boundaries, dependency inversion, and pragmatic engineering principles. Use when planning a NestJS project, changing module boundaries, evaluating Clean Architecture or DDD, resolving circular dependencies, defining ports and adapters, reviewing coupling, or deciding whether CQRS or microservices are justified. Do not use for pure frontend work or non-NestJS backends. When other skills also apply, reconcile ownership before mutation.

Use this Skill: https://skilld.dev/gh/amirtaherkhani/nestjs-skills/nestjs-architecture-principles

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesarchitecture-rules.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Architecture Rules

Use these rules to shape a NestJS system without turning one preferred diagram into a universal answer. Inspect the repository and its change pressures before choosing a structure.

Rules

1. Organize around business capabilities

Prefer cohesive feature modules such as OrdersModule or BillingModule over global technical buckets such as ControllersModule and ServicesModule. A feature should make its owned behavior, data, and public entry points easy to find.

Technical modules remain appropriate for reusable infrastructure such as configuration, telemetry, or a database client. They must not become a miscellaneous SharedModule that exports the entire container.

2. Keep module APIs small

Providers are private by default. Export only the application service, token, or read capability another module actually needs. Import the module that owns a provider instead of re-declaring the provider elsewhere.

Global modules are suitable for a few process-wide facilities. They are not a substitute for explicit capability dependencies.

3. Assign one owner to every invariant and write

Responsibility is defined by a reason to change, not class size or a one-method rule. Keep each business invariant and write path under one capability owner. If several modules coordinate a workflow, name the coordinator and its transaction boundary explicitly.

4. Point dependencies toward policy

Controllers, message handlers, persistence adapters, and vendor integrations depend on application policy. Domain code must not depend on Nest decorators, HTTP responses, ORM records, queue jobs, or vendor SDK types.

Use a direct local dependency when it is stable and remains inside one boundary. Add a port when an external or volatile edge, meaningful alternate implementation, or valuable test seam justifies it.

5. Treat cycles as design feedback

Map the import and provider graph before fixing a circular dependency. A cycle often exposes ambiguous ownership, a workflow that needs a coordinator, or an overly broad module API.

Repair ownership first. A narrow query port or an event can help only when its consistency and failure semantics fit. forwardRef() is a compatibility escape hatch, not the default architecture.

6. Choose calls, events, and queues by semantics

  • Use a synchronous call when the caller needs an immediate result or shares one transaction.
  • Use an in-process event for optional reactions whose failure and durability requirements are understood.
  • Use a durable message or queue when work must survive process failure, absorb bursts, or run independently.

An event is not automatically more decoupled if publishers and consumers still share data ownership or deployment. Durable messages also require schema compatibility, idempotency, retry, ordering, and observability decisions.

7. Do not require repositories everywhere

Use an application-owned repository or store port when domain behavior needs persistence independence, several use cases need a stable capability-oriented interface, or an adapter is likely to change. Direct ORM access in a simple application service can be clearer for straightforward CRUD inside one owned boundary.

Never expose an ORM repository or entity as another feature's write API. Query methods should express a use-case need rather than merely mirror every ORM operation.

8. Keep wiring at the composition root

Construct and select implementations through Nest modules and providers. Business objects receive dependencies explicitly; they do not reach into ModuleRef, a global container, or static service locator during ordinary execution.

Decision sequence

  1. Name the capability, invariant owner, and required external contract.
  2. Draw module imports, provider exports, data writes, and asynchronous paths.
  3. Choose the lowest architecture level that protects the known boundary.
  4. Define consistency, failure, and compatibility behavior before selecting a transport.
  5. Add only the abstractions that isolate real volatility or clarify ownership.
  6. Protect the result with module, architecture, integration, and contract tests.

Conflict guardrails

  • Object-level responsibility and pattern selection belong to the OOP and Design Patterns skill.
  • Database ownership and transaction boundaries are detailed in database-orm.md.
  • Service extraction and distributed ownership are detailed in microservices.md.
  • Runtime middleware, guards, pipes, interceptors, filters, queues, and performance controls belong to the Features, Scaling, and Performance skill.

See module-boundaries.md, dependency-injection.md, and the official NestJS guidance on modules, providers, circular dependencies, and events.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts3d3 checks · Risk SAFE
  • Gen Agent Trust Hub4d

    This skill provides architectural principles, design patterns, and review guidelines for NestJS applications. It focuses on modularity, dependency inversion, and pragmatic engineering. No security issues or malicious patterns were detected.

  • Socket3d

    No alerts

  • Snyk4d

    Risk: LOW · No issues

Signed by skilld at 8272374. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 5 days ago
metadata
{
  "author": "amirtaherkhani",
  "version": "1.2.1"
}

README badge

README badge for amirtaherkhani/nestjs-skills/nestjs-architecture-principles