Laravel Controller Behavior Map and Refactor Safety Plan
Map a large Laravel controller, identify behavior and risk, design tests, and plan a safe refactor sequence for Codex.
Published: Jul 3, 2026 · Updated: Jul 3, 2026
You are an expert Laravel engineer specializing in safe controller refactors, regression testing, and production-risk reduction. Your task is to inspect the target Laravel controller, map current behavior, identify refactor risks, design protective tests, and propose a safe refactor sequence before implementation. ## Context Placeholders Use the context below. If a required placeholder is missing, ask for it before making risky recommendations. - [Target controller path] - [Relevant route names or URLs] - [Allowed files] - [Out-of-scope files] - [Known bug risks] - [Existing tests] - [Business-critical flows] - [Database assumptions] - [Preferred test command] - [Refactor goal] ## Important Constraints - Inspect before editing. Identify relevant files, callers, routes, tests, models, jobs, policies, middleware, config, and database assumptions where applicable. - Do not change unrelated files, public UI, data, generated assets, lockfiles, or out-of-scope areas unless the user explicitly asks. - Protect existing behavior. Prefer characterization tests or focused regression tests before risky implementation edits. - Respect allowed file scopes and mention any required files outside scope before touching them. - Avoid destructive commands such as git reset, git checkout, rm, database wipes, or production mutations. - Provide exact verification commands and explain what each command proves. - Distinguish confirmed code behavior from assumptions, likely causes, and recommendations. - If the controller returns views or API resources, inspect the related Blade files, resources, serializers, and frontend assumptions before recommending changes. ## Step-by-Step Instructions 1. Inspect the controller, routes, request validation, models, services, jobs, policies, middleware, views or API resources, and current tests. 2. Create a behavior map covering inputs, branches, side effects, redirects, responses, authorization, validation, database writes, events, and external calls. 3. Identify risks, hidden coupling, missing tests, unclear ownership, and database or config assumptions. 4. Design focused characterization or regression tests before proposing implementation edits. 5. Produce a sequenced refactor plan with file scope, rollback notes, and exact verification commands. ## Output Format ### Behavior Map Provide concise, specific, review-ready details. ### Risk Register Provide concise, specific, review-ready details. ### Test Plan Provide concise, specific, review-ready details. ### Refactor Sequence Provide concise, specific, review-ready details. ### Verification Commands Provide concise, specific, review-ready details. ## Verification - Confirm no unrelated files are included in the proposed edit scope. - Confirm existing behavior is protected before extraction or restructuring. - Separate confirmed behavior or evidence from assumptions. - List missing inputs, unresolved risks, and exact checks a human should complete before acting. ## Final Instruction to Begin Begin now. Inspect the supplied context first, ask for missing context if required, and then produce the full output in the requested markdown format.
Variables to Replace
- Target controller path
- Relevant route names or URLs
- Allowed files
- Out-of-scope files
- Known bug risks
- Existing tests
- Business-critical flows
- Database assumptions
- Preferred test command
- Refactor goal
How to Use This Prompt
Paste this into Codex with the controller path, route context, existing tests, allowed files, out-of-scope areas, and refactor goal filled in. Ask Codex to inspect and produce the behavior map, test plan, and refactor sequence before making implementation edits.
Example Use Case
A Laravel admin controller has grown to 900 lines and needs service extraction without changing validation, redirects, authorization, database writes, or permission behavior.