@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.
Files changed (115) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +176 -0
  4. package/bin/cli.js +37 -0
  5. package/package.json +55 -0
  6. package/src/commands/init.js +301 -0
  7. package/src/index.js +168 -0
  8. package/src/lib/config.js +200 -0
  9. package/src/lib/generator.js +166 -0
  10. package/src/utils/display.js +95 -0
  11. package/src/utils/readme.js +196 -0
  12. package/src/utils/tool-specific.js +233 -0
  13. package/templates/ai-engineering/agent-orchestration-planner/ SKILL.md +266 -0
  14. package/templates/ai-engineering/cost-latency-optimizer/ SKILL.md +270 -0
  15. package/templates/ai-engineering/doc-to-vector-dataset-generator/ SKILL.md +239 -0
  16. package/templates/ai-engineering/evaluation-harness/ SKILL.md +219 -0
  17. package/templates/ai-engineering/guardrails-safety-filter-builder/ SKILL.md +226 -0
  18. package/templates/ai-engineering/llm-debugger/ SKILL.md +283 -0
  19. package/templates/ai-engineering/prompt-regression-tester/ SKILL.md +216 -0
  20. package/templates/ai-engineering/prompt-template-builder/ SKILL.md +393 -0
  21. package/templates/ai-engineering/rag-pipeline-builder/ SKILL.md +244 -0
  22. package/templates/ai-engineering/tool-function-schema-designer/ SKILL.md +219 -0
  23. package/templates/architecture/adr-writer/ SKILL.md +250 -0
  24. package/templates/architecture/api-versioning-deprecation-planner/ SKILL.md +331 -0
  25. package/templates/architecture/domain-model-boundaries-mapper/ SKILL.md +300 -0
  26. package/templates/architecture/migration-planner/ SKILL.md +376 -0
  27. package/templates/architecture/performance-budget-setter/ SKILL.md +318 -0
  28. package/templates/architecture/reliability-strategy-builder/ SKILL.md +286 -0
  29. package/templates/architecture/rfc-generator/ SKILL.md +362 -0
  30. package/templates/architecture/scalability-playbook/ SKILL.md +279 -0
  31. package/templates/architecture/system-design-generator/ SKILL.md +339 -0
  32. package/templates/architecture/tech-debt-prioritizer/ SKILL.md +329 -0
  33. package/templates/backend/api-contract-normalizer/ SKILL.md +487 -0
  34. package/templates/backend/api-endpoint-generator/ SKILL.md +415 -0
  35. package/templates/backend/auth-module-builder/ SKILL.md +99 -0
  36. package/templates/backend/background-jobs-designer/ SKILL.md +166 -0
  37. package/templates/backend/caching-strategist/ SKILL.md +190 -0
  38. package/templates/backend/error-handling-standardizer/ SKILL.md +174 -0
  39. package/templates/backend/rate-limiting-abuse-protection/ SKILL.md +147 -0
  40. package/templates/backend/rbac-permissions-builder/ SKILL.md +158 -0
  41. package/templates/backend/service-layer-extractor/ SKILL.md +269 -0
  42. package/templates/backend/webhook-receiver-hardener/ SKILL.md +211 -0
  43. package/templates/ci-cd/artifact-sbom-publisher/ SKILL.md +236 -0
  44. package/templates/ci-cd/caching-strategy-optimizer/ SKILL.md +195 -0
  45. package/templates/ci-cd/deployment-checklist-generator/ SKILL.md +381 -0
  46. package/templates/ci-cd/github-actions-pipeline-creator/ SKILL.md +348 -0
  47. package/templates/ci-cd/monorepo-ci-optimizer/ SKILL.md +298 -0
  48. package/templates/ci-cd/preview-environments-builder/ SKILL.md +187 -0
  49. package/templates/ci-cd/quality-gates-enforcer/ SKILL.md +342 -0
  50. package/templates/ci-cd/release-automation-builder/ SKILL.md +281 -0
  51. package/templates/ci-cd/rollback-workflow-builder/ SKILL.md +372 -0
  52. package/templates/ci-cd/secrets-env-manager/ SKILL.md +242 -0
  53. package/templates/db-management/backup-restore-runbook-generator/ SKILL.md +505 -0
  54. package/templates/db-management/data-integrity-auditor/ SKILL.md +505 -0
  55. package/templates/db-management/data-retention-archiving-planner/ SKILL.md +430 -0
  56. package/templates/db-management/data-seeding-fixtures-builder/ SKILL.md +375 -0
  57. package/templates/db-management/db-performance-watchlist/ SKILL.md +425 -0
  58. package/templates/db-management/etl-sync-job-builder/ SKILL.md +457 -0
  59. package/templates/db-management/multi-tenant-safety-checker/ SKILL.md +398 -0
  60. package/templates/db-management/prisma-migration-assistant/ SKILL.md +379 -0
  61. package/templates/db-management/schema-consistency-checker/ SKILL.md +440 -0
  62. package/templates/db-management/sql-query-optimizer/ SKILL.md +324 -0
  63. package/templates/foundation/changelog-writer/ SKILL.md +431 -0
  64. package/templates/foundation/code-formatter-installer/ SKILL.md +320 -0
  65. package/templates/foundation/codebase-summarizer/ SKILL.md +360 -0
  66. package/templates/foundation/dependency-doctor/ SKILL.md +163 -0
  67. package/templates/foundation/dev-environment-bootstrapper/ SKILL.md +259 -0
  68. package/templates/foundation/dev-onboarding-builder/ SKILL.md +556 -0
  69. package/templates/foundation/docs-starter-kit/ SKILL.md +574 -0
  70. package/templates/foundation/explaining-code/SKILL.md +13 -0
  71. package/templates/foundation/git-hygiene-enforcer/ SKILL.md +455 -0
  72. package/templates/foundation/project-scaffolder/ SKILL.md +65 -0
  73. package/templates/foundation/project-scaffolder/references/templates.md +126 -0
  74. package/templates/foundation/repo-structure-linter/ SKILL.md +0 -0
  75. package/templates/foundation/repo-structure-linter/references/conventions.md +98 -0
  76. package/templates/frontend/animation-micro-interaction-pack/ SKILL.md +41 -0
  77. package/templates/frontend/component-scaffold-generator/ SKILL.md +562 -0
  78. package/templates/frontend/design-to-component-translator/ SKILL.md +547 -0
  79. package/templates/frontend/form-wizard-builder/ SKILL.md +553 -0
  80. package/templates/frontend/frontend-refactor-planner/ SKILL.md +37 -0
  81. package/templates/frontend/i18n-frontend-implementer/ SKILL.md +44 -0
  82. package/templates/frontend/modal-drawer-system/ SKILL.md +377 -0
  83. package/templates/frontend/page-layout-builder/ SKILL.md +630 -0
  84. package/templates/frontend/state-ux-flow-builder/ SKILL.md +23 -0
  85. package/templates/frontend/table-builder/ SKILL.md +350 -0
  86. package/templates/performance/alerting-dashboard-builder/ SKILL.md +162 -0
  87. package/templates/performance/backend-latency-profiler-helper/ SKILL.md +108 -0
  88. package/templates/performance/caching-cdn-strategy-planner/ SKILL.md +150 -0
  89. package/templates/performance/capacity-planning-helper/ SKILL.md +242 -0
  90. package/templates/performance/core-web-vitals-tuner/ SKILL.md +126 -0
  91. package/templates/performance/incident-runbook-generator/ SKILL.md +162 -0
  92. package/templates/performance/load-test-scenario-builder/ SKILL.md +256 -0
  93. package/templates/performance/observability-setup/ SKILL.md +232 -0
  94. package/templates/performance/postmortem-writer/ SKILL.md +203 -0
  95. package/templates/performance/structured-logging-standardizer/ SKILL.md +122 -0
  96. package/templates/security/auth-security-reviewer/ SKILL.md +428 -0
  97. package/templates/security/dependency-vulnerability-triage/ SKILL.md +495 -0
  98. package/templates/security/input-validation-sanitization-auditor/ SKILL.md +76 -0
  99. package/templates/security/pii-redaction-logging-policy-builder/ SKILL.md +65 -0
  100. package/templates/security/rbac-policy-tester/ SKILL.md +80 -0
  101. package/templates/security/secrets-scanner/ SKILL.md +462 -0
  102. package/templates/security/secure-headers-csp-builder/ SKILL.md +404 -0
  103. package/templates/security/security-incident-playbook-generator/ SKILL.md +76 -0
  104. package/templates/security/security-pr-checklist-skill/ SKILL.md +62 -0
  105. package/templates/security/threat-model-generator/ SKILL.md +394 -0
  106. package/templates/testing/contract-testing-builder/ SKILL.md +492 -0
  107. package/templates/testing/coverage-strategist/ SKILL.md +436 -0
  108. package/templates/testing/e2e-test-builder/ SKILL.md +382 -0
  109. package/templates/testing/flaky-test-detective/ SKILL.md +416 -0
  110. package/templates/testing/integration-test-builder/ SKILL.md +525 -0
  111. package/templates/testing/mocking-assistant/ SKILL.md +383 -0
  112. package/templates/testing/snapshot-test-refactorer/ SKILL.md +375 -0
  113. package/templates/testing/test-data-factory-builder/ SKILL.md +449 -0
  114. package/templates/testing/test-reporting-triage-skill/ SKILL.md +469 -0
  115. package/templates/testing/unit-test-generator/ SKILL.md +548 -0
