dto-contract
Ensures data integrity across application layers by enforcing structured DTO contracts.
Install
mkdir -p .claude/skills/dto-contract && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16868" && unzip -o skill.zip -d .claude/skills/dto-contract && rm skill.zipInstalls to .claude/skills/dto-contract
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Defines DTO structure, lifecycle, and transformation rules across the applicationKey capabilities
- →Represent structured application data
- →Act as transport carriers between layers
- →Be filled by Transformers
- →Avoid business logic within DTOs
- →Avoid persistence logic within DTOs
- →Define DTO structure with fluent getters and setters
How it works
The skill defines rules for Data Transfer Objects (DTOs) as simple POPOs with fluent interfaces, created exclusively by Transformers, to ensure structured data contracts without business or persistence logic.
Inputs & outputs
When to use dto-contract
- →create new DTO classes
- →implement data transformation logic
- →standardize data contracts between layers
About this skill
DTO Contracts
DTOs define structured, transport-safe data contracts used between layers of the application.
They exist to replace unstructured arrays when data shape matters, is reused, or must remain consistent across boundaries.
1. Responsibility
DTOs MUST:
- represent structured application data
- act as transport carriers between layers
- be filled by Transformers
- avoid business logic
- avoid persistence logic
DTOs MUST NOT:
- contain ORM logic
- contain validation rules
- contain side effects
- depend on framework components (
Request, Eloquent models, etc.)
2. Structure
DTOs are simple POPOs with fluent getters and setters.
Example:
class InvoiceDto
{
private int $invoiceId;
private int $companyId;
private float $amount;
public function getInvoiceId(): int
{
return $this->invoiceId;
}
public function setInvoiceId(int $invoiceId): self
{
$this->invoiceId = $invoiceId;
return $this;
}
public function getCompanyId(): int
{
return $this->companyId;
}
public function setCompanyId(int $companyId): self
{
$this->companyId = $companyId;
return $this;
}
public function getAmount(): float
{
return $this->amount;
}
public function setAmount(float $amount): self
{
$this->amount = $amount;
return $this;
}
}
3. Creation Rule
DTOs MUST be created via Transformers.
$dto = InvoiceTransformer::fromModel($invoice);
or
$dto = InvoiceTransformer::fromArray($data);
DTOs MUST NOT be manually assembled inside services unless trivial and explicitly justified.
4. Transformer Dependency Rule
Transformers are the ONLY layer allowed to construct DTOs.
DTOs MUST NOT depend on Transformers.
Direction is strictly:
Model / Array → Transformer → DTO → Service
5. When DTOs are Required
Use DTOs when:
- data is shared across multiple services
- structure must remain stable across changes
- transformation logic exists (model → structured output)
- array shape would otherwise be ambiguous or inconsistent
6. When DTOs are NOT Required
DTOs MAY be skipped when:
- data is short-lived within a single method
- input comes from a validated
FormRequest - structure is trivial and not reused elsewhere
7. Core Principle
DTOs are explicit data contracts, not business logic containers.
IDE Hints (Optional)
DTOs MAY include region markers to improve IDE navigation (e.g. PhpStorm folding).
These are purely cosmetic and MUST NOT affect runtime behavior or architecture decisions.
Example:
class InvoiceDto
{
#region Properties
private int $invoiceId;
private int $companyId;
private float $amount;
#endregion
#region Getters
public function getInvoiceId(): int { ... }
public function getCompanyId(): int { ... }
public function getAmount(): float { ... }
#endregion
#region Setters
public function setInvoiceId(int $invoiceId): self { ... }
public function setCompanyId(int $companyId): self { ... }
public function setAmount(float $amount): self { ... }
#endregion
}
They exist to stabilize data shape across the system, not to introduce unnecessary abstraction.
When not to use it
- →When data is short-lived within a single method
- →When input comes from a validated `FormRequest`
- →When structure is trivial and not reused elsewhere
Limitations
- →DTOs must not contain ORM logic
- →DTOs must not contain validation rules
- →DTOs must not depend on framework components
How it compares
This skill enforces a strict separation of concerns for DTOs, ensuring they are pure data carriers created only by Transformers, unlike DTOs that might contain business or persistence logic.
Compared to similar skills
dto-contract side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| dto-contract (this skill) | 0 | 1mo | No flags | Intermediate |
| laravel-patterns | 0 | 4mo | Review | Advanced |
| create-di-container | 0 | 6mo | No flags | Intermediate |
| laravel-event-driven-architecture | 0 | 1mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
laravel-patterns
helmordev
Laravel architecture patterns, routing/controllers, Eloquent ORM, service layers, queues, events, caching, and API resources for production apps.
create-di-container
dykyi-roman
Generates DI Container configuration for PHP 8.4. Creates module classes, service providers, container configuration, and autowiring setup. Supports Symfony, Laravel, and PHP-DI patterns. Includes unit tests.
laravel-event-driven-architecture
noemdb
Best practices for Laravel events and listeners including event discovery, queued listeners, subscribers, and model events for decoupled architecture.
woocommerce-code-review
woocommerce
Review WooCommerce code changes for coding standards compliance. Use when reviewing code locally, performing automated PR reviews, or checking code quality.
laravel-pdf
spatie
Generate PDFs from Blade views or HTML using spatie/laravel-pdf. Covers creating, formatting, saving, downloading, and testing PDFs with the Browsershot, Cloudflare, or DOMPDF driver.
laravel-architecture
HoangNguyen0403
Core architectural standards for scalable Laravel applications.