@patricio0312rev/skillset 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.
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +176 -0
- package/bin/cli.js +37 -0
- package/package.json +55 -0
- package/src/commands/init.js +301 -0
- package/src/index.js +168 -0
- package/src/lib/config.js +200 -0
- package/src/lib/generator.js +166 -0
- package/src/utils/display.js +95 -0
- package/src/utils/readme.js +196 -0
- package/src/utils/tool-specific.js +233 -0
- package/templates/ai-engineering/agent-orchestration-planner/ SKILL.md +266 -0
- package/templates/ai-engineering/cost-latency-optimizer/ SKILL.md +270 -0
- package/templates/ai-engineering/doc-to-vector-dataset-generator/ SKILL.md +239 -0
- package/templates/ai-engineering/evaluation-harness/ SKILL.md +219 -0
- package/templates/ai-engineering/guardrails-safety-filter-builder/ SKILL.md +226 -0
- package/templates/ai-engineering/llm-debugger/ SKILL.md +283 -0
- package/templates/ai-engineering/prompt-regression-tester/ SKILL.md +216 -0
- package/templates/ai-engineering/prompt-template-builder/ SKILL.md +393 -0
- package/templates/ai-engineering/rag-pipeline-builder/ SKILL.md +244 -0
- package/templates/ai-engineering/tool-function-schema-designer/ SKILL.md +219 -0
- package/templates/architecture/adr-writer/ SKILL.md +250 -0
- package/templates/architecture/api-versioning-deprecation-planner/ SKILL.md +331 -0
- package/templates/architecture/domain-model-boundaries-mapper/ SKILL.md +300 -0
- package/templates/architecture/migration-planner/ SKILL.md +376 -0
- package/templates/architecture/performance-budget-setter/ SKILL.md +318 -0
- package/templates/architecture/reliability-strategy-builder/ SKILL.md +286 -0
- package/templates/architecture/rfc-generator/ SKILL.md +362 -0
- package/templates/architecture/scalability-playbook/ SKILL.md +279 -0
- package/templates/architecture/system-design-generator/ SKILL.md +339 -0
- package/templates/architecture/tech-debt-prioritizer/ SKILL.md +329 -0
- package/templates/backend/api-contract-normalizer/ SKILL.md +487 -0
- package/templates/backend/api-endpoint-generator/ SKILL.md +415 -0
- package/templates/backend/auth-module-builder/ SKILL.md +99 -0
- package/templates/backend/background-jobs-designer/ SKILL.md +166 -0
- package/templates/backend/caching-strategist/ SKILL.md +190 -0
- package/templates/backend/error-handling-standardizer/ SKILL.md +174 -0
- package/templates/backend/rate-limiting-abuse-protection/ SKILL.md +147 -0
- package/templates/backend/rbac-permissions-builder/ SKILL.md +158 -0
- package/templates/backend/service-layer-extractor/ SKILL.md +269 -0
- package/templates/backend/webhook-receiver-hardener/ SKILL.md +211 -0
- package/templates/ci-cd/artifact-sbom-publisher/ SKILL.md +236 -0
- package/templates/ci-cd/caching-strategy-optimizer/ SKILL.md +195 -0
- package/templates/ci-cd/deployment-checklist-generator/ SKILL.md +381 -0
- package/templates/ci-cd/github-actions-pipeline-creator/ SKILL.md +348 -0
- package/templates/ci-cd/monorepo-ci-optimizer/ SKILL.md +298 -0
- package/templates/ci-cd/preview-environments-builder/ SKILL.md +187 -0
- package/templates/ci-cd/quality-gates-enforcer/ SKILL.md +342 -0
- package/templates/ci-cd/release-automation-builder/ SKILL.md +281 -0
- package/templates/ci-cd/rollback-workflow-builder/ SKILL.md +372 -0
- package/templates/ci-cd/secrets-env-manager/ SKILL.md +242 -0
- package/templates/db-management/backup-restore-runbook-generator/ SKILL.md +505 -0
- package/templates/db-management/data-integrity-auditor/ SKILL.md +505 -0
- package/templates/db-management/data-retention-archiving-planner/ SKILL.md +430 -0
- package/templates/db-management/data-seeding-fixtures-builder/ SKILL.md +375 -0
- package/templates/db-management/db-performance-watchlist/ SKILL.md +425 -0
- package/templates/db-management/etl-sync-job-builder/ SKILL.md +457 -0
- package/templates/db-management/multi-tenant-safety-checker/ SKILL.md +398 -0
- package/templates/db-management/prisma-migration-assistant/ SKILL.md +379 -0
- package/templates/db-management/schema-consistency-checker/ SKILL.md +440 -0
- package/templates/db-management/sql-query-optimizer/ SKILL.md +324 -0
- package/templates/foundation/changelog-writer/ SKILL.md +431 -0
- package/templates/foundation/code-formatter-installer/ SKILL.md +320 -0
- package/templates/foundation/codebase-summarizer/ SKILL.md +360 -0
- package/templates/foundation/dependency-doctor/ SKILL.md +163 -0
- package/templates/foundation/dev-environment-bootstrapper/ SKILL.md +259 -0
- package/templates/foundation/dev-onboarding-builder/ SKILL.md +556 -0
- package/templates/foundation/docs-starter-kit/ SKILL.md +574 -0
- package/templates/foundation/explaining-code/SKILL.md +13 -0
- package/templates/foundation/git-hygiene-enforcer/ SKILL.md +455 -0
- package/templates/foundation/project-scaffolder/ SKILL.md +65 -0
- package/templates/foundation/project-scaffolder/references/templates.md +126 -0
- package/templates/foundation/repo-structure-linter/ SKILL.md +0 -0
- package/templates/foundation/repo-structure-linter/references/conventions.md +98 -0
- package/templates/frontend/animation-micro-interaction-pack/ SKILL.md +41 -0
- package/templates/frontend/component-scaffold-generator/ SKILL.md +562 -0
- package/templates/frontend/design-to-component-translator/ SKILL.md +547 -0
- package/templates/frontend/form-wizard-builder/ SKILL.md +553 -0
- package/templates/frontend/frontend-refactor-planner/ SKILL.md +37 -0
- package/templates/frontend/i18n-frontend-implementer/ SKILL.md +44 -0
- package/templates/frontend/modal-drawer-system/ SKILL.md +377 -0
- package/templates/frontend/page-layout-builder/ SKILL.md +630 -0
- package/templates/frontend/state-ux-flow-builder/ SKILL.md +23 -0
- package/templates/frontend/table-builder/ SKILL.md +350 -0
- package/templates/performance/alerting-dashboard-builder/ SKILL.md +162 -0
- package/templates/performance/backend-latency-profiler-helper/ SKILL.md +108 -0
- package/templates/performance/caching-cdn-strategy-planner/ SKILL.md +150 -0
- package/templates/performance/capacity-planning-helper/ SKILL.md +242 -0
- package/templates/performance/core-web-vitals-tuner/ SKILL.md +126 -0
- package/templates/performance/incident-runbook-generator/ SKILL.md +162 -0
- package/templates/performance/load-test-scenario-builder/ SKILL.md +256 -0
- package/templates/performance/observability-setup/ SKILL.md +232 -0
- package/templates/performance/postmortem-writer/ SKILL.md +203 -0
- package/templates/performance/structured-logging-standardizer/ SKILL.md +122 -0
- package/templates/security/auth-security-reviewer/ SKILL.md +428 -0
- package/templates/security/dependency-vulnerability-triage/ SKILL.md +495 -0
- package/templates/security/input-validation-sanitization-auditor/ SKILL.md +76 -0
- package/templates/security/pii-redaction-logging-policy-builder/ SKILL.md +65 -0
- package/templates/security/rbac-policy-tester/ SKILL.md +80 -0
- package/templates/security/secrets-scanner/ SKILL.md +462 -0
- package/templates/security/secure-headers-csp-builder/ SKILL.md +404 -0
- package/templates/security/security-incident-playbook-generator/ SKILL.md +76 -0
- package/templates/security/security-pr-checklist-skill/ SKILL.md +62 -0
- package/templates/security/threat-model-generator/ SKILL.md +394 -0
- package/templates/testing/contract-testing-builder/ SKILL.md +492 -0
- package/templates/testing/coverage-strategist/ SKILL.md +436 -0
- package/templates/testing/e2e-test-builder/ SKILL.md +382 -0
- package/templates/testing/flaky-test-detective/ SKILL.md +416 -0
- package/templates/testing/integration-test-builder/ SKILL.md +525 -0
- package/templates/testing/mocking-assistant/ SKILL.md +383 -0
- package/templates/testing/snapshot-test-refactorer/ SKILL.md +375 -0
- package/templates/testing/test-data-factory-builder/ SKILL.md +449 -0
- package/templates/testing/test-reporting-triage-skill/ SKILL.md +469 -0
- package/templates/testing/unit-test-generator/ SKILL.md +548 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: migration-planner
|
|
3
|
+
description: Builds phased data and system migrations using feature flags, dual writes, backfills, and validation. Includes rollback plans and risk mitigation. Use for "data migration", "system migration", "database migration", or "platform migration".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Migration Planner
|
|
7
|
+
|
|
8
|
+
Execute safe, zero-downtime migrations with validation and rollback plans.
|
|
9
|
+
|
|
10
|
+
## Migration Patterns
|
|
11
|
+
|
|
12
|
+
### 1. Feature Flag Migration (Safest)
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
Phase 1: Deploy new code (disabled)
|
|
16
|
+
Phase 2: Enable for 1% traffic
|
|
17
|
+
Phase 3: Ramp to 10%, 50%, 100%
|
|
18
|
+
Phase 4: Remove old code
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Dual Write Migration
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
Phase 1: Write to both old and new
|
|
25
|
+
Phase 2: Backfill old → new
|
|
26
|
+
Phase 3: Read from new (write both)
|
|
27
|
+
Phase 4: Stop writing to old
|
|
28
|
+
Phase 5: Decommission old
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 3. Blue-Green Deployment
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Blue (current) → Green (new)
|
|
35
|
+
Switch traffic: Blue → Green
|
|
36
|
+
Rollback available: Green → Blue
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Complete Migration Plan Template
|
|
40
|
+
|
|
41
|
+
````markdown
|
|
42
|
+
# Migration Plan: MySQL → PostgreSQL
|
|
43
|
+
|
|
44
|
+
## Overview
|
|
45
|
+
|
|
46
|
+
**What:** Migrate user database from MySQL to PostgreSQL
|
|
47
|
+
**Why:** Better JSON support, improved performance
|
|
48
|
+
**When:** Q1 2024
|
|
49
|
+
**Owner:** Database Team
|
|
50
|
+
**Risk Level:** HIGH
|
|
51
|
+
|
|
52
|
+
## Current State
|
|
53
|
+
|
|
54
|
+
- MySQL 8.0
|
|
55
|
+
- 500GB data
|
|
56
|
+
- 100K users
|
|
57
|
+
- 1000 writes/min
|
|
58
|
+
- 10,000 reads/min
|
|
59
|
+
|
|
60
|
+
## Target State
|
|
61
|
+
|
|
62
|
+
- PostgreSQL 15
|
|
63
|
+
- Same data model
|
|
64
|
+
- No downtime
|
|
65
|
+
- Data validation 100% match
|
|
66
|
+
|
|
67
|
+
## Phases
|
|
68
|
+
|
|
69
|
+
### Phase 1: Dual Write (Week 1-2)
|
|
70
|
+
|
|
71
|
+
**Goal:** Write to both databases
|
|
72
|
+
|
|
73
|
+
**Steps:**
|
|
74
|
+
|
|
75
|
+
1. Deploy PostgreSQL cluster
|
|
76
|
+
2. Create schema in PostgreSQL
|
|
77
|
+
3. Deploy dual-write code
|
|
78
|
+
4. Enable dual writes (MySQL primary, PostgreSQL secondary)
|
|
79
|
+
|
|
80
|
+
**Code:**
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
async function createUser(data: CreateUserDto) {
|
|
84
|
+
// Write to MySQL (primary)
|
|
85
|
+
const mysqlUser = await mysql.users.create(data);
|
|
86
|
+
|
|
87
|
+
// Write to PostgreSQL (secondary, fire and forget)
|
|
88
|
+
postgres.users.create(data).catch((err) => {
|
|
89
|
+
logger.error("PostgreSQL write failed", err);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return mysqlUser; // Still trust MySQL
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
````
|
|
96
|
+
|
|
97
|
+
**Validation:**
|
|
98
|
+
|
|
99
|
+
- Monitor PostgreSQL write success rate
|
|
100
|
+
- Compare row counts daily
|
|
101
|
+
- Alert if drift >0.1%
|
|
102
|
+
|
|
103
|
+
**Rollback:** Disable PostgreSQL writes
|
|
104
|
+
|
|
105
|
+
### Phase 2: Backfill (Week 3-4)
|
|
106
|
+
|
|
107
|
+
**Goal:** Copy historical data
|
|
108
|
+
|
|
109
|
+
**Steps:**
|
|
110
|
+
|
|
111
|
+
1. Take MySQL snapshot
|
|
112
|
+
2. Run backfill script in batches
|
|
113
|
+
3. Validate data integrity
|
|
114
|
+
4. Resume from failure automatically
|
|
115
|
+
|
|
116
|
+
**Script:**
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
def backfill():
|
|
120
|
+
last_id = get_last_migrated_id()
|
|
121
|
+
batch_size = 1000
|
|
122
|
+
|
|
123
|
+
while True:
|
|
124
|
+
users = mysql.query(
|
|
125
|
+
"SELECT * FROM users WHERE id > %s LIMIT %s",
|
|
126
|
+
[last_id, batch_size]
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
if not users:
|
|
130
|
+
break
|
|
131
|
+
|
|
132
|
+
postgres.bulk_insert(users)
|
|
133
|
+
last_id = users[-1]['id']
|
|
134
|
+
save_checkpoint(last_id)
|
|
135
|
+
|
|
136
|
+
time.sleep(0.1) # Rate limit
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Validation:**
|
|
140
|
+
|
|
141
|
+
- Row count match
|
|
142
|
+
- Random sample comparison (1000 rows)
|
|
143
|
+
- Checksum comparison
|
|
144
|
+
|
|
145
|
+
**Rollback:** Delete PostgreSQL data
|
|
146
|
+
|
|
147
|
+
### Phase 3: Dual Read (Week 5)
|
|
148
|
+
|
|
149
|
+
**Goal:** Validate PostgreSQL reads
|
|
150
|
+
|
|
151
|
+
**Steps:**
|
|
152
|
+
|
|
153
|
+
1. Deploy shadow read code
|
|
154
|
+
2. Read from both (MySQL primary)
|
|
155
|
+
3. Compare results
|
|
156
|
+
4. Log mismatches
|
|
157
|
+
|
|
158
|
+
**Code:**
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
async function getUser(id: string) {
|
|
162
|
+
const mysqlUser = await mysql.users.findById(id);
|
|
163
|
+
|
|
164
|
+
// Shadow read from PostgreSQL
|
|
165
|
+
postgres.users.findById(id).then((pgUser) => {
|
|
166
|
+
if (!deepEqual(mysqlUser, pgUser)) {
|
|
167
|
+
logger.warn("Data mismatch", { id, mysqlUser, pgUser });
|
|
168
|
+
metrics.increment("migration.mismatch");
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return mysqlUser; // Still trust MySQL
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Validation:**
|
|
177
|
+
|
|
178
|
+
- Mismatch rate <0.01%
|
|
179
|
+
- PostgreSQL query performance acceptable
|
|
180
|
+
|
|
181
|
+
**Rollback:** Remove shadow reads
|
|
182
|
+
|
|
183
|
+
### Phase 4: Flip Read Traffic (Week 6)
|
|
184
|
+
|
|
185
|
+
**Goal:** Read from PostgreSQL
|
|
186
|
+
|
|
187
|
+
**Steps:**
|
|
188
|
+
|
|
189
|
+
1. Feature flag: read from PostgreSQL (1% traffic)
|
|
190
|
+
2. Monitor errors, latency
|
|
191
|
+
3. Ramp: 1% → 10% → 50% → 100%
|
|
192
|
+
4. Still writing to both
|
|
193
|
+
|
|
194
|
+
**Code:**
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
async function getUser(id: string) {
|
|
198
|
+
if (featureFlags.readFromPostgres) {
|
|
199
|
+
return postgres.users.findById(id);
|
|
200
|
+
}
|
|
201
|
+
return mysql.users.findById(id);
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Validation:**
|
|
206
|
+
|
|
207
|
+
- Error rate unchanged
|
|
208
|
+
- Latency p95 <500ms
|
|
209
|
+
- No user complaints
|
|
210
|
+
|
|
211
|
+
**Rollback:** Flip feature flag off
|
|
212
|
+
|
|
213
|
+
### Phase 5: Stop MySQL Writes (Week 7)
|
|
214
|
+
|
|
215
|
+
**Goal:** PostgreSQL is now primary
|
|
216
|
+
|
|
217
|
+
**Steps:**
|
|
218
|
+
|
|
219
|
+
1. Stop writing to MySQL
|
|
220
|
+
2. Keep MySQL running (read-only)
|
|
221
|
+
3. Monitor for issues
|
|
222
|
+
|
|
223
|
+
**Code:**
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
async function createUser(data: CreateUserDto) {
|
|
227
|
+
return postgres.users.create(data);
|
|
228
|
+
// No longer writing to MySQL
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Validation:**
|
|
233
|
+
|
|
234
|
+
- All operations working
|
|
235
|
+
- MySQL not receiving writes
|
|
236
|
+
|
|
237
|
+
**Rollback:** Re-enable MySQL writes
|
|
238
|
+
|
|
239
|
+
### Phase 6: Decommission (Week 8)
|
|
240
|
+
|
|
241
|
+
**Goal:** Remove MySQL
|
|
242
|
+
|
|
243
|
+
**Steps:**
|
|
244
|
+
|
|
245
|
+
1. Archive MySQL data
|
|
246
|
+
2. Shutdown MySQL cluster
|
|
247
|
+
3. Remove MySQL client code
|
|
248
|
+
|
|
249
|
+
**Rollback:** Not available (point of no return)
|
|
250
|
+
|
|
251
|
+
## Validation Strategy
|
|
252
|
+
|
|
253
|
+
### Data Integrity Checks
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
def validate_migration():
|
|
257
|
+
# Row counts
|
|
258
|
+
mysql_count = mysql.query("SELECT COUNT(*) FROM users")[0]
|
|
259
|
+
pg_count = postgres.query("SELECT COUNT(*) FROM users")[0]
|
|
260
|
+
assert mysql_count == pg_count
|
|
261
|
+
|
|
262
|
+
# Random sampling
|
|
263
|
+
sample = mysql.query("SELECT * FROM users ORDER BY RAND() LIMIT 1000")
|
|
264
|
+
for row in sample:
|
|
265
|
+
pg_row = postgres.query("SELECT * FROM users WHERE id = %s", [row['id']])
|
|
266
|
+
assert row == pg_row
|
|
267
|
+
|
|
268
|
+
# Checksums
|
|
269
|
+
mysql_checksum = mysql.query("SELECT MD5(GROUP_CONCAT(id, email)) FROM users")
|
|
270
|
+
pg_checksum = postgres.query("SELECT MD5(STRING_AGG(id::text || email, '')) FROM users")
|
|
271
|
+
assert mysql_checksum == pg_checksum
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Rollback Plans
|
|
275
|
+
|
|
276
|
+
### Phase 1-3 Rollback (Easy)
|
|
277
|
+
|
|
278
|
+
- Disable PostgreSQL writes
|
|
279
|
+
- No impact to users
|
|
280
|
+
- Data in MySQL still valid
|
|
281
|
+
|
|
282
|
+
### Phase 4 Rollback (Medium)
|
|
283
|
+
|
|
284
|
+
- Flip feature flag
|
|
285
|
+
- Route reads back to MySQL
|
|
286
|
+
- Minor user impact (seconds)
|
|
287
|
+
|
|
288
|
+
### Phase 5+ Rollback (Hard)
|
|
289
|
+
|
|
290
|
+
- Must re-enable MySQL writes
|
|
291
|
+
- Potential data loss (writes since phase 5)
|
|
292
|
+
- Requires dual-write resumption
|
|
293
|
+
|
|
294
|
+
## Risk Mitigation
|
|
295
|
+
|
|
296
|
+
### Risk 1: Data Loss
|
|
297
|
+
|
|
298
|
+
**Mitigation:**
|
|
299
|
+
|
|
300
|
+
- Dual writes until validated
|
|
301
|
+
- Transaction logs captured
|
|
302
|
+
- Continuous backups
|
|
303
|
+
|
|
304
|
+
### Risk 2: Performance Degradation
|
|
305
|
+
|
|
306
|
+
**Mitigation:**
|
|
307
|
+
|
|
308
|
+
- Load test PostgreSQL
|
|
309
|
+
- Query optimization
|
|
310
|
+
- Connection pooling
|
|
311
|
+
|
|
312
|
+
### Risk 3: Schema Differences
|
|
313
|
+
|
|
314
|
+
**Mitigation:**
|
|
315
|
+
|
|
316
|
+
- Schema validation script
|
|
317
|
+
- Test migrations in staging
|
|
318
|
+
- Document data type differences
|
|
319
|
+
|
|
320
|
+
## Communication Plan
|
|
321
|
+
|
|
322
|
+
### Stakeholder Updates
|
|
323
|
+
|
|
324
|
+
```markdown
|
|
325
|
+
**Week 0:** Migration announced
|
|
326
|
+
**Week 2:** Phase 1 complete (dual writes)
|
|
327
|
+
**Week 4:** Backfill complete
|
|
328
|
+
**Week 6:** Traffic shifted to PostgreSQL
|
|
329
|
+
**Week 8:** Migration complete
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Status Dashboard
|
|
333
|
+
|
|
334
|
+
- Current phase
|
|
335
|
+
- Data sync status (%)
|
|
336
|
+
- Validation results
|
|
337
|
+
- Error rates
|
|
338
|
+
|
|
339
|
+
## Testing Plan
|
|
340
|
+
|
|
341
|
+
### Pre-Migration Testing
|
|
342
|
+
|
|
343
|
+
1. Test in development
|
|
344
|
+
2. Full migration in staging
|
|
345
|
+
3. Load test PostgreSQL
|
|
346
|
+
4. Validate rollback procedures
|
|
347
|
+
|
|
348
|
+
### During Migration
|
|
349
|
+
|
|
350
|
+
1. Continuous monitoring
|
|
351
|
+
2. Automated validation
|
|
352
|
+
3. Manual spot checks
|
|
353
|
+
4. User acceptance testing
|
|
354
|
+
|
|
355
|
+
## Best Practices
|
|
356
|
+
|
|
357
|
+
1. **Small batches**: Migrate incrementally
|
|
358
|
+
2. **Dual write**: Keep both systems synchronized
|
|
359
|
+
3. **Feature flags**: Control rollout
|
|
360
|
+
4. **Validate continuously**: Don't trust, verify
|
|
361
|
+
5. **Rollback ready**: Plan for worst case
|
|
362
|
+
6. **Monitor closely**: Track metrics
|
|
363
|
+
7. **Communicate often**: Keep stakeholders informed
|
|
364
|
+
|
|
365
|
+
## Output Checklist
|
|
366
|
+
|
|
367
|
+
- [ ] Migration phases defined (5-7 phases)
|
|
368
|
+
- [ ] Dual write implementation
|
|
369
|
+
- [ ] Backfill script ready
|
|
370
|
+
- [ ] Validation strategy
|
|
371
|
+
- [ ] Feature flags configured
|
|
372
|
+
- [ ] Rollback plans per phase
|
|
373
|
+
- [ ] Risk mitigation strategies
|
|
374
|
+
- [ ] Communication plan
|
|
375
|
+
- [ ] Monitoring dashboard
|
|
376
|
+
- [ ] Testing checklist
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: performance-budget-setter
|
|
3
|
+
description: Defines measurable performance budgets for bundle size, API latency, database queries, and render times. Provides enforcement strategies and monitoring plans. Use for "performance budgets", "performance monitoring", "web vitals", or "optimization targets".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Performance Budget Setter
|
|
7
|
+
|
|
8
|
+
Set and enforce performance budgets to maintain fast user experiences.
|
|
9
|
+
|
|
10
|
+
## Performance Budget Template
|
|
11
|
+
|
|
12
|
+
```markdown
|
|
13
|
+
# Performance Budget: E-Commerce Website
|
|
14
|
+
|
|
15
|
+
## Bundle Size Budget
|
|
16
|
+
|
|
17
|
+
| Asset Type | Budget | Current | Status |
|
|
18
|
+
| ---------------------- | ---------- | ---------- | ------ |
|
|
19
|
+
| Initial JS | 200 KB | 185 KB | ✅ |
|
|
20
|
+
| Initial CSS | 50 KB | 48 KB | ✅ |
|
|
21
|
+
| Vendor JS | 150 KB | 145 KB | ✅ |
|
|
22
|
+
| Fonts | 100 KB | 95 KB | ✅ |
|
|
23
|
+
| Images (above fold) | 300 KB | 320 KB | ❌ |
|
|
24
|
+
| **Total Initial Load** | **800 KB** | **793 KB** | ✅ |
|
|
25
|
+
|
|
26
|
+
## API Latency Budget
|
|
27
|
+
|
|
28
|
+
| Endpoint | p50 | p95 | p99 |
|
|
29
|
+
| -------------- | ------ | ------ | ------- |
|
|
30
|
+
| GET /products | <100ms | <300ms | <500ms |
|
|
31
|
+
| POST /checkout | <200ms | <500ms | <1000ms |
|
|
32
|
+
| GET /search | <150ms | <400ms | <800ms |
|
|
33
|
+
|
|
34
|
+
## Database Query Budget
|
|
35
|
+
|
|
36
|
+
| Query Type | Budget | Current |
|
|
37
|
+
| ---------------- | ------ | ------- |
|
|
38
|
+
| Simple reads | <50ms | 42ms |
|
|
39
|
+
| Complex joins | <200ms | 185ms |
|
|
40
|
+
| Aggregations | <500ms | 450ms |
|
|
41
|
+
| Queries per page | <20 | 18 |
|
|
42
|
+
|
|
43
|
+
## Core Web Vitals
|
|
44
|
+
|
|
45
|
+
| Metric | Good | Poor | Target |
|
|
46
|
+
| ------------------------------ | ------ | ------ | ------ |
|
|
47
|
+
| LCP (Largest Contentful Paint) | <2.5s | >4.0s | <2.0s |
|
|
48
|
+
| FID (First Input Delay) | <100ms | >300ms | <50ms |
|
|
49
|
+
| CLS (Cumulative Layout Shift) | <0.1 | >0.25 | <0.05 |
|
|
50
|
+
|
|
51
|
+
## Page-Specific Budgets
|
|
52
|
+
|
|
53
|
+
### Homepage
|
|
54
|
+
|
|
55
|
+
- Time to Interactive: <3s
|
|
56
|
+
- Total Blocking Time: <300ms
|
|
57
|
+
- Speed Index: <3s
|
|
58
|
+
|
|
59
|
+
### Product Page
|
|
60
|
+
|
|
61
|
+
- Time to Interactive: <4s
|
|
62
|
+
- Images loaded: <2s
|
|
63
|
+
- Reviews section: <1s
|
|
64
|
+
|
|
65
|
+
### Checkout
|
|
66
|
+
|
|
67
|
+
- Time to Interactive: <3s
|
|
68
|
+
- Payment processing: <2s
|
|
69
|
+
- Zero layout shifts
|
|
70
|
+
|
|
71
|
+
## Third-Party Scripts
|
|
72
|
+
|
|
73
|
+
| Service | Budget | Purpose |
|
|
74
|
+
| ----------- | ---------- | ---------------- |
|
|
75
|
+
| Analytics | 30 KB | Google Analytics |
|
|
76
|
+
| Chat Widget | 50 KB | Customer support |
|
|
77
|
+
| Payment | 100 KB | Stripe |
|
|
78
|
+
| **Total** | **180 KB** | |
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Enforcement Strategy
|
|
82
|
+
|
|
83
|
+
### 1. CI/CD Integration
|
|
84
|
+
|
|
85
|
+
```yaml
|
|
86
|
+
# .github/workflows/performance-budget.yml
|
|
87
|
+
name: Performance Budget Check
|
|
88
|
+
|
|
89
|
+
on: [pull_request]
|
|
90
|
+
|
|
91
|
+
jobs:
|
|
92
|
+
budget-check:
|
|
93
|
+
runs-on: ubuntu-latest
|
|
94
|
+
steps:
|
|
95
|
+
- uses: actions/checkout@v2
|
|
96
|
+
|
|
97
|
+
- name: Build production bundle
|
|
98
|
+
run: npm run build
|
|
99
|
+
|
|
100
|
+
- name: Check bundle size
|
|
101
|
+
run: |
|
|
102
|
+
npx bundlesize
|
|
103
|
+
|
|
104
|
+
- name: Lighthouse CI
|
|
105
|
+
run: |
|
|
106
|
+
npm install -g @lhci/cli
|
|
107
|
+
lhci autorun
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 2. Webpack Bundle Analyzer
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
// webpack.config.js
|
|
114
|
+
const BundleAnalyzerPlugin =
|
|
115
|
+
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
|
116
|
+
|
|
117
|
+
module.exports = {
|
|
118
|
+
plugins: [
|
|
119
|
+
new BundleAnalyzerPlugin({
|
|
120
|
+
analyzerMode: process.env.ANALYZE ? "server" : "disabled",
|
|
121
|
+
}),
|
|
122
|
+
],
|
|
123
|
+
performance: {
|
|
124
|
+
hints: "error",
|
|
125
|
+
maxAssetSize: 200000, // 200 KB
|
|
126
|
+
maxEntrypointSize: 400000, // 400 KB
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 3. package.json Configuration
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"bundlesize": [
|
|
136
|
+
{
|
|
137
|
+
"path": "./dist/js/main.*.js",
|
|
138
|
+
"maxSize": "200 KB"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"path": "./dist/css/main.*.css",
|
|
142
|
+
"maxSize": "50 KB"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"path": "./dist/js/vendor.*.js",
|
|
146
|
+
"maxSize": "150 KB"
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Monitoring Plan
|
|
153
|
+
|
|
154
|
+
### Real User Monitoring (RUM)
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// Track Core Web Vitals
|
|
158
|
+
import { getCLS, getFID, getFCP, getLCP, getTTFB } from "web-vitals";
|
|
159
|
+
|
|
160
|
+
function sendToAnalytics(metric) {
|
|
161
|
+
const body = JSON.stringify(metric);
|
|
162
|
+
|
|
163
|
+
if (navigator.sendBeacon) {
|
|
164
|
+
navigator.sendBeacon("/analytics", body);
|
|
165
|
+
} else {
|
|
166
|
+
fetch("/analytics", { body, method: "POST", keepalive: true });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
getCLS(sendToAnalytics);
|
|
171
|
+
getFID(sendToAnalytics);
|
|
172
|
+
getLCP(sendToAnalytics);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Synthetic Monitoring
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Lighthouse CI
|
|
179
|
+
lhci autorun --config=.lighthouserc.json
|
|
180
|
+
|
|
181
|
+
# WebPageTest API
|
|
182
|
+
curl "https://www.webpagetest.org/runtest.php?url=https://example.com&k=API_KEY"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Performance Dashboard
|
|
186
|
+
|
|
187
|
+
```markdown
|
|
188
|
+
**Daily Metrics:**
|
|
189
|
+
|
|
190
|
+
- Bundle size trend
|
|
191
|
+
- API latency percentiles
|
|
192
|
+
- Core Web Vitals scores
|
|
193
|
+
- Page load times
|
|
194
|
+
|
|
195
|
+
**Alerts:**
|
|
196
|
+
|
|
197
|
+
- Bundle size exceeds budget by 10%
|
|
198
|
+
- LCP >2.5s for >5% of users
|
|
199
|
+
- API p95 >500ms
|
|
200
|
+
- Any metric exceeds budget
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Optimization Strategies
|
|
204
|
+
|
|
205
|
+
### Reduce Bundle Size
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// Code splitting
|
|
209
|
+
const ProductPage = lazy(() => import("./ProductPage"));
|
|
210
|
+
|
|
211
|
+
// Tree shaking
|
|
212
|
+
import { specific } from "library"; // ✅
|
|
213
|
+
import * as library from "library"; // ❌
|
|
214
|
+
|
|
215
|
+
// Dynamic imports
|
|
216
|
+
if (featureFlag) {
|
|
217
|
+
const module = await import("./feature");
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Optimize API Calls
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
// Parallel requests
|
|
225
|
+
const [user, orders] = await Promise.all([fetchUser(id), fetchOrders(id)]);
|
|
226
|
+
|
|
227
|
+
// Caching
|
|
228
|
+
const cachedData = await redis.get(key);
|
|
229
|
+
if (cachedData) return cachedData;
|
|
230
|
+
|
|
231
|
+
// Pagination
|
|
232
|
+
const products = await db.products
|
|
233
|
+
.find()
|
|
234
|
+
.limit(20)
|
|
235
|
+
.skip((page - 1) * 20);
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Optimize Database Queries
|
|
239
|
+
|
|
240
|
+
```sql
|
|
241
|
+
-- Add indexes
|
|
242
|
+
CREATE INDEX idx_orders_user_created ON orders(user_id, created_at);
|
|
243
|
+
|
|
244
|
+
-- Limit columns
|
|
245
|
+
SELECT id, name FROM products; -- ✅
|
|
246
|
+
SELECT * FROM products; -- ❌
|
|
247
|
+
|
|
248
|
+
-- Use EXPLAIN
|
|
249
|
+
EXPLAIN ANALYZE SELECT ...;
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Budget Violation Response
|
|
253
|
+
|
|
254
|
+
### When Budget Exceeded
|
|
255
|
+
|
|
256
|
+
1. **Immediate:**
|
|
257
|
+
|
|
258
|
+
- Block PR from merging
|
|
259
|
+
- Notify team in Slack
|
|
260
|
+
- Create ticket
|
|
261
|
+
|
|
262
|
+
2. **Within 24 hours:**
|
|
263
|
+
|
|
264
|
+
- Investigate cause
|
|
265
|
+
- Identify optimization opportunities
|
|
266
|
+
- Propose fix or budget increase
|
|
267
|
+
|
|
268
|
+
3. **Decision:**
|
|
269
|
+
- Fix code (preferred)
|
|
270
|
+
- Increase budget (requires justification)
|
|
271
|
+
|
|
272
|
+
### Budget Increase Request Template
|
|
273
|
+
|
|
274
|
+
```markdown
|
|
275
|
+
## Budget Increase Request
|
|
276
|
+
|
|
277
|
+
**Component:** Main JS bundle
|
|
278
|
+
**Current Budget:** 200 KB
|
|
279
|
+
**Requested Budget:** 250 KB
|
|
280
|
+
**Reason:** Added critical feature X
|
|
281
|
+
|
|
282
|
+
**Impact Analysis:**
|
|
283
|
+
|
|
284
|
+
- Load time increase: +0.5s
|
|
285
|
+
- User impact: Medium
|
|
286
|
+
- Revenue impact: Unknown
|
|
287
|
+
|
|
288
|
+
**Alternatives Considered:**
|
|
289
|
+
|
|
290
|
+
1. Code splitting: Reduces to 210 KB (preferred)
|
|
291
|
+
2. Remove feature Y: Reduces to 195 KB (rejected)
|
|
292
|
+
3. Lazy loading: Complex, 3 weeks effort
|
|
293
|
+
|
|
294
|
+
**Recommendation:** Implement code splitting
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Best Practices
|
|
298
|
+
|
|
299
|
+
1. **Set realistic budgets**: Based on user data
|
|
300
|
+
2. **Enforce in CI**: Automated checks
|
|
301
|
+
3. **Monitor continuously**: RUM + synthetic
|
|
302
|
+
4. **Review quarterly**: Adjust as needed
|
|
303
|
+
5. **Prioritize UX**: User-centric metrics
|
|
304
|
+
6. **Document exceptions**: Why budget increased
|
|
305
|
+
7. **Celebrate wins**: When under budget
|
|
306
|
+
|
|
307
|
+
## Output Checklist
|
|
308
|
+
|
|
309
|
+
- [ ] Bundle size budgets defined
|
|
310
|
+
- [ ] API latency targets set
|
|
311
|
+
- [ ] Database query budgets
|
|
312
|
+
- [ ] Core Web Vitals targets
|
|
313
|
+
- [ ] Page-specific budgets
|
|
314
|
+
- [ ] CI/CD enforcement configured
|
|
315
|
+
- [ ] Monitoring dashboard
|
|
316
|
+
- [ ] Alert thresholds set
|
|
317
|
+
- [ ] Violation response process
|
|
318
|
+
- [ ] Regular review schedule
|