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★ 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 deptracshows 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.xmlmappings).
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/
Установить implementing-ddd-architecture в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
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), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic