class-ai-agent 1.4.0 → 1.5.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/.agent/README.md +10 -5
- package/.agent/SESSION.md +18 -13
- package/.agent/rules/agent-continuity.md +44 -0
- package/.agent/rules/antigravity-overview.md +38 -0
- package/.agent/rules/api-conventions.md +85 -0
- package/.agent/rules/clean-code.md +211 -0
- package/.agent/rules/code-style.md +92 -0
- package/.agent/rules/codegraph.md +47 -0
- package/.agent/rules/database.md +66 -0
- package/.agent/rules/error-handling.md +98 -0
- package/.agent/rules/git-workflow.md +83 -0
- package/.agent/rules/monitoring.md +317 -0
- package/.agent/rules/naming-conventions.md +266 -0
- package/.agent/rules/project-structure.md +71 -0
- package/.agent/rules/security.md +95 -0
- package/.agent/rules/system-design.md +168 -0
- package/.agent/rules/tech-stack.md +463 -0
- package/.agent/rules/testing.md +110 -0
- package/.agents/agents/backend.md +395 -0
- package/.agents/agents/business-analyst.md +380 -0
- package/.agents/agents/code-reviewer.md +110 -0
- package/.agents/agents/copywriter-seo.md +236 -0
- package/.agents/agents/frontend.md +384 -0
- package/.agents/agents/project-manager.md +201 -0
- package/.agents/agents/qa.md +221 -0
- package/.agents/agents/security-auditor.md +143 -0
- package/.agents/agents/systems-architect.md +211 -0
- package/.agents/agents/test-engineer.md +123 -0
- package/.agents/agents/ui-ux-designer.md +210 -0
- package/.agents/references/accessibility-checklist.md +174 -0
- package/.agents/references/agent-continuity.md +42 -0
- package/.agents/references/codegraph.md +90 -0
- package/.agents/references/mcp-antigravity.md +71 -0
- package/.agents/references/performance-checklist.md +150 -0
- package/.agents/references/security-checklist.md +94 -0
- package/.agents/references/supabase.md +55 -0
- package/.agents/references/testing-patterns.md +183 -0
- package/.agents/skills/agent-continuity/SKILL.md +70 -0
- package/.agents/skills/code-review/SKILL.md +208 -0
- package/.agents/skills/deploy/SKILL.md +68 -0
- package/.agents/skills/deploy/deploy.md +735 -0
- package/.agents/skills/incremental-implementation/SKILL.md +210 -0
- package/.agents/skills/security-review/SKILL.md +71 -0
- package/.agents/skills/supabase/SKILL.md +135 -0
- package/.agents/skills/supabase/UPSTREAM.md +16 -0
- package/.agents/skills/supabase/assets/feedback-issue-template.md +17 -0
- package/.agents/skills/supabase/references/skill-feedback.md +17 -0
- package/.agents/skills/supabase-postgres-best-practices/SKILL.md +64 -0
- package/.agents/skills/supabase-postgres-best-practices/UPSTREAM.md +16 -0
- package/.agents/skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
- package/.agents/skills/supabase-postgres-best-practices/references/_sections.md +39 -0
- package/.agents/skills/supabase-postgres-best-practices/references/_template.md +34 -0
- package/.agents/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
- package/.agents/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
- package/.agents/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
- package/.agents/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
- package/.agents/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
- package/.agents/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
- package/.agents/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
- package/.agents/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
- package/.agents/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
- package/.agents/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
- package/.agents/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
- package/.agents/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
- package/.agents/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
- package/.agents/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
- package/.agents/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
- package/.agents/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
- package/.agents/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
- package/.agents/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
- package/.agents/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
- package/.agents/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
- package/.agents/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
- package/.agents/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
- package/.agents/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
- package/.agents/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
- package/.agents/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
- package/.agents/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
- package/.agents/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
- package/.agents/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
- package/.agents/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
- package/.agents/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
- package/.agents/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
- package/.agents/skills/tdd/SKILL.md +217 -0
- package/.agents/skills/ui-ux-pro-max/SKILL.md +288 -0
- package/.agents/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agents/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agents/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agents/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agents/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/.agents/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agents/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agents/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/.agents/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agents/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agents/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agents/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.agents/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/.agents/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/.agents/skills/ui-ux-pro-max/scripts/search.py +114 -0
- package/.agents/workflows/build.md +132 -0
- package/.agents/workflows/debug.md +242 -0
- package/.agents/workflows/deploy.md +43 -0
- package/.agents/workflows/fix-issue.md +45 -0
- package/.agents/workflows/handoff.md +93 -0
- package/.agents/workflows/plan.md +125 -0
- package/.agents/workflows/publish-npm.md +122 -0
- package/.agents/workflows/resume.md +106 -0
- package/.agents/workflows/review.md +53 -0
- package/.agents/workflows/simplify.md +221 -0
- package/.agents/workflows/spec.md +95 -0
- package/.agents/workflows/test.md +213 -0
- package/.claude/CLAUDE.md +23 -0
- package/.claude/agents/business-analyst.md +380 -0
- package/.claude/references/codegraph.md +26 -14
- package/.claude/rules/agent-continuity.md +3 -2
- package/.claude/rules/api-conventions.md +1 -0
- package/.claude/rules/clean-code.md +1 -0
- package/.claude/rules/code-style.md +1 -0
- package/.claude/rules/codegraph.md +43 -0
- package/.claude/rules/database.md +2 -1
- package/.claude/rules/error-handling.md +1 -0
- package/.claude/rules/git-workflow.md +1 -0
- package/.claude/rules/monitoring.md +1 -0
- package/.claude/rules/naming-conventions.md +1 -0
- package/.claude/rules/project-structure.md +1 -0
- package/.claude/rules/security.md +1 -0
- package/.claude/rules/system-design.md +1 -0
- package/.claude/rules/tech-stack.md +1 -0
- package/.claude/rules/testing.md +1 -0
- package/.claude/settings.json +3 -1
- package/.claude/skills/ui-ux-pro-max/SKILL.md +1 -90
- package/.cursor/CURSOR.md +1 -1
- package/.cursor/agents/business-analyst.md +380 -0
- package/.cursor/rules/cursor-overview.mdc +4 -3
- package/.cursor/rules/database.mdc +2 -2
- package/.kiro/KIRO.md +3 -3
- package/.kiro/agents/business-analyst.md +380 -0
- package/.kiro/steering/database.md +2 -2
- package/.kiro/steering/kiro-overview.md +2 -2
- package/AGENTS.md +23 -1
- package/GEMINI.md +152 -0
- package/README.md +65 -19
- package/bin/class-ai-agent.cjs +85 -9
- package/package.json +11 -4
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
---
|
|
2
|
+
trigger: glob
|
|
3
|
+
globs: {ts,tsx,js,jsx,mjs,cjs,json,md,prisma,yml,yaml}
|
|
4
|
+
description: "Naming Conventions"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Naming Conventions
|
|
8
|
+
|
|
9
|
+
> Standard naming rules for cache keys, database identifiers, queues, events, environment variables, and more.
|
|
10
|
+
|
|
11
|
+
## 🔑 Cache Key Naming
|
|
12
|
+
|
|
13
|
+
### Format
|
|
14
|
+
```
|
|
15
|
+
{app}:{version}:{entity}:{identifier}:{variant}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Rules
|
|
19
|
+
- Use **colons** (`:`) as separators
|
|
20
|
+
- Use **lowercase snake_case** for each segment
|
|
21
|
+
- Always prefix with app/service name to avoid collision
|
|
22
|
+
- Include version for easy cache invalidation
|
|
23
|
+
|
|
24
|
+
### Examples
|
|
25
|
+
```
|
|
26
|
+
# User data
|
|
27
|
+
myapp:v1:user:12345
|
|
28
|
+
myapp:v1:user:12345:profile
|
|
29
|
+
myapp:v1:user:12345:permissions
|
|
30
|
+
|
|
31
|
+
# Lists / collections
|
|
32
|
+
myapp:v1:users:active:list
|
|
33
|
+
myapp:v1:products:category:electronics:page:1
|
|
34
|
+
|
|
35
|
+
# Sessions
|
|
36
|
+
myapp:v1:session:abc123xyz
|
|
37
|
+
|
|
38
|
+
# Rate limiting
|
|
39
|
+
myapp:v1:rate_limit:user:12345:api
|
|
40
|
+
myapp:v1:rate_limit:ip:192.168.1.1
|
|
41
|
+
|
|
42
|
+
# Feature flags
|
|
43
|
+
myapp:v1:feature:new_checkout:enabled
|
|
44
|
+
|
|
45
|
+
# Temporary locks (mutex)
|
|
46
|
+
myapp:v1:lock:payment:order:99999
|
|
47
|
+
|
|
48
|
+
# Aggregates / computed
|
|
49
|
+
myapp:v1:dashboard:user:12345:stats:daily
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### TTL Conventions
|
|
53
|
+
| Data Type | Recommended TTL |
|
|
54
|
+
|-----------|----------------|
|
|
55
|
+
| User session | 7 days |
|
|
56
|
+
| Auth tokens | 15 minutes |
|
|
57
|
+
| User profile | 1 hour |
|
|
58
|
+
| Product catalog | 6 hours |
|
|
59
|
+
| Config/settings | 24 hours |
|
|
60
|
+
| Rate limit windows | 15 minutes |
|
|
61
|
+
| Temporary locks | 30 seconds |
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 🗄️ Database Naming
|
|
66
|
+
|
|
67
|
+
### Tables
|
|
68
|
+
```sql
|
|
69
|
+
-- snake_case, plural nouns
|
|
70
|
+
users
|
|
71
|
+
order_items
|
|
72
|
+
product_categories
|
|
73
|
+
user_role_mappings -- junction tables: entity1_entity2_mappings
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Columns
|
|
77
|
+
```sql
|
|
78
|
+
-- snake_case
|
|
79
|
+
id -- primary key (always 'id')
|
|
80
|
+
user_id -- foreign key: {referenced_table_singular}_id
|
|
81
|
+
created_at -- timestamps: {event}_at
|
|
82
|
+
updated_at
|
|
83
|
+
deleted_at -- soft delete
|
|
84
|
+
is_active -- booleans: is_, has_, can_
|
|
85
|
+
has_verified_email
|
|
86
|
+
email -- data fields: plain descriptive name
|
|
87
|
+
full_name
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Indexes
|
|
91
|
+
```sql
|
|
92
|
+
-- Pattern: idx_{table}_{columns}
|
|
93
|
+
idx_users_email
|
|
94
|
+
idx_orders_user_id_created_at
|
|
95
|
+
idx_products_category_id_is_active
|
|
96
|
+
|
|
97
|
+
-- Unique indexes
|
|
98
|
+
uniq_users_email
|
|
99
|
+
uniq_products_sku
|
|
100
|
+
|
|
101
|
+
-- Full-text search
|
|
102
|
+
fts_products_name_description
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Foreign Keys
|
|
106
|
+
```sql
|
|
107
|
+
-- Pattern: fk_{child_table}_{parent_table}
|
|
108
|
+
fk_orders_users
|
|
109
|
+
fk_order_items_orders
|
|
110
|
+
fk_order_items_products
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Stored Procedures / Functions
|
|
114
|
+
```sql
|
|
115
|
+
-- snake_case verbs
|
|
116
|
+
get_user_by_email()
|
|
117
|
+
calculate_order_total()
|
|
118
|
+
archive_old_sessions()
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 📨 Message Queue / Event Naming
|
|
124
|
+
|
|
125
|
+
### Queue Names
|
|
126
|
+
```
|
|
127
|
+
# Pattern: {app}.{entity}.{action}
|
|
128
|
+
# Use dots as separators for queues
|
|
129
|
+
|
|
130
|
+
myapp.email.send
|
|
131
|
+
myapp.payment.process
|
|
132
|
+
myapp.order.fulfillment
|
|
133
|
+
myapp.notification.push
|
|
134
|
+
myapp.report.generate
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Event Names (Domain Events)
|
|
138
|
+
```
|
|
139
|
+
# Pattern: {entity}.{past_tense_verb}
|
|
140
|
+
# Events describe things that HAPPENED
|
|
141
|
+
|
|
142
|
+
user.registered
|
|
143
|
+
user.email_verified
|
|
144
|
+
order.placed
|
|
145
|
+
order.payment_received
|
|
146
|
+
order.fulfilled
|
|
147
|
+
order.cancelled
|
|
148
|
+
payment.failed
|
|
149
|
+
product.stock_depleted
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Dead Letter Queues (DLQ)
|
|
153
|
+
```
|
|
154
|
+
myapp.email.send.dlq
|
|
155
|
+
myapp.payment.process.dlq
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 🌍 Environment Variables
|
|
161
|
+
|
|
162
|
+
### Rules
|
|
163
|
+
- **UPPER_SNAKE_CASE** for all env vars
|
|
164
|
+
- Prefix with app/service name for non-standard vars
|
|
165
|
+
- Be descriptive, avoid abbreviations
|
|
166
|
+
|
|
167
|
+
### Standard Variables
|
|
168
|
+
```bash
|
|
169
|
+
# App
|
|
170
|
+
NODE_ENV=production
|
|
171
|
+
PORT=3000
|
|
172
|
+
APP_NAME=myapp
|
|
173
|
+
APP_URL=https://myapp.com
|
|
174
|
+
LOG_LEVEL=info
|
|
175
|
+
|
|
176
|
+
# Database
|
|
177
|
+
DATABASE_URL=postgresql://...
|
|
178
|
+
DB_HOST=localhost
|
|
179
|
+
DB_PORT=5432
|
|
180
|
+
DB_NAME=myapp_production
|
|
181
|
+
DB_USER=myapp_user
|
|
182
|
+
DB_PASSWORD=...
|
|
183
|
+
DB_POOL_MIN=2
|
|
184
|
+
DB_POOL_MAX=10
|
|
185
|
+
|
|
186
|
+
# Cache
|
|
187
|
+
REDIS_URL=redis://localhost:6379
|
|
188
|
+
REDIS_PASSWORD=...
|
|
189
|
+
CACHE_TTL_DEFAULT=3600
|
|
190
|
+
|
|
191
|
+
# Auth
|
|
192
|
+
JWT_SECRET=...
|
|
193
|
+
JWT_EXPIRES_IN=15m
|
|
194
|
+
JWT_REFRESH_SECRET=...
|
|
195
|
+
JWT_REFRESH_EXPIRES_IN=7d
|
|
196
|
+
BCRYPT_ROUNDS=12
|
|
197
|
+
|
|
198
|
+
# External Services
|
|
199
|
+
SMTP_HOST=...
|
|
200
|
+
SMTP_PORT=587
|
|
201
|
+
SMTP_USER=...
|
|
202
|
+
SMTP_PASS=...
|
|
203
|
+
STRIPE_SECRET_KEY=...
|
|
204
|
+
STRIPE_WEBHOOK_SECRET=...
|
|
205
|
+
AWS_ACCESS_KEY_ID=...
|
|
206
|
+
AWS_SECRET_ACCESS_KEY=...
|
|
207
|
+
AWS_REGION=ap-southeast-1
|
|
208
|
+
S3_BUCKET_NAME=...
|
|
209
|
+
|
|
210
|
+
# Monitoring
|
|
211
|
+
SENTRY_DSN=...
|
|
212
|
+
GRAFANA_API_KEY=...
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 📁 File & Folder Naming
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
# Files: kebab-case
|
|
221
|
+
user-service.js
|
|
222
|
+
auth-middleware.js
|
|
223
|
+
order-repository.js
|
|
224
|
+
send-welcome-email.js # specific action scripts
|
|
225
|
+
|
|
226
|
+
# Folders: kebab-case, plural for collections
|
|
227
|
+
controllers/
|
|
228
|
+
services/
|
|
229
|
+
repositories/
|
|
230
|
+
utils/
|
|
231
|
+
middleware/
|
|
232
|
+
config/
|
|
233
|
+
|
|
234
|
+
# Test files: match source file + .test
|
|
235
|
+
user-service.test.js
|
|
236
|
+
auth-middleware.test.js
|
|
237
|
+
|
|
238
|
+
# Config files
|
|
239
|
+
.env.development
|
|
240
|
+
.env.production
|
|
241
|
+
docker-compose.dev.yml
|
|
242
|
+
docker-compose.prod.yml
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 🌐 URL / Route Naming
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
# REST: plural nouns, kebab-case, versioned
|
|
251
|
+
GET /api/v1/users
|
|
252
|
+
GET /api/v1/users/:id
|
|
253
|
+
POST /api/v1/users
|
|
254
|
+
PATCH /api/v1/users/:id
|
|
255
|
+
DELETE /api/v1/users/:id
|
|
256
|
+
|
|
257
|
+
# Nested resources
|
|
258
|
+
GET /api/v1/users/:id/orders
|
|
259
|
+
POST /api/v1/users/:id/orders
|
|
260
|
+
|
|
261
|
+
# Actions that don't fit CRUD (use verbs sparingly)
|
|
262
|
+
POST /api/v1/auth/login
|
|
263
|
+
POST /api/v1/auth/logout
|
|
264
|
+
POST /api/v1/auth/refresh
|
|
265
|
+
POST /api/v1/payments/:id/refund
|
|
266
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
trigger: glob
|
|
3
|
+
globs: {ts,tsx,js,jsx,mjs,cjs,json,md,prisma,yml,yaml}
|
|
4
|
+
description: "Project Structure"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Project Structure
|
|
8
|
+
|
|
9
|
+
## Standard Folder Layout
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
project-root/
|
|
13
|
+
├── .agents/ # AI Agent configuration
|
|
14
|
+
│ ├── agents/ # Sub-agent definitions
|
|
15
|
+
│ ├── commands/ # Reusable command workflows
|
|
16
|
+
│ ├── rules/ # Mandatory rules for AI
|
|
17
|
+
│ ├── skills/ # Specialized AI skills
|
|
18
|
+
│ ├── settings.json # Project-level settings
|
|
19
|
+
│ ├── settings.local.json # Local settings (gitignored)
|
|
20
|
+
│ ├── CLAUDE.md # Main AI instructions
|
|
21
|
+
│ └── CLAUDE.local.md # Local AI overrides (gitignored)
|
|
22
|
+
│
|
|
23
|
+
├── src/ # Application source code
|
|
24
|
+
│ ├── config/ # Configuration files
|
|
25
|
+
│ ├── controllers/ # Route handlers (thin layer)
|
|
26
|
+
│ ├── middleware/ # Express middleware
|
|
27
|
+
│ ├── models/ # Database models/schemas
|
|
28
|
+
│ ├── repositories/ # Data access layer
|
|
29
|
+
│ ├── routes/ # Route definitions
|
|
30
|
+
│ ├── services/ # Business logic layer
|
|
31
|
+
│ ├── utils/ # Utility functions
|
|
32
|
+
│ └── index.js # Application entry point
|
|
33
|
+
│
|
|
34
|
+
├── tests/ # Test files
|
|
35
|
+
│ ├── unit/ # Unit tests
|
|
36
|
+
│ ├── integration/ # Integration tests
|
|
37
|
+
│ └── e2e/ # End-to-end tests
|
|
38
|
+
│
|
|
39
|
+
├── docs/ # Documentation
|
|
40
|
+
│ ├── api/ # API documentation
|
|
41
|
+
│ └── architecture/ # Architecture diagrams
|
|
42
|
+
│
|
|
43
|
+
├── scripts/ # Build and utility scripts
|
|
44
|
+
├── .env.example # Example environment variables
|
|
45
|
+
├── .gitignore # Git ignore rules
|
|
46
|
+
├── package.json
|
|
47
|
+
├── README.md
|
|
48
|
+
└── CLAUDE.md # Root-level AI instructions (optional)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Layered Architecture
|
|
52
|
+
```
|
|
53
|
+
Request → Routes → Middleware → Controllers → Services → Repositories → Database
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- **Routes**: URL mapping only, no logic
|
|
57
|
+
- **Controllers**: Request/response handling, input validation
|
|
58
|
+
- **Services**: Business logic, orchestration
|
|
59
|
+
- **Repositories**: Data access, queries
|
|
60
|
+
- **Models**: Data schemas and types
|
|
61
|
+
|
|
62
|
+
## File Naming
|
|
63
|
+
- Source files: `kebab-case.js` (`user-service.js`)
|
|
64
|
+
- Test files: `[name].test.js` (`user-service.test.js`)
|
|
65
|
+
- Config files: `kebab-case.js` or `kebab-case.json`
|
|
66
|
+
|
|
67
|
+
## Environment Files
|
|
68
|
+
- `.env` — Local development (gitignored)
|
|
69
|
+
- `.env.example` — Template committed to git
|
|
70
|
+
- `.env.test` — Test environment (gitignored)
|
|
71
|
+
- `.env.production` — Set in CI/CD, never committed
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
trigger: always_on
|
|
3
|
+
description: "Security Rules"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Security Rules
|
|
7
|
+
|
|
8
|
+
## 🚨 CRITICAL — Never Violate These
|
|
9
|
+
|
|
10
|
+
- **Never** hardcode secrets, API keys, passwords, or tokens in source code
|
|
11
|
+
- **Never** commit `.env` files to version control
|
|
12
|
+
- **Never** log sensitive data (passwords, tokens, PII)
|
|
13
|
+
- **Never** use `eval()` or `Function()` with user input
|
|
14
|
+
- **Always** validate and sanitize all user inputs
|
|
15
|
+
|
|
16
|
+
## Environment Variables
|
|
17
|
+
```js
|
|
18
|
+
// ✅ Always use environment variables for secrets
|
|
19
|
+
const dbPassword = process.env.DB_PASSWORD;
|
|
20
|
+
const jwtSecret = process.env.JWT_SECRET;
|
|
21
|
+
|
|
22
|
+
// ❌ Never hardcode secrets
|
|
23
|
+
const dbPassword = 'mypassword123';
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Input Validation
|
|
27
|
+
```js
|
|
28
|
+
// ✅ Validate all incoming data with a schema
|
|
29
|
+
import { z } from 'zod';
|
|
30
|
+
|
|
31
|
+
const loginSchema = z.object({
|
|
32
|
+
email: z.string().email().max(255),
|
|
33
|
+
password: z.string().min(8).max(128)
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Sanitize HTML to prevent XSS
|
|
37
|
+
import DOMPurify from 'dompurify';
|
|
38
|
+
const cleanContent = DOMPurify.sanitize(userInput);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Authentication
|
|
42
|
+
- Use **JWT** with short expiry (15 min access token, 7 day refresh token)
|
|
43
|
+
- Hash passwords with **bcrypt** (rounds: 12+)
|
|
44
|
+
- Implement rate limiting on auth endpoints
|
|
45
|
+
```js
|
|
46
|
+
import bcrypt from 'bcrypt';
|
|
47
|
+
const SALT_ROUNDS = 12;
|
|
48
|
+
const hashed = await bcrypt.hash(password, SALT_ROUNDS);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Authorization
|
|
52
|
+
```js
|
|
53
|
+
// ✅ Check permissions on every protected route
|
|
54
|
+
router.delete('/posts/:id', authenticate, authorize('admin'), asyncHandler(deletePost));
|
|
55
|
+
|
|
56
|
+
// ✅ Verify resource ownership
|
|
57
|
+
if (post.authorId !== req.user.id && req.user.role !== 'admin') {
|
|
58
|
+
throw new AppError('Forbidden', 403);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## HTTP Security Headers
|
|
63
|
+
```js
|
|
64
|
+
// Use Helmet.js
|
|
65
|
+
import helmet from 'helmet';
|
|
66
|
+
app.use(helmet());
|
|
67
|
+
|
|
68
|
+
// Configure CORS strictly
|
|
69
|
+
app.use(cors({
|
|
70
|
+
origin: process.env.ALLOWED_ORIGINS?.split(',') || [],
|
|
71
|
+
credentials: true
|
|
72
|
+
}));
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Rate Limiting
|
|
76
|
+
```js
|
|
77
|
+
import rateLimit from 'express-rate-limit';
|
|
78
|
+
|
|
79
|
+
const apiLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 100 });
|
|
80
|
+
const authLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 5 });
|
|
81
|
+
|
|
82
|
+
app.use('/api/', apiLimiter);
|
|
83
|
+
app.use('/api/auth/', authLimiter);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## SQL Injection Prevention
|
|
87
|
+
- Always use ORM parameterized queries
|
|
88
|
+
- Never concatenate user input into SQL strings
|
|
89
|
+
|
|
90
|
+
## Dependency Security
|
|
91
|
+
```bash
|
|
92
|
+
# Regularly audit dependencies
|
|
93
|
+
npm audit
|
|
94
|
+
npm audit fix
|
|
95
|
+
```
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
---
|
|
2
|
+
trigger: glob
|
|
3
|
+
globs: {ts,tsx,js,jsx,mjs,cjs,json,md,prisma,yml,yaml}
|
|
4
|
+
description: "System Design Rules"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# System Design Rules
|
|
8
|
+
|
|
9
|
+
> Principles from "System Design Interview" (Alex Xu), "Designing Data-Intensive Applications" (Martin Kleppmann), and industry best practices.
|
|
10
|
+
|
|
11
|
+
## 🏗️ Core Principles
|
|
12
|
+
|
|
13
|
+
### CAP Theorem
|
|
14
|
+
- A distributed system can only guarantee 2 of 3: **Consistency**, **Availability**, **Partition Tolerance**
|
|
15
|
+
- **CP systems** (sacrifice availability): MySQL, ZooKeeper, HBase → use when data correctness is critical
|
|
16
|
+
- **AP systems** (sacrifice consistency): Cassandra, DynamoDB, CouchDB → use for high availability
|
|
17
|
+
|
|
18
|
+
### Design for Failure
|
|
19
|
+
- Every external call CAN fail — design for it
|
|
20
|
+
- Use **circuit breakers** to prevent cascade failures
|
|
21
|
+
- Use **bulkhead pattern** to isolate failures
|
|
22
|
+
- Implement **graceful degradation** (serve cached/partial data when dependencies fail)
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 📐 Scalability Patterns
|
|
27
|
+
|
|
28
|
+
### Horizontal vs Vertical Scaling
|
|
29
|
+
```
|
|
30
|
+
Vertical → More CPU/RAM on one machine (limited ceiling)
|
|
31
|
+
Horizontal → More machines (preferred for production)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Load Balancing
|
|
35
|
+
- **Round Robin** — equal distribution
|
|
36
|
+
- **Least Connections** — route to least busy server
|
|
37
|
+
- **Consistent Hashing** — for cache/session affinity (minimize remapping on scale)
|
|
38
|
+
|
|
39
|
+
### Caching Strategies
|
|
40
|
+
| Strategy | Use Case |
|
|
41
|
+
|----------|----------|
|
|
42
|
+
| **Cache-Aside** (Lazy Loading) | Read-heavy, content changes frequently |
|
|
43
|
+
| **Write-Through** | Write-heavy, data must be consistent |
|
|
44
|
+
| **Write-Behind** (Write-Back) | High write throughput, some lag acceptable |
|
|
45
|
+
| **Read-Through** | Cache is always up to date |
|
|
46
|
+
|
|
47
|
+
### Database Scaling
|
|
48
|
+
- **Read Replicas** — scale read-heavy workloads
|
|
49
|
+
- **Sharding** — partition data horizontally by shard key
|
|
50
|
+
- **Vertical Partitioning** — split tables by column groups
|
|
51
|
+
- **CQRS** — separate read model and write model
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🔄 Async Patterns
|
|
56
|
+
|
|
57
|
+
### Message Queues
|
|
58
|
+
Use queues (Redis, RabbitMQ, Kafka) when:
|
|
59
|
+
- Processing can be deferred
|
|
60
|
+
- Tasks are slow/expensive (email, PDF gen, notifications)
|
|
61
|
+
- You need to decouple producers from consumers
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
Producer → [Queue] → Consumer(s)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Event-Driven Architecture
|
|
68
|
+
```js
|
|
69
|
+
// Publish domain events instead of direct service calls
|
|
70
|
+
eventBus.publish('order.created', { orderId, userId, total });
|
|
71
|
+
// Other services subscribe independently
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Saga Pattern (Distributed Transactions)
|
|
75
|
+
- **Choreography** — each service reacts to events (no central coordinator)
|
|
76
|
+
- **Orchestration** — a saga orchestrator tells each service what to do
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🗄️ Database Design
|
|
81
|
+
|
|
82
|
+
### Normalization vs Denormalization
|
|
83
|
+
- **Normalize** (OLTP) — avoid data duplication, use JOINs
|
|
84
|
+
- **Denormalize** (OLAP/Read-heavy) — duplicate data to eliminate JOINs
|
|
85
|
+
|
|
86
|
+
### Indexing Rules
|
|
87
|
+
```sql
|
|
88
|
+
-- ✅ Index columns used in WHERE, JOIN, ORDER BY
|
|
89
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
90
|
+
|
|
91
|
+
-- ❌ Don't index every column — indexes slow down writes
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### N+1 Query Prevention
|
|
95
|
+
```js
|
|
96
|
+
// ❌ N+1: one query per user
|
|
97
|
+
const users = await db.users.findAll();
|
|
98
|
+
for (const user of users) {
|
|
99
|
+
user.orders = await db.orders.findAll({ where: { userId: user.id } });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ✅ Single query with JOIN or include
|
|
103
|
+
const users = await db.users.findAll({ include: [{ model: db.orders }] });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 🌐 API Design Patterns
|
|
109
|
+
|
|
110
|
+
### Rate Limiting Algorithms
|
|
111
|
+
| Algorithm | Best For |
|
|
112
|
+
|-----------|----------|
|
|
113
|
+
| **Token Bucket** | Burst traffic allowed (API gateways) |
|
|
114
|
+
| **Leaky Bucket** | Smooth/constant output rate |
|
|
115
|
+
| **Fixed Window** | Simple, but spiky at window boundaries |
|
|
116
|
+
| **Sliding Window** | Most accurate, higher memory cost |
|
|
117
|
+
|
|
118
|
+
### Idempotency
|
|
119
|
+
- GET, PUT, DELETE must be idempotent
|
|
120
|
+
- POST operations: use **idempotency keys** for payment/critical actions
|
|
121
|
+
```
|
|
122
|
+
POST /api/payments
|
|
123
|
+
Idempotency-Key: <uuid>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Pagination Patterns
|
|
127
|
+
```
|
|
128
|
+
Offset: ?page=2&limit=20 → Simple but slow on large offsets
|
|
129
|
+
Cursor: ?cursor=<encoded>&limit=20 → ✅ Preferred for large datasets
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🔒 Reliability
|
|
135
|
+
|
|
136
|
+
### Circuit Breaker States
|
|
137
|
+
```
|
|
138
|
+
CLOSED → OPEN (after N failures) → HALF-OPEN (probe) → CLOSED
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Retry Strategy
|
|
142
|
+
```js
|
|
143
|
+
// ✅ Exponential backoff with jitter
|
|
144
|
+
const delay = Math.min(baseDelay * 2 ** attempt + Math.random() * 1000, maxDelay);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Health Checks
|
|
148
|
+
```
|
|
149
|
+
GET /health → Basic liveness (is the service running?)
|
|
150
|
+
GET /health/ready → Readiness (is the service ready to serve traffic?)
|
|
151
|
+
GET /health/live → Liveness (should Kubernetes restart this pod?)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 📊 Back-of-Envelope Estimation
|
|
157
|
+
|
|
158
|
+
| Resource | Approximate Speed |
|
|
159
|
+
|----------|------------------|
|
|
160
|
+
| L1 cache reference | 0.5 ns |
|
|
161
|
+
| L2 cache reference | 7 ns |
|
|
162
|
+
| RAM access | 100 ns |
|
|
163
|
+
| SSD random read | 150 μs |
|
|
164
|
+
| Network round trip (same DC) | 0.5 ms |
|
|
165
|
+
| HDD seek | 10 ms |
|
|
166
|
+
| Network round trip (cross continent) | 150 ms |
|
|
167
|
+
|
|
168
|
+
> Rule of thumb: Prefer Redis (in-memory) over DB for anything needing < 1ms latency
|