domain-validation

Enforce domain business rules before persisting entities with DomainValidation<T>.

Updated Mar 1, 2026
One-click install
npx skills add https://github.com/Zoppy-crm/.github --skill domain-validation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: domain-validation
Source: https://github.com/Zoppy-crm/.github/tree/main/skills/backend/domain-validation
Command: npx skills add https://github.com/Zoppy-crm/.github --skill domain-validation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Domain validations ensure business rules are consistently enforced before persisting entities, preventing invalid data from entering the system and reducing downstream errors.

Core Features & Use Cases

  • DomainValidation<T> base class that collects validation errors, supports asynchronous checks, and raises a unified UnprocessableEntityException when necessary.
  • Application Service integration with Scope.REQUEST to run domain validations before saving via a reusable validation pipeline.
  • Cross-entity reuse of validation logic to guarantee consistent rules across create and update operations.

Quick Start

Create a domain validation class extending DomainValidation for your entity and invoke its execute method within your application service before persisting the entity.

Frequently Asked Questions about domain-validation

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

FAQPage Schema
How do I enforce domain validation rules before saving an entity in NestJS?

To enforce domain validation before saving an entity in NestJS, you extend the DomainValidation<T> base class and invoke its execute method within your application service to run checks before persisting. It aggregates errors and throws an UnprocessableEntityException when violations are found.

Can I run asynchronous database lookups during domain validation in NestJS?

Yes, you can run asynchronous database lookups during domain validation in NestJS. The DomainValidation<T> base class supports async validations by running checks against a RepositoryAdapter, enabling complex business rules that require querying the database before entity persistence.

What is the best way to reuse business rules across create and update operations in TypeScript?

The best way to reuse business rules across create and update operations in TypeScript is using a reusable validation pipeline. By extending a DomainValidation<T> class, you share validation logic across services to guarantee consistent rules for both operations.

How does an application service handle UnprocessableEntityException when domain validations fail?

An application service handles UnprocessableEntityException when domain validations fail by relying on an injectable Scope.REQUEST validator. This validator aggregates all domain rule violations into a single error list and throws the exception, preventing invalid data from entering the system.

Do I need to register a Scope.REQUEST validator in my NestJS module to use domain validation?

Yes, you need to register the Scope.REQUEST validator in your NestJS module to use domain validation. Proper module registration is required to inject the validator into your application service and execute the domain rules before saving entities.

When should I use a RepositoryAdapter for domain validation instead of standard class-validator checks?

You should use a RepositoryAdapter for domain validation instead of standard checks when business rules require async database lookups. It allows your DomainValidation<T> logic to query existing data dynamically before persistence, preventing invalid data from entering the system.