Ddd knowledge

From dykyi-roman/awesome-claude-code · View interactive version

Ddd knowledge is an AI agent skill from the GitHub repository dykyi-roman/awesome-claude-code. DDD architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Domain-Driven Design audits.

How to use this skill

Skill file

DDD Knowledge Base

Quick reference for DDD architecture patterns and PHP implementation guidelines.

Core Principles

Layer Dependencies (Clean Architecture)

Presentation → Application → Domain ← Infrastructure
                    ↓
              Domain (center)

Rule: Dependencies point INWARD. Domain has ZERO external dependencies.

Layer Responsibilities

| Layer | Contains | Depends On |

|-------|----------|------------|

| Domain | Entities, Value Objects, Aggregates, Domain Services, Repository Interfaces, Domain Events | Nothing |

| Application | Use Cases, DTOs, Application Services | Domain |

| Infrastructure | Repository Implementations, External APIs, DB, Cache, Queue | Domain, Application |

| Presentation | Controllers, Actions, Request/Response, CLI | Application |

Quick Checklists

Domain Layer Checklist

Application Layer Checklist

Infrastructure Layer Checklist

Presentation Layer Checklist

Common Violations Quick Reference

| Violation | Where to Look | Severity |

|-----------|---------------|----------|

| use Doctrine\\ in Domain | Domain/*.php | Critical |

| use Illuminate\\ in Domain | Domain/*.php | Critical |

| use Infrastructure\\ in Domain | Domain/*.php | Critical |

| Only getters/setters in Entity | Domain/Entity/*.php | Warning |

| === 'pending' magic strings | Any PHP file | Warning |

| public function set*() | Domain/Entity/*.php | Warning |

| Business logic in Controller | Presentation/*.php | Warning |

| Business logic in Repository | Infrastructure/*.php | Warning |

PHP 8.4 DDD Patterns

Value Object

final readonly class Email
{
    public function __construct(
        public string $value
    ) {
        if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
            throw new InvalidArgumentException('Invalid email');
        }
    }

    public function equals(self $other): bool
    {
        return $this->value === $other->value;
    }
}

Entity with Behavior

final class Order
{
    private OrderStatus $status;

    public function __construct(
        private readonly OrderId $id,
        private readonly CustomerId $customerId
    ) {
        $this->status = OrderStatus::Pending;
    }

    public function confirm(): void
    {
        if (!$this->status->canTransitionTo(OrderStatus::Confirmed)) {
            throw new DomainException('Cannot confirm order');
        }
        $this->status = OrderStatus::Confirmed;
    }
}

Repository Interface

// Domain/Repository/OrderRepositoryInterface.php
interface OrderRepositoryInterface
{
    public function findById(OrderId $id): ?Order;
    public function save(Order $order): void;
}

References

For detailed information, load these reference files:

Assets

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.