@wipal/agent-team 1.0.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 (89) hide show
  1. package/.claude/rules/common/general-rules.md +141 -0
  2. package/.claude/rules/lessons/lessons.md +91 -0
  3. package/.claude/rules/role-rules/dev-fe-rules.md +146 -0
  4. package/.claude/rules/role-rules/sa-rules.md +226 -0
  5. package/.claude/skills/SKILL-INDEX.md +299 -0
  6. package/.claude/skills/community/security-validator/SKILL.md +392 -0
  7. package/.claude/skills/core/agent-creation/SKILL.md +338 -0
  8. package/.claude/skills/core/code-review/SKILL.md +154 -0
  9. package/.claude/skills/core/git-automation/SKILL.md +93 -0
  10. package/.claude/skills/core/retrospect-work/SKILL.md +172 -0
  11. package/.claude/skills/domain/architecture/adr-writing/SKILL.md +254 -0
  12. package/.claude/skills/domain/architecture/adr-writing/references/adr-best-practices.md +257 -0
  13. package/.claude/skills/domain/architecture/adr-writing/references/adr-examples.md +246 -0
  14. package/.claude/skills/domain/architecture/adr-writing/references/adr-template.md +160 -0
  15. package/.claude/skills/domain/architecture/architecture-patterns/SKILL.md +316 -0
  16. package/.claude/skills/domain/architecture/architecture-patterns/references/event-driven.md +393 -0
  17. package/.claude/skills/domain/architecture/architecture-patterns/references/microservices.md +315 -0
  18. package/.claude/skills/domain/architecture/architecture-patterns/references/monolith.md +321 -0
  19. package/.claude/skills/domain/architecture/architecture-patterns/references/serverless.md +457 -0
  20. package/.claude/skills/domain/architecture/performance-engineering/SKILL.md +227 -0
  21. package/.claude/skills/domain/architecture/performance-engineering/references/benchmarking.md +336 -0
  22. package/.claude/skills/domain/architecture/performance-engineering/references/caching-strategies.md +284 -0
  23. package/.claude/skills/domain/architecture/performance-engineering/references/optimization.md +298 -0
  24. package/.claude/skills/domain/architecture/security-architecture/SKILL.md +206 -0
  25. package/.claude/skills/domain/architecture/security-architecture/references/auth-patterns.md +209 -0
  26. package/.claude/skills/domain/architecture/security-architecture/references/compliance.md +246 -0
  27. package/.claude/skills/domain/architecture/security-architecture/references/threat-modeling.md +219 -0
  28. package/.claude/skills/domain/architecture/system-design/SKILL.md +227 -0
  29. package/.claude/skills/domain/architecture/system-design/references/distributed-systems.md +231 -0
  30. package/.claude/skills/domain/architecture/system-design/references/resilience.md +344 -0
  31. package/.claude/skills/domain/architecture/system-design/references/scalability.md +303 -0
  32. package/.claude/skills/domain/architecture/tech-selection/SKILL.md +192 -0
  33. package/.claude/skills/domain/architecture/tech-selection/references/build-vs-buy.md +258 -0
  34. package/.claude/skills/domain/architecture/tech-selection/references/evaluation-framework.md +203 -0
  35. package/.claude/skills/domain/architecture/tech-selection/references/tech-radar.md +257 -0
  36. package/.claude/skills/domain/backend/api-design/SKILL.md +121 -0
  37. package/.claude/skills/domain/backend/database-design/SKILL.md +156 -0
  38. package/.claude/skills/domain/backend/performance-be/SKILL.md +210 -0
  39. package/.claude/skills/domain/backend/security/SKILL.md +138 -0
  40. package/.claude/skills/domain/backend/testing-be/SKILL.md +203 -0
  41. package/.claude/skills/domain/devops/ci-cd/SKILL.md +188 -0
  42. package/.claude/skills/domain/devops/containerization/SKILL.md +177 -0
  43. package/.claude/skills/domain/devops/deployment/SKILL.md +198 -0
  44. package/.claude/skills/domain/devops/infrastructure-as-code/SKILL.md +178 -0
  45. package/.claude/skills/domain/devops/monitoring/SKILL.md +163 -0
  46. package/.claude/skills/domain/frontend/accessibility/SKILL.md +179 -0
  47. package/.claude/skills/domain/frontend/frontend-design/SKILL.md +138 -0
  48. package/.claude/skills/domain/frontend/performance-fe/SKILL.md +195 -0
  49. package/.claude/skills/domain/frontend/state-management/SKILL.md +190 -0
  50. package/.claude/skills/domain/frontend/testing-fe/SKILL.md +193 -0
  51. package/.claude/skills/domain/product/requirements-gathering/SKILL.md +136 -0
  52. package/.claude/skills/domain/product/roadmap-planning/SKILL.md +169 -0
  53. package/.claude/skills/domain/product/sprint-planning/SKILL.md +151 -0
  54. package/.claude/skills/domain/product/stakeholder-communication/SKILL.md +162 -0
  55. package/.claude/skills/domain/product/user-stories/SKILL.md +141 -0
  56. package/.claude/skills/domain/quality/bug-reporting/SKILL.md +150 -0
  57. package/.claude/skills/domain/quality/regression-testing/SKILL.md +178 -0
  58. package/.claude/skills/domain/quality/test-automation/SKILL.md +185 -0
  59. package/.claude/skills/domain/quality/test-planning/SKILL.md +177 -0
  60. package/.claude/skills/leadership/code-review-advanced/SKILL.md +167 -0
  61. package/.claude/skills/leadership/mentoring/SKILL.md +151 -0
  62. package/.claude/skills/leadership/technical-debt/SKILL.md +166 -0
  63. package/.claude/skills/leadership/technical-decision/SKILL.md +160 -0
  64. package/.claude/skills/security-reports/.gitkeep +0 -0
  65. package/.claude/skills/skills-registry.yaml +441 -0
  66. package/README.md +232 -0
  67. package/bin/agent-team.js +107 -0
  68. package/package.json +51 -0
  69. package/src/commands/add.js +227 -0
  70. package/src/commands/init.js +136 -0
  71. package/src/commands/list.js +66 -0
  72. package/src/commands/remove.js +71 -0
  73. package/src/commands/switch.js +53 -0
  74. package/src/index.js +11 -0
  75. package/src/interactive/prompts.js +153 -0
  76. package/src/server/api/agents.js +150 -0
  77. package/src/server/api/roles.js +97 -0
  78. package/src/server/api/skills.js +79 -0
  79. package/src/server/index.js +78 -0
  80. package/src/ui/agents.html +174 -0
  81. package/src/ui/css/styles.css +470 -0
  82. package/src/ui/index.html +107 -0
  83. package/src/ui/roles.html +371 -0
  84. package/src/ui/skills.html +332 -0
  85. package/src/utils/file-utils.js +193 -0
  86. package/src/utils/skill-resolver.js +594 -0
  87. package/src/utils/skill-scanner.js +154 -0
  88. package/templates/CLAUDE.md.tmpl +42 -0
  89. package/templates/knowledge.md.tmpl +31 -0
