agentleFS
KaidevLabsKaidevLabs/Skills/skills/resource-first-controllers/SKILL.md

resource-first-controllers

Skill1 starsChanged 34 days agoMITView on GitHub

Enforces resource-first controller design in Laravel. Apply whenever creating, modifying, or reviewing controllers, defining routes, or planning new features that involve HTTP endpoints.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every controller is a resource until proven otherwise.

    line 10
  2. Distinctive:

    Only when ALL of these are true:

    line 47
  3. Distinctive:

    When the user asks for any controller or endpoint:

    line 55
  4. Distinctive:

    If proposing an invokable controller, explicitly justify why none of the 7 methods fit.

    line 61

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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

Resource-First Controller Design

Core Principle

Every controller is a resource until proven otherwise. Before writing any controller, ask: "Can this be modeled as a resource?"

Decision Flow

  1. Identify the noun (the thing being acted upon). If you can name a resource, use a resource controller.
  2. Map actions to the 7 standard methods:
    • index → list
    • create → show creation form
    • store → persist new
    • show → display one
    • edit → show edit form
    • update → persist changes
    • destroy → delete
  3. Partial resources are encouraged (1–7 methods). Use Route::resource(...)->only([...]) or ->except([...]).
  4. Invokable controllers are a LAST RESORT — only when the action genuinely cannot map to any standard method (e.g., GenerateMonthlyReportController, ExchangeOAuthTokenController).

Hard Rules (do not violate)

  • ❌ No custom methods on resource controllers. A controller either has only resource methods, or it is invokable.
  • ❌ No mixed controllers. If you feel tempted to add publish(), archive(), approve() → that's a new resource (PublishedPostController@store, PostArchiveController@store, etc.).
  • ❌ No grab-bag controllers (e.g., UserController with profile(), settings(), avatar()). Split into UserProfileController, UserSettingsController, UserAvatarController.
  • ✅ Nested resources are preferred over custom methods: Route::resource('posts.comments', ...).
  • ✅ State changes are resources too: subscribing = SubscriptionController@store, unsubscribing = SubscriptionController@destroy.

Reframing Patterns (use these)

Tempting custom methodResource-first refactor
PostController@publishPublishedPostController@store
UserController@activateActiveUserController@store
OrderController@cancelOrderController@destroy or CancelledOrderController@store
AuthController@loginSessionController@store
AuthController@logoutSessionController@destroy
UserController@searchUserController@index (filter via query params)

When Invokable Is Acceptable

Only when ALL of these are true:

  • The action does not create/read/update/delete an identifiable resource.
  • It cannot be reframed as a state-resource without contortion.
  • Examples: webhooks (StripeWebhookController), one-off jobs (RecalculateRankingsController), pure RPC integrations.

Required Workflow For The Assistant

When the user asks for any controller or endpoint:

  1. State the resource you've identified.
  2. List which of the 7 methods apply, and which are excluded.
  3. Generate the artisan command: php artisan make:controller {Name}Controller --resource --model={Model}.
  4. Generate the route using Route::resource(...) (with ->only(...) if partial).
  5. If proposing an invokable controller, explicitly justify why none of the 7 methods fit.

Self-Check Before Returning Code

  • Does this controller have ONLY resource methods, OR is it __invoke?
  • Did I avoid adding publish/approve/toggle/etc. as a method?
  • If I used invokable, did I justify why no resource framing works?
  • Are routes declared with Route::resource / Route::apiResource (not individual Route::get/post)?

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.