create-dto

Generate DTOs (data transfer objects) for PHP 8.4, creating immutable objects for layer boundaries, API requests/responses, and data serialization, and including unit tests.

Last repository push
GitHub Stars
109
Forks
26
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "create-dto" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-5fccb26b8067487b9af6c1a7465c303d5e381e3ebe01c99e8666275eb008ca9a. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Generate DTOs (data transfer objects) for PHP 8.4, creating immutable objects for layer boundaries, API requests/responses, and data serialization, and including unit tests.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Generates DTO (Data Transfer Object) for PHP 8.4. Creates immutable objects for layer boundaries, API requests/responses, and data serialization. Includes unit tests.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: create-dto
description: Generates DTO (Data Transfer Object) for PHP 8.4. Creates immutable objects for layer boundaries, API requests/responses, and data serialization. Includes unit tests.

DTO Generator

Generate DTOs for transferring data between layers, API boundaries, and external systems.

DTO Characteristics

  • Immutable: Read-only after creation
  • No Behavior: Pure data container, no business logic
  • Serializable: JSON/array conversion support
  • Typed: Strictly typed properties
  • Validated: Input validation at creation (for requests)
  • Layer-Specific: Different DTOs for different purposes

DTO Types

Type Purpose Location
Request DTO API input validation Presentation layer
Response DTO API output formatting Presentation layer
Command DTO Use case input Application layer
Query Result DTO Read model output Application layer
Integration DTO External API data Infrastructure layer

Generation Process

Step 1: Identify DTO Type

Determine the purpose and layer for the DTO.

Step 2: Generate DTO Class

Path based on type:

  • Request: src/Presentation/Api/{Context}/Request/
  • Response: src/Presentation/Api/{Context}/Response/
  • Application: src/Application/{Context}/DTO/
  • Integration: src/Infrastructure/ExternalApi/{Service}/DTO/

Step 3: Add Conversion Methods

  1. fromArray() — Create from raw data
  2. fromEntity() — Create from domain entity (Response DTOs)
  3. toArray() / jsonSerialize() — Serialize for output

Step 4: Generate Tests

Path: tests/Unit/{Layer}/{Context}/{Type}/


File Placement

Type Path
Request DTO src/Presentation/Api/{Context}/Request/
Response DTO src/Presentation/Api/{Context}/Response/
Application DTO src/Application/{Context}/DTO/
Integration DTO src/Infrastructure/ExternalApi/{Service}/DTO/
Unit Tests tests/Unit/{Layer}/{Context}/{Type}/

Naming Conventions

Type Pattern Example
Request {Action}{Entity}Request CreateOrderRequest, UpdateUserRequest
Response {Entity}Response OrderResponse, UserResponse
Collection {Entity}CollectionResponse OrderCollectionResponse
Application {Entity}DTO UserDTO, OrderDTO
Integration {Service}{Action}Response PaymentGatewayResponse

Quick Template Reference

Request DTO

final readonly class {Name}Request
{
    public function __construct(
        #[Assert\NotBlank]
        public string $field,
        #[Assert\Valid]
        public ?NestedRequest $nested = null
    ) {}

    public static function fromArray(array $data): self;
}

Response DTO

final readonly class {Name}Response implements \JsonSerializable
{
    public function __construct(
        public string $id,
        public string $name,
        /** @var array<ItemResponse> */
        public array $items = []
    ) {}

    public static function fromEntity({Entity} $entity): self;
    public function jsonSerialize(): array;
}

Application DTO

final readonly class {Name}DTO
{
    public function __construct(
        public string $id,
        public string $field
    ) {}

    public static function fromRequest({Name}Request $request): self;
    public function toArray(): array;
}

Anti-patterns to Avoid

Anti-pattern Problem Solution
Business Logic DTO with calculations Keep DTOs data-only
Mutable DTO setters, state changes Use readonly, immutable
Domain Objects Returning entities from API Map to Response DTO
Anemic Validation No input validation Use Assert attributes
Deep Nesting Complex nested DTOs Flatten or split
Missing Serialization No JSON support Implement JsonSerializable

References

For complete PHP templates and examples, see:

  • references/templates.md — Request, Response, Application, Collection, Integration DTO templates
  • references/examples.md — Order, User, Payment examples and tests

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value78/100

Highlights

  • 提供 PHP 8.4 DTO 生成能力,覆盖请求、响应、应用层、集成等多种类型
  • 包含完整的目录结构、命名规范和反模式指导,具备工程实用价值
Trigger Precision85/100

Highlights

  • 触发词精准,明确限定 PHP 8.4 和 DTO 生成场景,边界清晰
Structure and Standards72/100

Areas to improve

  • 缺少端到端完整示例 Reported severity: Minor

    文档提供了模板参考,但缺少一个从请求到响应的完整流程示例

    Recommendation: 补充一个完整的端到端示例,展示如何从 Request DTO 到 Response DTO 的完整流程

  • Document is too long Reported severity: Minor

    文档内容约 600 行,可能影响用户快速获取关键信息

    Recommendation: 考虑将详细模板和示例移至引用文件,主文档保留核心流程和快速参考

Highlights

  • 结构清晰,包含生成流程、文件路径、命名规范等完整信息
Execution Reliability60/100

Areas to improve

  • 缺乏错误处理机制说明 Reported severity: Major

    未说明如何处理无效输入、字段类型错误或路径不存在等异常情况

    Recommendation: 补充错误处理机制,如输入验证、异常捕获和用户提示

  • 工具来源不明 Reported severity: Minor

    未说明底层实现机制或依赖的工具库

    Recommendation: 明确说明生成工具的技术实现或依赖的库

Evidence Verifiability (mean of the first four)74/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.