agentleFS
ci4meci4me/CQRSTemplate/.claude/skills/domain-scaffolding/SKILL.md

domain-scaffolding

Skill0 starsChanged 6 months agoMITView on GitHub

Scaffolds a complete new domain from scratch with full CQRS structure (45+ files/touchpoints: entities, value objects, DTOs, ports, commands, queries, events, handlers, repository, controller, views, tests). Use when user requests to create a new domain/module/bounded context. References Cookie domain as template.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before starting, confirm with user:

    line 15
  2. Very specific:

    Use ddd-specialist to create value objects following this pattern:

    line 42
  3. Very specific:

    Use ddd-specialist to create entity with:

    line 62
  4. Very specific:

    Add method to app/Config/Services.php:

    line 156
  5. Distinctive:

    Create{Entity}() method for test data

    line 253
  6. Distinctive:

    Run ALL quality checks:

    line 261
  7. Distinctive:

    If ANY check fails, fix violations before completing.

    line 274

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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

Domain Scaffolding Skill

Automates creation of a complete domain with all standard files and touchpoints.


Prerequisites

Before starting, confirm with user:

  1. Domain name (PascalCase, singular): e.g., "Order", "Product"
  2. Primary value objects needed (e.g., OrderNumber, ProductSKU)
  3. Additional properties beyond standard (name, description, etc.)

Step 1: Create Directory Structure

mkdir -p app/Domain/{Domain}/{Commands,Queries,Events,Entities,ValueObjects,DTOs,Ports}
mkdir -p app/Models/{Domain}
mkdir -p app/Infrastructure/Persistence/Repositories
mkdir -p app/Controllers/Domain/{Domain}
mkdir -p app/Views/{entities}
mkdir -p tests/Unit/Domain/{Domain}/{ValueObjects,Entities,Commands,Queries,Events}
mkdir -p tests/Integration/Repositories
mkdir -p tests/Feature/{Domain}
mkdir -p tests/Support/Factories

Step 2: Create Value Objects

For EACH value object:

Use ddd-specialist to create value objects following this pattern:

Reference: app/Domain/Cookie/ValueObjects/CookieName.php Reference: app/Domain/Cookie/ValueObjects/CookiePrice.php

Key points:

  • Readonly class
  • Private constructor with validation
  • Static factory method (fromString, fromFloat, etc.)
  • getValue() method
  • equals() method for comparison

Invoke: ddd-specialist + php-specialist to review


Step 3: Create Entity

Reference: app/Domain/Cookie/Entities/Cookie.php

Use ddd-specialist to create entity with:

  • Private constructor
  • Static create() method (for new entities)
  • Static reconstitute() method (from database)
  • Getters for all properties
  • Business methods (not setters!)

Invoke: ddd-specialist + clean-code-specialist to review


Step 4: Create Commands (Create, Update, Delete)

For EACH command:

Command (readonly DTO):

  • Reference: app/Domain/Cookie/Commands/CreateCookie/CreateCookieCommand.php
  • Readonly class with public properties

Handler:

  • Reference: app/Domain/Cookie/Commands/CreateCookie/CreateCookieHandler.php
  • Inject repository interface, event dispatcher interface, and logger
  • handle() method with business logic
  • Dispatch events

Invoke: cqrs-specialist + clean-code-specialist to review


Step 5: Create Queries (ById, All, Paginated)

For EACH query:

Query (readonly DTO):

  • Reference: app/Domain/Cookie/Queries/GetCookieById/GetCookieByIdQuery.php

Handler:

  • Reference: app/Domain/Cookie/Queries/GetCookieById/GetCookieByIdHandler.php
  • Inject repository
  • handle() method returns DTOs for presentation/API reads

Invoke: cqrs-specialist to review


Step 6: Create Events (Created, Updated, Deleted)

For EACH event:

Event (readonly DTO):

  • Reference: app/Domain/Cookie/Events/CookieCreated/CookieCreatedEvent.php
  • Past tense name
  • Readonly with public properties

