Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

implementing-ddd-architecture

БесплатноБез исполняемых скриптовНе проверен

Design and implement DDD patterns (entities, value objects, aggregates, CQRS). Use when creating new domain objects, implementing bounded contexts, designing…

VilnaCRM-Orgот VilnaCRM-Org★ 16 звёзд на GitHub

Об этом скилле

Implementing DDD Architecture

Context (Input)

  • Creating new entities, value objects, or aggregates
  • Implementing bounded contexts or modules
  • Designing repository interfaces and implementations
  • Learning proper layer separation (Domain/Application/Infrastructure)
  • Need to understand CQRS pattern (Commands, Handlers, Events)
  • Code review for architectural compliance

Task (Function)

Design and implement rich domain models following DDD, hexagonal architecture, and CQRS patterns.

Success Criteria:

  • Domain entities remain framework-agnostic (no framework imports)
  • Business logic in Domain layer, not in Application handlers
  • make deptrac shows zero violations
  • Repository interfaces in Domain, implementations in Infrastructure

Core Principle

Rich Domain Models, Not Anemic

Business logic belongs in the Domain layer. Application layer orchestrates, Domain executes.


Layer Dependency Rules

Domain ─────────────────> (NO dependencies - pure PHP)
           │
           │
Application ──────────> Domain + Infrastructure
           │
           │
Infrastructure ───────> Domain + Application

Allowed Dependencies:

Layer Can Import
Domain ❌ Nothing (pure PHP, SPL, domain-specific libraries only)
Application ✅ Domain, Infrastructure, Symfony, API Platform
Infrastructure ✅ Domain, Application, Symfony, Doctrine ORM

Template examples may show Doctrine ODM/MongoDB constructs. In this service, use Doctrine ORM with MySQL (EntityManagerInterface, .orm.xml mappings).

See: DIRECTORY-STRUCTURE.md for complete file placement guide.


Critical Rules

1. Domain Layer Purity

❌ FORBIDDEN in Domain:

  • Symfony components (use Symfony\...)
  • Doctrine annotations/attributes
  • API Platform attributes
  • Any framework-specific code

✅ ALLOWED in Domain:

  • Pure PHP
  • SPL (Standard PHP Library)
  • Domain-specific value objects
  • Domain interfaces

2. Rich Domain Models

❌ BAD (Anemic):

class Customer {
    public function setName(string $name): void {
        $this->name = $name;  // No validation!
    }
}

✅ GOOD (Rich):

class Customer {
    public function changeName(CustomerName $name): void {
        // Business rules enforced
        $this->record(new CustomerNameChanged($this->id, $name));
        $this->name = $name;
    }
}

3. Validation Pattern

❌ BAD: Validation in Domain with Symfony

use Symfony\Component\Validator\Constraints as Assert;

class Customer {
    #[Assert\NotBlank]  // ❌ Framework in Domain!
    private string $name;
}

✅ GOOD: Validation in YAML config (Preferred)

# config/validator/Customer.yaml
App\Application\DTO\CustomerCreate:
  properties:
    name:
      - NotBlank: ~
      - Length:
          min: 2
          max: 100

Framework validators should always be used when possible. They provide:

  • Centralized configuration
  • Easy maintenance
  • Standard error messages
  • Built-in constraints (NotBlank, Email, Length, etc.)
  • Custom validators for business rules

Value Objects should only be used when:

  • Framework validators cannot express the business rule
  • Complex domain logic requires encapsulation
  • The validation is part of domain invariants

See: REFERENCE.md for complete validation patterns.


CQRS Pattern Quick Start

Commands (Write Operations)

// src/Core/{Context}/Application/Command/{Action}{Entity}Command.php
final readonly class CreateCustomerCommand implements CommandInterface
{
    public function __construct(
        public string $id,
        public string $name,
        public string $email
    ) {}
}

Command Handlers

// src/Core/{Context}/Application/CommandHandler/{Action}{Entity}CommandHandler.php
final readonly class CreateCustomerCommandHandler implements CommandHandlerInterface
{
    public function __invoke(CreateCustomerCommand $command): Customer
    {
        // Minimal orchestration only
        $customer = Customer::create(
            Ulid::fromString($command->id),
            new CustomerName($command->name),
            new Email($command->email)
        );

        $this->repository->save($customer);
        $this->eventBus->publish(...$customer->pullDomainEvents());

        return $customer;
    }
}

See: REFERENCE.md for complete CQRS patterns.


Repository Pattern

Interface (Domain Layer)

// src/Core/{Context}/Domain/Repository/{Entity}RepositoryInterface.php
interface CustomerRepositoryInterface
{
    public function save(Customer $customer): void;
    public function findById(string $id): ?Customer;
}

Implementation (Infrastructure Layer)

// src/
Полный SKILL.md на GitHub

Установить implementing-ddd-architecture в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

DIRECTORY-STRUCTURE.mdREFERENCE.mdexamples/01-entity-example.phpexamples/02-value-object-examples.phpexamples/03-cqrs-pattern-example.phpexamples/04-fixing-deptrac-violations.phpexamples/README.md

FAQ

Что делает скилл implementing-ddd-architecture?

Design and implement DDD patterns (entities, value objects, aggregates, CQRS). Use when creating new domain objects, implementing bounded contexts, designing repository interfaces, or learning proper layer separation. For fixing existing Deptrac violations, use the deptrac-fixer skill instead.

Как установить скилл implementing-ddd-architecture?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл implementing-ddd-architecture запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить implementing-ddd-architecture с