Laravel Best Practices: Install, Source and Security

Laravel Best Practices

Published by paulofelipem in agent-laravel-skills

No known issues56 installs

What this skill does

Laravel best practices and architecture patterns for building production-ready applications. Use when writing, reviewing, or refactoring Laravel code to ensure proper patterns for service providers, dependency injection, security, Eloquent, and performance.

Add Laravel Best Practices to your agent

Review the source and files first. When you are ready, copy the prompt instruction or use the CLI command supported by your environment.

Install with a prompt

Paste this into a compatible coding agent:

add this skill "laravel-best-practices" from https://github.com/paulofelipem/agent-laravel-skills

Install with the CLI

Run this command in a controlled environment after reviewing the repository:

npx skills add https://github.com/paulofelipem/agent-laravel-skills --skill laravel-best-practices

Skill instructions

Laravel Best Practices

Comprehensive best practices guide for Laravel applications. Contains 40 rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.

When to Apply

Reference these guidelines when:

  • Writing new Laravel controllers, services, or models
  • Implementing authentication and authorization
  • Reviewing code for architecture and security issues
  • Refactoring existing Laravel codebases
  • Optimizing performance or database queries
  • Building microservices or queue-based architectures

Rule Categories by Priority

PriorityCategoryImpactPrefix
1ArchitectureCRITICALarch-
2Dependency InjectionCRITICALdi-
3Error HandlingHIGHerror-
4SecurityHIGHsecurity-
5PerformanceHIGHperf-
6TestingMEDIUM-HIGHtest-
7Database & ORMMEDIUM-HIGHdb-
8API DesignMEDIUMapi-
9MicroservicesMEDIUMmicro-
10DevOps & DeploymentLOW-MEDIUMdevops-

Quick Reference

1. Architecture (CRITICAL)

  • arch-avoid-circular-deps - Avoid circular service provider dependencies
  • arch-feature-modules - Organize by domain/feature, not technical layer
  • arch-single-responsibility - Focused services over "god services"
  • arch-use-repository-pattern - Abstract database logic for testability
  • arch-use-events - Event-driven architecture for decoupling

2. Dependency Injection (CRITICAL)

  • di-avoid-service-locator - Avoid app() helper as service locator
  • di-interface-segregation - Interface Segregation Principle (ISP)
  • di-liskov-substitution - Liskov Substitution Principle (LSP)
  • di-prefer-constructor-injection - Constructor over facade/helper injection
  • di-scope-awareness - Understand singleton/bind/scoped bindings
  • di-use-interfaces-tokens - Bind interfaces to implementations

3. Error Handling (HIGH)

  • error-use-exception-handler - Centralized exception handling
  • error-throw-http-exceptions - Use proper HTTP exceptions
  • error-handle-queue-errors - Handle queue and job errors properly

4. Security (HIGH)

  • security-auth-jwt - Secure authentication with Sanctum/Passport
  • security-validate-all-input - Validate with Form Requests
  • security-use-guards - Authentication guards, gates, and policies
  • security-sanitize-output - Prevent XSS attacks
  • security-rate-limiting - Implement rate limiting

5. Performance (HIGH)

  • perf-service-provider-lifecycle - Proper service provider boot/register lifecycle
  • perf-use-caching - Implement caching strategies
  • perf-optimize-database - Optimize database queries
  • perf-lazy-loading - Lazy collections and route caching

6. Testing (MEDIUM-HIGH)

  • test-use-testcase-refresh-database - Use Laravel TestCase and RefreshDatabase
  • test-e2e-http - HTTP/feature testing with Laravel
  • test-mock-external-services - Mock external dependencies with facades

7. Database & ORM (MEDIUM-HIGH)

  • db-use-transactions - Transaction management
  • db-avoid-n-plus-one - Avoid N+1 query problems with eager loading
  • db-use-migrations - Use migrations for schema changes

8. API Design (MEDIUM)

  • api-use-dto-serialization - API Resources and serialization
  • api-use-interceptors - Middleware for cross-cutting concerns
  • api-versioning - API versioning strategies
  • api-use-pipes - Form Requests for input transformation

9. Microservices (MEDIUM)

  • micro-use-patterns - Message and event patterns
  • micro-use-health-checks - Health checks for orchestration
  • micro-use-queues - Background job processing with queues

10. DevOps & Deployment (LOW-MEDIUM)

  • devops-use-config-module - Environment configuration with config()
  • devops-use-logging - Structured logging with channels
  • devops-graceful-shutdown - Zero-downtime deployments

How to Use

Read individual rule files for detailed explanations and code examples:

rules/arch-avoid-circular-deps.md
rules/security-validate-all-input.md

Each rule file contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

Only read AGENTS.md or individual rules/*.md files when you need full implementation detail for a specific rule. Do not load them proactively.

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

Laravel Boost Compatibility

If Laravel Boost is installed, the following rules are already covered by its core guidelines and can be skipped:

security-validate-all-input, security-auth-jwt, db-avoid-n-plus-one, db-use-migrations, perf-use-caching, test-use-testcase-refresh-database, devops-use-logging, api-versioning

Files included

  • SKILL.md
  • .gitignore
  • metadata.json
  • rules/_template.md
  • rules/api-use-dto-serialization.md
  • rules/api-use-pipes.md
  • rules/api-use-interceptors.md
  • rules/api-versioning.md
  • README.md
  • rules/arch-single-responsibility.md
  • rules/arch-avoid-circular-deps.md
  • rules/arch-use-events.md
  • rules/db-use-transactions.md
  • rules/arch-feature-modules.md
  • rules/db-avoid-n-plus-one.md
  • rules/arch-use-repository-pattern.md
  • rules/db-use-migrations.md
  • rules/devops-graceful-shutdown.md
  • AGENTS.md
  • rules/devops-use-config-module.md
  • rules/devops-use-logging.md
  • rules/error-handle-queue-errors.md
  • rules/di-prefer-constructor-injection.md
  • rules/di-interface-segregation.md
  • rules/di-liskov-substitution.md
  • rules/di-use-interfaces-tokens.md
  • rules/di-avoid-service-locator.md
  • rules/di-scope-awareness.md
  • rules/error-throw-http-exceptions.md
  • rules/micro-use-health-checks.md
  • rules/error-use-exception-handler.md
  • rules/micro-use-queues.md
  • rules/perf-optimize-database.md
  • rules/micro-use-patterns.md
  • rules/perf-service-provider-lifecycle.md
  • rules/perf-lazy-loading.md
  • rules/perf-use-caching.md
  • rules/security-rate-limiting.md
  • rules/security-auth-jwt.md
  • rules/security-use-guards.md
  • rules/security-sanitize-output.md
  • rules/security-validate-all-input.md
  • rules/test-e2e-http.md
  • rules/test-mock-external-services.md
  • rules/test-use-testcase-refresh-database.md
  • scripts/build-agents.ts
  • scripts/build.sh
  • scripts/package-lock.json
  • scripts/package.json

More skills