Overview
rich-domain provides built-in validation support using the Standard Schema specification. This means you can use your favorite validation library - Zod, Valibot, ArkType, or any other Standard Schema-compatible library.Why Standard Schema?
Library Agnostic
Use Zod, Valibot, ArkType, or any Standard Schema-compatible library
Type Inference
Get full TypeScript inference from your schemas
Validation Timing
Control when validation runs (create, update, or both)
Error Handling
Choose between throwing errors or collecting them
Supported Libraries
Any library implementing the Standard Schema spec works:Basic Usage
1. Define Your Schema
2. Apply to Entity/Aggregate
3. Validation in Action
Validation Configuration
onCreate
Whentrue, validates the entire entity when constructed:
onUpdate
Whentrue, validates after every property change:
throwOnError
Controls error handling behavior:Validation for Value Objects
Value Objects also support validation:Non-Throwing Mode
Collect errors without throwing:ValidationError
TheValidationError class provides rich error information: