360 Secure SkillHub
360 安全技能中心

backend-best-practices

提供按影响优先级组织的 Laravel/PHP 后端规则,覆盖 API 设计、数据库模式、认证、错误处理、性能与安全,用于编写新端点、审查代码、设计数据库和执行团队编码规范。

分类:开发
未知作者
热度 0.00
最近更新 2026-11-06 23:50:37

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add handbook.adra.dev/backend-best-practices
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
backend-best-practices
description
Best practices for backend development including API design, database patterns, authentication, error handling, performance, and security. Use when reviewing backend code, building APIs, designing database schemas, or enforcing backend coding standards.

Backend Best Practices

Comprehensive backend development guidelines for API design, database patterns, authentication, error handling, performance, and security. Contains rules prioritized by impact to guide code generation and review.

When to Apply

Reference these guidelines when:

  • Writing new API endpoints or controllers
  • Designing database schemas or writing queries
  • Implementing authentication or authorization logic
  • Reviewing backend code for quality or security issues
  • Refactoring existing backend code
  • Enforcing coding standards across the team

Quick Reference

  • artisan-tests-use-command-class - Call $this->artisan(Command::class) instead of string signatures in tests
  • console-command-signature-adra-prefix - Artisan command signatures start with adra: and a clear domain segment
  • eloquent-eager-load-relationships - Eager load relations with with() / load() to avoid N+1 queries
  • eloquent-mass-assignment-protection - Use $fillable / $guarded; never open mass assignment from raw request data
  • feature-flag-usage-backend - Gate features behind flags using the correct backend service pattern
  • feature-specification-and-tdd-first - Document acceptance criteria, then write failing tests before implementation
  • form-request-for-http-validation - Use Form Request classes for non-trivial validation and authorization
  • laravel-coding-standards-naming - PSR-12, PascalCase classes, snake_case columns, kebab-case route names
  • lean-controller-orchestrates-actions-services - Controllers orchestrate Actions/Services; keep business logic out of HTTP layer for testability
  • one-class-per-file - Keep only one class per PHP file for better organization and testability
  • openapi-spec-sync-with-api - Update each service’s openapi/openapi.yml when the HTTP contract changes
  • phpunit-test-naming-and-groups - Use test_ or @test and stable @group labels for predictable discovery/filtering
  • tenant-scoped-test-case-pattern - Extend the service tenant test base (e.g. TenantTestCase) for tenant-bound tests

How to Use

Read individual rule files under rules/ for detailed explanations and code examples (see Quick Reference for slugs).

Each rule file contains:

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