class-ai-agent 1.2.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 (93) hide show
  1. package/.claude/CLAUDE.md +155 -0
  2. package/.claude/agents/backend.md +395 -0
  3. package/.claude/agents/code-reviewer.md +110 -0
  4. package/.claude/agents/copywriter-seo.md +236 -0
  5. package/.claude/agents/frontend.md +384 -0
  6. package/.claude/agents/project-manager.md +201 -0
  7. package/.claude/agents/qa.md +221 -0
  8. package/.claude/agents/security-auditor.md +143 -0
  9. package/.claude/agents/systems-architect.md +211 -0
  10. package/.claude/agents/test-engineer.md +123 -0
  11. package/.claude/agents/ui-ux-designer.md +210 -0
  12. package/.claude/commands/build.md +132 -0
  13. package/.claude/commands/debug.md +242 -0
  14. package/.claude/commands/deploy.md +40 -0
  15. package/.claude/commands/fix-issue.md +42 -0
  16. package/.claude/commands/plan.md +125 -0
  17. package/.claude/commands/review.md +50 -0
  18. package/.claude/commands/simplify.md +222 -0
  19. package/.claude/commands/spec.md +95 -0
  20. package/.claude/commands/test.md +214 -0
  21. package/.claude/references/accessibility-checklist.md +174 -0
  22. package/.claude/references/performance-checklist.md +150 -0
  23. package/.claude/references/security-checklist.md +94 -0
  24. package/.claude/references/testing-patterns.md +183 -0
  25. package/.claude/rules/api-conventions.md +79 -0
  26. package/.claude/rules/clean-code.md +205 -0
  27. package/.claude/rules/code-style.md +86 -0
  28. package/.claude/rules/database.md +60 -0
  29. package/.claude/rules/error-handling.md +92 -0
  30. package/.claude/rules/git-workflow.md +77 -0
  31. package/.claude/rules/monitoring.md +311 -0
  32. package/.claude/rules/naming-conventions.md +260 -0
  33. package/.claude/rules/project-structure.md +65 -0
  34. package/.claude/rules/security.md +90 -0
  35. package/.claude/rules/system-design.md +162 -0
  36. package/.claude/rules/tech-stack.md +456 -0
  37. package/.claude/rules/testing.md +104 -0
  38. package/.claude/settings.json +14 -0
  39. package/.claude/skills/code-review/SKILL.md +208 -0
  40. package/.claude/skills/deploy/SKILL.md +68 -0
  41. package/.claude/skills/deploy/deploy.md +735 -0
  42. package/.claude/skills/incremental-implementation/SKILL.md +210 -0
  43. package/.claude/skills/security-review/SKILL.md +71 -0
  44. package/.claude/skills/tdd/SKILL.md +217 -0
  45. package/.cursor/CURSOR.md +112 -0
  46. package/.cursor/agents/backend.md +395 -0
  47. package/.cursor/agents/code-reviewer.md +110 -0
  48. package/.cursor/agents/copywriter-seo.md +236 -0
  49. package/.cursor/agents/frontend.md +384 -0
  50. package/.cursor/agents/project-manager.md +201 -0
  51. package/.cursor/agents/qa.md +221 -0
  52. package/.cursor/agents/security-auditor.md +143 -0
  53. package/.cursor/agents/systems-architect.md +211 -0
  54. package/.cursor/agents/test-engineer.md +123 -0
  55. package/.cursor/agents/ui-ux-designer.md +210 -0
  56. package/.cursor/commands/build.md +132 -0
  57. package/.cursor/commands/debug.md +242 -0
  58. package/.cursor/commands/deploy.md +40 -0
  59. package/.cursor/commands/fix-issue.md +42 -0
  60. package/.cursor/commands/plan.md +125 -0
  61. package/.cursor/commands/review.md +50 -0
  62. package/.cursor/commands/simplify.md +222 -0
  63. package/.cursor/commands/spec.md +95 -0
  64. package/.cursor/commands/test.md +214 -0
  65. package/.cursor/references/accessibility-checklist.md +174 -0
  66. package/.cursor/references/performance-checklist.md +150 -0
  67. package/.cursor/references/security-checklist.md +94 -0
  68. package/.cursor/references/testing-patterns.md +183 -0
  69. package/.cursor/rules/api-conventions.mdc +85 -0
  70. package/.cursor/rules/clean-code.mdc +211 -0
  71. package/.cursor/rules/code-style.mdc +92 -0
  72. package/.cursor/rules/cursor-overview.mdc +35 -0
  73. package/.cursor/rules/database.mdc +66 -0
  74. package/.cursor/rules/error-handling.mdc +98 -0
  75. package/.cursor/rules/git-workflow.mdc +83 -0
  76. package/.cursor/rules/monitoring.mdc +317 -0
  77. package/.cursor/rules/naming-conventions.mdc +266 -0
  78. package/.cursor/rules/project-structure.mdc +71 -0
  79. package/.cursor/rules/security.mdc +95 -0
  80. package/.cursor/rules/system-design.mdc +168 -0
  81. package/.cursor/rules/tech-stack.mdc +462 -0
  82. package/.cursor/rules/testing.mdc +110 -0
  83. package/.cursor/settings.json +8 -0
  84. package/.cursor/skills/code-review/SKILL.md +208 -0
  85. package/.cursor/skills/deploy/SKILL.md +68 -0
  86. package/.cursor/skills/deploy/deploy.md +735 -0
  87. package/.cursor/skills/incremental-implementation/SKILL.md +210 -0
  88. package/.cursor/skills/security-review/SKILL.md +71 -0
  89. package/.cursor/skills/tdd/SKILL.md +217 -0
  90. package/AGENTS.md +11 -0
  91. package/README.md +405 -0
  92. package/bin/class-ai-agent.cjs +176 -0
  93. package/package.json +38 -0
