| Deep Coding Principle | PHP Technical Equivalent |
|---|---|
| Intent–Structure–Implementation Separation | Interfaces + DI (structure) vs. concrete classes (implementation) |
| Generative Conformance | OpenAPI Generator + Nette PhpGenerator + validation gates |
| Recursive Refinement with Fixed Premises | Git tags + FIXED_PREMISE.md + phase branches |
| Skeleton–Tissue Architecture | src/Skeleton/ (manual) + src/Tissue/ (generated) + Deptrac |
| Validation Gates | PHPStan (level max) + Deptrac + PHPUnit + Symfony Validator |
project-root/
├── spec/
│ ├── openapi.yaml # API contract
│ └── schema/ # JSON Schema files
├── src/
│ ├── Skeleton/ # Manual, immutable
│ │ ├── Contracts/ # Interfaces
│ │ └── Base/ # Abstract classes (template methods)
│ ├── Tissue/ # AI-generated, regenerable
│ │ ├── Api/ # OpenAPI Generator output
│ │ ├── Repository/ # Concrete repositories
│ │ └── Service/ # Concrete services
│ └── Domain/ # Entities, value objects (manual)
├── tests/
│ ├── Unit/
│ ├── Architecture/ # Deptrac + PHPArkitect tests
│ └── Integration/
├── composer.json # With automation scripts
├── phpstan.neon # Level max configuration
├── deptrac.yaml # Layer dependency rules
├── FIXED_PREMISE.md # Phase checkpoint
└── .github/workflows/ci.yml
Each phase follows: Plan → Approve → Generate → Validate → Commit → Tag
phpstan/phpstan, deptrac/deptrac, phpunit/phpunit, symfony/validator, nette/php-generatorphpstan.neon with level max and strict rulesdeptrac.yaml (see Section 5)openapi-generator validate -i spec/openapi.yamlsrc/Skeleton/Contracts/__call, __get, reflection) in skeletonopenapi-generator generate -i spec/openapi.yaml -g php -o src/Tissue/Apisrc/Tissue/phpunit)All gates run automatically on pre-commit and in CI:
| Gate | Tool | Command |
|---|---|---|
| Syntax | php -l |
On staged PHP files |
| Static types | PHPStan | phpstan analyse --level=max src/ |
| Architecture | Deptrac | deptrac analyse |
| Naming conventions | PHPArkitect | phparkitect check |
| Runtime validation | Symfony Validator | phpunit --testsuite=validation |
| Unit tests | PHPUnit | phpunit --coverage-text |
fix(premise): Phase N completegit tag phase-N-completeFIXED_PREMISE.md with:
# deptrac.yaml
deptrac:
paths: ["./src"]
layers:
- name: Skeleton
collectors:
- type: directory
value: "./src/Skeleton/.*"
- name: Tissue
collectors:
- type: directory
value: "./src/Tissue/.*"
- name: Domain
collectors:
- type: directory
value: "./src/Domain/.*"
ruleset:
Tissue:
- Skeleton
- Domain
Domain: ~
Skeleton: ~
Enforced property: Tissue may depend on Skeleton and Domain, but never the reverse.
{
"scripts": {
"dc:validate": [
"@dc:validate:static",
"@dc:validate:architecture"
],
"dc:validate:static": "phpstan analyse --level=max src/",
"dc:validate:architecture": "deptrac analyse",
"dc:generate:api": "openapi-generator generate -i spec/openapi.yaml -g php -o src/Tissue/Api",
"dc:generate:dto": "php bin/generate-dto.php",
"dc:generate:all": [
"@dc:generate:api",
"@dc:generate:dto"
],
"dc:phase:complete": [
"@dc:generate:all",
"@dc:validate",
"phpunit"
]
}
}
#!/bin/sh
# .git/hooks/pre-commit
for file in $(git diff --cached --name-only --diff-filter=ACM | grep '\.php$'); do
php -l "$file" || exit 1
done
composer dc:validate || exit 1
name: CI
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with: { php-version: '8.2' }
- run: composer install
- run: composer dc:validate
- run: vendor/bin/phpunit --coverage-text
| Constraint | Workaround |
|---|---|
| Single inheritance | Use interfaces + delegation instead of multiple abstract classes |
Dynamic features (__call, __get) |
Forbid in coding standards; detect with PHPStan custom rule |
| No built-in spec→code transform layer | Implement a small adapter using Nette PhpGenerator (reusable across projects) |
| Legacy codebases | Apply Deep Coding only to new modules; incrementally extract specifications |
| Metric | Target | Measurement |
|---|---|---|
| Skeleton modification count | 0 per phase | Git diff on src/Skeleton/ |
| Static analysis pass rate | 100% | PHPStan exit code |
| Architecture rule violations | 0 | Deptrac exit code |
| Test pass rate | 100% | PHPUnit exit code |
| Human intervention per phase | < 10% of phases | Manual edits in src/Tissue/ |
This implementation plan provides a concrete, toolchain-integrated pathway for applying Deep Coding to PHP projects. By encoding structural specifications in OpenAPI/JSON Schema, enforcing architectural constraints via Deptrac, validating types with PHPStan, and automating the recursive refinement workflow with Git tags and Composer scripts, PHP becomes a viable substrate for specification-driven, AI‑collaborative software development. The plan assumes PHP 8.2+, strict typing, and disciplined avoidance of dynamic features. When these conditions are met, the first generated tissue code becomes the final artifact for each phase, and long‑term maintainability is built into the process.