Architect Laravel APIs with JSON:API Standards
Enforces a strict layered architecture, JSON:API v1.1, and full test coverage for Laravel API projects, with 14-file entity generation.
Why it matters
Ensure your Laravel API projects adhere to architectural best practices and the JSON:API v1.1 specification. This skill enforces strict typing and comprehensive test coverage for robust and maintainable code.
Outcomes
What it gets done
Implement JSON:API v1.1 specification.
Enforce layered architecture principles.
Generate fully tested, strictly typed code.
Maintain high code quality through architectural discipline.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/laravel-api-architecture-skill | bash Overview
Laravel API Architecture
Enforces a strict layered Laravel API architecture - Controller, Service, Repository, QueryBuilder, Model - with JSON:API v1.1 responses, strict PHP types, and full test coverage. Generates all 14 files for a new entity and runs a 13-section code review checklist. Use it on Laravel API projects that need consistent architecture across many entities - creating a new resource, reviewing a controller for layer violations, or writing tests to the project's coverage bar. It installs a CLAUDE.md phase dispatcher so rules apply every session.
What it does
Laravel API Architecture enforces a strict, layered architecture on every Laravel API project it touches: HTTP Request → Route → Middleware → Controller → Service → Repository → QueryBuilder → Model → DB, with responses flowing back out through a JsonApiResource. Each layer has a defined job and an explicit "does not" list - controllers stay thin and never touch the database directly, services hold business logic but never query directly, repositories handle CRUD and delegate querying to a QueryBuilder, and models hold relations/casts/accessors but never scopes. On top of the architecture, it enforces JSON:API v1.1 responses, strict PHP types, and a minimum 85% test coverage bar.
When to use - and when NOT to
Use it on any Laravel API project where consistent layering matters across many entities and contributors - creating a new resource end to end, fixing a controller that's grown business logic it shouldn't have, writing tests to the project's coverage requirement, or running the skill's 13-section code review checklist before a merge. It is opinionated by design: it forbids mixed types, skipping declare(strict_types=1), PHPStan baselines (errors must be fixed, not suppressed), $guarded = [] (always use $fillable), and logging PII like emails, tokens, or passwords. Projects that don't want this level of architectural rigidity, or that aren't using JSON:API-style responses, are not the intended fit.
Inputs and outputs
Installation is npx skills add streeboga/laravel-api-skill; on first use it checks the project's CLAUDE.md and either creates one from a bundled template, appends a Laravel-specific section, or leaves an already-configured file alone. That CLAUDE.md acts as a phase dispatcher - loaded every session - that detects what's being done (creating an entity, reviewing code, writing tests) and forces the agent to read the matching reference files before writing anything. Asking the agent to create a new entity produces 14 files: migration, model (with ULID public keys), enum(s), Create/Update DTOs (via Spatie Data), Store/Update form requests (with toDto()), a QueryBuilder, a repository interface plus implementation, a service, a thin JSON:API-compliant controller, a JsonApiResource, versioned routes, a service-provider binding, and feature tests.
Integrations
The skill leans on a specific dependency set: timacdonald/json-api for JSON:API resources, spatie/laravel-query-builder for filtering/sorting/includes, spatie/laravel-data for DTOs, brick/money for monetary values, laravel/sanctum for API auth, and dedoc/scramble for auto-generated OpenAPI docs, backed on the quality side by PHPStan/Larastan at level 8 with zero errors, Laravel Pint for PSR-12 style, Pest for testing and mutation coverage, PHP Insights, Rector, and Deptrac for layer-dependency enforcement. Context is kept lean by loading only SKILL.md (~170 lines) by default and pulling in specific reference files on demand per task - roughly 1500 lines for a new entity, 640 for a controller fix, 800 for test writing - out of 19 total reference files covering architecture, each layer, security, performance, and more.
Who it's for
Teams building Laravel APIs with AI coding agents (Claude Code, Cursor, Copilot) who want every generated entity and endpoint to follow the same layered architecture, JSON:API conventions, strict typing, and test-coverage bar automatically, instead of relying on manual review to catch drift.
Source README
Laravel API Production-Ready Architecture Skill
A skill for AI coding agents (Claude Code, Cursor, Copilot, etc.) that enforces architectural discipline in Laravel API projects: JSON:API v1.1, layered architecture, strict types, full test coverage.
Installation
Step 1: Install the skill
npx skills add streeboga/laravel-api-skill
Step 2: Setup CLAUDE.md (automatic)
On first use, the skill automatically checks your project's CLAUDE.md:
- No CLAUDE.md? - Creates one from
templates/CLAUDE.mdwith Laravel architecture rules - CLAUDE.md exists but no Laravel section? - Appends the Laravel section
- Already configured? - Proceeds normally
The CLAUDE.md template acts as a phase dispatcher - it detects what you're doing (creating an entity, reviewing code, writing tests) and forces the agent to read the correct reference files before writing any code.
Manual setup (alternative)
If you prefer to set it up manually:
# Copy the template to your project root
cp ~/.claude/skills/laravel-api/templates/CLAUDE.md ./CLAUDE.md
Or append to an existing CLAUDE.md:
cat ~/.claude/skills/laravel-api/templates/CLAUDE.md >> ./CLAUDE.md
What It Does
When activated, the skill enforces a strict layered architecture for every Laravel API project:
HTTP Request → Route → Middleware → Controller → Service → Repository → QueryBuilder → Model → DB
Response ← JsonApiResource ← Service ← Repository ← QueryBuilder
Layer Boundaries
| Layer | Does | Does NOT |
|---|---|---|
| Controller | Accept request, call Service, return JsonApiResource | Access DB, inject Repository/Model, contain logic |
| Service | Business logic, transactions, events, caching | Query DB directly, grow into God Class |
| Repository | CRUD operations, delegates queries to QueryBuilder | Contain business logic |
| QueryBuilder | Scopes, filters, sorts, eager loading, pagination | Contain CRUD or business logic |
| Model | Relations, casts, accessors. NO scopes | Contain scopeXxx() methods |
| DTO | Type-safe data transfer between layers | -- |
| JsonApiResource | Transform model to JSON:API format | -- |
| Enum | All constants, statuses, cache keys | -- |
New Entity Generation
Ask the agent to create a new entity and it generates 14 files following the architecture:
- Migration
- Model (with ULID public keys)
- Enum(s)
- Create DTO + Update DTO (Spatie Data)
- Store Request + Update Request (with
toDto()) - QueryBuilder
- Repository Interface + Implementation
- Service
- Controller (thin, JSON:API compliant)
- JsonApiResource
- Routes (versioned, PATCH for updates)
- Service Provider binding
- Feature Tests
Code Review
The skill includes a 13-section code review checklist covering architecture compliance, security, performance, and testing.
How It Works
Hub + Reference Files
SKILL.md (~170 lines) is always loaded into context. It contains the architecture diagram, JSON:API rules, routing table to reference files, and constraints.
Reference files are loaded on demand -- only those needed for the current task:
| Task | Files Loaded | ~Lines |
|---|---|---|
| Any request | SKILL.md | 170 |
| New entity | + architecture + 6-8 reference files | ~1500 |
| Fix a controller | + controller.md + api-docs.md | ~640 |
| Code review | + code-review.md + as needed | ~260+ |
| Writing tests | + testing.md + testing-edge-cases.md | ~800 |
| Quality check | + quality.md | ~300 |
Max context usage (~1700 lines) leaves plenty of room for project code.
Skill Structure
laravel-api-skill/
├── SKILL.md # Entry point (always loaded)
├── README.md # This file
├── README.ru.md # Russian documentation
├── templates/
│ └── CLAUDE.md # Template for project CLAUDE.md (phase dispatcher)
└── references/ # Loaded on demand
├── architecture.md # Layer diagram, DB access policy
├── controller.md # Thin controllers, JSON:API, middleware
├── service-layer.md # Business logic, events, jobs, caching
├── repository-layer.md # Repository + QueryBuilder patterns
├── dto.md # Spatie Data DTOs, FormRequests
├── models.md # Models, public keys, migrations
├── enums.md # PHP Enums, HasLabel/HasColor, CacheKey
├── api-resources.md # JSON:API resources (timacdonald/json-api)
├── api-docs.md # Scramble OpenAPI documentation
├── security.md # Auth, policies, IDOR, headers, CORS
├── testing.md # API tests, edge cases, facade fakes
├── testing-edge-cases.md # Edge/corner/smoke case catalog
├── quality.md # strict_types, PHPStan, Pint, CI
├── phpstan-rules.md # Custom PHPStan rules
├── performance.md # N+1, eager loading, indexes, caching
├── laravel-11.md # Laravel 11/12 structure and patterns
├── patterns.md # Manager/Driver for swappable components
├── money.md # Brick\Money for monetary values
└── code-review.md # Master checklist (13 sections)
Key Dependencies
| Package | Purpose |
|---|---|
timacdonald/json-api |
JSON:API resources |
spatie/laravel-query-builder |
Filtering, sorting, includes |
spatie/laravel-data |
DTOs |
brick/money |
Money objects |
laravel/sanctum |
API authentication |
dedoc/scramble |
Auto-generated OpenAPI docs |
Dev Dependencies
| Package | Purpose |
|---|---|
phpstan/phpstan + larastan/larastan |
Static analysis level 8 |
laravel/pint |
PSR-12 code style |
pestphp/pest |
Testing + coverage (>= 85%) + mutation testing |
nunomaduro/phpinsights |
Code quality metrics |
rector/rector |
Automated refactoring |
deptrac/deptrac |
Layer dependency control |
Constraints
MUST DO
declare(strict_types=1)in every PHP filefinalon controllers, services, repositories, DTOs, resources, requestsreadonlyon services and DTOs- Type hint ALL parameters, properties, and return types
- PHPStan level 8 -- zero errors, no baseline
- Test coverage >= 85%
- Policies for authorization of every entity
MUST NOT DO
- Use
mixedtype - Skip
declare(strict_types=1) - Deploy without PHPStan + Pint + tests passing
- Use PHPStan baseline -- fix errors, don't suppress them
- Use
$guarded = []-- always use$fillable - Log PII (emails, tokens, passwords)
How It Works
The skill consists of two parts:
CLAUDE.md - lives in your project root, loaded by Claude Code every session. Contains hard architectural rules and a phase dispatcher that forces the agent to read the correct reference files before writing code. This ensures rules are always enforced, not just when the skill activates.
SKILL.md + references/ - lives in ~/.claude/skills/, loaded on demand. Contains detailed architecture knowledge, code templates, and checklists across 19 reference files.
User: "Create Invoice entity"
↓
CLAUDE.md (always loaded):
→ Detects phase: "Entity creation"
→ Forces reading references/architecture.md, then per-layer references
→ Lists all 14 required files
↓
SKILL.md + references/*.md (loaded per layer):
→ Provides exact code templates and patterns
Workflows
The skill integrates with multiple development workflows:
- Parallel agents -- split entity generation across worktrees
- Code review loop -- iterative review/fix cycles
- Quality gates -- pre-commit checks (tests + PHPStan + Pint)
See README.ru.md for detailed workflow documentation including Ralph Loop, Superpowers, BMAD, and GSD integrations.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.