agentleFS
AlizHarbAlizHarb/agent-skills/skills/create-dto/SKILL.md

create-dto

Skill1 starsChanged 5 months agoMITView on GitHub

Use when creating or changing DTOs, data objects, value objects, or input/output contracts for Laravel features.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 12 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when data crosses a boundary or must be reused by web, API, Livewire, jobs, commands, or integrations.

    line 13
  2. Distinctive:

    Use Spatie Laravel Data by default now that it is installed.

    line 22
  3. Very specific:

    Prefer final readonly class with constructor property promotion for immutable DTOs.

    line 23
  4. Distinctive:

    Use Spatie Data attributes where they fit the property:

    line 24
  5. Distinctive:

    Use enums for closed sets and typed class constants for reusable scalar contracts.

    line 36
  6. Very specific:

    Add named constructors such as fromArray, fromRequest, or fromModel only when useful.

    line 38
  7. Distinctive:

    Place validation rules near DTOs when the project convention supports it.

    line 39
  8. Distinctive:

    Avoid persistence, authorization, or workflow logic.

    line 40
  9. Distinctive:

    Add tests for construction, validation rules, serialization, and edge cases.

    line 41
  10. Distinctive:

    Use Spatie Data collections/resources when a feature needs nested, transformed, or reusable data shapes.

    line 58
  11. Distinctive:

    Prefer Spatie Data validation attributes before ad hoc array validation inside reusable code.

    line 59
  12. Distinctive:

    Test required fields, type conversion, defaults, invalid data, and serialization if exposed.

    line 63
  13. Distinctive:

    Do not trust DTO construction as authorization.

    line 67
  14. Distinctive:

    Avoid including sensitive fields in output DTOs unless explicitly intended.

    line 68

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Create DTO Or Data Object

When To Use

Use this skill when data crosses a boundary or must be reused by web, API, Livewire, jobs, commands, or integrations.

Inputs Needed

  • Fields, types, validation rules, source boundaries, output consumers, defaults, and serialization needs.

Workflow

  1. Inspect existing data object conventions.
  2. Use Spatie Laravel Data by default now that it is installed. If a different data style already exists in a nearby module, follow the local convention.
  3. Prefer final readonly class with constructor property promotion for immutable DTOs.
  4. Use Spatie Data attributes where they fit the property:
    • #[MapInputName]
    • #[MapOutputName]
    • #[WithCast]
    • #[WithTransformer]
    • #[Computed]
    • #[ValidationAttribute] or package validation attributes
    • #[DataCollectionOf]
    • #[Lazy]
    • #[Hidden]
    • #[LoadRelation] and #[LoadMissing]
    • #[Inject] or property injection attributes when the package or project convention uses them
  5. Use enums for closed sets and typed class constants for reusable scalar contracts.
  6. Keep DTOs client-agnostic.
  7. Add named constructors such as fromArray, fromRequest, or fromModel only when useful.
  8. Place validation rules near DTOs when the project convention supports it.
  9. Avoid persistence, authorization, or workflow logic.
  10. Add tests for construction, validation rules, serialization, and edge cases.

Files That May Be Created

  • app/Data/*.php, app/DTOs/*.php, or the existing local equivalent.
  • DTO tests.

Files That May Be Modified

  • Form Requests, Actions, Resources, Livewire components, controllers, jobs, and tests.

Architecture Rules

  • DTOs represent input or output contracts.
  • DTOs support API and UI reuse.
  • DTOs must not depend on Livewire, Blade, controllers, or responses.
  • DTOs should use modern PHP typing instead of unstructured arrays whenever practical.
  • Use Spatie Data collections/resources when a feature needs nested, transformed, or reusable data shapes.
  • Prefer Spatie Data validation attributes before ad hoc array validation inside reusable code.

Testing Requirements

  • Test required fields, type conversion, defaults, invalid data, and serialization if exposed.

Security Requirements

  • Do not trust DTO construction as authorization.
  • Avoid including sensitive fields in output DTOs unless explicitly intended.

Review Checklist

  • Is the DTO stable and client-agnostic?
  • Are fields typed?
  • Are validation rules close enough to stay synchronized?

Examples

Good Example

namespace App\Data;

use Spatie\LaravelData\Data;
use Spatie\LaravelData\Attributes\Validation\Email;
use Spatie\LaravelData\Attributes\Validation\Required;
use Spatie\LaravelData\Attributes\Validation\Max;

final readonly class RegisterUserData extends Data
{
    public function __construct(
        #[Required, Max(255)]
        public string $name,

        #[Required, Email]
        public string $email,
    ) {}
}

Bad Example

// ❌ Poor type safety, no validation context, difficult to reuse in background jobs.
class RegisterController extends Controller
{
    public function store(Request $request)
    {
        $this->action->handle($request->all());
    }
}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.