adonisjs-value-objects

Create immutable domain value objects for AdonisJS TypeScript applications.

2|1|Updated Mar 16, 2026
One-click install
npx skills add https://github.com/omakei/adonisjs-architecture-skill --skill adonisjs-value-objects
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: adonisjs-value-objects
Source: https://github.com/omakei/adonisjs-architecture-skill/tree/main/adonisjs/skills/adonisjs-value-objects
Command: npx skills add https://github.com/omakei/adonisjs-architecture-skill --skill adonisjs-value-objects

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Domain concepts in AdonisJS apps often leak mutable state and scattered validation logic, making it hard to guarantee consistency across layers. Immutable value objects enforce invariants, encapsulate domain rules, and provide predictable behavior.

Core Features & Use Cases

  • Immutability: readonly properties and private constructors prevent mutation after creation.
  • Static factories: validated constructors ensure safe instantiation.
  • Domain logic encapsulation: arithmetic and rules live inside the value objects (e.g., Money, EmailAddress, Coordinate).
  • Value equality and serialization: equality by value and ready-to-persist representations for Lucid.
  • Real-world use: modeling money, emails, and coordinates in AdonisJS domain models.

Quick Start

Create a Money value with Money.fromDollars(29.99) and compare it to another Money using equals.

Frequently Asked Questions about adonisjs-value-objects

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

FAQPage Schema
How do I create immutable domain value objects in an AdonisJS application?

Immutable domain value objects in AdonisJS use readonly properties and private constructors to prevent mutation after creation, ensuring consistent state across application layers and encapsulating domain rules.

What's the best way to model Money and EmailAddress values in TypeScript?

Modeling Money and EmailAddress values in TypeScript is best handled by immutable value objects with static factory methods for validated instantiation, encapsulating arithmetic and validation rules inside the domain primitives.

Does this approach to value objects work with Lucid models for database persistence?

Yes, value objects provide ready-to-persist representations compatible with Lucid, allowing seamless serialization of domain primitives like Coordinate and Money for database storage in AdonisJS.

How do you compare two value objects for equality in TypeScript?

Value objects compare for equality by value rather than reference, meaning two Money or EmailAddress instances are equal if their underlying properties match, ensuring predictable domain behavior.

Can I use static factory methods to validate domain primitives before instantiation?

Static factory methods validate domain primitives before instantiation, ensuring safe creation of value objects by enforcing invariants and rejecting invalid inputs at the point of construction.

Why does my domain logic scatter validation across multiple layers in AdonisJS?

Domain logic scatters when validation is not encapsulated within value objects, a problem solved by moving invariants and rules into immutable domain primitives that guarantee consistency across layers.