{
  "id": 18276626,
  "title": "Your architecture rules are code too: mutation-testing a DDD ruleset in PHP 8.4",
  "url": "https://urgent.news/2026/11/05/your-architecture-rules-are-code-too-mutation-testing-a-ddd-ruleset",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-05T08:36:35.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/_er2es_/your-architecture-rules-are-code-too-mutation-testing-a-ddd-ruleset-in-php-84-3p33"
  },
  "original_language": "en",
  "account": "In September 2017, Lukas Taake published the first part of his master's thesis on static code analysis for Domain-Driven Design (DDD) as a SonarQube plugin for Java. Taake's rules for DDD were based on class hierarchy, name patterns, and annotations, but he acknowledged the limitations of this approach: the tool could only help maintain basic principles over time, and it could not prove that DDD was correctly implemented. Taake revisited these rules in PHP 8.4, where attributes provide a natural way to enforce them.\n\nThe PHP 8.4 implementation follows Taake's eight rules:\n\n1. Every entity type has an identity.\n2. Value objects are immutable.\n3. No anemic domain model (entities that are only getters and setters).\n4. Aggregates are trees and link to other aggregates only by identity.\n5. An aggregate has a maximum size.\n6. Domain services exist only where behavior cannot sit in an entity.\n7. Repository implementations live outside the domain model.\n8. The domain model depends on nothing else in the application.\n\nTaake created PHP classes to represent entities, aggregates, and value objects, using attributes to identify their types. He implemented these classes using PHP 8.4 features, such as readonly properties, asymmetric visibility, and attributes. The demo domain includes two aggregate roots, Customer and Order, with value objects for Money, IDs, and Order numbers. Customer and Order refer to each other by their respective IDs, adhering to rule 4.\n\nTaake also created a PHPStan rule to check that aggregates do not contain other aggregates, which is necessary because PHP's language features do not enforce this rule directly. He used PHPStan version 2.3.5 for this purpose. The demo domain uses PHP 8.4.16, PHPStan 2.3.5, phpat 0.12.5, Deptrac 4.7.2, and PHP Arikitect 1.3.1.\n\nTaake highlights the value of mutation testing, which asks whether a set of checks would catch a rule violation if one were introduced. He tested his PHP implementation with mutants and found that the checks generally caught the issues, demonstrating the effectiveness of the rules in PHP 8.4.",
  "summary": "In September 2017 Lukas Taake published the first part of a write-up of his master's thesis about static code analysis for Domain-Driven Design. It was built as a SonarQube plugin for Java, and its thesis is the most honest sentence in the genre: static analysis cannot show that DDD is done correctly; it can help keep some basic principles intact over time. I wanted to know what that looks like…",
  "key_points": [],
  "editors_take": "Leveraging PHP 8.4 attributes and mutation testing transforms domain-driven design from a set of theoretical guidelines into a verifiable architectural framework that actively prevents structural decay.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}