@@ -0,0 +1,457 @@
1
+ # Serverless Architecture
2
+
3
+ ## Overview
4
+ Serverless is a cloud execution model where the cloud provider dynamically manages infrastructure allocation and scaling. You focus on code, not servers.
5
+
6
+ ## Core Concepts
7
+
8
+ ### What "Serverless" Really Means
9
+ ```
10
+ Not "no servers" but "no server management":
11
+
12
+ Traditional: Serverless:
13
+ ┌─────────────────────┐ ┌─────────────────────┐
14
+ │ Your Responsibility │ │ Your Responsibility │
15
+ ├─────────────────────┤ ├─────────────────────┤
16
+ │ - Application code │ │ - Application code │
17
+ │ - Runtime │ │ - Function logic │
18
+ │ - OS updates │ │ │
19
+ │ - Server patching │ │ │
20
+ │ - Scaling │ │ │
21
+ │ - High availability │ │ │
22
+ └─────────────────────┘ └─────────────────────┘
23
+
24
+ Cloud Provider handles:
25
+ - Server provisioning
26
+ - OS management
27
+ - Scaling (auto)
28
+ - High availability
29
+ - Security patching
30
+ ```
31
+
32
+ ## Serverless Components
33
+
34
+ ### 1. Function as a Service (FaaS)
35
+ ```
36
+ ┌─────────────────────────────────────────────┐
37
+ │ Lambda / Function │
38
+ ├─────────────────────────────────────────────┤
39
+ │ - Event-triggered execution │
40
+ │ - Stateless │
41
+ │ - Short-lived (15 min max typically) │
42
+ │ - Pay per invocation + execution time │
43
+ └─────────────────────────────────────────────┘
44
+
45
+ Triggers:
46
+ - HTTP requests (API Gateway)
47
+ - Database changes (DynamoDB Streams)
48
+ - File uploads (S3)
49
+ - Messages (SQS, SNS, EventBridge)
50
+ - Scheduled (CloudWatch Events)
51
+ - Custom events
52
+ ```
53
+
54
+ ### 2. Backend as a Service (BaaS)
55
+ ```
56
+ Managed Services (no code needed):
57
+
58
+ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
59
+ │ Database │ │ Storage │ │ Auth │
60
+ │ (DynamoDB, │ │ (S3, Blob │ │ (Cognito, │
61
+ │ Firestore) │ │ Storage) │ │ Auth0) │
62
+ └──────────────┘ └──────────────┘ └──────────────┘
63
+
64
+ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
65
+ │ Queue │ │ Cache │ │ Search │
66
+ │ (SQS, Pub/Sub│ │ (ElastiCache,│ │ (Elasticsearch│
67
+ │ Service Bus)│ │ Redis Cloud)│ │ Cloud Search)│
68
+ └──────────────┘ └──────────────┘ └──────────────┘
69
+ ```
70
+
71
+ ## Architecture Patterns
72
+
73
+ ### 1. API Backend
74
+ ```
75
+ ┌─────────┐ ┌─────────────┐ ┌─────────────┐
76
+ │ Client │────▶│ API Gateway │────▶│ Lambda │
77
+ │ (Web/ │ │ │ │ Function │
78
+ │ Mobile)│ │ │ └──────┬──────┘
79
+ └─────────┘ └─────────────┘ │
80
+
81
+ ┌─────────────┐
82
+ │ DynamoDB │
83
+ └─────────────┘
84
+
85
+ Flow:
86
+ 1. Client makes HTTP request
87
+ 2. API Gateway routes to Lambda
88
+ 3. Lambda processes, reads/writes DB
89
+ 4. Response returned
90
+
91
+ Cost: Pay per API call + Lambda execution
92
+ ```
93
+
94
+ ### 2. Event Processing
95
+ ```
96
+ ┌─────────┐ ┌─────────────┐ ┌─────────────┐
97
+ │ S3 │────▶│ Lambda │────▶│ SNS │
98
+ │ Upload │ │ (resize) │ │(notify) │
99
+ └─────────┘ └─────────────┘ └─────────────┘
100
+
101
+
102
+ ┌─────────────┐
103
+ │ S3 (thumb) │
104
+ └─────────────┘
105
+
106
+ Flow:
107
+ 1. Image uploaded to S3
108
+ 2. S3 triggers Lambda
109
+ 3. Lambda creates thumbnail
110
+ 4. Stores in another S3 bucket
111
+ 5. Sends notification
112
+ ```
113
+
114
+ ### 3. Data Pipeline
115
+ ```
116
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
117
+ │ Kinesis/ │────▶│ Lambda │────▶│ Redshift/ │
118
+ │ EventBridge │ │ (transform) │ │ S3 │
119
+ └─────────────┘ └─────────────┘ └─────────────┘
120
+
121
+ Flow:
122
+ 1. Events stream in
123
+ 2. Lambda transforms data
124
+ 3. Loads to data warehouse
125
+ ```
126
+
127
+ ### 4. Chatbot / Webhook
128
+ ```
129
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
130
+ │ Slack/Teams │────▶│ API Gateway │────▶│ Lambda │
131
+ │ Webhook │ │ │ │ │
132
+ └─────────────┘ └─────────────┘ └──────┬──────┘
133
+
134
+
135
+ ┌─────────────┐
136
+ │ Third-party │
137
+ │ API │
138
+ └─────────────┘
139
+ ```
140
+
141
+ ## Provider Comparison
142
+
143
+ ### Major Providers
144
+ ```
145
+ ┌──────────────┬────────────────┬────────────────┬────────────────┐
146
+ │ Feature │ AWS Lambda │ Azure Functions │ Google Cloud │
147
+ ├──────────────┼────────────────┼────────────────┼────────────────┤
148
+ │ Max runtime │ 15 minutes │ 10 minutes │ 9 minutes │
149
+ │ Memory │ 128MB - 10GB │ 128MB - 1.5GB │ 128MB - 32GB │
150
+ │ Cold start │ 100-500ms │ 100-300ms │ 100-300ms │
151
+ │ Triggers │ 20+ services │ 15+ services │ 15+ services │
152
+ │ Languages │ Node, Python, │ C#, Node, │ Node, Python, │
153
+ │ │ Java, Go, C# │ Python, Java │ Go, Java │
154
+ └──────────────┴────────────────┴────────────────┴────────────────┘
155
+ ```
156
+
157
+ ### Cold Starts
158
+ ```
159
+ Why cold starts happen:
160
+ 1. No warm instances available
161
+ 2. New container needs to be created
162
+ 3. Runtime initialized
163
+ 4. Function code loaded
164
+ 5. Handler executed
165
+
166
+ Cold start times:
167
+ - Node.js: 100-200ms
168
+ - Python: 100-300ms
169
+ - Java: 500-2000ms
170
+ - .NET: 500-1500ms
171
+
172
+ Mitigation:
173
+ - Provisioned concurrency (keep warm)
174
+ - Smaller deployment packages
175
+ - Choose faster runtime
176
+ - Connection pooling
177
+ ```
178
+
179
+ ## Best Practices
180
+
181
+ ### 1. Function Design
182
+ ```
183
+ DO:
184
+ ✅ Single responsibility
185
+ ✅ Stateless functions
186
+ ✅ Idempotent operations
187
+ ✅ Quick execution (< 5 seconds ideal)
188
+ ✅ Handle retries gracefully
189
+
190
+ DON'T:
191
+ ❌ Long-running processes
192
+ ❌ Stateful logic
193
+ ❌ Heavy initialization
194
+ ❌ Synchronous external calls (if avoidable)
195
+ ❌ Large dependencies
196
+ ```
197
+
198
+ ### 2. Cold Start Optimization
199
+ ```
200
+ 1. Minimize dependencies:
201
+ - Use tree-shaking
202
+ - Only import what you need
203
+ - Consider bundle size
204
+
205
+ 2. Lazy loading:
206
+ const heavyLib = null;
207
+
208
+ export const handler = async (event) => {
209
+ if (!heavyLib) {
210
+ heavyLib = await import('heavy-library');
211
+ }
212
+ // ...
213
+ };
214
+
215
+ 3. Connection reuse:
216
+ // Outside handler - reused across invocations
217
+ const db = new DatabaseClient();
218
+
219
+ export const handler = async (event) => {
220
+ return db.query(...);
221
+ };
222
+
223
+ 4. Provisioned concurrency:
224
+ - Pre-warmed instances
225
+ - Pay for reserved capacity
226
+ - Use for latency-sensitive functions
227
+ ```
228
+
229
+ ### 3. Error Handling
230
+ ```
231
+ Structued error handling:
232
+
233
+ export const handler = async (event) => {
234
+ try {
235
+ const result = await processEvent(event);
236
+ return {
237
+ statusCode: 200,
238
+ body: JSON.stringify(result)
239
+ };
240
+ } catch (error) {
241
+ console.error('Error:', error);
242
+
243
+ // DLQ for failed events
244
+ if (error.isRetryable) {
245
+ throw error; // Will retry
246
+ }
247
+
248
+ return {
249
+ statusCode: 500,
250
+ body: JSON.stringify({
251
+ error: error.message,
252
+ requestId: event.requestContext.requestId
253
+ })
254
+ };
255
+ }
256
+ };
257
+ ```
258
+
259
+ ### 4. Security
260
+ ```
261
+ 1. Least privilege IAM:
262
+ - Function-specific roles
263
+ - Minimum required permissions
264
+ - No wildcard permissions
265
+
266
+ 2. Secrets management:
267
+ - Use Secrets Manager / Parameter Store
268
+ - Never hardcode secrets
269
+ - Rotate credentials
270
+
271
+ 3. VPC configuration:
272
+ - Place in VPC if accessing private resources
273
+ - Use VPC endpoints for AWS services
274
+ - Consider NAT gateway costs
275
+
276
+ 4. Input validation:
277
+ - Validate all inputs
278
+ - Sanitize user data
279
+ - Rate limiting at API Gateway
280
+ ```
281
+
282
+ ## Cost Optimization
283
+
284
+ ### Pricing Model
285
+ ```
286
+ AWS Lambda example:
287
+ - Request price: $0.20 per 1M requests
288
+ - Duration price: $0.00001667 per GB-second
289
+
290
+ Monthly cost calculation:
291
+ - 1M requests/month
292
+ - 256MB memory
293
+ - 100ms average duration
294
+
295
+ Cost = (1M × $0.20/1M) + (1M × 0.1s × 0.25GB × $0.00001667)
296
+ = $0.20 + $0.42
297
+ = $0.62/month
298
+
299
+ vs EC2 t3.micro (always on): ~$8.50/month
300
+ ```
301
+
302
+ ### Cost Optimization Tips
303
+ ```
304
+ 1. Right-size memory:
305
+ - More memory = faster execution
306
+ - Test different configurations
307
+ - Find cost/performance sweet spot
308
+
309
+ 2. Optimize duration:
310
+ - Faster code = less cost
311
+ - Cache expensive operations
312
+ - Minimize cold starts
313
+
314
+ 3. Reduce requests:
315
+ - Batch processing
316
+ - Combine functions
317
+ - Use caching at API Gateway
318
+
319
+ 4. Free tier awareness:
320
+ - AWS: 1M requests + 400K GB-seconds/month free
321
+ - Monitor usage
322
+ ```
323
+
324
+ ## Limitations & Challenges
325
+
326
+ ### Technical Limitations
327
+ ```
328
+ 1. Execution time:
329
+ - AWS Lambda: 15 minutes max
330
+ - Not for long-running jobs
331
+
332
+ 2. Memory:
333
+ - AWS Lambda: 128MB - 10GB
334
+ - Limited for memory-intensive tasks
335
+
336
+ 3. Deployment size:
337
+ - AWS Lambda: 250MB (unzipped)
338
+ - Large dependencies problematic
339
+
340
+ 4. Cold starts:
341
+ - Latency spikes
342
+ - Not ideal for real-time apps
343
+
344
+ 5. Vendor lock-in:
345
+ - Provider-specific APIs
346
+ - Migration challenges
347
+ ```
348
+
349
+ ### Operational Challenges
350
+ ```
351
+ 1. Debugging:
352
+ - Distributed tracing needed
353
+ - Local testing differs from production
354
+ - Limited visibility
355
+
356
+ 2. Monitoring:
357
+ - Need specialized tools
358
+ - Multiple data sources
359
+ - Complex alerting
360
+
361
+ 3. Testing:
362
+ - Local emulation imperfect
363
+ - Integration testing complex
364
+ - End-to-end testing challenging
365
+ ```
366
+
367
+ ## When to Use Serverless
368
+
369
+ ### ✅ Best Use Cases
370
+ ```
371
+ - Variable/unpredictable traffic
372
+ - Event-driven processing
373
+ - API backends for mobile/web
374
+ - Scheduled tasks
375
+ - Data transformation pipelines
376
+ - Chatbots and webhooks
377
+ - File processing
378
+ - Quick prototypes and MVPs
379
+ ```
380
+
381
+ ### ❌ Avoid Serverless For
382
+ ```
383
+ - Long-running processes (> 15 min)
384
+ - Consistent, high traffic (EC2 cheaper)
385
+ - Real-time/gaming applications
386
+ - Complex state management
387
+ - Predictable workload (reserved instances)
388
+ - Heavy computational tasks
389
+ - Strict latency requirements (< 100ms)
390
+ ```
391
+
392
+ ## Serverless Frameworks
393
+
394
+ ### Infrastructure as Code
395
+ ```
396
+ 1. AWS SAM (Serverless Application Model):
397
+ - AWS-native
398
+ - YAML-based
399
+ - Good for AWS-only projects
400
+
401
+ 2. Serverless Framework:
402
+ - Multi-cloud
403
+ - YAML-based
404
+ - Large plugin ecosystem
405
+
406
+ 3. Terraform:
407
+ - Multi-cloud
408
+ - HCL language
409
+ - Full infrastructure management
410
+
411
+ 4. AWS CDK:
412
+ - AWS-native
413
+ - TypeScript/Python/Java
414
+ - Programmatic infrastructure
415
+ ```
416
+
417
+ ### Example: Serverless Framework
418
+ ```yaml
419
+ # serverless.yml
420
+ service: my-api
421
+
422
+ provider:
423
+ name: aws
424
+ runtime: nodejs18.x
425
+ region: us-east-1
426
+
427
+ functions:
428
+ getUser:
429
+ handler: src/handlers/getUser.handler
430
+ events:
431
+ - http:
432
+ path: users/{id}
433
+ method: get
434
+ environment:
435
+ TABLE_NAME: ${self:service}-users
436
+
437
+ resources:
438
+ Resources:
439
+ UsersTable:
440
+ Type: AWS::DynamoDB::Table
441
+ Properties:
442
+ TableName: ${self:service}-users
443
+ BillingMode: PAY_PER_REQUEST
444
+ AttributeDefinitions:
445
+ - AttributeName: id
446
+ AttributeType: S
447
+ KeySchema:
448
+ - AttributeName: id
449
+ KeyType: HASH
450
+ ```
451
+
452
+ ## Further Reading
453
+
454
+ - "Serverless Architectures on AWS" - Peter Sbarski
455
+ - AWS Serverless Application Lens
456
+ - serverless.com/learn
457
+ - AWS Well-Architected Serverless Lens
@@ -0,0 +1,227 @@
1
+ ---
2
+ name: performance-engineering
3
+ description: |
4
+ Use when optimizing system performance, designing caching strategies,
5
+ or planning for scalability. Covers caching, optimization techniques,
6
+ and performance testing.
7
+ version: 1.0.0
8
+ category: performance
9
+ tags:
10
+ - performance
11
+ - caching
12
+ - optimization
13
+ - benchmarking
14
+ dependencies:
15
+ - system-design
16
+ references:
17
+ - references/caching-strategies.md
18
+ - references/optimization.md
19
+ - references/benchmarking.md
20
+ ---
21
+
22
+ # Performance Engineering
23
+
24
+ ## Core Principle
25
+ **Measure first, optimize what matters, trade-off consciously.**
26
+
27
+ ## When to Use This Skill
28
+
29
+ ### Trigger Conditions
30
+ - System performance issues
31
+ - Capacity planning
32
+ - Caching strategy design
33
+ - Performance optimization
34
+ - Load testing
35
+
36
+ ### Keywords
37
+ - "performance"
38
+ - "optimization"
39
+ - "caching"
40
+ - "latency"
41
+ - "throughput"
42
+ - "load testing"
43
+
44
+ ## Performance Metrics
45
+
46
+ ### Key Metrics (USE/RED)
47
+ ```
48
+ USE Method (Resources):
49
+ - Utilization: % busy
50
+ - Saturation: Queue length
51
+ - Errors: Error count
52
+
53
+ RED Method (Services):
54
+ - Rate: Requests/second
55
+ - Errors: Failed requests/second
56
+ - Duration: Latency distribution (p50, p95, p99)
57
+ ```
58
+
59
+ ### Latency Percentiles
60
+ ```
61
+ p50 (median): 50% of requests faster than this
62
+ p95: 95% of requests faster than this
63
+ p99: 99% of requests faster than this
64
+
65
+ Example:
66
+ p50: 100ms - Most users see this
67
+ p95: 250ms - 5% see slower
68
+ p99: 500ms - 1% see slower (often problematic queries)
69
+
70
+ Target: Focus on p95/p99 for user experience
71
+ ```
72
+
73
+ ## Caching Strategies
74
+
75
+ ### Cache Locations
76
+ ```
77
+ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
78
+ │ Browser │────▶│ CDN │────▶│ Load │────▶│ App │
79
+ │ Cache │ │ Cache │ │Balancer │ │ Cache │
80
+ └─────────┘ └─────────┘ └─────────┘ └────┬────┘
81
+
82
+ ┌────┴────┐
83
+ │Database │
84
+ │ Cache │
85
+ └─────────┘
86
+ ```
87
+
88
+ ### Caching Patterns
89
+ ```
90
+ 1. Cache-Aside (Lazy Load)
91
+ - Check cache first
92
+ - On miss, load from DB
93
+ - Populate cache
94
+ - Return data
95
+
96
+ 2. Write-Through
97
+ - Write to cache AND DB
98
+ - Always consistent
99
+ - Higher write latency
100
+
101
+ 3. Write-Behind
102
+ - Write to cache
103
+ - Async write to DB
104
+ - Risk of data loss
105
+
106
+ 4. Refresh-Ahead
107
+ - Pre-refresh before expiry
108
+ - Good for predictable access
109
+ ```
110
+
111
+ ## Optimization Techniques
112
+
113
+ ### Application Level
114
+ ```
115
+ 1. Database Queries
116
+ - Use indexes effectively
117
+ - Avoid N+1 queries
118
+ - Use connection pooling
119
+ - Query optimization
120
+
121
+ 2. Code Optimization
122
+ - Algorithm efficiency
123
+ - Memory management
124
+ - Avoid premature optimization
125
+ - Profile before optimizing
126
+
127
+ 3. Concurrency
128
+ - Async/await patterns
129
+ - Thread pools
130
+ - Non-blocking I/O
131
+ ```
132
+
133
+ ### Infrastructure Level
134
+ ```
135
+ 1. Horizontal Scaling
136
+ - Add more instances
137
+ - Load balance
138
+
139
+ 2. Vertical Scaling
140
+ - More CPU/RAM
141
+ - Faster storage
142
+
143
+ 3. CDN
144
+ - Static assets
145
+ - Edge caching
146
+ - Geographic distribution
147
+ ```
148
+
149
+ ## Performance Testing
150
+
151
+ ### Types of Tests
152
+ ```
153
+ 1. Load Testing
154
+ - Expected load
155
+ - Normal conditions
156
+
157
+ 2. Stress Testing
158
+ - Beyond capacity
159
+ - Find breaking point
160
+
161
+ 3. Spike Testing
162
+ - Sudden traffic increase
163
+ - Auto-scaling validation
164
+
165
+ 4. Soak Testing
166
+ - Extended period
167
+ - Memory leaks, resource exhaustion
168
+ ```
169
+
170
+ ### Testing Tools
171
+ ```
172
+ - k6: Modern load testing
173
+ - JMeter: Feature-rich, Java-based
174
+ - Locust: Python-based
175
+ - Artillery: Node.js based
176
+ - Gatling: Scala-based, high performance
177
+ ```
178
+
179
+ ## Performance Checklist
180
+
181
+ ### Frontend
182
+ - [ ] Minimize HTTP requests
183
+ - [ ] Enable compression (gzip/brotli)
184
+ - [ ] Optimize images
185
+ - [ ] Use CDN
186
+ - [ ] Minify CSS/JS
187
+ - [ ] Lazy loading
188
+ - [ ] Code splitting
189
+
190
+ ### Backend
191
+ - [ ] Database indexing
192
+ - [ ] Query optimization
193
+ - [ ] Connection pooling
194
+ - [ ] Caching implemented
195
+ - [ ] Async processing
196
+ - [ ] Rate limiting
197
+
198
+ ### Infrastructure
199
+ - [ ] Load balancing
200
+ - [ ] Auto-scaling
201
+ - [ ] Monitoring & alerting
202
+ - [ ] CDN configuration
203
+ - [ ] SSL termination
204
+
205
+ ## Output
206
+
207
+ When optimizing performance:
208
+ 1. **Performance Report** - Current metrics, bottlenecks
209
+ 2. **Optimization Plan** - Prioritized improvements
210
+ 3. **Before/After Metrics** - Measured impact
211
+ 4. **ADR** - Significant performance decisions
212
+
213
+ ## Rules
214
+
215
+ ### DO
216
+ - ✅ Measure before optimizing
217
+ - ✅ Focus on bottlenecks
218
+ - ✅ Set performance targets
219
+ - ✅ Monitor continuously
220
+ - ✅ Test at production scale
221
+
222
+ ### DON'T
223
+ - ❌ Premature optimization
224
+ - ❌ Optimize without profiling
225
+ - ❌ Ignore trade-offs
226
+ - ❌ Skip load testing
227
+ - ❌ Trust benchmarks blindly