@h1dr0n/skill-pool 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +296 -0
  3. package/bin/cli.js +157 -0
  4. package/package.json +41 -0
  5. package/skills/api/agents/backend-specialist.md +69 -0
  6. package/skills/api/agents/database-optimizer.md +176 -0
  7. package/skills/api/manifest.yaml +20 -0
  8. package/skills/api/rules/auth-security.md +45 -0
  9. package/skills/api/skills/api-patterns/SKILL.md +81 -0
  10. package/skills/api/skills/api-patterns/api-style.md +42 -0
  11. package/skills/api/skills/api-patterns/auth.md +24 -0
  12. package/skills/api/skills/api-patterns/documentation.md +26 -0
  13. package/skills/api/skills/api-patterns/graphql.md +41 -0
  14. package/skills/api/skills/api-patterns/rate-limiting.md +31 -0
  15. package/skills/api/skills/api-patterns/response.md +37 -0
  16. package/skills/api/skills/api-patterns/rest.md +40 -0
  17. package/skills/api/skills/api-patterns/scripts/api_validator.py +211 -0
  18. package/skills/api/skills/api-patterns/security-testing.md +122 -0
  19. package/skills/api/skills/api-patterns/trpc.md +41 -0
  20. package/skills/api/skills/api-patterns/versioning.md +22 -0
  21. package/skills/api/skills/database-patterns.md +126 -0
  22. package/skills/api/skills/deployment-patterns.md +105 -0
  23. package/skills/api/skills/docker-patterns.md +135 -0
  24. package/skills/common/agents/code-reviewer.md +78 -0
  25. package/skills/common/agents/planner.md +80 -0
  26. package/skills/common/agents/security-reviewer.md +82 -0
  27. package/skills/common/agents/software-architect.md +81 -0
  28. package/skills/common/manifest.yaml +25 -0
  29. package/skills/common/rules/coding-style.md +39 -0
  30. package/skills/common/rules/git-workflow.md +33 -0
  31. package/skills/common/rules/security.md +25 -0
  32. package/skills/common/skills/architecture/SKILL.md +55 -0
  33. package/skills/common/skills/architecture/context-discovery.md +43 -0
  34. package/skills/common/skills/architecture/examples.md +94 -0
  35. package/skills/common/skills/architecture/pattern-selection.md +68 -0
  36. package/skills/common/skills/architecture/patterns-reference.md +50 -0
  37. package/skills/common/skills/architecture/trade-off-analysis.md +77 -0
  38. package/skills/common/skills/brainstorming/SKILL.md +163 -0
  39. package/skills/common/skills/brainstorming/dynamic-questioning.md +350 -0
  40. package/skills/common/skills/clean-code.md +99 -0
  41. package/skills/common/skills/code-review-checklist.md +86 -0
  42. package/skills/common/skills/plan-writing/SKILL.md +152 -0
  43. package/skills/common/skills/skill-feedback.md +94 -0
  44. package/skills/common/skills/tdd-workflow.md +130 -0
  45. package/skills/common/skills/verification-loop.md +112 -0
  46. package/skills/cpp/agents/cpp-build-resolver.md +90 -0
  47. package/skills/cpp/agents/cpp-reviewer.md +72 -0
  48. package/skills/cpp/manifest.yaml +15 -0
  49. package/skills/cpp/skills/cpp-coding-standards.md +722 -0
  50. package/skills/cpp/skills/cpp-testing.md +323 -0
  51. package/skills/devops/agents/devops-automator.md +376 -0
  52. package/skills/devops/agents/sre.md +90 -0
  53. package/skills/devops/manifest.yaml +20 -0
  54. package/skills/devops/skills/deployment-patterns.md +427 -0
  55. package/skills/devops/skills/deployment-procedures/SKILL.md +241 -0
  56. package/skills/devops/skills/docker-patterns.md +364 -0
  57. package/skills/devops/skills/e2e-testing.md +326 -0
  58. package/skills/devops/skills/github-ops.md +144 -0
  59. package/skills/django/manifest.yaml +16 -0
  60. package/skills/django/skills/django-patterns.md +734 -0
  61. package/skills/django/skills/django-security.md +593 -0
  62. package/skills/django/skills/django-tdd.md +729 -0
  63. package/skills/django/skills/django-verification.md +469 -0
  64. package/skills/dotnet/agents/csharp-reviewer.md +101 -0
  65. package/skills/dotnet/manifest.yaml +14 -0
  66. package/skills/dotnet/skills/csharp-testing.md +321 -0
  67. package/skills/dotnet/skills/dotnet-patterns.md +321 -0
  68. package/skills/go/agents/code-reviewer.md +76 -0
  69. package/skills/go/agents/go-build-resolver.md +94 -0
  70. package/skills/go/agents/go-reviewer.md +76 -0
  71. package/skills/go/manifest.yaml +17 -0
  72. package/skills/go/rules/go-style.md +55 -0
  73. package/skills/go/skills/golang-patterns.md +674 -0
  74. package/skills/go/skills/golang-testing.md +720 -0
  75. package/skills/java/agents/java-build-resolver.md +153 -0
  76. package/skills/java/agents/java-reviewer.md +92 -0
  77. package/skills/java/manifest.yaml +18 -0
  78. package/skills/java/skills/java-coding-standards.md +147 -0
  79. package/skills/java/skills/jpa-patterns.md +151 -0
  80. package/skills/java/skills/springboot-patterns.md +314 -0
  81. package/skills/java/skills/springboot-security.md +272 -0
  82. package/skills/kotlin/agents/kotlin-build-resolver.md +118 -0
  83. package/skills/kotlin/agents/kotlin-reviewer.md +159 -0
  84. package/skills/kotlin/manifest.yaml +17 -0
  85. package/skills/kotlin/skills/kotlin-coroutines-flows.md +284 -0
  86. package/skills/kotlin/skills/kotlin-patterns.md +711 -0
  87. package/skills/kotlin/skills/kotlin-testing.md +824 -0
  88. package/skills/laravel/manifest.yaml +15 -0
  89. package/skills/laravel/skills/laravel-patterns.md +409 -0
  90. package/skills/laravel/skills/laravel-security.md +279 -0
  91. package/skills/laravel/skills/laravel-tdd.md +277 -0
  92. package/skills/laravel/skills/laravel-verification.md +173 -0
  93. package/skills/mobile/agents/dart-build-resolver.md +201 -0
  94. package/skills/mobile/agents/flutter-reviewer.md +243 -0
  95. package/skills/mobile/manifest.yaml +19 -0
  96. package/skills/mobile/skills/android-clean-architecture.md +339 -0
  97. package/skills/mobile/skills/dart-flutter-patterns.md +563 -0
  98. package/skills/mobile/skills/swiftui-patterns.md +259 -0
  99. package/skills/nestjs/manifest.yaml +13 -0
  100. package/skills/nestjs/skills/nestjs-patterns.md +230 -0
  101. package/skills/perl/manifest.yaml +13 -0
  102. package/skills/perl/skills/perl-patterns.md +504 -0
  103. package/skills/perl/skills/perl-security.md +503 -0
  104. package/skills/perl/skills/perl-testing.md +475 -0
  105. package/skills/python/agents/python-reviewer.md +98 -0
  106. package/skills/python/manifest.yaml +18 -0
  107. package/skills/python/rules/python-style.md +69 -0
  108. package/skills/python/skills/python-patterns/SKILL.md +441 -0
  109. package/skills/python/skills/python-patterns.md +90 -0
  110. package/skills/python/skills/python-testing.md +81 -0
  111. package/skills/rust/agents/rust-build-resolver.md +148 -0
  112. package/skills/rust/agents/rust-reviewer.md +94 -0
  113. package/skills/rust/manifest.yaml +16 -0
  114. package/skills/rust/rules/rust-style.md +107 -0
  115. package/skills/rust/skills/rust-patterns.md +499 -0
  116. package/skills/rust/skills/rust-testing.md +500 -0
  117. package/skills/security/agents/accessibility-auditor.md +316 -0
  118. package/skills/security/agents/security-reviewer.md +108 -0
  119. package/skills/security/manifest.yaml +19 -0
  120. package/skills/security/skills/red-team-tactics/SKILL.md +199 -0
  121. package/skills/security/skills/security-bounty-hunter.md +99 -0
  122. package/skills/security/skills/security-review.md +495 -0
  123. package/skills/security/skills/security-scan.md +165 -0
  124. package/skills/security/skills/vulnerability-scanner/SKILL.md +276 -0
  125. package/skills/security/skills/vulnerability-scanner/checklists.md +121 -0
  126. package/skills/security/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
  127. package/skills/swift/manifest.yaml +16 -0
  128. package/skills/swift/skills/swift-actor-persistence.md +142 -0
  129. package/skills/swift/skills/swift-concurrency.md +216 -0
  130. package/skills/swift/skills/swift-protocol-di-testing.md +190 -0
  131. package/skills/swift/skills/swiftui-patterns.md +259 -0
  132. package/skills/unity/agents/game-designer.md +167 -0
  133. package/skills/unity/agents/unity-architect.md +52 -0
  134. package/skills/unity/agents/unity-editor-tool-developer.md +310 -0
  135. package/skills/unity/agents/unity-multiplayer-engineer.md +321 -0
  136. package/skills/unity/agents/unity-shader-graph-artist.md +269 -0
  137. package/skills/unity/manifest.yaml +21 -0
  138. package/skills/unity/rules/csharp-patterns.md +48 -0
  139. package/skills/unity/rules/unity-specific.md +53 -0
  140. package/skills/unity/skills/systematic-debugging.md +92 -0
  141. package/skills/unity/skills/unity-architecture.md +173 -0
  142. package/skills/unreal/agents/level-designer.md +208 -0
  143. package/skills/unreal/agents/technical-artist.md +229 -0
  144. package/skills/unreal/agents/unreal-multiplayer-architect.md +313 -0
  145. package/skills/unreal/agents/unreal-systems-engineer.md +310 -0
  146. package/skills/unreal/agents/unreal-technical-artist.md +256 -0
  147. package/skills/unreal/agents/unreal-world-builder.md +273 -0
  148. package/skills/unreal/manifest.yaml +21 -0
  149. package/skills/unreal/skills/unreal-patterns.md +183 -0
  150. package/skills/web/agents/frontend-specialist.md +71 -0
  151. package/skills/web/agents/ui-designer.md +383 -0
  152. package/skills/web/agents/ux-architect.md +469 -0
  153. package/skills/web/manifest.yaml +22 -0
  154. package/skills/web/rules/accessibility.md +54 -0
  155. package/skills/web/rules/css-performance.md +52 -0
  156. package/skills/web/skills/e2e-testing.md +132 -0
  157. package/skills/web/skills/frontend-design/SKILL.md +452 -0
  158. package/skills/web/skills/frontend-design/animation-guide.md +331 -0
  159. package/skills/web/skills/frontend-design/color-system.md +311 -0
  160. package/skills/web/skills/frontend-design/decision-trees.md +418 -0
  161. package/skills/web/skills/frontend-design/motion-graphics.md +306 -0
  162. package/skills/web/skills/frontend-design/scripts/accessibility_checker.py +183 -0
  163. package/skills/web/skills/frontend-design/scripts/ux_audit.py +722 -0
  164. package/skills/web/skills/frontend-design/typography-system.md +345 -0
  165. package/skills/web/skills/frontend-design/ux-psychology.md +1116 -0
  166. package/skills/web/skills/frontend-design/visual-effects.md +383 -0
  167. package/skills/web/skills/react-nextjs.md +135 -0
  168. package/skills/web/skills/tailwind-patterns/SKILL.md +269 -0
  169. package/src/adapters/antigravity.js +164 -0
  170. package/src/adapters/claude.js +188 -0
  171. package/src/adapters/cursor.js +161 -0
  172. package/src/adapters/index.js +67 -0
  173. package/src/adapters/windsurf.js +158 -0
  174. package/src/commands/add.js +266 -0
  175. package/src/commands/create.js +127 -0
  176. package/src/commands/diff.js +78 -0
  177. package/src/commands/info.js +88 -0
  178. package/src/commands/init.js +224 -0
  179. package/src/commands/install.js +90 -0
  180. package/src/commands/list.js +54 -0
  181. package/src/commands/remove.js +101 -0
  182. package/src/commands/targets.js +32 -0
  183. package/src/commands/update.js +57 -0
  184. package/src/core/manifest.js +57 -0
  185. package/src/core/plugins.js +86 -0
  186. package/src/core/resolver.js +84 -0
  187. package/src/core/tracker.js +49 -0
  188. package/src/utils/fs.js +80 -0
  189. package/src/utils/git.js +52 -0
