Index of every page on this site: llms.txt
All skills
Run it yourself

Use when building, reviewing or refactoring Laravel code organised as a Domain-Driven Design layout in src/Domain and src/Presentation — adding a domain or deciding where a file belongs; writing Actions (static handle()), DTOs (*Data classes, Filter/Create/Update data, sent keys), Contracts and Services, ServiceProvider bindings, Models with Entities/Scopes/Abilities/Traits, backed Enums, statuses and transitions, filter scopes and Eloquent queries; writing thin controllers, Form Requests, Inertia or Blade page responses, API Resources and the status/data JSON envelope; events, jobs, commands and observers; migrations (index and foreign-key policy) and Pest and architecture tests for this layout; or reviewing a diff for layer and boundary violations. Also triggers on "DDD", "domain layer", "bounded context", "where does this file go", "Action vs Service", "بنية الكود", "هيكلة المشروع", "طبقات", "طبقة الدومين", "الأكشن", "الكونتراكت", "DTO".

Use this Skill: https://skilld.dev/gh/haythamasalama/skills/laravel-ddd

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈256 tokens for metadata: the name and description. ≈2.5k when used: this file. ≈42k more on demand in 12 files.

Description uses 12.1% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈968 characters, or 12.1%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Laravel DDD layout

Read when: writing or reviewing PHP in a Laravel app that splits code into src/Domain/{Domain}/ and src/Presentation/{Panel}/, or setting up that layout in a new app. Owns: the layer rules, the folder map, one request end to end, and the review checklist. Each layer's detail lives in its own reference (table at the end).

Written for PHP 8.4 and Laravel 12 (checked 2026-11-03). Where generic Laravel guidance disagrees on the topics below, this skill wins.

Consistency first

These rules are defaults for new code. Before applying one, open two neighbouring files in the same domain and match them: a working local pattern beats a default here. Do not retrofit old code as a side effect of an unrelated change; a rename across many files is its own task.

TL;DR

  • Dependencies point inward through Contracts. Controller → Contract → Service → Action → Model. Why: each domain has one published door, so its internals can change without breaking callers.
  • Across domains, only the Contract. Never import another domain's Model, Action or Service; resolve app(OtherContract::class). Inside a domain, import the Action directly. Why: a cross-domain import couples two domains for good.
  • Actions are final with one public static function handle() and no constructor. Dependencies are resolved inside handle() with app(). Why: callable from a controller, job, command or test with no wiring.
  • Services contain zero queries. Each method is one delegation to an Action. Why: the query lives in one reusable, testable place.
  • Multi-statement writes run in DB::transaction() inside the Action; a once-only change claims its row first. Why: no partial writes, no double runs.
  • DTOs end in Data, have public readonly snake_case properties, and are built with fromArray() or fromRequest(). They remember which keys were sent, so an update writes only those. Why: keys match columns, and a form can clear a column to null without wiping the ones it did not send.
  • Controllers are thin and inject Contracts only. Form Request → DTO → Contract → response. No Eloquent, no business rules, no Action calls. Why: the same operation must work from a job or the CLI.
  • No route-model binding. Take string $id, fetch through the Contract, 404 on null. Why: binding queries past the Contract and skips its scopes and tenant filter.
  • Validation lives in Form Requests, never in an Action. Why: by the time a DTO reaches the domain, the data is trusted.
  • The domain never reads auth(), request() or session(). It asks a CurrentUser contract. Why: jobs and commands have no request.
  • Enum cases are UPPER_SNAKE_CASE; statuses change only through the transition Action. Why: one style to grep, and the guard, side effects and audit run every time.
  • Migrations: anonymous classes, no index "just in case", no ->index() on a foreign key, no custom index names. Why: speculative indexes slow writes; custom names drift between environments.
  • Domain and Presentation files are created by hand (or cloned from a neighbour). The make:* generators write into app/.

The layers in one picture

HTTP ─► FormRequest ─► Controller ─► {Domain}Contract ─► {Domain}Service ─► Action ─► Model
        (validates)    (thin)        (interface)        (delegates)        (queries,   (casts,
                                                                            writes,     relations,
                                                                            transaction) scopes)
Other domain ─────────────────────► app({Domain}Contract::class)
Job / Command / Listener ─────────► app({Domain}Contract::class)

Folder map

src/Domain/{Domain}/                     src/Presentation/{Panel}/
├── Actions/          may group by entity ├── Controllers/{Feature}/
├── Commands/                            ├── Requests/{Feature}/
├── Contracts/                           ├── Resources/        JSON and page shapes
├── DataTransferObjects/ may nest        ├── Props/            one class per Inertia page
├── Enums/                               ├── Routes/{web,api}.php
├── Events/           only if published  ├── Providers/
├── Exceptions/                          └── Rules/
├── Jobs/
├── Listeners/        only if it reacts
├── Models/
│   ├── Entities/     Eloquent models
│   ├── Scopes/       {Entity}Filter traits, global scopes
│   ├── Abilities/    {Entity}Abilities
│   ├── Features/     feature-flag wrappers (optional)
│   └── Traits/
├── Observers/
├── Providers/        {Domain}ServiceProvider ($bindings, events)
└── Services/
app/                  framework glue only: middleware, providers, adapters

