agentleFS
michaelalbermichaelalber/ai-toolkit/skills/php-api-scaffolder/SKILL.md

php-api-scaffolder

Skill3 starsChanged 3 months agoMITView on GitHub

Scaffolds Laravel API endpoints with API Resource responses, Form Request validation, Sanctum authentication, throttle-based rate limiting, URI versioning, OpenAPI documentation, and health checks. PHP analog of fastapi-scaffolder, minimal-api-scaffolder, and axum-scaffolder. Use when creating REST APIs in Laravel, adding API endpoints, setting up API routing and middleware, or configuring API infrastructure.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If routes/api.php is absent on Laravel 11-13, run php artisan install:api (installs Sanctum, creates the file).

    line 56

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

PHP API Scaffolder (Laravel)

"A good API is easy to use correctly and hard to use incorrectly." -- Joshua Bloch

"Be conservative in what you send, be liberal in what you accept." -- Postel's Law

Core Philosophy

This skill scaffolds production-grade Laravel API endpoints — not just a route and a closure. Every endpoint ships with input validation (Form Request), output shaping (API Resource), authentication (Sanctum), rate limiting (throttle), a version prefix, a documented OpenAPI contract, and a consistent error envelope. The default is routes/api.php with the api middleware group, which is stateless and already namespaced under /api.

The endpoint is a boundary. Untrusted input is validated and typed before it reaches any service; output is shaped through a Resource so schema and sensitive columns never leak. Errors return a predictable JSON shape with the correct HTTP status — 422 for validation, 401/403 for auth, 429 for throttling.

Non-Negotiable Constraints:

  1. declare(strict_types=1) in every generated PHP file
  2. Form Request validation on every write endpoint — never raw $request->input()
  3. API Resource on every response — never return Eloquent models or arrays directly
  4. Versioned URIs — /api/v1/...; breaking changes bump the version, never mutate v1
  5. Auth + throttle middleware declared on every non-public route
  6. OpenAPI annotations kept next to the controller action they describe

The full domain-principle set, knowledge-base lookups, AI discipline rules, anti-patterns, and error-recovery procedures live in references/api-conventions.md.

Workflow

Phase 1: DETECT

php -v | head -1
grep -E '"(php|laravel/framework)"' composer.json
# Does an API route file / Sanctum exist yet?
ls routes/api.php 2>/dev/null && grep -rn "Sanctum\|auth:sanctum" routes/ app/ | head
# Existing version prefixes and limiters
grep -rn "prefix('v" routes/ ; grep -rn "RateLimiter::for" app/

If routes/api.php is absent on Laravel 11-13, run php artisan install:api (installs Sanctum, creates the file). Record version, whether Sanctum is present, existing limiters, and the OpenAPI tool in use (l5-swagger, scribe, or none).

Phase 2: SCAFFOLD

See references/route-template.md for full controller, request, resource, and route content, and references/security-patterns.md for auth, throttle, CORS, and the error envelope.

app/Http/Controllers/Api/V1/<Name>Controller.php   # OpenAPI annotations + thin actions
app/Http/Requests/Api/V1/Store<Name>Request.php
app/Http/Resources/V1/<Name>Resource.php
routes/api.php                                       # v1 group: auth + throttle
app/Providers/AppServiceProvider.php / RouteServiceProvider  # RateLimiter::for('api', ...)
tests/Feature/Api/V1/<Name>EndpointTest.php

Phase 3: SECURE & DOCUMENT

// routes/api.php
Route::get('/health', HealthController::class);     // public liveness

Route::prefix('v1')->middleware(['auth:sanctum', 'throttle:api'])->group(function (): void {
    Route::apiResource('users', UserController::class);
});

Generate the spec: php artisan l5-swagger:generate (or php artisan scribe:generate).

Phase 4: VERIFY

php artisan route:list --path=api
vendor/bin/pest tests/Feature/Api          # or phpunit
vendor/bin/pint --dirty                    # Laravel's default style fixer (wraps php-cs-fixer)
curl -s localhost:8000/api/health          # {"status":"ok"}
# 429 after exceeding the limiter; 422 on bad input; 401 without a token

State Block

<php-api-scaffolder-state>
  phase: DETECT | SCAFFOLD | SECURE | VERIFY | COMPLETE
  endpoint: [resource name]
  laravel_version: [detected]
  api_version: v1
  sanctum_installed: true | false
  throttle_configured: true | false
  openapi_tool: l5-swagger | scribe | none
  resource_created: true | false
  request_created: true | false
  tests_scaffolded: true | false
  last_action: [description]
</php-api-scaffolder-state>

Output Template

Laravel API Endpoint Scaffold: [Endpoint Name]

## API Endpoint Scaffold: [Endpoint Name]

### Files Created
- [ ] `app/Http/Controllers/Api/V1/<Name>Controller.php` (OpenAPI annotated)
- [ ] `app/Http/Requests/Api/V1/Store<Name>Request.php`
- [ ] `app/Http/Resources/V1/<Name>Resource.php`
- [ ] `tests/Feature/Api/V1/<Name>EndpointTest.php`

### Routing & Middleware
- [ ] Registered under `Route::prefix('v1')`
- [ ] `auth:sanctum` applied (or documented as public)
- [ ] `throttle:api` applied; limiter defined
- [ ] Health route `GET /api/health` present

### Contract
- [ ] OpenAPI annotations on each action
- [ ] Spec regenerated (`l5-swagger:generate` / `scribe:generate`)
- [ ] Error envelope consistent (422 / 401 / 403 / 429)

### Verification
- [ ] `route:list` shows versioned routes
- [ ] Feature tests green (happy path + 422 + 401 + 429)
- [ ] `pint --dirty` clean

Integration with Other Skills

SkillRelationship
php-feature-sliceProvides the feature folder + service layer the controller delegates to. Use together for a full slice with production endpoints.
php-security-reviewAudit the new endpoints for OWASP API risks (authz, mass assignment, rate limits) after scaffolding.
php-migration-managerWhen an endpoint needs new tables/columns, manage the migration lifecycle.
php-package-scaffoldWhen the API client/SDK is published as a Composer package.
tdd-loopDrive each endpoint test-first (request → 422/401/200) before generating the action.

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.