@@ -0,0 +1,15 @@
1
+ name: laravel
2
+ version: 0.1.0
3
+ description: Laravel development - architecture patterns, Eloquent ORM, security, TDD with PHPUnit/Pest, verification loops
4
+ depends:
5
+ - common
6
+ tags:
7
+ - php
8
+ - laravel
9
+ rules: []
10
+ skills:
11
+ - skills/laravel-patterns.md
12
+ - skills/laravel-security.md
13
+ - skills/laravel-tdd.md
14
+ - skills/laravel-verification.md
15
+ agents: []
@@ -0,0 +1,409 @@
1
+ # Laravel Development Patterns
2
+
3
+ Production-grade Laravel architecture patterns for scalable, maintainable applications.
4
+
5
+ ## When to Use
6
+
7
+ - Building Laravel web applications or APIs
8
+ - Structuring controllers, services, and domain logic
9
+ - Working with Eloquent models and relationships
10
+ - Designing APIs with resources and pagination
11
+ - Adding queues, events, caching, and background jobs
12
+
13
+ ## How It Works
14
+
15
+ - Structure the app around clear boundaries (controllers -> services/actions -> models).
16
+ - Use explicit bindings and scoped bindings to keep routing predictable; still enforce authorization for access control.
17
+ - Favor typed models, casts, and scopes to keep domain logic consistent.
18
+ - Keep IO-heavy work in queues and cache expensive reads.
19
+ - Centralize config in `config/*` and keep environments explicit.
20
+
21
+ ## Examples
22
+
23
+ ### Project Structure
24
+
25
+ Use a conventional Laravel layout with clear layer boundaries (HTTP, services/actions, models).
26
+
27
+ ### Recommended Layout
28
+
29
+ ```
30
+ app/
31
+ ├── Actions/ # Single-purpose use cases
32
+ ├── Console/
33
+ ├── Events/
34
+ ├── Exceptions/
35
+ ├── Http/
36
+ │ ├── Controllers/
37
+ │ ├── Middleware/
38
+ │ ├── Requests/ # Form request validation
39
+ │ └── Resources/ # API resources
40
+ ├── Jobs/
41
+ ├── Models/
42
+ ├── Policies/
43
+ ├── Providers/
44
+ ├── Services/ # Coordinating domain services
45
+ └── Support/
46
+ config/
47
+ database/
48
+ ├── factories/
49
+ ├── migrations/
50
+ └── seeders/
51
+ resources/
52
+ ├── views/
53
+ └── lang/
54
+ routes/
55
+ ├── api.php
56
+ ├── web.php
57
+ └── console.php
58
+ ```
59
+
60
+ ### Controllers -> Services -> Actions
61
+
62
+ Keep controllers thin. Put orchestration in services and single-purpose logic in actions.
63
+
64
+ ```php
65
+ final class CreateOrderAction
66
+ {
67
+ public function __construct(private OrderRepository $orders) {}
68
+
69
+ public function handle(CreateOrderData $data): Order
70
+ {
71
+ return $this->orders->create($data);
72
+ }
73
+ }
74
+
75
+ final class OrdersController extends Controller
76
+ {
77
+ public function __construct(private CreateOrderAction $createOrder) {}
78
+
79
+ public function store(StoreOrderRequest $request): JsonResponse
80
+ {
81
+ $order = $this->createOrder->handle($request->toDto());
82
+
83
+ return response()->json([
84
+ 'success' => true,
85
+ 'data' => OrderResource::make($order),
86
+ 'error' => null,
87
+ 'meta' => null,
88
+ ], 201);
89
+ }
90
+ }
91
+ ```
92
+
93
+ ### Routing and Controllers
94
+
95
+ Prefer route-model binding and resource controllers for clarity.
96
+
97
+ ```php
98
+ use Illuminate\Support\Facades\Route;
99
+
100
+ Route::middleware('auth:sanctum')->group(function () {
101
+ Route::apiResource('projects', ProjectController::class);
102
+ });
103
+ ```
104
+
105
+ ### Route Model Binding (Scoped)
106
+
107
+ Use scoped bindings to prevent cross-tenant access.
108
+
109
+ ```php
110
+ Route::scopeBindings()->group(function () {
111
+ Route::get('/accounts/{account}/projects/{project}', [ProjectController::class, 'show']);
112
+ });
113
+ ```
114
+
115
+ ### Nested Routes and Binding Names
116
+
117
+ - Keep prefixes and paths consistent to avoid double nesting (e.g., `conversation` vs `conversations`).
118
+ - Use a single parameter name that matches the bound model (e.g., `{conversation}` for `Conversation`).
119
+ - Prefer scoped bindings when nesting to enforce parent-child relationships.
120
+
121
+ ```php
122
+ use App\Http\Controllers\Api\ConversationController;
123
+ use App\Http\Controllers\Api\MessageController;
124
+ use Illuminate\Support\Facades\Route;
125
+
126
+ Route::middleware('auth:sanctum')->prefix('conversations')->group(function () {
127
+ Route::post('/', [ConversationController::class, 'store'])->name('conversations.store');
128
+
129
+ Route::scopeBindings()->group(function () {
130
+ Route::get('/{conversation}', [ConversationController::class, 'show'])
131
+ ->name('conversations.show');
132
+
133
+ Route::post('/{conversation}/messages', [MessageController::class, 'store'])
134
+ ->name('conversation-messages.store');
135
+
136
+ Route::get('/{conversation}/messages/{message}', [MessageController::class, 'show'])
137
+ ->name('conversation-messages.show');
138
+ });
139
+ });
140
+ ```
141
+
142
+ If you want a parameter to resolve to a different model class, define explicit binding. For custom binding logic, use `Route::bind()` or implement `resolveRouteBinding()` on the model.
143
+
144
+ ```php
145
+ use App\Models\AiConversation;
146
+ use Illuminate\Support\Facades\Route;
147
+
148
+ Route::model('conversation', AiConversation::class);
149
+ ```
150
+
151
+ ### Service Container Bindings
152
+
153
+ Bind interfaces to implementations in a service provider for clear dependency wiring.
154
+
155
+ ```php
156
+ use App\Repositories\EloquentOrderRepository;
157
+ use App\Repositories\OrderRepository;
158
+ use Illuminate\Support\ServiceProvider;
159
+
160
+ final class AppServiceProvider extends ServiceProvider
161
+ {
162
+ public function register(): void
163
+ {
164
+ $this->app->bind(OrderRepository::class, EloquentOrderRepository::class);
165
+ }
166
+ }
167
+ ```
168
+
169
+ ### Eloquent Model Patterns
170
+
171
+ ### Model Configuration
172
+
173
+ ```php
174
+ final class Project extends Model
175
+ {
176
+ use HasFactory;
177
+
178
+ protected $fillable = ['name', 'owner_id', 'status'];
179
+
180
+ protected $casts = [
181
+ 'status' => ProjectStatus::class,
182
+ 'archived_at' => 'datetime',
183
+ ];
184
+
185
+ public function owner(): BelongsTo
186
+ {
187
+ return $this->belongsTo(User::class, 'owner_id');
188
+ }
189
+
190
+ public function scopeActive(Builder $query): Builder
191
+ {
192
+ return $query->whereNull('archived_at');
193
+ }
194
+ }
195
+ ```
196
+
197
+ ### Custom Casts and Value Objects
198
+
199
+ Use enums or value objects for strict typing.
200
+
201
+ ```php
202
+ use Illuminate\Database\Eloquent\Casts\Attribute;
203
+
204
+ protected $casts = [
205
+ 'status' => ProjectStatus::class,
206
+ ];
207
+ ```
208
+
209
+ ```php
210
+ protected function budgetCents(): Attribute
211
+ {
212
+ return Attribute::make(
213
+ get: fn (int $value) => Money::fromCents($value),
214
+ set: fn (Money $money) => $money->toCents(),
215
+ );
216
+ }
217
+ ```
218
+
219
+ ### Eager Loading to Avoid N+1
220
+
221
+ ```php
222
+ $orders = Order::query()
223
+ ->with(['customer', 'items.product'])
224
+ ->latest()
225
+ ->paginate(25);
226
+ ```
227
+
228
+ ### Query Objects for Complex Filters
229
+
230
+ ```php
231
+ final class ProjectQuery
232
+ {
233
+ public function __construct(private Builder $query) {}
234
+
235
+ public function ownedBy(int $userId): self
236
+ {
237
+ $query = clone $this->query;
238
+
239
+ return new self($query->where('owner_id', $userId));
240
+ }
241
+
242
+ public function active(): self
243
+ {
244
+ $query = clone $this->query;
245
+
246
+ return new self($query->whereNull('archived_at'));
247
+ }
248
+
249
+ public function builder(): Builder
250
+ {
251
+ return $this->query;
252
+ }
253
+ }
254
+ ```
255
+
256
+ ### Global Scopes and Soft Deletes
257
+
258
+ Use global scopes for default filtering and `SoftDeletes` for recoverable records.
259
+ Use either a global scope or a named scope for the same filter, not both, unless you intend layered behavior.
260
+
261
+ ```php
262
+ use Illuminate\Database\Eloquent\SoftDeletes;
263
+ use Illuminate\Database\Eloquent\Builder;
264
+
265
+ final class Project extends Model
266
+ {
267
+ use SoftDeletes;
268
+
269
+ protected static function booted(): void
270
+ {
271
+ static::addGlobalScope('active', function (Builder $builder): void {
272
+ $builder->whereNull('archived_at');
273
+ });
274
+ }
275
+ }
276
+ ```
277
+
278
+ ### Query Scopes for Reusable Filters
279
+
280
+ ```php
281
+ use Illuminate\Database\Eloquent\Builder;
282
+
283
+ final class Project extends Model
284
+ {
285
+ public function scopeOwnedBy(Builder $query, int $userId): Builder
286
+ {
287
+ return $query->where('owner_id', $userId);
288
+ }
289
+ }
290
+
291
+ // In service, repository etc.
292
+ $projects = Project::ownedBy($user->id)->get();
293
+ ```
294
+
295
+ ### Transactions for Multi-Step Updates
296
+
297
+ ```php
298
+ use Illuminate\Support\Facades\DB;
299
+
300
+ DB::transaction(function (): void {
301
+ $order->update(['status' => 'paid']);
302
+ $order->items()->update(['paid_at' => now()]);
303
+ });
304
+ ```
305
+
306
+ ### Migrations
307
+
308
+ ### Naming Convention
309
+
310
+ - File names use timestamps: `YYYY_MM_DD_HHMMSS_create_users_table.php`
311
+ - Migrations use anonymous classes (no named class); the filename communicates intent
312
+ - Table names are `snake_case` and plural by default
313
+
314
+ ### Example Migration
315
+
316
+ ```php
317
+ use Illuminate\Database\Migrations\Migration;
318
+ use Illuminate\Database\Schema\Blueprint;
319
+ use Illuminate\Support\Facades\Schema;
320
+
321
+ return new class extends Migration
322
+ {
323
+ public function up(): void
324
+ {
325
+ Schema::create('orders', function (Blueprint $table): void {
326
+ $table->id();
327
+ $table->foreignId('customer_id')->constrained()->cascadeOnDelete();
328
+ $table->string('status', 32)->index();
329
+ $table->unsignedInteger('total_cents');
330
+ $table->timestamps();
331
+ });
332
+ }
333
+
334
+ public function down(): void
335
+ {
336
+ Schema::dropIfExists('orders');
337
+ }
338
+ };
339
+ ```
340
+
341
+ ### Form Requests and Validation
342
+
343
+ Keep validation in form requests and transform inputs to DTOs.
344
+
345
+ ```php
346
+ use App\Models\Order;
347
+
348
+ final class StoreOrderRequest extends FormRequest
349
+ {
350
+ public function authorize(): bool
351
+ {
352
+ return $this->user()?->can('create', Order::class) ?? false;
353
+ }
354
+
355
+ public function rules(): array
356
+ {
357
+ return [
358
+ 'customer_id' => ['required', 'integer', 'exists:customers,id'],
359
+ 'items' => ['required', 'array', 'min:1'],
360
+ 'items.*.sku' => ['required', 'string'],
361
+ 'items.*.quantity' => ['required', 'integer', 'min:1'],
362
+ ];
363
+ }
364
+
365
+ public function toDto(): CreateOrderData
366
+ {
367
+ return new CreateOrderData(
368
+ customerId: (int) $this->validated('customer_id'),
369
+ items: $this->validated('items'),
370
+ );
371
+ }
372
+ }
373
+ ```
374
+
375
+ ### API Resources
376
+
377
+ Keep API responses consistent with resources and pagination.
378
+
379
+ ```php
380
+ $projects = Project::query()->active()->paginate(25);
381
+
382
+ return response()->json([
383
+ 'success' => true,
384
+ 'data' => ProjectResource::collection($projects->items()),
385
+ 'error' => null,
386
+ 'meta' => [
387
+ 'page' => $projects->currentPage(),
388
+ 'per_page' => $projects->perPage(),
389
+ 'total' => $projects->total(),
390
+ ],
391
+ ]);
392
+ ```
393
+
394
+ ### Events, Jobs, and Queues
395
+
396
+ - Emit domain events for side effects (emails, analytics)
397
+ - Use queued jobs for slow work (reports, exports, webhooks)
398
+ - Prefer idempotent handlers with retries and backoff
399
+
400
+ ### Caching
401
+
402
+ - Cache read-heavy endpoints and expensive queries
403
+ - Invalidate caches on model events (created/updated/deleted)
404
+ - Use tags when caching related data for easy invalidation
405
+
406
+ ### Configuration and Environments
407
+
408
+ - Keep secrets in `.env` and config in `config/*.php`
409
+ - Use per-environment config overrides and `config:cache` in production
@@ -0,0 +1,279 @@
1
+ # Laravel Security Best Practices
2
+
3
+ Comprehensive security guidance for Laravel applications to protect against common vulnerabilities.
4
+
5
+ ## When to Activate
6
+
7
+ - Adding authentication or authorization
8
+ - Handling user input and file uploads
9
+ - Building new API endpoints
10
+ - Managing secrets and environment settings
11
+ - Hardening production deployments
12
+
13
+ ## How It Works
14
+
15
+ - Middleware provides baseline protections (CSRF via `VerifyCsrfToken`, security headers via `SecurityHeaders`).
16
+ - Guards and policies enforce access control (`auth:sanctum`, `$this->authorize`, policy middleware).
17
+ - Form Requests validate and shape input (`UploadInvoiceRequest`) before it reaches services.
18
+ - Rate limiting adds abuse protection (`RateLimiter::for('login')`) alongside auth controls.
19
+ - Data safety comes from encrypted casts, mass-assignment guards, and signed routes (`URL::temporarySignedRoute` + `signed` middleware).
20
+
21
+ ## Core Security Settings
22
+
23
+ - `APP_DEBUG=false` in production
24
+ - `APP_KEY` must be set and rotated on compromise
25
+ - Set `SESSION_SECURE_COOKIE=true` and `SESSION_SAME_SITE=lax` (or `strict` for sensitive apps)
26
+ - Configure trusted proxies for correct HTTPS detection
27
+
28
+ ## Session and Cookie Hardening
29
+
30
+ - Set `SESSION_HTTP_ONLY=true` to prevent JavaScript access
31
+ - Use `SESSION_SAME_SITE=strict` for high-risk flows
32
+ - Regenerate sessions on login and privilege changes
33
+
34
+ ## Authentication and Tokens
35
+
36
+ - Use Laravel Sanctum or Passport for API auth
37
+ - Prefer short-lived tokens with refresh flows for sensitive data
38
+ - Revoke tokens on logout and compromised accounts
39
+
40
+ Example route protection:
41
+
42
+ ```php
43
+ use Illuminate\Http\Request;
44
+ use Illuminate\Support\Facades\Route;
45
+
46
+ Route::middleware('auth:sanctum')->get('/me', function (Request $request) {
47
+ return $request->user();
48
+ });
49
+ ```
50
+
51
+ ## Password Security
52
+
53
+ - Hash passwords with `Hash::make()` and never store plaintext
54
+ - Use Laravel's password broker for reset flows
55
+
56
+ ```php
57
+ use Illuminate\Support\Facades\Hash;
58
+ use Illuminate\Validation\Rules\Password;
59
+
60
+ $validated = $request->validate([
61
+ 'password' => ['required', 'string', Password::min(12)->letters()->mixedCase()->numbers()->symbols()],
62
+ ]);
63
+
64
+ $user->update(['password' => Hash::make($validated['password'])]);
65
+ ```
66
+
67
+ ## Authorization: Policies and Gates
68
+
69
+ - Use policies for model-level authorization
70
+ - Enforce authorization in controllers and services
71
+
72
+ ```php
73
+ $this->authorize('update', $project);
74
+ ```
75
+
76
+ Use policy middleware for route-level enforcement:
77
+
78
+ ```php
79
+ use Illuminate\Support\Facades\Route;
80
+
81
+ Route::put('/projects/{project}', [ProjectController::class, 'update'])
82
+ ->middleware(['auth:sanctum', 'can:update,project']);
83
+ ```
84
+
85
+ ## Validation and Data Sanitization
86
+
87
+ - Always validate inputs with Form Requests
88
+ - Use strict validation rules and type checks
89
+ - Never trust request payloads for derived fields
90
+
91
+ ## Mass Assignment Protection
92
+
93
+ - Use `$fillable` or `$guarded` and avoid `Model::unguard()`
94
+ - Prefer DTOs or explicit attribute mapping
95
+
96
+ ## SQL Injection Prevention
97
+
98
+ - Use Eloquent or query builder parameter binding
99
+ - Avoid raw SQL unless strictly necessary
100
+
101
+ ```php
102
+ DB::select('select * from users where email = ?', [$email]);
103
+ ```
104
+
105
+ ## XSS Prevention
106
+
107
+ - Blade escapes output by default (`{{ }}`)
108
+ - Use `{!! !!}` only for trusted, sanitized HTML
109
+ - Sanitize rich text with a dedicated library
110
+
111
+ ## CSRF Protection
112
+
113
+ - Keep `VerifyCsrfToken` middleware enabled
114
+ - Include `@csrf` in forms and send XSRF tokens for SPA requests
115
+
116
+ For SPA authentication with Sanctum, ensure stateful requests are configured:
117
+
118
+ ```php
119
+ // config/sanctum.php
120
+ 'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', 'localhost')),
121
+ ```
122
+
123
+ ## File Upload Safety
124
+
125
+ - Validate file size, MIME type, and extension
126
+ - Store uploads outside the public path when possible
127
+ - Scan files for malware if required
128
+
129
+ ```php
130
+ final class UploadInvoiceRequest extends FormRequest
131
+ {
132
+ public function authorize(): bool
133
+ {
134
+ return (bool) $this->user()?->can('upload-invoice');
135
+ }
136
+
137
+ public function rules(): array
138
+ {
139
+ return [
140
+ 'invoice' => ['required', 'file', 'mimes:pdf', 'max:5120'],
141
+ ];
142
+ }
143
+ }
144
+ ```
145
+
146
+ ```php
147
+ $path = $request->file('invoice')->store(
148
+ 'invoices',
149
+ config('filesystems.private_disk', 'local') // set this to a non-public disk
150
+ );
151
+ ```
152
+
153
+ ## Rate Limiting
154
+
155
+ - Apply `throttle` middleware on auth and write endpoints
156
+ - Use stricter limits for login, password reset, and OTP
157
+
158
+ ```php
159
+ use Illuminate\Cache\RateLimiting\Limit;
160
+ use Illuminate\Http\Request;
161
+ use Illuminate\Support\Facades\RateLimiter;
162
+
163
+ RateLimiter::for('login', function (Request $request) {
164
+ return [
165
+ Limit::perMinute(5)->by($request->ip()),
166
+ Limit::perMinute(5)->by(strtolower((string) $request->input('email'))),
167
+ ];
168
+ });
169
+ ```
170
+
171
+ ## Secrets and Credentials
172
+
173
+ - Never commit secrets to source control
174
+ - Use environment variables and secret managers
175
+ - Rotate keys after exposure and invalidate sessions
176
+
177
+ ## Encrypted Attributes
178
+
179
+ Use encrypted casts for sensitive columns at rest.
180
+
181
+ ```php
182
+ protected $casts = [
183
+ 'api_token' => 'encrypted',
184
+ ];
185
+ ```
186
+
187
+ ## Security Headers
188
+
189
+ - Add CSP, HSTS, and frame protection where appropriate
190
+ - Use trusted proxy configuration to enforce HTTPS redirects
191
+
192
+ Example middleware to set headers:
193
+
194
+ ```php
195
+ use Illuminate\Http\Request;
196
+ use Symfony\Component\HttpFoundation\Response;
197
+
198
+ final class SecurityHeaders
199
+ {
200
+ public function handle(Request $request, \Closure $next): Response
201
+ {
202
+ $response = $next($request);
203
+
204
+ $response->headers->add([
205
+ 'Content-Security-Policy' => "default-src 'self'",
206
+ 'Strict-Transport-Security' => 'max-age=31536000', // add includeSubDomains/preload only when all subdomains are HTTPS
207
+ 'X-Frame-Options' => 'DENY',
208
+ 'X-Content-Type-Options' => 'nosniff',
209
+ 'Referrer-Policy' => 'no-referrer',
210
+ ]);
211
+
212
+ return $response;
213
+ }
214
+ }
215
+ ```
216
+
217
+ ## CORS and API Exposure
218
+
219
+ - Restrict origins in `config/cors.php`
220
+ - Avoid wildcard origins for authenticated routes
221
+
222
+ ```php
223
+ // config/cors.php
224
+ return [
225
+ 'paths' => ['api/*', 'sanctum/csrf-cookie'],
226
+ 'allowed_methods' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
227
+ 'allowed_origins' => ['https://app.example.com'],
228
+ 'allowed_headers' => [
229
+ 'Content-Type',
230
+ 'Authorization',
231
+ 'X-Requested-With',
232
+ 'X-XSRF-TOKEN',
233
+ 'X-CSRF-TOKEN',
234
+ ],
235
+ 'supports_credentials' => true,
236
+ ];
237
+ ```
238
+
239
+ ## Logging and PII
240
+
241
+ - Never log passwords, tokens, or full card data
242
+ - Redact sensitive fields in structured logs
243
+
244
+ ```php
245
+ use Illuminate\Support\Facades\Log;
246
+
247
+ Log::info('User updated profile', [
248
+ 'user_id' => $user->id,
249
+ 'email' => '[REDACTED]',
250
+ 'token' => '[REDACTED]',
251
+ ]);
252
+ ```
253
+
254
+ ## Dependency Security
255
+
256
+ - Run `composer audit` regularly
257
+ - Pin dependencies with care and update promptly on CVEs
258
+
259
+ ## Signed URLs
260
+
261
+ Use signed routes for temporary, tamper-proof links.
262
+
263
+ ```php
264
+ use Illuminate\Support\Facades\URL;
265
+
266
+ $url = URL::temporarySignedRoute(
267
+ 'downloads.invoice',
268
+ now()->addMinutes(15),
269
+ ['invoice' => $invoice->id]
270
+ );
271
+ ```
272
+
273
+ ```php
274
+ use Illuminate\Support\Facades\Route;
275
+
276
+ Route::get('/invoices/{invoice}/download', [InvoiceController::class, 'download'])
277
+ ->name('downloads.invoice')
278
+ ->middleware('signed');
279
+ ```