agentleFS
soden46soden46/syarif-laravel-ai-skills/skills/controller-cleanup/SKILL.md

controller-cleanup

Skill4 starsChanged 5 months agoMITView on GitHub

Keep Laravel controllers focused on HTTP orchestration by moving validation, authorization, and business workflows outward.

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 8 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when controllers become difficult to understand, test, or maintain.

    line 11
  2. Very specific:

    When a Laravel app has several menus/pages, also use module-per-menu: avoid one broad controller for the whole app, and split by menu, page …

    line 13
  3. Very specific:

    call $this->authorize() or rely on middleware/Form Request authorization.

    line 22
  4. Very specific:

    call a Form Request's validated() data.

    line 23
  5. Distinctive:

    Keep coarse access requirements visible in routes or route groups.

    line 38
  6. Very specific:

    Use Policies for model-state rules and Form Request authorize() for request-input-dependent authorization.

    line 50
  7. Distinctive:

    Use controller actions for committed production endpoints that need middleware, sessions, tests, cache headers, or deployment route caching.

    line 54
  8. Distinctive:

    Place static or specific routes before broad resource routes when URI patterns could collide.

    line 58
  9. Very specific:

    Verify collision-prone route changes with php artisan route:list or a feature test.

    line 67
  10. Distinctive:

    Do not extract one-line code merely to create more layers.

    line 87
  11. Distinctive:

    Do not require Repository Pattern by default.

    line 88
  12. Distinctive:

    Keep framework-specific HTTP concerns in controllers.

    line 89
  13. Distinctive:

    Keep reusable business operations outside controllers.

    line 90

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Controller Cleanup

Use this skill when controllers become difficult to understand, test, or maintain.

When a Laravel app has several menus/pages, also use module-per-menu: avoid one broad controller for the whole app, and split by menu, page group, or resource boundary.

Controllers should stay thin and focused on HTTP orchestration. They should not contain long business workflows, provider payload construction, repeated query logic, or file-processing loops.

Responsibilities

A controller may:

  • receive route-bound models and requests;
  • call $this->authorize() or rely on middleware/Form Request authorization;
  • call a Form Request's validated() data;
  • invoke an Action or Service;
  • return redirects, views, JSON resources, streams, or downloads;
  • attach session flash messages.

A controller should not:

  • build external provider payloads inline;
  • contain multi-step write workflows without a transaction boundary;
  • duplicate validation rules;
  • hide authorization inside unrelated branches;
  • contain heavy report/query logic that is reused elsewhere.

Route Boundaries

Keep coarse access requirements visible in routes or route groups.

Route::middleware(['auth', 'verified'])->group(function () {
    Route::resource('records', RecordController::class)
        ->middlewareFor('index', 'can:viewAny,' . Record::class)
        ->middlewareFor(['create', 'store'], 'can:create,' . Record::class)
        ->middlewareFor(['edit', 'update'], 'can:update,record')
        ->middlewareFor('destroy', 'can:delete,record');
});

Use Policies for model-state rules and Form Request authorize() for request-input-dependent authorization.

Route Order And Cache Safety

Use controller actions for committed production endpoints that need middleware, sessions, tests, cache headers, or deployment route caching.

Route closures are acceptable for static views, simple redirects, prototypes, and temporary debugging.

Place static or specific routes before broad resource routes when URI patterns could collide.

Route::get('records/export', ExportRecordsController::class)
    ->name('records.export');

Route::resource('records', RecordController::class);

Verify collision-prone route changes with php artisan route:list or a feature test.

Generic Store Pattern

final class RecordController
{
    public function store(StoreRecordRequest $request, CreateRecord $create): RedirectResponse
    {
        $record = $create->handle($request->user(), $request->validated());

        return redirect()
            ->route('records.show', $record)
            ->with('status', 'Record created.');
    }
}

Guardrails

  • Do not extract one-line code merely to create more layers.
  • Do not require Repository Pattern by default.
  • Keep framework-specific HTTP concerns in controllers.
  • Keep reusable business operations outside controllers.

Context Efficiency

Layer: 3 (Implementation)

Load this skill only when controllers need cleanup. Do not load with unrelated skills. Keep the diff minimal: inline validation only when rules are tiny, otherwise Form Request; one Action per use case; no repository by default.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.