Laravel Project Patterns
Route each touched behavior surface to its domain router and only the focused
leaves matching the live contract. The executable router, not manual browsing
of references/MAP.md, decides which branch to expose.
Examples are synthetic; preserve them and their placeholder entities.
Required Workflow
- Read the nearest
AGENTS.md and project guidance.
- Identify every touched path. Before any tool call that discovers, searches,
lists, or opens pattern references, and before editing, run the
executable context router with plain
php and all touched paths. This preflight is mandatory.
- Read only exact references selected by the result. Expand one or more named
frontiers, then select only children printed by those frontiers. Never use
rg, find, globs, directory listings, guessed paths, or broad sed reads
to discover or choose references. If the touched-path set grows, rerun the
complete preflight before further reference reads or edits; stale results do
not authorize the new surface.
- Identify every behavior owner. Read the exact live project code files
and the nearest equivalent siblings before editing. Equivalent means the
same precondition, operation, outcome, route depth, binding ownership,
transport, and response contract, not merely a nearby directory.
Repository search is allowed here for live code evidence because the router
preflight has already succeeded; it is never a substitute for that preflight.
- For each touched surface, use the router-selected focused leaves and core
contracts. References expose possible patterns; absent behavior is not mandatory.
- Do not edit until this routing tuple is known: touched surface, behavior
owner, live sibling evidence, and selected reference. Continue discovery if
any element is missing. If no equivalent sibling exists, preserve the live
shape and keep the rule local instead of generalizing. Check versioned
framework documentation when needed.
- Implement, run focused verification, review the complete diff, and confirm
every affected owner surface remains covered.
Controller tests start at their
router, then select
only the action, route depth, transport, pattern, and validation in scope.
Non-Negotiable Router Contract
- Live evidence and nearest equivalent siblings override generic habits and examples.
Preserve concurrent work and avoid unrelated refactors.
- Match finality, schema, migrations, generated files, and unguarded models to
the sibling family:
code and schema.
- Choose tests by behavior owner. Layered HTTP, action, model, and database
tests are distinct when they prove different contracts. Follow persistence,
Pest, fixture,
and(), and refresh() rules in
test design.
- Controllers remain tested entry points when actions own persistence. Mock
delegated actions and preserve each distinct HTTP-owned path, minimal
Request-to-Input mapping,
$response, and public response contract:
HTTP boundaries.
- Form Requests own HTTP shape, normalization, scoped validation, and
request-safe cross-field rules. Actions own transactional and dependent-state
guards. Preserve or convert public IDs according to the live boundary.
- Actions accept business inputs only. Do not repeat binding/ownership queries.
Default to no row lock or improvised concurrency substitute:
actions and concurrency.
Main Routers
These links keep the full tree auditable. Do not open one to choose a task
branch unless the executable router returned it.
context resolver: mandatory deterministic
path, operation, concern, gate, and progressive-leaf selection.
project: routes, configuration, tooling,
localization, bootstrap, public files, and seeders.
database: migrations and factories.
app: PHP under app/**.
resources: JavaScript, Blade, React
Email, TypeScript, and CSS.
tests: suite ownership, paths, and support.
core: cross-cutting contracts and completion.
See the reference structure. Finish with focused tests,
PHP formatting, complete diff review, and the
completion checklist. Passing tests
prove execution, not that an HTTP, domain, persistence, or regression contract
was not deleted.
1---2name: laravel-project-patterns3description: Use when writing, changing, testing, or reviewing Laravel application code, schema, factories, project tooling, resources, or Pest tests. Route repository-derived conventions from each touched path to focused references; live files and nearest equivalent siblings decide applicability.4---5
6# Laravel Project Patterns
7
8Route each touched behavior surface to its domain router and only the focused
9leaves matching the live contract. The executable router, not manual browsing
10of [`references/MAP.md`](references/MAP.md), decides which branch to expose.
11Examples are synthetic; preserve them and their placeholder entities.
12
13## Required Workflow
14
151. Read the nearest `AGENTS.md` and project guidance.
162. Identify every touched path. Before any tool call that discovers, searches,
17 lists, or opens pattern references, and before editing, run the
18 [`executable context router`](references/context-resolver.md) with plain
19 `php` and all touched paths. This preflight is mandatory.
203. Read only exact references selected by the result. Expand one or more named
21 frontiers, then select only children printed by those frontiers. Never use
22 `rg`, `find`, globs, directory listings, guessed paths, or broad `sed` reads
23 to discover or choose references. If the touched-path set grows, rerun the
24 complete preflight before further reference reads or edits; stale results do
25 not authorize the new surface.
264. Identify every behavior owner. Read the exact live project code files
27 and the nearest equivalent siblings before editing. Equivalent means the
28 same precondition, operation, outcome, route depth, binding ownership,
29 transport, and response contract, not merely a nearby directory.
30 Repository search is allowed here for live code evidence because the router
31 preflight has already succeeded; it is never a substitute for that preflight.
325. For each touched surface, use the router-selected focused leaves and core
33 contracts. References expose possible patterns; absent behavior is not mandatory.
346. Do not edit until this routing tuple is known: touched surface, behavior
35 owner, live sibling evidence, and selected reference. Continue discovery if
36 any element is missing. If no equivalent sibling exists, preserve the live
37 shape and keep the rule local instead of generalizing. Check versioned
38 framework documentation when needed.
397. Implement, run focused verification, review the complete diff, and confirm
40 every affected owner surface remains covered.
41
42Controller tests start at their
43[`router`](references/tests/Feature/Http/Controllers/README.md), then select
44only the action, route depth, transport, pattern, and validation in scope.
45
46## Non-Negotiable Router Contract
47
48- Live evidence and nearest equivalent siblings override generic habits and examples.
49 Preserve concurrent work and avoid unrelated refactors.
50- Match finality, schema, migrations, generated files, and unguarded models to
51 the sibling family: [`code and schema`](references/core/code-and-schema.md).
52- Choose tests by behavior owner. Layered HTTP, action, model, and database
53 tests are distinct when they prove different contracts. Follow persistence,
54 Pest, fixture, `and()`, and `refresh()` rules in
55 [`test design`](references/core/test-design-and-style.md).
56- Controllers remain tested entry points when actions own persistence. Mock
57 delegated actions and preserve each distinct HTTP-owned path, minimal
58 Request-to-Input mapping, `$response`, and public response contract:
59 [`HTTP boundaries`](references/core/http-and-request-boundaries.md).
60- Form Requests own HTTP shape, normalization, scoped validation, and
61 request-safe cross-field rules. Actions own transactional and dependent-state
62 guards. Preserve or convert public IDs according to the live boundary.
63- Actions accept business inputs only. Do not repeat binding/ownership queries.
64 Default to no row lock or improvised concurrency substitute:
65 [`actions and concurrency`](references/core/actions-and-concurrency.md).
66
67## Main Routers
68
69These links keep the full tree auditable. Do not open one to choose a task
70branch unless the executable router returned it.
71
72- [`context resolver`](references/context-resolver.md): mandatory deterministic
73 path, operation, concern, gate, and progressive-leaf selection.
74- [`project`](references/project/README.md): routes, configuration, tooling,
75 localization, bootstrap, public files, and seeders.
76- [`database`](references/database/README.md): migrations and factories.
77- [`app`](references/app/README.md): PHP under `app/**`.
78- [`resources`](references/resources/README.md): JavaScript, Blade, React
79 Email, TypeScript, and CSS.
80- [`tests`](references/tests/README.md): suite ownership, paths, and support.
81- [`core`](references/core/README.md): cross-cutting contracts and completion.
82
83See the [reference structure](references/README.md). Finish with focused tests,
84PHP formatting, complete diff review, and the
85[completion checklist](references/core/completion-checklist.md). Passing tests
86prove execution, not that an HTTP, domain, persistence, or regression contract
87was not deleted.