A shared Core domain holds the kernel every domain uses: the Arrayable DTO base, FilterData, GetDataAbstract, query macros, BaseEnum, ModelAbility, BaseException, CurrentUser. Detail: architecture.md, core-kernel.md.

One request, end to end

// Presentation\Admin\Controllers\Employee\EmployeeController
public function __construct(private readonly EmployeeContract $employees) {}

public function store(StoreEmployeeRequest $request): RedirectResponse
{
    $employee = $this->employees->create(CreateEmployeeData::fromRequest($request));

    return to_route('admin.employees.show', $employee->id)->with('success', __('messages.saved'));
}

// Domain\Employee\DataTransferObjects\CreateEmployeeData
public static function fromRequest(StoreEmployeeRequest $request): self
{
    return self::fromArray([
        ...$request->validated(),
        'contacts' => EmployeeContactData::arrayFrom($request->validated('contacts')),
    ]);
}

// Domain\Employee\Services\EmployeeService
public function create(CreateEmployeeData $data): Employee
{
    return CreateEmployee::handle($data);
}

// Domain\Employee\Actions\Employee\CreateEmployee
final class CreateEmployee
{
    public static function handle(CreateEmployeeData $data): Employee
    {
        return DB::transaction(function () use ($data) {
            $user = app(UserContract::class)->getUser($data->user_id);
            $employee = Employee::create([...(clone $data)->exclude(['contacts'])->toArray(), 'user_id' => $user->id]);
            $employee->contacts()->createMany(array_map(fn (EmployeeContactData $contact) => $contact->toArray(), $data->contacts));

            return $employee;
        });
    }
}

Choices to make once per project

These are real alternatives, not drift. Pick one, write it in the project's README, and do not mix them.

Topic Choose between Detail
What panels return Inertia or Blade pages with redirects, a JSON API with the envelope, or both http.md, json-api.md
Strict DTO input Lenient fromArray() (default) or strict, throwing on an unknown key dtos.md
Feature flags Per-domain Models/Features/ wrappers or Pennant called directly core-kernel.md
Tenancy A single tenant, or every row scoped by a tenant resolved in middleware architecture.md
Enforcement Pest arch() tests, PHPStan rules, or both testing.md

Where each topic lives

I'm working on… Read
Placing a file, adding a domain, boundaries, events, jobs, commands, observers architecture.md
The shared kernel a new project needs core-kernel.md
An Action: shape, naming, transactions, concurrency, templates actions.md
A Contract, its Service, the provider binding contracts-and-services.md
A Create, Update, Filter, nested or options DTO dtos.md
An Entity: casts, attributes, scopes, abilities, traits, translated names models.md
An enum, a status and its transitions, once-only work, request idempotency enums-and-states.md
A filter scope, eager loading, counting, chunking, raw SQL queries.md
A controller, Form Request, page response, redirect, authorization http.md
The JSON envelope, status codes, Resources, API CRUD json-api.md
A migration or seeded reference rows migrations.md
A test, or an architecture test that enforces the layers testing.md

Review checklist

  1. Every new file sits in the folder the map gives it; no invented layer (Handlers/, Resolvers/).
  2. No cross-domain import of a Model, Action or Service.
  3. Actions are final, static, constructor-free; writes touching more than one row use a transaction.
  4. Services are one-line delegations; $withRelations / $withCount are forwarded.
  5. DTOs end in Data, are snake_case, come from validated() on writes, and updates write sent keys only.
  6. Controllers inject Contracts only, hold no Eloquent, take string $id, and redirect or return 201/204 after a write.
  7. No auth(), request() or session() under src/Domain.
  8. Migrations follow the index policy and have a real down().
  9. Each comment you added says a WHY someone would get wrong without it; delete the rest.
  10. A test covers the Action (logic) or the endpoint (routing, validation, response), including a failure path.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts20d3 checks · Risk SAFE
  • Gen Agent Trust Hub20d

    The skill provides comprehensive documentation and architectural patterns for building Laravel applications using Domain-Driven Design (DDD). It includes detailed references for various layers like Actions, Contracts, DTOs, Models, and Migrations, along with local verification scripts to ensure code compliance. No security threats or malicious patterns were detected.

  • Socket20d

    No alerts

  • Snyk20d

    Risk: LOW · No issues

Signed by skilld at 54e769e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 3 weeks ago
Other metadata
metadata
{
  "summary": "Domain-Driven Design (DDD) folder structure for Laravel: where every file goes and why.",
  "tags": "laravel, php, ddd, domain-driven-design, architecture"
}

README badge

README badge for haythamasalama/skills/laravel-ddd