@@ -0,0 +1,92 @@
1
+ # Error Handling
2
+
3
+ ## Core Principles
4
+ - **Never swallow errors silently** — always log or rethrow
5
+ - Use a centralized error handler
6
+ - Return consistent error responses to the API
7
+ - Distinguish between operational errors (expected) and programmer errors (bugs)
8
+
9
+ ## Custom Error Class
10
+ ```js
11
+ // src/utils/app-error.js
12
+ class AppError extends Error {
13
+ constructor(message, statusCode = 500, code = 'INTERNAL_ERROR') {
14
+ super(message);
15
+ this.name = 'AppError';
16
+ this.statusCode = statusCode;
17
+ this.code = code;
18
+ this.isOperational = true;
19
+ Error.captureStackTrace(this, this.constructor);
20
+ }
21
+ }
22
+
23
+ export default AppError;
24
+ ```
25
+
26
+ ## Throwing Errors
27
+ ```js
28
+ // ✅ Use AppError for known operational errors
29
+ if (!user) {
30
+ throw new AppError('User not found', 404, 'USER_NOT_FOUND');
31
+ }
32
+
33
+ if (!hasPermission) {
34
+ throw new AppError('Forbidden', 403, 'ACCESS_DENIED');
35
+ }
36
+ ```
37
+
38
+ ## Async Error Handling
39
+ ```js
40
+ // ✅ Always wrap async route handlers
41
+ const asyncHandler = (fn) => (req, res, next) =>
42
+ Promise.resolve(fn(req, res, next)).catch(next);
43
+
44
+ router.get('/users/:id', asyncHandler(async (req, res) => {
45
+ const user = await userService.findById(req.params.id);
46
+ res.json({ success: true, data: user });
47
+ }));
48
+ ```
49
+
50
+ ## Global Error Handler (Express)
51
+ ```js
52
+ // middleware/error-handler.js
53
+ export function errorHandler(err, req, res, next) {
54
+ const statusCode = err.statusCode || 500;
55
+ const isOperational = err.isOperational || false;
56
+
57
+ // Log all errors
58
+ logger.error({ err, req: { method: req.method, url: req.url } });
59
+
60
+ // Don't expose internal errors to clients
61
+ if (!isOperational) {
62
+ return res.status(500).json({
63
+ success: false,
64
+ error: { code: 'INTERNAL_ERROR', message: 'An unexpected error occurred' }
65
+ });
66
+ }
67
+
68
+ res.status(statusCode).json({
69
+ success: false,
70
+ error: { code: err.code, message: err.message }
71
+ });
72
+ }
73
+ ```
74
+
75
+ ## Validation Errors
76
+ ```js
77
+ // Use a validation library (Zod/Joi/Yup) and throw structured errors
78
+ import { z } from 'zod';
79
+
80
+ const userSchema = z.object({
81
+ email: z.string().email(),
82
+ name: z.string().min(2)
83
+ });
84
+
85
+ function validateUser(data) {
86
+ const result = userSchema.safeParse(data);
87
+ if (!result.success) {
88
+ throw new AppError('Validation failed', 422, 'VALIDATION_ERROR');
89
+ }
90
+ return result.data;
91
+ }
92
+ ```
@@ -0,0 +1,77 @@
1
+ # Git Workflow
2
+
3
+ ## Branch Strategy (Git Flow)
4
+
5
+ ```
6
+ main — Production-ready code only
7
+ develop — Integration branch for features
8
+ feature/* — New features
9
+ fix/* — Bug fixes
10
+ hotfix/* — Urgent production fixes
11
+ release/* — Release preparation
12
+ ```
13
+
14
+ ## Branch Naming
15
+ ```
16
+ feature/user-authentication
17
+ feature/payment-integration
18
+ fix/login-redirect-bug
19
+ fix/order-calculation-issue
20
+ hotfix/critical-security-patch
21
+ release/v1.2.0
22
+ ```
23
+
24
+ ## Commit Message Format (Conventional Commits)
25
+
26
+ ```
27
+ <type>(<scope>): <short description>
28
+
29
+ [optional body]
30
+
31
+ [optional footer]
32
+ ```
33
+
34
+ ### Types
35
+ | Type | Usage |
36
+ |------|-------|
37
+ | `feat` | New feature |
38
+ | `fix` | Bug fix |
39
+ | `docs` | Documentation only |
40
+ | `style` | Formatting, no logic change |
41
+ | `refactor` | Code restructure, no feature/fix |
42
+ | `test` | Adding or fixing tests |
43
+ | `chore` | Build process, dependencies |
44
+ | `perf` | Performance improvement |
45
+
46
+ ### Examples
47
+ ```
48
+ feat(auth): add JWT refresh token support
49
+
50
+ fix(orders): correct total price calculation when discount applied
51
+
52
+ docs(api): add Swagger annotations to user endpoints
53
+
54
+ test(users): add unit tests for UserService.findById
55
+
56
+ chore: upgrade express to v5.0.0
57
+ ```
58
+
59
+ ## Pull Request Rules
60
+ - PRs must reference an issue: `Closes #123`
61
+ - Minimum 1 reviewer approval required
62
+ - All CI checks must pass
63
+ - No direct commits to `main` or `develop`
64
+ - PR title must follow conventional commit format
65
+
66
+ ## Commit Best Practices
67
+ - Commit frequently with small, focused changes
68
+ - Each commit should be a single logical change
69
+ - Never commit: `.env` files, secrets, `node_modules`
70
+ - Always run tests before committing
71
+
72
+ ## Tags & Releases
73
+ ```bash
74
+ # Tag a release
75
+ git tag -a v1.2.0 -m "Release version 1.2.0"
76
+ git push origin v1.2.0
77
+ ```
@@ -0,0 +1,311 @@
1
+ # Monitoring & Observability
2
+
3
+ > Standards for logging, metrics, tracing, alerting, and Grafana dashboard design.
4
+
5
+ ## 🔭 The Three Pillars of Observability
6
+
7
+ | Pillar | Tool | Purpose |
8
+ |--------|------|---------|
9
+ | **Logs** | Winston / Pino + Loki | What happened |
10
+ | **Metrics** | Prometheus + Grafana | How the system is behaving |
11
+ | **Traces** | OpenTelemetry + Jaeger | Why something is slow |
12
+
13
+ ---
14
+
15
+ ## 📝 Logging Rules
16
+
17
+ ### Log Levels
18
+ | Level | When to Use |
19
+ |-------|-------------|
20
+ | `error` | Unexpected failure requiring attention |
21
+ | `warn` | Unexpected but recoverable situation |
22
+ | `info` | Normal significant events (startup, request lifecycle) |
23
+ | `debug` | Detailed debugging info (dev only) |
24
+ | `trace` | Very verbose (never in production) |
25
+
26
+ ### Log Format — Structured JSON (always!)
27
+ ```js
28
+ // ✅ Structured log — searchable and parseable
29
+ logger.info({
30
+ event: 'order.placed',
31
+ orderId: order.id,
32
+ userId: user.id,
33
+ amount: order.total,
34
+ durationMs: Date.now() - startTime,
35
+ requestId: req.id,
36
+ });
37
+
38
+ // ❌ Unstructured log — cannot be queried
39
+ console.log(`Order ${orderId} placed by user ${userId}`);
40
+ ```
41
+
42
+ ### Mandatory Fields
43
+ ```js
44
+ {
45
+ level: 'info',
46
+ timestamp: '2026-01-01T00:00:00.000Z',
47
+ service: 'order-service',
48
+ version: '1.2.3',
49
+ environment: 'production',
50
+ requestId: 'uuid', // trace across services
51
+ userId: 'uuid', // who triggered it
52
+ event: 'order.placed', // what happened
53
+ durationMs: 45, // how long
54
+ // ... domain-specific fields
55
+ }
56
+ ```
57
+
58
+ ### What NOT to Log
59
+ ```js
60
+ // ❌ Never log sensitive data
61
+ logger.info({ password: user.password }); // NEVER
62
+ logger.info({ token: req.headers.authorization }); // NEVER
63
+ logger.info({ creditCard: payment.card }); // NEVER
64
+ logger.info({ ssn: user.socialSecurityNumber }); // NEVER
65
+ ```
66
+
67
+ ### Logger Setup (Pino)
68
+ ```js
69
+ // src/utils/logger.js
70
+ import pino from 'pino';
71
+
72
+ export const logger = pino({
73
+ level: process.env.LOG_LEVEL || 'info',
74
+ base: {
75
+ service: process.env.APP_NAME,
76
+ version: process.env.npm_package_version,
77
+ env: process.env.NODE_ENV,
78
+ },
79
+ timestamp: pino.stdTimeFunctions.isoTime,
80
+ });
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 📊 Metrics (Prometheus + Grafana)
86
+
87
+ ### Metric Types
88
+ | Type | Use Case | Example |
89
+ |------|----------|---------|
90
+ | **Counter** | Values that only increase | `http_requests_total` |
91
+ | **Gauge** | Values that go up and down | `active_connections`, `memory_usage_bytes` |
92
+ | **Histogram** | Distribution of values | `http_request_duration_seconds` |
93
+ | **Summary** | Pre-calculated percentiles | `request_latency_percentiles` |
94
+
95
+ ### Naming Convention
96
+ ```
97
+ # Pattern: {namespace}_{subsystem}_{name}_{unit}
98
+ # All lowercase, underscores, snake_case
99
+
100
+ http_request_duration_seconds # histogram
101
+ http_requests_total # counter
102
+ http_requests_in_flight # gauge
103
+ db_query_duration_seconds # histogram
104
+ cache_hits_total # counter
105
+ cache_misses_total # counter
106
+ queue_messages_pending # gauge
107
+ queue_processing_duration_seconds # histogram
108
+ payment_transactions_total # counter (+ status label)
109
+ ```
110
+
111
+ ### Labels (Dimensions)
112
+ ```js
113
+ // ✅ Use labels for meaningful dimensions
114
+ httpRequestCounter.labels({
115
+ method: req.method, // GET, POST, etc.
116
+ route: '/api/v1/users', // normalized route
117
+ status_code: res.statusCode,
118
+ service: 'user-service',
119
+ }).inc();
120
+
121
+ // ❌ Don't use high-cardinality labels (userId, orderId)
122
+ // This creates millions of time series → kills Prometheus
123
+ ```
124
+
125
+ ### Express Middleware for Metrics
126
+ ```js
127
+ // middleware/metrics.js
128
+ import client from 'prom-client';
129
+
130
+ const httpDuration = new client.Histogram({
131
+ name: 'http_request_duration_seconds',
132
+ help: 'Duration of HTTP requests in seconds',
133
+ labelNames: ['method', 'route', 'status_code'],
134
+ buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
135
+ });
136
+
137
+ export function metricsMiddleware(req, res, next) {
138
+ const end = httpDuration.startTimer();
139
+ res.on('finish', () => {
140
+ end({ method: req.method, route: req.route?.path || req.path, status_code: res.statusCode });
141
+ });
142
+ next();
143
+ }
144
+
145
+ // Expose metrics endpoint
146
+ app.get('/metrics', async (req, res) => {
147
+ res.set('Content-Type', client.register.contentType);
148
+ res.end(await client.register.metrics());
149
+ });
150
+ ```
151
+
152
+ ---
153
+
154
+ ## 📈 Grafana Dashboard Design
155
+
156
+ ### Dashboard Naming
157
+ ```
158
+ # Pattern: {Service} — {Category}
159
+ User Service — Overview
160
+ User Service — Errors & Latency
161
+ Order Service — Business Metrics
162
+ Infrastructure — Redis
163
+ Infrastructure — PostgreSQL
164
+ ```
165
+
166
+ ### Panel Naming
167
+ ```
168
+ # Use title case, include units in title
169
+ Request Rate (req/s)
170
+ P99 Latency (ms)
171
+ Error Rate (%)
172
+ Active DB Connections
173
+ Cache Hit Rate (%)
174
+ Queue Depth
175
+ Memory Usage (MB)
176
+ ```
177
+
178
+ ### The RED Method (for Services)
179
+ Every service dashboard MUST have these 3 panels:
180
+ - **R** — **Rate**: requests per second
181
+ - **E** — **Errors**: error rate (%)
182
+ - **D** — **Duration**: P50, P95, P99 latency
183
+
184
+ ```promql
185
+ # Rate
186
+ rate(http_requests_total{service="order-service"}[5m])
187
+
188
+ # Error rate
189
+ rate(http_requests_total{status_code=~"5.."}[5m])
190
+ / rate(http_requests_total[5m]) * 100
191
+
192
+ # P99 latency (ms)
193
+ histogram_quantile(0.99,
194
+ rate(http_request_duration_seconds_bucket{service="order-service"}[5m])
195
+ ) * 1000
196
+ ```
197
+
198
+ ### The USE Method (for Infrastructure)
199
+ Every infrastructure dashboard MUST have:
200
+ - **U** — **Utilization**: % of resource being used
201
+ - **S** — **Saturation**: queue depth, wait time
202
+ - **E** — **Errors**: error count/rate
203
+
204
+ ### Standard Dashboard Layout
205
+ ```
206
+ Row 1: Summary / Health Overview (traffic lights)
207
+ Row 2: RED metrics (Rate, Errors, Duration)
208
+ Row 3: Resource usage (CPU, Memory, DB connections)
209
+ Row 4: Business metrics (orders/min, signups, payments)
210
+ Row 5: Logs panel (Loki integration)
211
+ ```
212
+
213
+ ---
214
+
215
+ ## 🚨 Alerting Rules
216
+
217
+ ### Severity Levels
218
+ | Level | Response Time | Example |
219
+ |-------|--------------|---------|
220
+ | `critical` | Immediate (PagerDuty) | Service down, payment failures |
221
+ | `warning` | Within 30min (Slack) | High error rate, slow queries |
222
+ | `info` | Business hours | Unusual traffic patterns |
223
+
224
+ ### Standard Alert Rules (Prometheus AlertManager)
225
+ ```yaml
226
+ groups:
227
+ - name: service-alerts
228
+ rules:
229
+ # Service is down
230
+ - alert: ServiceDown
231
+ expr: up{job="my-service"} == 0
232
+ for: 1m
233
+ severity: critical
234
+ annotations:
235
+ summary: "Service {{ $labels.job }} is down"
236
+
237
+ # High error rate
238
+ - alert: HighErrorRate
239
+ expr: |
240
+ rate(http_requests_total{status_code=~"5.."}[5m])
241
+ / rate(http_requests_total[5m]) > 0.05
242
+ for: 5m
243
+ severity: warning
244
+ annotations:
245
+ summary: "Error rate > 5% on {{ $labels.service }}"
246
+
247
+ # High P99 latency
248
+ - alert: HighLatency
249
+ expr: |
250
+ histogram_quantile(0.99,
251
+ rate(http_request_duration_seconds_bucket[5m])
252
+ ) > 1
253
+ for: 5m
254
+ severity: warning
255
+ annotations:
256
+ summary: "P99 latency > 1s on {{ $labels.service }}"
257
+
258
+ # Low cache hit rate
259
+ - alert: LowCacheHitRate
260
+ expr: |
261
+ rate(cache_hits_total[5m])
262
+ / (rate(cache_hits_total[5m]) + rate(cache_misses_total[5m])) < 0.7
263
+ for: 10m
264
+ severity: warning
265
+ ```
266
+
267
+ ### Alert Naming Convention
268
+ ```
269
+ {Severity}{Service}{Problem}
270
+ CriticalPaymentServiceDown
271
+ WarningOrderServiceHighLatency
272
+ WarningRedisLowHitRate
273
+ CriticalDatabaseConnectionsExhausted
274
+ ```
275
+
276
+ ---
277
+
278
+ ## 🔍 Distributed Tracing (OpenTelemetry)
279
+
280
+ ```js
281
+ // src/tracing.js
282
+ import { NodeSDK } from '@opentelemetry/sdk-node';
283
+ import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
284
+ import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
285
+
286
+ const sdk = new NodeSDK({
287
+ traceExporter: new JaegerExporter({ endpoint: process.env.JAEGER_ENDPOINT }),
288
+ instrumentations: [getNodeAutoInstrumentations()],
289
+ serviceName: process.env.APP_NAME,
290
+ });
291
+
292
+ sdk.start();
293
+ ```
294
+
295
+ ### Span Naming
296
+ ```
297
+ # HTTP: {method} {route}
298
+ GET /api/v1/users/:id
299
+
300
+ # DB: {operation} {table}
301
+ SELECT users
302
+ INSERT orders
303
+
304
+ # Cache: {operation} {key_pattern}
305
+ GET user:{id}
306
+ SET session:{id}
307
+
308
+ # Queue: {operation} {queue_name}
309
+ PUBLISH order.placed
310
+ CONSUME email.send
311
+ ```