php-architect
Architect-level PHP guidance — framework and layering choices, request lifecycle and shared-nothing deployment, autoloading and dependency injection, database and session boundaries, and the operational reality of PHP-FPM. Use when designing or reviewing a PHP backend.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- php-architect
- license
- MIT
- metadata
- { "crusor-path": "website-architect/backend-development-architect/php-architect", "crusor-domain": "website-architect", "crusor-origin": "original", "crusor-sources": "php.net/manual; laravel.com/docs; symfony.com/doc/current; php-fig.org/psr", "crusor-triggers": "php, laravel, symfony, php-fpm, composer, psr, eloquent, blade", "crusor-verified-on": "2026-10-30" }
- description
- Architect-level PHP guidance — framework and layering choices, request lifecycle and shared-nothing deployment, autoloading and dependency injection, database and session boundaries, and the operational reality of PHP-FPM. Use when designing or reviewing a PHP backend.
- compatibility
- PHP 8.2+; Laravel / Symfony / plain PSR-15
03 SKILL.md 正文
PHP Architect
PHP's defining property is shared-nothing: each request starts clean. That is a strength — until someone reintroduces hidden global state.
When to use
- Content platforms, e-commerce, internal apps with a PHP team.
- Laravel/Symfony projects needing boundaries beyond "everything in controllers".
- Migrating legacy PHP into a maintained structure.
When NOT to use
- Long-running, stateful services (websockets, workers) — possible, but other runtimes fit better.
Decision 1 — Structure
public/index.php front controller, nothing else
src/Http/ controllers, requests/validation
src/Domain/ entities, value objects, rules
src/Application/ services, use-cases
src/Infrastructure/ repositories, external clients
- PSR-4 autoloading; one class per file;
composerowns the autoloader. - Framework code stays in
Http/Infrastructure; the domain has no framework imports. - Dependency injection via the container, constructor injection only; no service locators inside domain code.
Decision 2 — Request lifecycle
| Concern | Rule |
|---|---|
| validation | at the edge (FormRequest/Validator), typed DTO inward |
| auth | middleware/guard; authorization policies per resource |
| sessions | server-side store, regenerated on login |
| output | escaped by default (Blade/Twig); raw output requires a sanitiser |
| errors | one handler → JSON envelope, never a stack trace |
- Shared-nothing means no static caches surviving a request — use the cache backend, not a static property.
- Config from environment, validated at boot;
env()outside config files is a bug.
Decision 3 — Data access
- Eloquent/Doctrine are fine in
Infrastructure; the domain sees repository interfaces. - Eager-load relations (
with()), otherwise N+1 is guaranteed on list pages. - Migrations versioned and reversible; no manual DDL in production.
- Transactions in services; no email/HTTP calls inside a transaction.
Decision 4 — Runtime and operations
- PHP-FPM pool sized to CPU and DB connections;
pm.max_childrenis the real concurrency limit. - Opcache enabled in production;
preloadonly after measuring. - Queues (Horizon/Worker) for anything slow; jobs idempotent.
- Deploy: build artefacts,
composer install --no-dev --optimize-autoloader, cache warm-up, then release — nocomposer updateon the production box.
Failure modes at scale
- Business logic in Blade templates.
env()called in application code (breaks once config is cached).- N+1 on the product listing page.
- Unbounded FPM children exhausting DB connections.
- A deploy that runs migrations and code changes at the same instant, with no rollback path.
Verification receipts
- Query count on the busiest list page (eager loading proven).
- Config cache + opcache verified in production.
- FPM children vs DB max_connections documented.
- Queue job idempotency test.
- Static analysis (PHPStan/Psalm) and
composer auditclean in CI.
04 同仓库更多 Skills
interaction-patterns-architect
Architect-level interaction design in code — choosing established patterns over invented ones, feedback and latency behaviour, destructive-action safeguards, navigation and overlay conventions, and the state model behind every interactive surface. Use when a screen has to behave, not just look.
design-system-ops-architect
Architect-level operation of a design system in code — token pipelines and versioning, component API and variant policy, the catalogue as the contract, adoption metrics, and the governance that stops a system from forking into three. Use when a component library must survive several teams.
design-handoff-architect
Architect-level design handoff — what must be specified before implementation starts, tokens over raw values, responsive and content-limit contracts, state matrices, and the review loop that catches drift between design and code. Use when a design is about to become code.
content-microcopy-architect
Architect-level UI content — where strings live, voice and terminology consistency, error and empty-state copy as part of the interface, translation-ready authoring, and the content model a product needs before it multiplies screens. Use when the words in the interface matter as much as the pixels.
ui-ux-implementation-architect
Architect-level direction for turning a design into working UI — the handoff contract, component ownership versus screen-level layout, interaction and state conventions, design QA gates, and the review habits that keep an implementation faithful without frozen pixels. Use before any specific UI implementation skill.
test-strategy-architect
Architect-level test strategy — allocating assertions across unit, integration, contract and end-to-end layers, designing for testability through dependency boundaries, fixture and data strategy, and the flake and coverage policies that keep a suite trustworthy. Use when defining how a codebase is tested.