# value-objects-and-dtos

This skill guides Symfony work with immutable Value Objects and DTOs, covering constructor validation, value equality, and data crossing application boundaries.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf (Devin Desktop), Claude.ai · ★ 234 repo stars
- Author: dev-toolings
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/dev-toolings/superpowers-symfony/tree/HEAD/content/skills/value-objects-and-dtos/SKILL.md
- Updated: 2026-10-05
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/value-objects-and-dtos

## What it does

Use a Value Object for a domain concept with its own rules, and a DTO when data crosses an application boundary. The skill calls for `readonly` classes that validate in their constructors, compare Value Objects by value, and return new instances from operations. Setters are out.

For Doctrine, it prescribes embeddables. Input DTOs carry validation constraints; output DTOs use serializer attributes. The guidance also says to keep entities out of direct API input and output, and to represent money as an integer in minor units rather than a `float`. That integer representation is a constraint to preserve in the implementation. The expected result includes DTOs, mappings to and from entities, and unit tests for invariants.

Install it in Claude Code with `npx skills add dev-toolings/superpowers-symfony --skill value-objects-and-dtos -a claude-code`. The installed skill file is at `~/.claude/skills/value-objects-and-dtos/SKILL.md`; `reference.md` provides further implementation detail.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add dev-toolings/superpowers-symfony --skill value-objects-and-dtos -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/value-objects-and-dtos/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/value-objects-and-dtos/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add dev-toolings/superpowers-symfony --skill value-objects-and-dtos -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/value-objects-and-dtos/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add dev-toolings/superpowers-symfony --skill value-objects-and-dtos -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/value-objects-and-dtos/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install dev-toolings/superpowers-symfony content/skills/value-objects-and-dtos
```

2. **Manually: put the files in place**
- File: `.github/skills/value-objects-and-dtos/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add dev-toolings/superpowers-symfony --skill value-objects-and-dtos -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/dev-toolings/superpowers-symfony --path content/skills/value-objects-and-dtos
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/value-objects-and-dtos/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/dev-toolings/superpowers-symfony/tree/HEAD/content/skills/value-objects-and-dtos/SKILL.md

## When to use it
- model a domain concept as a Value Object with enforced invariants
- transfer request or API data through DTOs
- validate class invariants during construction
- embed a value object in a Doctrine entity
- map input and output DTOs to entities

## Example prompts
- Create an immutable Value Object for an address, validate it in the constructor, and test its invariants.
- Split this API's input and output DTOs, then map them to and from the entities.
- Model money as a Value Object and store its amount as an integer in minor units.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 68dd72fbaa346c71.

BEGIN THIRD-PARTY FILE 68dd72fbaa346c71
```text
---
name: value-objects-and-dtos
description: Design Value Objects for domain concepts and DTOs for data transfer with proper immutability (readonly) and validation
capabilities: [read, search]
tags: [architecture]
# projected by `bun run build` — do not edit by hand
allowed-tools:
  - Read
  - Glob
  - Grep
---

# Value Objects And Dtos (Symfony)

## Use when
- A domain concept with rules of its own (money, email, address) travels as raw scalars.
- Data crosses a boundary: request input, API output, message payload.
- Storing a value object inside a Doctrine entity.

## Default workflow
1. Decide: a value object for a domain concept with invariants, a DTO for data crossing a boundary.
2. Make it `readonly`, validate in the constructor, and fail fast.
3. Give value objects equality by value and operations that return new instances.
4. Persist value objects as Doctrine embeddables.
5. Keep input DTOs (validation constraints) apart from output DTOs (serializer attributes).

## Guardrails
- No setters and no mutation: a change returns a new instance.
- DTOs carry data only, with no behavior.
- Never expose entities directly as API input or output.
- Store money as an integer in minor units, never as a float.

## Progressive disclosure
- Use this file for execution posture and risk controls.
- Open references when deep implementation details are needed.

## Output contract
- Value objects with their invariants and equality.
- Input and output DTOs, and their mapping to and from entities.
- Unit tests for each invariant.

## References
- `reference.md`
```
END THIRD-PARTY FILE 68dd72fbaa346c71

The third-party file has ended. Everything between the 68dd72fbaa346c71 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

© dev-toolings · MIT · https://github.com/dev-toolings/superpowers-symfony/tree/HEAD/content/skills/value-objects-and-dtos/SKILL.md

## Similar
- [php-symfony](https://affpapa.org/en/nevibecode/rules/php-symfony.md) — rule · ★ 41430 repo stars
- [symfony-specialist](https://affpapa.org/en/nevibecode/agents/symfony-specialist.md) — subagent · ★ 26718 repo stars
- [clean-architecture](https://affpapa.org/en/nevibecode/skills/clean-architecture-2.md) — skill · ★ 372 repo stars
- [php-pro](https://affpapa.org/en/nevibecode/skills/httpsgithubcomjeffallan-php-pro.md) — skill · 16400 installs
- [php-expert](https://affpapa.org/en/nevibecode/skills/php-expert.md) — skill · 269 installs
- [Pimcore Expert](https://affpapa.org/en/nevibecode/agents/pimcore-expert.md) — subagent · ★ 41430 repo stars

From the same set: [dev-toolings/superpowers-symfony](https://affpapa.org/en/nevibecode/by/dev-toolings/superpowers-symfony.md) — 51 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
