Awesome-claude-code create-specification
Generates DDD Specification for PHP 8.4. Creates reusable business rule objects for validation, filtering, and querying with composite pattern support. Includes unit tests.
install
source · Clone the upstream repo
git clone https://github.com/dykyi-roman/awesome-claude-code
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/dykyi-roman/awesome-claude-code "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/create-specification" ~/.claude/skills/dykyi-roman-awesome-claude-code-create-specification && rm -rf "$T"
manifest:
skills/create-specification/SKILL.mdsource content
Specification Generator
Generate DDD-compliant Specifications for encapsulating business rules and filtering logic.
Specification Characteristics
- Single Responsibility: One business rule per specification
- Composable: AND, OR, NOT combinations
- Reusable: Same spec for validation and querying
- Domain Language: Named using ubiquitous language
- Testable: Easy to unit test in isolation
- Immutable: No state changes after creation
When to Use Specification
| Scenario | Example |
|---|---|
| Business rule validation | , |
| Collection filtering | , |
| Repository queries | , |
| Policy enforcement | , |
| Complex conditions | Composite AND/OR specifications |
Generation Process
Step 1: Generate Base Infrastructure
Path:
src/Domain/Shared/Specification/
— Generic interface withSpecificationInterface.phpisSatisfiedBy()
— Base with AND/OR/NOT methodsAbstractSpecification.php
— Composite ANDAndSpecification.php
— Composite OROrSpecification.php
— Negation wrapperNotSpecification.php
Step 2: Generate Concrete Specification
Path:
src/Domain/{BoundedContext}/Specification/
— Implements business rule{Name}Specification.php
Step 3: Generate Tests
Path:
tests/Unit/Domain/{BoundedContext}/Specification/
File Placement
| Component | Path |
|---|---|
| Base Interface | |
| Abstract Spec | |
| Composites | |
| Concrete Specs | |
| Unit Tests | |
Naming Conventions
| Pattern | Example |
|---|---|
| |
| |
| |
| Factory Method | |
Quick Template Reference
Specification Interface
/** * @template T */ interface SpecificationInterface { public function isSatisfiedBy(mixed $candidate): bool; public function and(self $other): self; public function or(self $other): self; public function not(): self; }
Concrete Specification
/** * @extends AbstractSpecification<{Entity}> */ final readonly class {Name}Specification extends AbstractSpecification { public function __construct({parameters}) {} public function isSatisfiedBy(mixed $candidate): bool { if (!$candidate instanceof {Entity}) { return false; } return {businessRule}; } }
Composite Usage
$eligible = $isActive ->and($hasPurchases) ->and($isNotBlacklisted->not()); $customers = array_filter( $all, fn($c) => $eligible->isSatisfiedBy($c) );
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| God Specification | Too many conditions | Split into composable specs |
| Side Effects | Modifies candidate | Keep pure, read-only |
| Infrastructure | DB calls in spec | Keep in domain, use for in-memory |
| Weak Typing | | Add type check first |
| No Composition | Copy-paste conditions | Use AND/OR composition |
References
For complete PHP templates and examples, see:
— Interface, Abstract, Composite, Concrete templatesreferences/templates.md
— Customer, Product, Invoice, Order specifications and testsreferences/examples.md