@@ -0,0 +1,324 @@
1
+ ---
2
+ name: sql-query-optimizer
3
+ description: Analyzes and optimizes SQL queries using EXPLAIN plans, index recommendations, query rewrites, and performance benchmarking. Use for "query optimization", "slow queries", "database performance", or "EXPLAIN analysis".
4
+ ---
5
+
6
+ # SQL Query Optimizer
7
+
8
+ Optimize SQL queries for maximum performance.
9
+
10
+ ## EXPLAIN Analysis
11
+
12
+ ```sql
13
+ -- Original slow query
14
+ EXPLAIN ANALYZE
15
+ SELECT u.*, COUNT(o.id) as order_count
16
+ FROM users u
17
+ LEFT JOIN orders o ON o.user_id = u.id
18
+ WHERE u.created_at > '2024-01-01'
19
+ GROUP BY u.id
20
+ ORDER BY order_count DESC
21
+ LIMIT 10;
22
+
23
+ -- Output analysis:
24
+ /*
25
+ Sort (cost=15234.32..15234.34 rows=10 width=120) (actual time=245.123..245.125 rows=10 loops=1)
26
+ Sort Key: (count(o.id)) DESC
27
+ -> HashAggregate (cost=15000.00..15100.00 rows=1000 width=120) (actual time=244.891..245.023 rows=1000 loops=1)
28
+ Group Key: u.id
29
+ -> Hash Left Join (cost=1234.56..14500.00 rows=50000 width=112) (actual time=12.345..230.456 rows=50000 loops=1)
30
+ Hash Cond: (o.user_id = u.id)
31
+ -> Seq Scan on orders o (cost=0.00..10000.00 rows=100000 width=8) (actual time=0.012..180.234 rows=100000 loops=1)
32
+ -> Hash (cost=1000.00..1000.00 rows=5000 width=112) (actual time=10.234..10.234 rows=5000 loops=1)
33
+ Buckets: 8192 Batches: 1 Memory Usage: 456kB
34
+ -> Seq Scan on users u (cost=0.00..1000.00 rows=5000 width=112) (actual time=0.008..5.123 rows=5000 loops=1)
35
+ Filter: (created_at > '2024-01-01'::date)
36
+ Rows Removed by Filter: 1000
37
+ Planning Time: 0.234 ms
38
+ Execution Time: 245.234 ms
39
+ */
40
+
41
+ -- Issues identified:
42
+ -- 1. Seq Scan on orders (no index on user_id)
43
+ -- 2. Seq Scan on users (no index on created_at)
44
+ -- 3. Full table scans expensive
45
+ ```
46
+
47
+ ## Index Recommendations
48
+
49
+ ```sql
50
+ -- Problem: Sequential scans
51
+ EXPLAIN ANALYZE
52
+ SELECT * FROM orders WHERE user_id = 123;
53
+ /*
54
+ Seq Scan on orders (cost=0.00..10000.00 rows=50 width=100) (actual time=0.012..89.456 rows=50 loops=1)
55
+ Filter: (user_id = 123)
56
+ Rows Removed by Filter: 99950
57
+ */
58
+
59
+ -- Solution: Add index
60
+ CREATE INDEX idx_orders_user_id ON orders(user_id);
61
+
62
+ -- After index:
63
+ /*
64
+ Index Scan using idx_orders_user_id on orders (cost=0.29..45.32 rows=50 width=100) (actual time=0.023..0.089 rows=50 loops=1)
65
+ Index Cond: (user_id = 123)
66
+ */
67
+
68
+ -- Performance: 89ms → 0.09ms (990x faster!)
69
+ ```
70
+
71
+ ## Query Rewrites
72
+
73
+ ### 1. Avoid SELECT \*
74
+
75
+ ```sql
76
+ -- āŒ Bad: Fetches all columns
77
+ SELECT * FROM users WHERE id = 123;
78
+
79
+ -- āœ… Good: Fetch only needed columns
80
+ SELECT id, email, name FROM users WHERE id = 123;
81
+
82
+ -- Performance: 50% faster, less network transfer
83
+ ```
84
+
85
+ ### 2. Use EXISTS Instead of IN
86
+
87
+ ```sql
88
+ -- āŒ Slow: Subquery executed fully
89
+ SELECT * FROM users
90
+ WHERE id IN (SELECT user_id FROM orders WHERE total > 100);
91
+
92
+ -- āœ… Fast: Short-circuits on first match
93
+ SELECT * FROM users u
94
+ WHERE EXISTS (
95
+ SELECT 1 FROM orders o
96
+ WHERE o.user_id = u.id AND o.total > 100
97
+ );
98
+
99
+ -- Performance: 3x faster on large datasets
100
+ ```
101
+
102
+ ### 3. Avoid Functions on Indexed Columns
103
+
104
+ ```sql
105
+ -- āŒ Bad: Index not used
106
+ SELECT * FROM users WHERE LOWER(email) = 'john@example.com';
107
+
108
+ -- āœ… Good: Index scan possible
109
+ SELECT * FROM users WHERE email = 'john@example.com';
110
+
111
+ -- Or create functional index:
112
+ CREATE INDEX idx_users_email_lower ON users(LOWER(email));
113
+ ```
114
+
115
+ ### 4. Use Covering Indexes
116
+
117
+ ```sql
118
+ -- Query needs: id, email, name
119
+ SELECT id, email, name FROM users WHERE email = 'john@example.com';
120
+
121
+ -- Create covering index (includes all needed columns)
122
+ CREATE INDEX idx_users_email_covering ON users(email) INCLUDE (id, name);
123
+
124
+ -- Result: Index-only scan (no table access needed)
125
+ ```
126
+
127
+ ### 5. Optimize JOIN Order
128
+
129
+ ```sql
130
+ -- āŒ Bad: Large table first
131
+ SELECT * FROM orders o
132
+ JOIN users u ON u.id = o.user_id
133
+ WHERE u.email = 'john@example.com';
134
+
135
+ -- āœ… Good: Filter first, join second
136
+ SELECT * FROM users u
137
+ JOIN orders o ON o.user_id = u.id
138
+ WHERE u.email = 'john@example.com';
139
+
140
+ -- Or use CTE for clarity:
141
+ WITH filtered_users AS (
142
+ SELECT id FROM users WHERE email = 'john@example.com'
143
+ )
144
+ SELECT o.* FROM orders o
145
+ JOIN filtered_users u ON u.id = o.user_id;
146
+ ```
147
+
148
+ ## Composite Indexes
149
+
150
+ ```sql
151
+ -- Query pattern: WHERE user_id = X AND status = 'active' ORDER BY created_at DESC
152
+ CREATE INDEX idx_orders_user_status_created
153
+ ON orders(user_id, status, created_at DESC);
154
+
155
+ -- Index column order matters!
156
+ -- Rule: Equality filters → Range filters → Sort columns
157
+
158
+ -- Example queries that use this index:
159
+ -- 1. SELECT * FROM orders WHERE user_id = 123; āœ…
160
+ -- 2. SELECT * FROM orders WHERE user_id = 123 AND status = 'active'; āœ…
161
+ -- 3. SELECT * FROM orders WHERE user_id = 123 ORDER BY created_at DESC; āœ…
162
+ -- 4. SELECT * FROM orders WHERE status = 'active'; āŒ (doesn't start with user_id)
163
+ ```
164
+
165
+ ## Query Performance Benchmarking
166
+
167
+ ```typescript
168
+ // scripts/benchmark-queries.ts
169
+ import { PrismaClient } from "@prisma/client";
170
+ import { performance } from "perf_hooks";
171
+
172
+ const prisma = new PrismaClient();
173
+
174
+ async function benchmarkQuery(
175
+ name: string,
176
+ query: () => Promise<any>,
177
+ iterations: number = 10
178
+ ) {
179
+ const times: number[] = [];
180
+
181
+ for (let i = 0; i < iterations; i++) {
182
+ const start = performance.now();
183
+ await query();
184
+ const end = performance.now();
185
+ times.push(end - start);
186
+ }
187
+
188
+ const avg = times.reduce((a, b) => a + b, 0) / times.length;
189
+ const min = Math.min(...times);
190
+ const max = Math.max(...times);
191
+
192
+ console.log(`\n${name}:`);
193
+ console.log(` Avg: ${avg.toFixed(2)}ms`);
194
+ console.log(` Min: ${min.toFixed(2)}ms`);
195
+ console.log(` Max: ${max.toFixed(2)}ms`);
196
+
197
+ return { avg, min, max };
198
+ }
199
+
200
+ // Compare queries
201
+ async function compareQueries() {
202
+ console.log("šŸ” Benchmarking queries...\n");
203
+
204
+ // Query 1: Original
205
+ const result1 = await benchmarkQuery("Original Query", async () => {
206
+ return prisma.$queryRaw`
207
+ SELECT u.*, COUNT(o.id) as order_count
208
+ FROM users u
209
+ LEFT JOIN orders o ON o.user_id = u.id
210
+ GROUP BY u.id
211
+ LIMIT 10
212
+ `;
213
+ });
214
+
215
+ // Query 2: Optimized
216
+ const result2 = await benchmarkQuery("Optimized Query", async () => {
217
+ return prisma.$queryRaw`
218
+ SELECT u.id, u.email, u.name,
219
+ (SELECT COUNT(*) FROM orders WHERE user_id = u.id) as order_count
220
+ FROM users u
221
+ LIMIT 10
222
+ `;
223
+ });
224
+
225
+ // Comparison
226
+ const improvement = (
227
+ ((result1.avg - result2.avg) / result1.avg) *
228
+ 100
229
+ ).toFixed(1);
230
+ console.log(`\nšŸ“Š Improvement: ${improvement}% faster`);
231
+ }
232
+
233
+ compareQueries();
234
+ ```
235
+
236
+ ## Query Optimization Checklist
237
+
238
+ ```typescript
239
+ interface QueryOptimization {
240
+ query: string;
241
+ issues: string[];
242
+ recommendations: string[];
243
+ estimatedImprovement: string;
244
+ }
245
+
246
+ const optimizations: QueryOptimization[] = [
247
+ {
248
+ query: "SELECT * FROM orders WHERE user_id = $1",
249
+ issues: [
250
+ "Missing index on user_id",
251
+ "SELECT * fetches unnecessary columns",
252
+ ],
253
+ recommendations: [
254
+ "CREATE INDEX idx_orders_user_id ON orders(user_id)",
255
+ "SELECT id, total, status instead of *",
256
+ ],
257
+ estimatedImprovement: "90% faster",
258
+ },
259
+ {
260
+ query: "SELECT COUNT(*) FROM orders",
261
+ issues: ["Full table scan", "No WHERE clause filtering"],
262
+ recommendations: [
263
+ "Add WHERE clause to filter rows",
264
+ "Consider approximate count for large tables",
265
+ ],
266
+ estimatedImprovement: "70% faster",
267
+ },
268
+ ];
269
+ ```
270
+
271
+ ## Automated Slow Query Detection
272
+
273
+ ```typescript
274
+ // scripts/detect-slow-queries.ts
275
+ async function detectSlowQueries() {
276
+ // Enable slow query logging in PostgreSQL
277
+ await prisma.$executeRaw`
278
+ ALTER DATABASE mydb SET log_min_duration_statement = 100;
279
+ `;
280
+
281
+ // Query pg_stat_statements for slow queries
282
+ const slowQueries = await prisma.$queryRaw<any[]>`
283
+ SELECT
284
+ query,
285
+ calls,
286
+ total_exec_time / 1000 as total_time_seconds,
287
+ mean_exec_time / 1000 as mean_time_ms,
288
+ max_exec_time / 1000 as max_time_ms
289
+ FROM pg_stat_statements
290
+ WHERE mean_exec_time > 100 -- > 100ms
291
+ ORDER BY mean_exec_time DESC
292
+ LIMIT 20
293
+ `;
294
+
295
+ console.log("🐌 Slow Queries Detected:\n");
296
+ slowQueries.forEach((q, i) => {
297
+ console.log(`${i + 1}. ${q.query.substring(0, 80)}...`);
298
+ console.log(` Calls: ${q.calls}`);
299
+ console.log(` Avg: ${q.mean_time_ms.toFixed(2)}ms`);
300
+ console.log(` Max: ${q.max_time_ms.toFixed(2)}ms\n`);
301
+ });
302
+ }
303
+ ```
304
+
305
+ ## Best Practices
306
+
307
+ 1. **Always use EXPLAIN**: Understand query plans
308
+ 2. **Index foreign keys**: Essential for joins
309
+ 3. **Avoid SELECT \***: Fetch only needed columns
310
+ 4. **Use composite indexes**: Multi-column queries
311
+ 5. **Consider covering indexes**: Eliminate table access
312
+ 6. **Batch operations**: Reduce round trips
313
+ 7. **Monitor regularly**: Track slow queries
314
+
315
+ ## Output Checklist
316
+
317
+ - [ ] EXPLAIN plan analyzed
318
+ - [ ] Missing indexes identified
319
+ - [ ] Query rewrite suggestions
320
+ - [ ] Performance benchmarks
321
+ - [ ] Before/after metrics
322
+ - [ ] Index creation scripts
323
+ - [ ] Slow query monitoring
324
+ - [ ] Optimization priority list