Event Handler:

  • Reference: app/Domain/Cookie/Events/CookieCreated/CookieCreatedEventHandler.php
  • __invoke() method
  • Log event occurrence

Invoke: cqrs-specialist to review


Step 7: Create Service Provider

Reference: app/Domain/Cookie/CookieServiceProvider.php

Critical:

  • Add #[DomainServiceProvider] attribute
  • Implement DomainServiceProviderInterface
  • Register all commands, queries, events

Invoke: cqrs-specialist + php-specialist to review


Step 8: Create Repository and Model

Model:

  • Reference: app/Models/Cookie/CookieModel.php
  • Extend CodeIgniter Model
  • Set $table, $allowedFields, timestamps, soft deletes

Repository:

  • Reference: app/Infrastructure/Persistence/Repositories/CookieRepository.php
  • save(), findById(), delete() methods
  • toDomainEntity() private method with array shape annotation

Invoke: codeigniter4-specialist + phpstan-specialist to review


Step 9: Add Repository to Services.php

Add method to app/Config/Services.php:

public static function {entity}Repository(bool $getShared = true): {Entity}RepositoryInterface
{
    if ($getShared) {
        return static::getSharedInstance('{entity}Repository');
    }
    return new {Entity}Repository(
        self::logger(),
        config('Logging')
    );
}

Step 10: Create Migration

php spark make:migration Create{Entities}Table

Reference: Cookie migration for structure

Include:

  • id (auto_increment)
  • All domain properties
  • created_at, updated_at, deleted_at (nullable)

Invoke: codeigniter4-specialist to review

Run: php spark migrate


Step 11: Create Controller

Reference: app/Controllers/Domain/Cookie/CookieController.php

Thin controller:

  • Delegate to command/query buses
  • Handle validation errors
  • Return responses

Invoke: cqrs-specialist + codeigniter4-specialist + clean-code-specialist


Step 12: Add Routes

Reference: Routes for Cookie in app/Config/Routes.php

Standard CRUD routes:

  • GET '/' - index
  • GET '/create' - create form
  • POST '/' - store
  • GET '/:num' - show
  • GET '/:num/edit' - edit form
  • POST '/:num' - update
  • POST '/:num/delete' - delete

Step 13: Create Views (4 files)

References:

  • app/Views/cookies/index.php
  • app/Views/cookies/show.php
  • app/Views/cookies/create.php
  • app/Views/cookies/edit.php

Use Bootstrap 5 with:

  • Form validation feedback
  • Flash messages
  • Responsive design

Step 14: Create ALL Tests

Use test-specialist to create:

Unit Tests:

  • Value object tests (validation, immutability, methods)
  • Entity tests (create, reconstitute, business methods)
  • Command handler tests (with mocks)
  • Query handler tests (with mocks)
  • Event tests

Integration Tests:

  • Repository tests (save, find, update, delete)

Feature Tests:

  • CRUD tests (all controller actions)

Test Factory:

  • Create{Entity}() method for test data

Invoke: test-specialist for comprehensive coverage


Step 15: Final Validation

Run ALL quality checks:

vendor/bin/phpstan analyse --level=8
vendor/bin/phpcs
vendor/bin/phpunit --coverage-text

Invoke in sequence:

  1. phpstan-specialist - MUST pass with 0 errors
  2. slevomat-specialist - MUST pass with 0 violations
  3. test-specialist - MUST achieve 90%+ coverage

If ANY check fails, fix violations before completing.


Completion Checklist

  • All 22 domain layer files created
  • All 2 infrastructure files created
  • Controller created
  • 4 views created
  • Migration created and run
  • Routes added
  • All 14 test files created
  • Repository added to Services.php
  • PHPStan Level 8: 0 errors
  • Slevomat: 0 violations
  • Tests: 90%+ coverage, all passing

Success Criteria

✅ Standard domain files/touchpoints created ✅ All specialists invoked for their expertise ✅ All quality checks passing ✅ Domain functional and tested

Report completion to user with file count and quality metrics.

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.