@cubis/foundry 0.3.71 → 0.3.73
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.
- package/CHANGELOG.md +23 -2
- package/dist/cli/core.js +9 -22
- package/dist/cli/core.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/core.ts +13 -22
- package/workflows/powers/accessibility/POWER.md +83 -94
- package/workflows/powers/accessibility/SKILL.md +82 -94
- package/workflows/powers/agent-design/POWER.md +201 -0
- package/workflows/powers/agent-design/SKILL.md +198 -0
- package/workflows/powers/agent-design/references/clarification-patterns.md +153 -0
- package/workflows/powers/agent-design/references/skill-testing.md +164 -0
- package/workflows/powers/agent-design/references/workflow-patterns.md +226 -0
- package/workflows/powers/agentic-eval/POWER.md +62 -0
- package/workflows/powers/agentic-eval/SKILL.md +59 -0
- package/workflows/powers/agentic-eval/references/rubric-and-regression-checklist.md +11 -0
- package/workflows/powers/api-designer/POWER.md +43 -71
- package/workflows/powers/api-designer/SKILL.md +43 -71
- package/workflows/powers/api-patterns/POWER.md +42 -56
- package/workflows/powers/api-patterns/SKILL.md +42 -57
- package/workflows/powers/architecture-designer/POWER.md +43 -60
- package/workflows/powers/architecture-designer/SKILL.md +43 -60
- package/workflows/powers/ask-questions-if-underspecified/POWER.md +51 -3
- package/workflows/powers/auth-architect/POWER.md +69 -0
- package/workflows/powers/auth-architect/SKILL.md +66 -0
- package/workflows/powers/auth-architect/references/session-token-policy-checklist.md +45 -0
- package/workflows/powers/behavioral-modes/POWER.md +100 -9
- package/workflows/powers/c-pro/POWER.md +105 -0
- package/workflows/powers/c-pro/SKILL.md +102 -0
- package/workflows/powers/c-pro/references/build-systems-and-toolchains.md +148 -0
- package/workflows/powers/c-pro/references/common-ub-and-portability.md +166 -0
- package/workflows/powers/c-pro/references/debugging-with-sanitizers.md +205 -0
- package/workflows/powers/c-pro/references/memory-safety-and-build-checklist.md +60 -0
- package/workflows/powers/c-pro/references/posix-and-platform-apis.md +244 -0
- package/workflows/powers/changelog-generator/POWER.md +127 -63
- package/workflows/powers/changelog-generator/SKILL.md +126 -63
- package/workflows/powers/ci-cd-pipelines/POWER.md +156 -0
- package/workflows/powers/ci-cd-pipelines/SKILL.md +153 -0
- package/workflows/powers/ci-cd-pipelines/references/github-actions-patterns.md +160 -0
- package/workflows/powers/ci-cd-pipelines/references/pipeline-security-checklist.md +57 -0
- package/workflows/powers/cli-developer/POWER.md +152 -95
- package/workflows/powers/cli-developer/SKILL.md +152 -95
- package/workflows/powers/cpp-pro/POWER.md +111 -0
- package/workflows/powers/cpp-pro/SKILL.md +108 -0
- package/workflows/powers/cpp-pro/references/concurrency-primitives.md +266 -0
- package/workflows/powers/cpp-pro/references/move-semantics-and-value-types.md +149 -0
- package/workflows/powers/cpp-pro/references/performance-and-profiling.md +191 -0
- package/workflows/powers/cpp-pro/references/raii-and-modern-cpp-checklist.md +87 -0
- package/workflows/powers/cpp-pro/references/template-and-concepts-patterns.md +205 -0
- package/workflows/powers/csharp-pro/POWER.md +47 -22
- package/workflows/powers/csharp-pro/SKILL.md +47 -22
- package/workflows/powers/dart-pro/POWER.md +68 -0
- package/workflows/powers/dart-pro/SKILL.md +65 -0
- package/workflows/powers/dart-pro/references/isolate-and-concurrency.md +180 -0
- package/workflows/powers/dart-pro/references/null-safety-and-async-patterns.md +133 -0
- package/workflows/powers/dart-pro/references/package-structure-and-linting.md +193 -0
- package/workflows/powers/dart-pro/references/sealed-records-patterns.md +173 -0
- package/workflows/powers/dart-pro/references/testing-and-mocking.md +235 -0
- package/workflows/powers/database-design/POWER.md +47 -33
- package/workflows/powers/database-design/SKILL.md +47 -33
- package/workflows/powers/database-optimizer/POWER.md +43 -64
- package/workflows/powers/database-optimizer/SKILL.md +43 -64
- package/workflows/powers/database-skills/POWER.md +59 -93
- package/workflows/powers/database-skills/SKILL.md +59 -93
- package/workflows/powers/debugging-strategies/POWER.md +69 -0
- package/workflows/powers/debugging-strategies/SKILL.md +66 -0
- package/workflows/powers/debugging-strategies/references/reproduce-isolate-verify-checklist.md +42 -0
- package/workflows/powers/deep-research/POWER.md +67 -0
- package/workflows/powers/deep-research/SKILL.md +64 -0
- package/workflows/powers/deep-research/references/multi-round-research-loop.md +80 -0
- package/workflows/powers/design-system-builder/POWER.md +130 -116
- package/workflows/powers/design-system-builder/SKILL.md +130 -116
- package/workflows/powers/devops-engineer/POWER.md +120 -57
- package/workflows/powers/devops-engineer/SKILL.md +120 -57
- package/workflows/powers/docker-kubernetes/POWER.md +94 -0
- package/workflows/powers/docker-kubernetes/SKILL.md +91 -0
- package/workflows/powers/docker-kubernetes/references/dockerfile-optimization-checklist.md +35 -0
- package/workflows/powers/docker-kubernetes/references/kubernetes-deployment-patterns.md +59 -0
- package/workflows/powers/documentation-templates/POWER.md +158 -127
- package/workflows/powers/documentation-templates/SKILL.md +158 -127
- package/workflows/powers/drizzle-expert/POWER.md +66 -0
- package/workflows/powers/drizzle-expert/SKILL.md +63 -0
- package/workflows/powers/drizzle-expert/references/runtime-pairing-matrix.md +16 -0
- package/workflows/powers/drizzle-expert/references/schema-and-migration-playbook.md +18 -0
- package/workflows/powers/error-ux-observability/POWER.md +144 -131
- package/workflows/powers/error-ux-observability/SKILL.md +143 -131
- package/workflows/powers/fastapi-expert/POWER.md +46 -60
- package/workflows/powers/fastapi-expert/SKILL.md +46 -60
- package/workflows/powers/firebase/POWER.md +65 -0
- package/workflows/powers/firebase/SKILL.md +62 -0
- package/workflows/powers/firebase/references/platform-routing.md +16 -0
- package/workflows/powers/firebase/references/rules-and-indexes-checklist.md +11 -0
- package/workflows/powers/flutter-design-system/POWER.md +63 -0
- package/workflows/powers/flutter-design-system/SKILL.md +60 -0
- package/workflows/powers/flutter-design-system/references/shared-widgets.md +29 -0
- package/workflows/powers/flutter-design-system/references/tokens-and-theme.md +34 -0
- package/workflows/powers/flutter-drift/POWER.md +65 -0
- package/workflows/powers/flutter-drift/SKILL.md +62 -0
- package/workflows/powers/flutter-drift/references/migrations.md +22 -0
- package/workflows/powers/flutter-drift/references/query-patterns.md +26 -0
- package/workflows/powers/flutter-feature/POWER.md +65 -0
- package/workflows/powers/flutter-feature/SKILL.md +62 -0
- package/workflows/powers/flutter-feature/references/architecture-rules.md +85 -0
- package/workflows/powers/flutter-feature/references/composite-provider.md +58 -0
- package/workflows/powers/flutter-feature/references/outbox-pattern.md +87 -0
- package/workflows/powers/flutter-feature/references/testing-patterns.md +218 -0
- package/workflows/powers/flutter-go-router/POWER.md +64 -0
- package/workflows/powers/flutter-go-router/SKILL.md +61 -0
- package/workflows/powers/flutter-go-router/references/guards-and-deeplinks.md +20 -0
- package/workflows/powers/flutter-go-router/references/typed-routes.md +27 -0
- package/workflows/powers/flutter-offline-sync/POWER.md +62 -0
- package/workflows/powers/flutter-offline-sync/SKILL.md +59 -0
- package/workflows/powers/flutter-offline-sync/references/outbox-full.md +44 -0
- package/workflows/powers/flutter-repository/POWER.md +64 -0
- package/workflows/powers/flutter-repository/SKILL.md +61 -0
- package/workflows/powers/flutter-repository/references/drift-patterns.md +21 -0
- package/workflows/powers/flutter-repository/references/retrofit-patterns.md +20 -0
- package/workflows/powers/flutter-riverpod/POWER.md +70 -0
- package/workflows/powers/flutter-riverpod/SKILL.md +67 -0
- package/workflows/powers/flutter-riverpod/references/async-and-mutations.md +19 -0
- package/workflows/powers/flutter-riverpod/references/async-lifecycle.md +19 -0
- package/workflows/powers/flutter-riverpod/references/provider-selection.md +20 -0
- package/workflows/powers/flutter-riverpod/references/testing.md +21 -0
- package/workflows/powers/flutter-riverpod/references/version-matrix.md +24 -0
- package/workflows/powers/flutter-state-machine/POWER.md +62 -0
- package/workflows/powers/flutter-state-machine/SKILL.md +59 -0
- package/workflows/powers/flutter-state-machine/references/app-state-contract.md +23 -0
- package/workflows/powers/flutter-state-machine/references/ui-rendering.md +14 -0
- package/workflows/powers/flutter-testing/POWER.md +64 -0
- package/workflows/powers/flutter-testing/SKILL.md +61 -0
- package/workflows/powers/flutter-testing/references/offline-sync-tests.md +16 -0
- package/workflows/powers/flutter-testing/references/test-layers.md +33 -0
- package/workflows/powers/frontend-code-review/POWER.md +137 -0
- package/workflows/powers/frontend-code-review/SKILL.md +134 -0
- package/workflows/powers/frontend-code-review/references/common-antipatterns.md +86 -0
- package/workflows/powers/frontend-code-review/references/performance-budgets.md +56 -0
- package/workflows/powers/frontend-code-review/references/review-checklists.md +47 -0
- package/workflows/powers/frontend-design/POWER.md +163 -362
- package/workflows/powers/frontend-design/SKILL.md +163 -362
- package/workflows/powers/game-development/POWER.md +57 -140
- package/workflows/powers/game-development/SKILL.md +57 -140
- package/workflows/powers/geo-fundamentals/POWER.md +64 -126
- package/workflows/powers/geo-fundamentals/SKILL.md +64 -127
- package/workflows/powers/git-workflow/POWER.md +135 -0
- package/workflows/powers/git-workflow/SKILL.md +132 -0
- package/workflows/powers/git-workflow/references/pr-review-checklist.md +63 -0
- package/workflows/powers/golang-pro/POWER.md +46 -35
- package/workflows/powers/golang-pro/SKILL.md +46 -35
- package/workflows/powers/graphql-architect/POWER.md +44 -62
- package/workflows/powers/graphql-architect/SKILL.md +44 -62
- package/workflows/powers/i18n-localization/POWER.md +118 -103
- package/workflows/powers/i18n-localization/SKILL.md +118 -103
- package/workflows/powers/java-pro/POWER.md +47 -22
- package/workflows/powers/java-pro/SKILL.md +47 -22
- package/workflows/powers/javascript-pro/POWER.md +47 -34
- package/workflows/powers/javascript-pro/SKILL.md +47 -34
- package/workflows/powers/kotlin-pro/POWER.md +46 -23
- package/workflows/powers/kotlin-pro/SKILL.md +46 -23
- package/workflows/powers/legacy-modernizer/POWER.md +43 -60
- package/workflows/powers/legacy-modernizer/SKILL.md +43 -60
- package/workflows/powers/mcp-builder/POWER.md +65 -0
- package/workflows/powers/mcp-builder/SKILL.md +62 -0
- package/workflows/powers/mcp-builder/references/testing-and-evals.md +17 -0
- package/workflows/powers/mcp-builder/references/transport-and-tool-design.md +17 -0
- package/workflows/powers/microservices-architect/POWER.md +43 -70
- package/workflows/powers/microservices-architect/SKILL.md +43 -70
- package/workflows/powers/mobile-design/POWER.md +110 -345
- package/workflows/powers/mobile-design/SKILL.md +110 -345
- package/workflows/powers/mongodb/POWER.md +67 -0
- package/workflows/powers/mongodb/SKILL.md +64 -0
- package/workflows/powers/mongodb/references/mongodb-checklist.md +20 -0
- package/workflows/powers/mysql/POWER.md +67 -0
- package/workflows/powers/mysql/SKILL.md +64 -0
- package/workflows/powers/mysql/references/mysql-checklist.md +20 -0
- package/workflows/powers/neki/POWER.md +67 -0
- package/workflows/powers/neki/SKILL.md +64 -0
- package/workflows/powers/neki/references/neki-checklist.md +18 -0
- package/workflows/powers/nestjs-expert/POWER.md +45 -91
- package/workflows/powers/nestjs-expert/SKILL.md +45 -91
- package/workflows/powers/nextjs-developer/POWER.md +51 -44
- package/workflows/powers/nextjs-developer/SKILL.md +51 -44
- package/workflows/powers/nodejs-best-practices/POWER.md +48 -29
- package/workflows/powers/nodejs-best-practices/SKILL.md +48 -29
- package/workflows/powers/observability/POWER.md +109 -0
- package/workflows/powers/observability/SKILL.md +106 -0
- package/workflows/powers/observability/references/alerting-and-slo-checklist.md +87 -0
- package/workflows/powers/observability/references/opentelemetry-setup-guide.md +121 -0
- package/workflows/powers/openai-docs/POWER.md +61 -0
- package/workflows/powers/openai-docs/SKILL.md +58 -0
- package/workflows/powers/openai-docs/references/official-source-playbook.md +10 -0
- package/workflows/powers/performance-profiling/POWER.md +61 -114
- package/workflows/powers/performance-profiling/SKILL.md +61 -114
- package/workflows/powers/php-pro/POWER.md +116 -0
- package/workflows/powers/php-pro/SKILL.md +113 -0
- package/workflows/powers/php-pro/references/architecture-and-di.md +239 -0
- package/workflows/powers/php-pro/references/modern-php-features.md +189 -0
- package/workflows/powers/php-pro/references/performance-and-deployment.md +197 -0
- package/workflows/powers/php-pro/references/php84-strict-typing-checklist.md +161 -0
- package/workflows/powers/php-pro/references/testing-and-static-analysis.md +235 -0
- package/workflows/powers/playwright-e2e/POWER.md +85 -0
- package/workflows/powers/playwright-e2e/SKILL.md +82 -0
- package/workflows/powers/playwright-e2e/references/locator-trace-flake-checklist.md +80 -0
- package/workflows/powers/postgres/POWER.md +67 -0
- package/workflows/powers/postgres/SKILL.md +64 -0
- package/workflows/powers/postgres/references/postgres-checklist.md +20 -0
- package/workflows/powers/prompt-engineer/POWER.md +47 -30
- package/workflows/powers/prompt-engineer/SKILL.md +47 -30
- package/workflows/powers/python-pro/POWER.md +47 -36
- package/workflows/powers/python-pro/SKILL.md +47 -36
- package/workflows/powers/react-best-practices/POWER.md +56 -33
- package/workflows/powers/react-best-practices/SKILL.md +56 -33
- package/workflows/powers/react-expert/POWER.md +47 -37
- package/workflows/powers/react-expert/SKILL.md +47 -37
- package/workflows/powers/redis/POWER.md +67 -0
- package/workflows/powers/redis/SKILL.md +64 -0
- package/workflows/powers/redis/references/redis-checklist.md +19 -0
- package/workflows/powers/ruby-pro/POWER.md +118 -0
- package/workflows/powers/ruby-pro/SKILL.md +115 -0
- package/workflows/powers/ruby-pro/references/modern-ruby-features.md +189 -0
- package/workflows/powers/ruby-pro/references/object-design-patterns.md +220 -0
- package/workflows/powers/ruby-pro/references/performance-and-profiling.md +224 -0
- package/workflows/powers/ruby-pro/references/ruby-concurrency-and-testing.md +190 -0
- package/workflows/powers/ruby-pro/references/testing-and-rspec.md +236 -0
- package/workflows/powers/rust-pro/POWER.md +45 -31
- package/workflows/powers/rust-pro/SKILL.md +45 -31
- package/workflows/powers/security-engineer/POWER.md +129 -0
- package/workflows/powers/security-engineer/SKILL.md +126 -0
- package/workflows/powers/seo-fundamentals/POWER.md +59 -102
- package/workflows/powers/seo-fundamentals/SKILL.md +59 -102
- package/workflows/powers/serverless-patterns/POWER.md +171 -0
- package/workflows/powers/serverless-patterns/SKILL.md +168 -0
- package/workflows/powers/skill-creator/POWER.md +90 -0
- package/workflows/powers/skill-creator/SKILL.md +87 -0
- package/workflows/powers/skill-creator/references/platform-formats.md +181 -0
- package/workflows/powers/skill-creator/references/schemas.md +430 -0
- package/workflows/powers/spec-miner/POWER.md +49 -57
- package/workflows/powers/spec-miner/SKILL.md +49 -57
- package/workflows/powers/sqlite/POWER.md +67 -0
- package/workflows/powers/sqlite/SKILL.md +64 -0
- package/workflows/powers/sqlite/references/sqlite-checklist.md +19 -0
- package/workflows/powers/sre-engineer/POWER.md +123 -64
- package/workflows/powers/sre-engineer/SKILL.md +123 -64
- package/workflows/powers/static-analysis/POWER.md +121 -77
- package/workflows/powers/static-analysis/SKILL.md +121 -77
- package/workflows/powers/stripe-best-practices/POWER.md +140 -17
- package/workflows/powers/stripe-best-practices/SKILL.md +139 -17
- package/workflows/powers/supabase/POWER.md +67 -0
- package/workflows/powers/supabase/SKILL.md +64 -0
- package/workflows/powers/supabase/references/supabase-checklist.md +19 -0
- package/workflows/powers/swift-pro/POWER.md +118 -0
- package/workflows/powers/swift-pro/SKILL.md +115 -0
- package/workflows/powers/swift-pro/references/concurrency-patterns.md +165 -0
- package/workflows/powers/swift-pro/references/protocol-and-generics.md +172 -0
- package/workflows/powers/swift-pro/references/sendable-and-isolation.md +116 -0
- package/workflows/powers/swift-pro/references/swift-concurrency-and-protocols.md +260 -0
- package/workflows/powers/swift-pro/references/testing-and-packages.md +192 -0
- package/workflows/powers/tailwind-patterns/POWER.md +71 -240
- package/workflows/powers/tailwind-patterns/SKILL.md +71 -240
- package/workflows/powers/testing-patterns/POWER.md +155 -10
- package/workflows/powers/testing-patterns/SKILL.md +155 -10
- package/workflows/powers/typescript-pro/POWER.md +47 -38
- package/workflows/powers/typescript-pro/SKILL.md +47 -38
- package/workflows/powers/vitess/POWER.md +67 -0
- package/workflows/powers/vitess/SKILL.md +64 -0
- package/workflows/powers/vitess/references/vitess-checklist.md +19 -0
- package/workflows/powers/vulnerability-scanner/POWER.md +146 -10
- package/workflows/powers/vulnerability-scanner/SKILL.md +146 -10
- package/workflows/powers/web-perf/POWER.md +43 -170
- package/workflows/powers/web-perf/SKILL.md +43 -170
- package/workflows/powers/webapp-testing/POWER.md +43 -164
- package/workflows/powers/webapp-testing/SKILL.md +43 -164
- package/workflows/workflows/agent-environment-setup/platforms/antigravity/rules/GEMINI.md +65 -42
- package/workflows/workflows/agent-environment-setup/platforms/claude/rules/CLAUDE.md +8 -6
- package/workflows/workflows/agent-environment-setup/platforms/codex/rules/AGENTS.md +65 -41
- package/workflows/workflows/agent-environment-setup/platforms/copilot/rules/copilot-instructions.md +8 -6
- package/workflows/workflows/agent-environment-setup/shared/rules/STEERING.md +9 -8
- package/workflows/workflows/agent-environment-setup/shared/rules/overrides/codex.md +1 -1
|
@@ -1,143 +1,90 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: performance-profiling
|
|
3
|
-
description:
|
|
4
|
-
|
|
3
|
+
description: "Use when measuring, analyzing, and optimizing application performance with Core Web Vitals, bundle analysis, runtime profiling, and lighthouse audits."
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: cubis-foundry
|
|
7
|
+
version: "1.0"
|
|
8
|
+
compatibility: Claude Code, Codex, GitHub Copilot
|
|
5
9
|
---
|
|
6
10
|
|
|
7
11
|
# Performance Profiling
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
## Purpose
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
Use when measuring, analyzing, and optimizing application performance with Core Web Vitals, bundle analysis, runtime profiling, and lighthouse audits.
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
## When to Use
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
- Measuring and improving Core Web Vitals (LCP, INP, CLS).
|
|
20
|
+
- Analyzing bundle size, finding large dependencies, and code splitting.
|
|
21
|
+
- Profiling runtime performance in browser Performance or Memory tabs.
|
|
22
|
+
- Diagnosing performance bottlenecks (slow API, large payload, memory leak, layout thrash).
|
|
23
|
+
- Planning performance optimization with measurement-first discipline.
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
## 1. Core Web Vitals
|
|
22
|
-
|
|
23
|
-
### Targets
|
|
24
|
-
|
|
25
|
-
| Metric | Good | Poor | Measures |
|
|
26
|
-
|--------|------|------|----------|
|
|
27
|
-
| **LCP** | < 2.5s | > 4.0s | Loading |
|
|
28
|
-
| **INP** | < 200ms | > 500ms | Interactivity |
|
|
29
|
-
| **CLS** | < 0.1 | > 0.25 | Stability |
|
|
30
|
-
|
|
31
|
-
### When to Measure
|
|
32
|
-
|
|
33
|
-
| Stage | Tool |
|
|
34
|
-
|-------|------|
|
|
35
|
-
| Development | Local Lighthouse |
|
|
36
|
-
| CI/CD | Lighthouse CI |
|
|
37
|
-
| Production | RUM (Real User Monitoring) |
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## 2. Profiling Workflow
|
|
42
|
-
|
|
43
|
-
### The 4-Step Process
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
1. BASELINE → Measure current state
|
|
47
|
-
2. IDENTIFY → Find the bottleneck
|
|
48
|
-
3. FIX → Make targeted change
|
|
49
|
-
4. VALIDATE → Confirm improvement
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Profiling Tool Selection
|
|
25
|
+
## Instructions
|
|
53
26
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
| Runtime | DevTools Performance |
|
|
59
|
-
| Memory | DevTools Memory |
|
|
60
|
-
| Network | DevTools Network |
|
|
27
|
+
1. Baseline — measure current performance with Lighthouse, WebPageTest, or browser DevTools.
|
|
28
|
+
2. Identify — find the biggest bottleneck using profiling data, not assumptions.
|
|
29
|
+
3. Fix — apply targeted optimization for the measured bottleneck.
|
|
30
|
+
4. Validate — re-measure to confirm improvement and check for regressions.
|
|
61
31
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
## 3. Bundle Analysis
|
|
65
|
-
|
|
66
|
-
### What to Look For
|
|
67
|
-
|
|
68
|
-
| Issue | Indicator |
|
|
69
|
-
|-------|-----------|
|
|
70
|
-
| Large dependencies | Top of bundle |
|
|
71
|
-
| Duplicate code | Multiple chunks |
|
|
72
|
-
| Unused code | Low coverage |
|
|
73
|
-
| Missing splits | Single large chunk |
|
|
74
|
-
|
|
75
|
-
### Optimization Actions
|
|
76
|
-
|
|
77
|
-
| Finding | Action |
|
|
78
|
-
|---------|--------|
|
|
79
|
-
| Big library | Import specific modules |
|
|
80
|
-
| Duplicate deps | Dedupe, update versions |
|
|
81
|
-
| Route in main | Code split |
|
|
82
|
-
| Unused exports | Tree shake |
|
|
32
|
+
### Core Web Vitals targets
|
|
83
33
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
34
|
+
| Metric | Good | Needs Improvement | Poor |
|
|
35
|
+
| ------ | ------- | ----------------- | ------- |
|
|
36
|
+
| LCP | < 2.5s | 2.5s – 4.0s | > 4.0s |
|
|
37
|
+
| INP | < 200ms | 200ms – 500ms | > 500ms |
|
|
38
|
+
| CLS | < 0.1 | 0.1 – 0.25 | > 0.25 |
|
|
87
39
|
|
|
88
|
-
###
|
|
40
|
+
### Baseline standards
|
|
89
41
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
| Script | JavaScript execution |
|
|
42
|
+
- Always measure before optimizing — intuition is unreliable for performance.
|
|
43
|
+
- Use real user metrics (RUM) alongside synthetic benchmarks.
|
|
44
|
+
- Profile on representative hardware, not just developer machines.
|
|
45
|
+
- Address the largest bottleneck first for maximum impact.
|
|
46
|
+
- Verify optimizations don't introduce regressions elsewhere.
|
|
96
47
|
|
|
97
|
-
###
|
|
48
|
+
### Quick wins priority
|
|
98
49
|
|
|
99
|
-
|
|
|
100
|
-
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
|
50
|
+
| Priority | Action | Typical Impact |
|
|
51
|
+
| -------- | -------------------------------- | ------------------------- |
|
|
52
|
+
| 1 | Enable compression (gzip/brotli) | 60-80% transfer reduction |
|
|
53
|
+
| 2 | Lazy load below-fold images | LCP improvement |
|
|
54
|
+
| 3 | Code split routes | Initial load reduction |
|
|
55
|
+
| 4 | Set proper cache headers | Repeat visit speed |
|
|
56
|
+
| 5 | Optimize images (WebP/AVIF) | Transfer size reduction |
|
|
104
57
|
|
|
105
|
-
|
|
58
|
+
### Common bottlenecks by symptom
|
|
106
59
|
|
|
107
|
-
|
|
60
|
+
| Symptom | Likely Cause | Investigation |
|
|
61
|
+
| ----------------- | --------------------------------------- | ---------------------------------- |
|
|
62
|
+
| Slow initial load | Large bundle, render-blocking resources | Bundle analysis, waterfall |
|
|
63
|
+
| Janky scrolling | Layout thrash, paint storms | Performance tab, layers panel |
|
|
64
|
+
| Memory growth | Detached DOM, event listener leaks | Memory tab, heap snapshots |
|
|
65
|
+
| Slow interaction | Long tasks, main thread blocking | Performance tab, long task markers |
|
|
108
66
|
|
|
109
|
-
###
|
|
67
|
+
### Constraints
|
|
110
68
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
| Jank during scroll | Layout thrashing |
|
|
116
|
-
| Growing memory | Leaks, retained refs |
|
|
69
|
+
- Never optimize without measuring first.
|
|
70
|
+
- Never assume a change improved performance — always validate with data.
|
|
71
|
+
- Never sacrifice correctness for performance.
|
|
72
|
+
- Avoid premature optimization of code paths that aren't bottlenecks.
|
|
117
73
|
|
|
118
|
-
|
|
74
|
+
## Output Format
|
|
119
75
|
|
|
120
|
-
|
|
76
|
+
Provide measurement data, identified bottlenecks with evidence, optimization recommendations, and before/after comparisons.
|
|
121
77
|
|
|
122
|
-
|
|
123
|
-
|----------|--------|--------|
|
|
124
|
-
| 1 | Enable compression | High |
|
|
125
|
-
| 2 | Lazy load images | High |
|
|
126
|
-
| 3 | Code split routes | High |
|
|
127
|
-
| 4 | Cache static assets | Medium |
|
|
128
|
-
| 5 | Optimize images | Medium |
|
|
78
|
+
## References
|
|
129
79
|
|
|
130
|
-
|
|
80
|
+
No reference files for this skill right now.
|
|
131
81
|
|
|
132
|
-
##
|
|
82
|
+
## Scripts
|
|
133
83
|
|
|
134
|
-
|
|
135
|
-
|----------|-------|
|
|
136
|
-
| Guess at problems | Profile first |
|
|
137
|
-
| Micro-optimize | Fix biggest issue |
|
|
138
|
-
| Optimize early | Optimize when needed |
|
|
139
|
-
| Ignore real users | Use RUM data |
|
|
84
|
+
No helper scripts are required for this skill right now.
|
|
140
85
|
|
|
141
|
-
|
|
86
|
+
## Examples
|
|
142
87
|
|
|
143
|
-
|
|
88
|
+
- "Profile and optimize the Core Web Vitals for our landing page"
|
|
89
|
+
- "Analyze our bundle and recommend code splitting strategy"
|
|
90
|
+
- "Find and fix the memory leak in our real-time dashboard"
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
````markdown
|
|
2
|
+
---
|
|
3
|
+
inclusion: manual
|
|
4
|
+
name: php-pro
|
|
5
|
+
description: "Use for modern PHP 8.4-era backend and application engineering with strict typing, framework-aware architecture, testing, and operational safety."
|
|
6
|
+
license: MIT
|
|
7
|
+
metadata:
|
|
8
|
+
author: cubis-foundry
|
|
9
|
+
version: "2.0"
|
|
10
|
+
compatibility: Claude Code, Codex, GitHub Copilot
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# PHP Pro
|
|
14
|
+
|
|
15
|
+
## Purpose
|
|
16
|
+
|
|
17
|
+
Use for modern PHP 8.4-era backend and application engineering with strict typing, framework-aware architecture, testing, and operational safety.
|
|
18
|
+
|
|
19
|
+
## When to Use
|
|
20
|
+
|
|
21
|
+
- Building or refactoring PHP services and applications.
|
|
22
|
+
- Tightening typing, dependency boundaries, and package hygiene.
|
|
23
|
+
- Improving request handling, background jobs, and test structure.
|
|
24
|
+
|
|
25
|
+
## Instructions
|
|
26
|
+
|
|
27
|
+
1. Confirm runtime, framework, and PHP version baseline.
|
|
28
|
+
2. Enable strict typing and explicit contracts at module boundaries.
|
|
29
|
+
3. Keep service, controller, and persistence responsibilities separate.
|
|
30
|
+
4. Prefer deterministic Composer and test workflows.
|
|
31
|
+
5. Validate with targeted tests and static analysis where available.
|
|
32
|
+
|
|
33
|
+
### Baseline standards
|
|
34
|
+
|
|
35
|
+
- Add `declare(strict_types=1);` to every PHP file. No exceptions.
|
|
36
|
+
- Use typed properties, parameter types, and return types on all public methods.
|
|
37
|
+
- Run PHPStan or Psalm at level 8+ in CI. Treat analysis failures as build failures.
|
|
38
|
+
- Use PHP CS Fixer or PHP_CodeSniffer for consistent formatting.
|
|
39
|
+
- Pin Composer dependencies to exact versions in `composer.lock`. Commit the lock file.
|
|
40
|
+
|
|
41
|
+
### Type system
|
|
42
|
+
|
|
43
|
+
- Use union types (`string|int`), intersection types (`Countable&Iterator`), and `never` return type where they add clarity.
|
|
44
|
+
- Use enums (backed or pure) instead of string/int constants for fixed value sets.
|
|
45
|
+
- Use readonly properties and readonly classes for immutable data transfer objects.
|
|
46
|
+
- Prefer named arguments for functions with many optional parameters.
|
|
47
|
+
- Use `null` as a return type only when null is a meaningful domain value — prefer exceptions or result objects for errors.
|
|
48
|
+
|
|
49
|
+
### Architecture patterns
|
|
50
|
+
|
|
51
|
+
- Separate request handling (controllers) from business logic (services) from persistence (repositories).
|
|
52
|
+
- Use dependency injection (constructor injection preferred) — avoid `new` inside business logic.
|
|
53
|
+
- Keep controllers thin: validate input, call service, return response. No business logic in controllers.
|
|
54
|
+
- Use value objects for domain concepts (Money, Email, UserId) instead of primitive types.
|
|
55
|
+
- Use interfaces at module boundaries. Concrete implementations are internal details.
|
|
56
|
+
|
|
57
|
+
### Error handling
|
|
58
|
+
|
|
59
|
+
- Use specific exception classes per failure domain (e.g., `UserNotFoundException`, `ValidationException`).
|
|
60
|
+
- Catch exceptions at the boundary layer (controller, middleware) — not inside business logic unless recovery is possible.
|
|
61
|
+
- Never catch `\Exception` or `\Throwable` silently. At minimum, log the exception.
|
|
62
|
+
- Use result objects or typed return values instead of exceptions for expected failure paths (validation, not-found).
|
|
63
|
+
|
|
64
|
+
### Testing
|
|
65
|
+
|
|
66
|
+
- Use PHPUnit for unit and integration tests. Use Pest for more readable test syntax when the team prefers it.
|
|
67
|
+
- Mock external dependencies (HTTP clients, databases, file systems) — test business logic in isolation.
|
|
68
|
+
- Use data providers for parameterized tests instead of copy-paste test methods.
|
|
69
|
+
- Run tests in CI with code coverage reporting. Target meaningful coverage, not 100%.
|
|
70
|
+
- Use fixtures and factories for test data — never rely on production database state.
|
|
71
|
+
|
|
72
|
+
### Composer and dependencies
|
|
73
|
+
|
|
74
|
+
- Run `composer audit` in CI to catch known vulnerabilities.
|
|
75
|
+
- Use `composer outdated` to identify stale dependencies. Update regularly.
|
|
76
|
+
- Prefer well-maintained packages with active security patch records.
|
|
77
|
+
- Use autoloading via `composer.json` PSR-4 — never use `require`/`include` for class loading.
|
|
78
|
+
|
|
79
|
+
### Performance
|
|
80
|
+
|
|
81
|
+
- Use OPcache in production with preloading for frequently used classes.
|
|
82
|
+
- Profile with Xdebug or Blackfire before optimizing. Measure, don't guess.
|
|
83
|
+
- Use connection pooling (Swoole, FrankenPHP, or external proxy) for high-concurrency workloads.
|
|
84
|
+
- Cache expensive computations and database queries — invalidate on writes.
|
|
85
|
+
|
|
86
|
+
### Constraints
|
|
87
|
+
|
|
88
|
+
- Avoid `mixed` type as a lazy escape — use proper union types or generics (via PHPStan/Psalm).
|
|
89
|
+
- Avoid `@` error suppression operator — handle errors explicitly.
|
|
90
|
+
- Avoid global functions or static state for business logic — makes testing impossible.
|
|
91
|
+
- Avoid concatenating SQL strings — use prepared statements or query builders.
|
|
92
|
+
- Avoid storing sensitive data in plain-text config files — use environment variables or vault.
|
|
93
|
+
|
|
94
|
+
## Output Format
|
|
95
|
+
|
|
96
|
+
Provide implementation guidance, code examples, and configuration as appropriate to the task.
|
|
97
|
+
|
|
98
|
+
## References
|
|
99
|
+
|
|
100
|
+
| File | Load when |
|
|
101
|
+
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
102
|
+
| `references/php84-strict-typing-checklist.md` | Strict typing migration, enum patterns, readonly properties, PHPStan configuration, or Composer security audit is needed. |
|
|
103
|
+
| `references/modern-php-features.md` | You need enums, fibers, readonly classes, match expressions, named args, or first-class callable syntax. |
|
|
104
|
+
| `references/testing-and-static-analysis.md` | You need PHPUnit/Pest setup, data providers, mocking, PHPStan/Psalm config, or CI test pipeline patterns. |
|
|
105
|
+
| `references/architecture-and-di.md` | You need DI container patterns, service layers, repository design, or value object implementations. |
|
|
106
|
+
| `references/performance-and-deployment.md` | You need OPcache tuning, preloading, connection pooling, profiling with Xdebug/Blackfire, or FrankenPHP/Swoole setup. |
|
|
107
|
+
|
|
108
|
+
## Scripts
|
|
109
|
+
|
|
110
|
+
No helper scripts are required for this skill right now. Keep execution in `SKILL.md` and `references/` unless repeated automation becomes necessary.
|
|
111
|
+
|
|
112
|
+
## Examples
|
|
113
|
+
|
|
114
|
+
- "Help me with php pro best practices in this project"
|
|
115
|
+
- "Review my php pro implementation for issues"
|
|
116
|
+
````
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: php-pro
|
|
3
|
+
description: "Use for modern PHP 8.4-era backend and application engineering with strict typing, framework-aware architecture, testing, and operational safety."
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: cubis-foundry
|
|
7
|
+
version: "2.0"
|
|
8
|
+
compatibility: Claude Code, Codex, GitHub Copilot
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# PHP Pro
|
|
12
|
+
|
|
13
|
+
## Purpose
|
|
14
|
+
|
|
15
|
+
Use for modern PHP 8.4-era backend and application engineering with strict typing, framework-aware architecture, testing, and operational safety.
|
|
16
|
+
|
|
17
|
+
## When to Use
|
|
18
|
+
|
|
19
|
+
- Building or refactoring PHP services and applications.
|
|
20
|
+
- Tightening typing, dependency boundaries, and package hygiene.
|
|
21
|
+
- Improving request handling, background jobs, and test structure.
|
|
22
|
+
|
|
23
|
+
## Instructions
|
|
24
|
+
|
|
25
|
+
1. Confirm runtime, framework, and PHP version baseline.
|
|
26
|
+
2. Enable strict typing and explicit contracts at module boundaries.
|
|
27
|
+
3. Keep service, controller, and persistence responsibilities separate.
|
|
28
|
+
4. Prefer deterministic Composer and test workflows.
|
|
29
|
+
5. Validate with targeted tests and static analysis where available.
|
|
30
|
+
|
|
31
|
+
### Baseline standards
|
|
32
|
+
|
|
33
|
+
- Add `declare(strict_types=1);` to every PHP file. No exceptions.
|
|
34
|
+
- Use typed properties, parameter types, and return types on all public methods.
|
|
35
|
+
- Run PHPStan or Psalm at level 8+ in CI. Treat analysis failures as build failures.
|
|
36
|
+
- Use PHP CS Fixer or PHP_CodeSniffer for consistent formatting.
|
|
37
|
+
- Pin Composer dependencies to exact versions in `composer.lock`. Commit the lock file.
|
|
38
|
+
|
|
39
|
+
### Type system
|
|
40
|
+
|
|
41
|
+
- Use union types (`string|int`), intersection types (`Countable&Iterator`), and `never` return type where they add clarity.
|
|
42
|
+
- Use enums (backed or pure) instead of string/int constants for fixed value sets.
|
|
43
|
+
- Use readonly properties and readonly classes for immutable data transfer objects.
|
|
44
|
+
- Prefer named arguments for functions with many optional parameters.
|
|
45
|
+
- Use `null` as a return type only when null is a meaningful domain value — prefer exceptions or result objects for errors.
|
|
46
|
+
|
|
47
|
+
### Architecture patterns
|
|
48
|
+
|
|
49
|
+
- Separate request handling (controllers) from business logic (services) from persistence (repositories).
|
|
50
|
+
- Use dependency injection (constructor injection preferred) — avoid `new` inside business logic.
|
|
51
|
+
- Keep controllers thin: validate input, call service, return response. No business logic in controllers.
|
|
52
|
+
- Use value objects for domain concepts (Money, Email, UserId) instead of primitive types.
|
|
53
|
+
- Use interfaces at module boundaries. Concrete implementations are internal details.
|
|
54
|
+
|
|
55
|
+
### Error handling
|
|
56
|
+
|
|
57
|
+
- Use specific exception classes per failure domain (e.g., `UserNotFoundException`, `ValidationException`).
|
|
58
|
+
- Catch exceptions at the boundary layer (controller, middleware) — not inside business logic unless recovery is possible.
|
|
59
|
+
- Never catch `\Exception` or `\Throwable` silently. At minimum, log the exception.
|
|
60
|
+
- Use result objects or typed return values instead of exceptions for expected failure paths (validation, not-found).
|
|
61
|
+
|
|
62
|
+
### Testing
|
|
63
|
+
|
|
64
|
+
- Use PHPUnit for unit and integration tests. Use Pest for more readable test syntax when the team prefers it.
|
|
65
|
+
- Mock external dependencies (HTTP clients, databases, file systems) — test business logic in isolation.
|
|
66
|
+
- Use data providers for parameterized tests instead of copy-paste test methods.
|
|
67
|
+
- Run tests in CI with code coverage reporting. Target meaningful coverage, not 100%.
|
|
68
|
+
- Use fixtures and factories for test data — never rely on production database state.
|
|
69
|
+
|
|
70
|
+
### Composer and dependencies
|
|
71
|
+
|
|
72
|
+
- Run `composer audit` in CI to catch known vulnerabilities.
|
|
73
|
+
- Use `composer outdated` to identify stale dependencies. Update regularly.
|
|
74
|
+
- Prefer well-maintained packages with active security patch records.
|
|
75
|
+
- Use autoloading via `composer.json` PSR-4 — never use `require`/`include` for class loading.
|
|
76
|
+
|
|
77
|
+
### Performance
|
|
78
|
+
|
|
79
|
+
- Use OPcache in production with preloading for frequently used classes.
|
|
80
|
+
- Profile with Xdebug or Blackfire before optimizing. Measure, don't guess.
|
|
81
|
+
- Use connection pooling (Swoole, FrankenPHP, or external proxy) for high-concurrency workloads.
|
|
82
|
+
- Cache expensive computations and database queries — invalidate on writes.
|
|
83
|
+
|
|
84
|
+
### Constraints
|
|
85
|
+
|
|
86
|
+
- Avoid `mixed` type as a lazy escape — use proper union types or generics (via PHPStan/Psalm).
|
|
87
|
+
- Avoid `@` error suppression operator — handle errors explicitly.
|
|
88
|
+
- Avoid global functions or static state for business logic — makes testing impossible.
|
|
89
|
+
- Avoid concatenating SQL strings — use prepared statements or query builders.
|
|
90
|
+
- Avoid storing sensitive data in plain-text config files — use environment variables or vault.
|
|
91
|
+
|
|
92
|
+
## Output Format
|
|
93
|
+
|
|
94
|
+
Provide implementation guidance, code examples, and configuration as appropriate to the task.
|
|
95
|
+
|
|
96
|
+
## References
|
|
97
|
+
|
|
98
|
+
| File | Load when |
|
|
99
|
+
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
100
|
+
| `references/php84-strict-typing-checklist.md` | Strict typing migration, enum patterns, readonly properties, PHPStan configuration, or Composer security audit is needed. |
|
|
101
|
+
| `references/modern-php-features.md` | You need enums, fibers, readonly classes, match expressions, named args, or first-class callable syntax. |
|
|
102
|
+
| `references/testing-and-static-analysis.md` | You need PHPUnit/Pest setup, data providers, mocking, PHPStan/Psalm config, or CI test pipeline patterns. |
|
|
103
|
+
| `references/architecture-and-di.md` | You need DI container patterns, service layers, repository design, or value object implementations. |
|
|
104
|
+
| `references/performance-and-deployment.md` | You need OPcache tuning, preloading, connection pooling, profiling with Xdebug/Blackfire, or FrankenPHP/Swoole setup. |
|
|
105
|
+
|
|
106
|
+
## Scripts
|
|
107
|
+
|
|
108
|
+
No helper scripts are required for this skill right now. Keep execution in `SKILL.md` and `references/` unless repeated automation becomes necessary.
|
|
109
|
+
|
|
110
|
+
## Examples
|
|
111
|
+
|
|
112
|
+
- "Help me with php pro best practices in this project"
|
|
113
|
+
- "Review my php pro implementation for issues"
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# Architecture and Dependency Injection
|
|
2
|
+
|
|
3
|
+
## Service Layer Pattern
|
|
4
|
+
|
|
5
|
+
```php
|
|
6
|
+
declare(strict_types=1);
|
|
7
|
+
|
|
8
|
+
// Controller — thin, delegates to service
|
|
9
|
+
final class OrderController
|
|
10
|
+
{
|
|
11
|
+
public function __construct(
|
|
12
|
+
private readonly OrderService $orderService,
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
public function create(Request $request): JsonResponse
|
|
16
|
+
{
|
|
17
|
+
$dto = CreateOrderDto::fromRequest($request);
|
|
18
|
+
$order = $this->orderService->create($dto);
|
|
19
|
+
return new JsonResponse(OrderResource::from($order), 201);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Service — business logic, orchestrates domain objects
|
|
24
|
+
final class OrderService
|
|
25
|
+
{
|
|
26
|
+
public function __construct(
|
|
27
|
+
private readonly OrderRepository $orderRepository,
|
|
28
|
+
private readonly PricingService $pricingService,
|
|
29
|
+
private readonly EventDispatcher $events,
|
|
30
|
+
) {}
|
|
31
|
+
|
|
32
|
+
public function create(CreateOrderDto $dto): Order
|
|
33
|
+
{
|
|
34
|
+
$price = $this->pricingService->calculate($dto->items);
|
|
35
|
+
$order = Order::create(
|
|
36
|
+
customerId: $dto->customerId,
|
|
37
|
+
items: $dto->items,
|
|
38
|
+
total: $price,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
$this->orderRepository->save($order);
|
|
42
|
+
$this->events->dispatch(new OrderCreated($order));
|
|
43
|
+
|
|
44
|
+
return $order;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Repository interface — persistence contract
|
|
49
|
+
interface OrderRepository
|
|
50
|
+
{
|
|
51
|
+
public function findById(int $id): ?Order;
|
|
52
|
+
public function save(Order $order): void;
|
|
53
|
+
/** @return list<Order> */
|
|
54
|
+
public function findByCustomer(int $customerId): array;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Value Objects
|
|
59
|
+
|
|
60
|
+
```php
|
|
61
|
+
// Type-safe wrappers with validation
|
|
62
|
+
readonly class Email
|
|
63
|
+
{
|
|
64
|
+
public function __construct(
|
|
65
|
+
public string $value,
|
|
66
|
+
) {
|
|
67
|
+
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
|
68
|
+
throw new \InvalidArgumentException("Invalid email: $value");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public function domain(): string
|
|
73
|
+
{
|
|
74
|
+
return substr($this->value, strpos($this->value, '@') + 1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public function equals(self $other): bool
|
|
78
|
+
{
|
|
79
|
+
return strtolower($this->value) === strtolower($other->value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
readonly class Money
|
|
84
|
+
{
|
|
85
|
+
public function __construct(
|
|
86
|
+
public int $amount, // store in cents
|
|
87
|
+
public string $currency,
|
|
88
|
+
) {
|
|
89
|
+
if ($amount < 0) throw new \DomainException('Amount cannot be negative');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public function add(self $other): self
|
|
93
|
+
{
|
|
94
|
+
if ($this->currency !== $other->currency) {
|
|
95
|
+
throw new \DomainException('Cannot add different currencies');
|
|
96
|
+
}
|
|
97
|
+
return new self($this->amount + $other->amount, $this->currency);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public function format(): string
|
|
101
|
+
{
|
|
102
|
+
return number_format($this->amount / 100, 2) . ' ' . $this->currency;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## DI Container Patterns
|
|
108
|
+
|
|
109
|
+
```php
|
|
110
|
+
// Constructor injection (preferred)
|
|
111
|
+
final class NotificationService
|
|
112
|
+
{
|
|
113
|
+
public function __construct(
|
|
114
|
+
private readonly MailerInterface $mailer,
|
|
115
|
+
private readonly LoggerInterface $logger,
|
|
116
|
+
private readonly string $fromAddress, // primitive config via container
|
|
117
|
+
) {}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Interface binding (Laravel example)
|
|
121
|
+
// AppServiceProvider
|
|
122
|
+
$this->app->bind(OrderRepository::class, EloquentOrderRepository::class);
|
|
123
|
+
$this->app->bind(MailerInterface::class, SmtpMailer::class);
|
|
124
|
+
|
|
125
|
+
// Singleton binding for shared instances
|
|
126
|
+
$this->app->singleton(CacheInterface::class, RedisCache::class);
|
|
127
|
+
|
|
128
|
+
// Factory binding for complex construction
|
|
129
|
+
$this->app->bind(PaymentGateway::class, function ($app) {
|
|
130
|
+
return new StripeGateway(
|
|
131
|
+
apiKey: config('services.stripe.secret'),
|
|
132
|
+
logger: $app->make(LoggerInterface::class),
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Symfony service configuration (services.yaml)
|
|
137
|
+
// services:
|
|
138
|
+
// App\Service\OrderService:
|
|
139
|
+
// arguments:
|
|
140
|
+
// $fromAddress: '%env(MAIL_FROM)%'
|
|
141
|
+
// App\Repository\OrderRepository: '@App\Infrastructure\EloquentOrderRepository'
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## DTOs and Request Validation
|
|
145
|
+
|
|
146
|
+
```php
|
|
147
|
+
// DTO with factory method from request
|
|
148
|
+
readonly class CreateOrderDto
|
|
149
|
+
{
|
|
150
|
+
/** @param list<OrderItemDto> $items */
|
|
151
|
+
public function __construct(
|
|
152
|
+
public int $customerId,
|
|
153
|
+
public array $items,
|
|
154
|
+
public ?string $notes = null,
|
|
155
|
+
) {}
|
|
156
|
+
|
|
157
|
+
public static function fromRequest(Request $request): self
|
|
158
|
+
{
|
|
159
|
+
$validated = $request->validate([
|
|
160
|
+
'customer_id' => 'required|integer|exists:customers,id',
|
|
161
|
+
'items' => 'required|array|min:1',
|
|
162
|
+
'items.*.product_id' => 'required|integer|exists:products,id',
|
|
163
|
+
'items.*.quantity' => 'required|integer|min:1',
|
|
164
|
+
'notes' => 'nullable|string|max:500',
|
|
165
|
+
]);
|
|
166
|
+
|
|
167
|
+
return new self(
|
|
168
|
+
customerId: $validated['customer_id'],
|
|
169
|
+
items: array_map(
|
|
170
|
+
fn (array $item) => new OrderItemDto(
|
|
171
|
+
productId: $item['product_id'],
|
|
172
|
+
quantity: $item['quantity'],
|
|
173
|
+
),
|
|
174
|
+
$validated['items'],
|
|
175
|
+
),
|
|
176
|
+
notes: $validated['notes'] ?? null,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Result Objects for Expected Failures
|
|
183
|
+
|
|
184
|
+
```php
|
|
185
|
+
// Instead of exceptions for validation/not-found
|
|
186
|
+
readonly class Result
|
|
187
|
+
{
|
|
188
|
+
private function __construct(
|
|
189
|
+
public bool $success,
|
|
190
|
+
public mixed $value = null,
|
|
191
|
+
public ?string $error = null,
|
|
192
|
+
) {}
|
|
193
|
+
|
|
194
|
+
public static function ok(mixed $value): self
|
|
195
|
+
{
|
|
196
|
+
return new self(success: true, value: $value);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public static function fail(string $error): self
|
|
200
|
+
{
|
|
201
|
+
return new self(success: false, error: $error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Usage in service
|
|
206
|
+
public function transfer(int $fromId, int $toId, Money $amount): Result
|
|
207
|
+
{
|
|
208
|
+
$from = $this->accountRepo->findById($fromId);
|
|
209
|
+
if ($from === null) return Result::fail('Source account not found');
|
|
210
|
+
|
|
211
|
+
if ($from->balance->amount < $amount->amount) {
|
|
212
|
+
return Result::fail('Insufficient funds');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ... perform transfer
|
|
216
|
+
return Result::ok($transaction);
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Middleware Pattern
|
|
221
|
+
|
|
222
|
+
```php
|
|
223
|
+
// Middleware for cross-cutting concerns
|
|
224
|
+
final class RateLimitMiddleware
|
|
225
|
+
{
|
|
226
|
+
public function __construct(
|
|
227
|
+
private readonly RateLimiter $limiter,
|
|
228
|
+
) {}
|
|
229
|
+
|
|
230
|
+
public function handle(Request $request, \Closure $next): Response
|
|
231
|
+
{
|
|
232
|
+
$key = $request->ip();
|
|
233
|
+
if (!$this->limiter->attempt($key, maxAttempts: 60, decayMinutes: 1)) {
|
|
234
|
+
return new JsonResponse(['error' => 'Too many requests'], 429);
|
|
235
|
+
}
|
|
236
|
+
return $next($request);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|