@devran-ai/kit 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agent/CheatSheet.md +350 -0
- package/.agent/README.md +76 -0
- package/.agent/agents/README.md +155 -0
- package/.agent/agents/architect.md +185 -0
- package/.agent/agents/backend-specialist.md +276 -0
- package/.agent/agents/build-error-resolver.md +207 -0
- package/.agent/agents/code-reviewer.md +162 -0
- package/.agent/agents/database-architect.md +138 -0
- package/.agent/agents/devops-engineer.md +144 -0
- package/.agent/agents/doc-updater.md +229 -0
- package/.agent/agents/e2e-runner.md +145 -0
- package/.agent/agents/explorer-agent.md +143 -0
- package/.agent/agents/frontend-specialist.md +144 -0
- package/.agent/agents/go-reviewer.md +128 -0
- package/.agent/agents/knowledge-agent.md +197 -0
- package/.agent/agents/mobile-developer.md +150 -0
- package/.agent/agents/performance-optimizer.md +175 -0
- package/.agent/agents/planner.md +133 -0
- package/.agent/agents/pr-reviewer.md +148 -0
- package/.agent/agents/python-reviewer.md +123 -0
- package/.agent/agents/refactor-cleaner.md +201 -0
- package/.agent/agents/reliability-engineer.md +156 -0
- package/.agent/agents/security-reviewer.md +141 -0
- package/.agent/agents/sprint-orchestrator.md +124 -0
- package/.agent/agents/tdd-guide.md +179 -0
- package/.agent/agents/typescript-reviewer.md +110 -0
- package/.agent/checklists/README.md +102 -0
- package/.agent/checklists/pre-commit.md +93 -0
- package/.agent/checklists/session-end.md +99 -0
- package/.agent/checklists/session-start.md +102 -0
- package/.agent/checklists/task-complete.md +81 -0
- package/.agent/commands/README.md +130 -0
- package/.agent/commands/adr.md +29 -0
- package/.agent/commands/ask.md +28 -0
- package/.agent/commands/build.md +30 -0
- package/.agent/commands/changelog.md +40 -0
- package/.agent/commands/checkpoint.md +28 -0
- package/.agent/commands/code-review.md +65 -0
- package/.agent/commands/compact.md +28 -0
- package/.agent/commands/cook.md +30 -0
- package/.agent/commands/db.md +30 -0
- package/.agent/commands/debug.md +31 -0
- package/.agent/commands/deploy.md +37 -0
- package/.agent/commands/design.md +29 -0
- package/.agent/commands/doc.md +30 -0
- package/.agent/commands/eval.md +30 -0
- package/.agent/commands/fix.md +32 -0
- package/.agent/commands/git.md +32 -0
- package/.agent/commands/help.md +273 -0
- package/.agent/commands/implement.md +30 -0
- package/.agent/commands/integrate.md +32 -0
- package/.agent/commands/learn.md +29 -0
- package/.agent/commands/perf.md +31 -0
- package/.agent/commands/plan.md +56 -0
- package/.agent/commands/pr-describe.md +65 -0
- package/.agent/commands/pr-fix.md +45 -0
- package/.agent/commands/pr-merge.md +45 -0
- package/.agent/commands/pr-review.md +50 -0
- package/.agent/commands/pr-split.md +54 -0
- package/.agent/commands/pr-status.md +56 -0
- package/.agent/commands/pr.md +58 -0
- package/.agent/commands/refactor.md +32 -0
- package/.agent/commands/research.md +28 -0
- package/.agent/commands/scout.md +30 -0
- package/.agent/commands/security-scan.md +33 -0
- package/.agent/commands/setup.md +31 -0
- package/.agent/commands/status.md +59 -0
- package/.agent/commands/tdd.md +73 -0
- package/.agent/commands/verify.md +58 -0
- package/.agent/contexts/brainstorm.md +26 -0
- package/.agent/contexts/debug.md +28 -0
- package/.agent/contexts/implement.md +29 -0
- package/.agent/contexts/plan-quality-log.md +30 -0
- package/.agent/contexts/review.md +27 -0
- package/.agent/contexts/ship.md +28 -0
- package/.agent/decisions/001-trust-grade-governance.md +46 -0
- package/.agent/decisions/002-cross-ide-generation.md +15 -0
- package/.agent/engine/identity.json +4 -0
- package/.agent/engine/loading-rules.json +193 -0
- package/.agent/engine/marketplace-index.json +29 -0
- package/.agent/engine/mcp-servers/filesystem.json +9 -0
- package/.agent/engine/mcp-servers/github.json +11 -0
- package/.agent/engine/mcp-servers/postgres.json +11 -0
- package/.agent/engine/mcp-servers/supabase.json +11 -0
- package/.agent/engine/mcp-servers/vercel.json +11 -0
- package/.agent/engine/reliability-config.json +14 -0
- package/.agent/engine/sdlc-map.json +50 -0
- package/.agent/engine/workflow-state.json +167 -0
- package/.agent/hooks/README.md +101 -0
- package/.agent/hooks/hooks.json +104 -0
- package/.agent/hooks/templates/session-end.md +110 -0
- package/.agent/hooks/templates/session-start.md +95 -0
- package/.agent/manifest.json +466 -0
- package/.agent/rules/agent-upgrade-policy.md +56 -0
- package/.agent/rules/architecture.md +111 -0
- package/.agent/rules/coding-style.md +75 -0
- package/.agent/rules/documentation.md +74 -0
- package/.agent/rules/git-workflow.md +140 -0
- package/.agent/rules/quality-gate.md +117 -0
- package/.agent/rules/security.md +67 -0
- package/.agent/rules/sprint-tracking.md +103 -0
- package/.agent/rules/testing.md +80 -0
- package/.agent/rules/workflow-standards.md +30 -0
- package/.agent/rules.md +293 -0
- package/.agent/session-context.md +69 -0
- package/.agent/session-state.json +27 -0
- package/.agent/skills/README.md +135 -0
- package/.agent/skills/api-patterns/SKILL.md +117 -0
- package/.agent/skills/app-builder/SKILL.md +202 -0
- package/.agent/skills/architecture/SKILL.md +101 -0
- package/.agent/skills/behavioral-modes/SKILL.md +295 -0
- package/.agent/skills/brainstorming/SKILL.md +156 -0
- package/.agent/skills/clean-code/SKILL.md +142 -0
- package/.agent/skills/context-budget/SKILL.md +78 -0
- package/.agent/skills/continuous-learning/SKILL.md +145 -0
- package/.agent/skills/database-design/SKILL.md +303 -0
- package/.agent/skills/debugging-strategies/SKILL.md +158 -0
- package/.agent/skills/deployment-procedures/SKILL.md +191 -0
- package/.agent/skills/docker-patterns/SKILL.md +161 -0
- package/.agent/skills/eval-harness/SKILL.md +89 -0
- package/.agent/skills/frontend-patterns/SKILL.md +141 -0
- package/.agent/skills/git-workflow/SKILL.md +159 -0
- package/.agent/skills/i18n-localization/SKILL.md +191 -0
- package/.agent/skills/intelligent-routing/SKILL.md +180 -0
- package/.agent/skills/mcp-integration/SKILL.md +240 -0
- package/.agent/skills/mobile-design/SKILL.md +191 -0
- package/.agent/skills/nodejs-patterns/SKILL.md +164 -0
- package/.agent/skills/parallel-agents/SKILL.md +200 -0
- package/.agent/skills/performance-profiling/SKILL.md +134 -0
- package/.agent/skills/plan-validation/SKILL.md +192 -0
- package/.agent/skills/plan-writing/SKILL.md +183 -0
- package/.agent/skills/plan-writing/domain-enhancers.md +184 -0
- package/.agent/skills/plan-writing/plan-retrospective.md +116 -0
- package/.agent/skills/plan-writing/plan-schema.md +119 -0
- package/.agent/skills/pr-toolkit/SKILL.md +174 -0
- package/.agent/skills/production-readiness/SKILL.md +126 -0
- package/.agent/skills/security-practices/SKILL.md +109 -0
- package/.agent/skills/shell-conventions/SKILL.md +92 -0
- package/.agent/skills/strategic-compact/SKILL.md +62 -0
- package/.agent/skills/testing-patterns/SKILL.md +141 -0
- package/.agent/skills/typescript-expert/SKILL.md +160 -0
- package/.agent/skills/ui-ux-pro-max/SKILL.md +137 -0
- package/.agent/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agent/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/.agent/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agent/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/.agent/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/.agent/skills/ui-ux-pro-max/scripts/search.py +114 -0
- package/.agent/skills/verification-loop/SKILL.md +89 -0
- package/.agent/skills/webapp-testing/SKILL.md +175 -0
- package/.agent/templates/adr-template.md +32 -0
- package/.agent/templates/bug-report.md +37 -0
- package/.agent/templates/feature-request.md +32 -0
- package/.agent/workflows/README.md +101 -0
- package/.agent/workflows/brainstorm.md +86 -0
- package/.agent/workflows/create.md +85 -0
- package/.agent/workflows/debug.md +83 -0
- package/.agent/workflows/deploy.md +114 -0
- package/.agent/workflows/enhance.md +85 -0
- package/.agent/workflows/orchestrate.md +106 -0
- package/.agent/workflows/plan.md +105 -0
- package/.agent/workflows/pr-fix.md +163 -0
- package/.agent/workflows/pr-merge.md +117 -0
- package/.agent/workflows/pr-review.md +178 -0
- package/.agent/workflows/pr-split.md +118 -0
- package/.agent/workflows/pr.md +184 -0
- package/.agent/workflows/preflight.md +107 -0
- package/.agent/workflows/preview.md +95 -0
- package/.agent/workflows/quality-gate.md +103 -0
- package/.agent/workflows/retrospective.md +100 -0
- package/.agent/workflows/review.md +104 -0
- package/.agent/workflows/status.md +89 -0
- package/.agent/workflows/test.md +98 -0
- package/.agent/workflows/ui-ux-pro-max.md +93 -0
- package/.agent/workflows/upgrade.md +97 -0
- package/LICENSE +21 -0
- package/README.md +218 -0
- package/bin/kit.js +773 -0
- package/lib/agent-registry.js +228 -0
- package/lib/agent-reputation.js +343 -0
- package/lib/circuit-breaker.js +195 -0
- package/lib/cli-commands.js +322 -0
- package/lib/config-validator.js +274 -0
- package/lib/conflict-detector.js +252 -0
- package/lib/constants.js +47 -0
- package/lib/engineering-manager.js +336 -0
- package/lib/error-budget.js +370 -0
- package/lib/hook-system.js +256 -0
- package/lib/ide-generator.js +434 -0
- package/lib/identity.js +240 -0
- package/lib/io.js +146 -0
- package/lib/learning-engine.js +163 -0
- package/lib/loading-engine.js +421 -0
- package/lib/logger.js +118 -0
- package/lib/marketplace.js +321 -0
- package/lib/plugin-system.js +604 -0
- package/lib/plugin-verifier.js +197 -0
- package/lib/rate-limiter.js +113 -0
- package/lib/security-scanner.js +312 -0
- package/lib/self-healing.js +468 -0
- package/lib/session-manager.js +264 -0
- package/lib/skill-sandbox.js +244 -0
- package/lib/task-governance.js +522 -0
- package/lib/task-model.js +332 -0
- package/lib/updater.js +240 -0
- package/lib/verify.js +279 -0
- package/lib/workflow-engine.js +373 -0
- package/lib/workflow-events.js +166 -0
- package/lib/workflow-persistence.js +160 -0
- package/package.json +57 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-design
|
|
3
|
+
description: Database schema design, optimization patterns, distributed system consistency models, and zero-downtime migration strategies
|
|
4
|
+
triggers: [context, database, schema, sql, prisma]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Database Design Skill
|
|
8
|
+
|
|
9
|
+
> **Purpose**: Design efficient, normalized database schemas
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
This skill provides guidance for designing performant, scalable database schemas following best practices.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Schema Design Principles
|
|
20
|
+
|
|
21
|
+
### 1. Normalization (3NF)
|
|
22
|
+
|
|
23
|
+
- **1NF**: Atomic values, no repeating groups
|
|
24
|
+
- **2NF**: No partial dependencies
|
|
25
|
+
- **3NF**: No transitive dependencies
|
|
26
|
+
|
|
27
|
+
### 2. Naming Conventions
|
|
28
|
+
|
|
29
|
+
```sql
|
|
30
|
+
-- Tables: plural, snake_case
|
|
31
|
+
users, order_items, user_preferences
|
|
32
|
+
|
|
33
|
+
-- Columns: singular, snake_case
|
|
34
|
+
user_id, created_at, is_active
|
|
35
|
+
|
|
36
|
+
-- Primary Keys: id or {table}_id
|
|
37
|
+
id, user_id
|
|
38
|
+
|
|
39
|
+
-- Foreign Keys: {referenced_table}_id
|
|
40
|
+
user_id, order_id
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Common Patterns
|
|
46
|
+
|
|
47
|
+
### User Entity
|
|
48
|
+
|
|
49
|
+
```prisma
|
|
50
|
+
model User {
|
|
51
|
+
id String @id @default(uuid())
|
|
52
|
+
email String @unique
|
|
53
|
+
password String
|
|
54
|
+
firstName String?
|
|
55
|
+
lastName String?
|
|
56
|
+
role Role @default(USER)
|
|
57
|
+
isActive Boolean @default(true)
|
|
58
|
+
createdAt DateTime @default(now())
|
|
59
|
+
updatedAt DateTime @updatedAt
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
enum Role {
|
|
63
|
+
USER
|
|
64
|
+
ADMIN
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### One-to-Many
|
|
69
|
+
|
|
70
|
+
```prisma
|
|
71
|
+
model User {
|
|
72
|
+
id String @id @default(uuid())
|
|
73
|
+
orders Order[]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
model Order {
|
|
77
|
+
id String @id @default(uuid())
|
|
78
|
+
userId String
|
|
79
|
+
user User @relation(fields: [userId], references: [id])
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Many-to-Many
|
|
84
|
+
|
|
85
|
+
```prisma
|
|
86
|
+
model User {
|
|
87
|
+
id String @id @default(uuid())
|
|
88
|
+
roles Role[]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
model Role {
|
|
92
|
+
id String @id @default(uuid())
|
|
93
|
+
users User[]
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Indexing Strategy
|
|
100
|
+
|
|
101
|
+
```prisma
|
|
102
|
+
model User {
|
|
103
|
+
id String @id @default(uuid())
|
|
104
|
+
email String @unique
|
|
105
|
+
|
|
106
|
+
@@index([createdAt])
|
|
107
|
+
@@index([isActive, role])
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### When to Index
|
|
112
|
+
|
|
113
|
+
| Scenario | Index Type |
|
|
114
|
+
| :---------------- | :------------- |
|
|
115
|
+
| Primary lookup | Primary Key |
|
|
116
|
+
| Unique constraint | Unique |
|
|
117
|
+
| Frequent WHERE | B-tree |
|
|
118
|
+
| Text search | Full-text |
|
|
119
|
+
| JSON fields | GIN (Postgres) |
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Query Optimization
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// N+1 Problem
|
|
127
|
+
const users = await prisma.user.findMany();
|
|
128
|
+
for (const user of users) {
|
|
129
|
+
const orders = await prisma.order.findMany({ where: { userId: user.id } });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Eager Loading
|
|
133
|
+
const users = await prisma.user.findMany({
|
|
134
|
+
include: { orders: true },
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## CAP Theorem
|
|
141
|
+
|
|
142
|
+
In a distributed system, you can guarantee at most two of three properties simultaneously:
|
|
143
|
+
|
|
144
|
+
- **Consistency (C)**: Every read returns the most recent write
|
|
145
|
+
- **Availability (A)**: Every request receives a response (no timeout)
|
|
146
|
+
- **Partition Tolerance (P)**: The system continues operating despite network partitions
|
|
147
|
+
|
|
148
|
+
Since network partitions are unavoidable in distributed systems, the real choice is between CP and AP.
|
|
149
|
+
|
|
150
|
+
### Decision Matrix
|
|
151
|
+
|
|
152
|
+
| Trade-off | Guarantees | Sacrifices | When to Choose | Example Systems |
|
|
153
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
154
|
+
| **CP** | Consistency + Partition Tolerance | Availability during partitions | Financial transactions, inventory counts, leader election | MongoDB (default), HBase, Zookeeper |
|
|
155
|
+
| **AP** | Availability + Partition Tolerance | Consistency (eventual) | Social feeds, caching layers, DNS, session stores | Cassandra, DynamoDB, CouchDB |
|
|
156
|
+
| **CA** | Consistency + Availability | Partition Tolerance | Single-node deployments only (no true distribution) | Traditional RDBMS (PostgreSQL, MySQL single-node) |
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## ACID vs BASE
|
|
161
|
+
|
|
162
|
+
### Property Comparison
|
|
163
|
+
|
|
164
|
+
| Property | ACID | BASE |
|
|
165
|
+
| :--- | :--- | :--- |
|
|
166
|
+
| **Full name** | Atomicity, Consistency, Isolation, Durability | Basically Available, Soft state, Eventually consistent |
|
|
167
|
+
| **Consistency** | Strong (immediate) | Eventual |
|
|
168
|
+
| **Availability** | May block under contention | Prioritizes availability |
|
|
169
|
+
| **Transactions** | Full multi-statement transactions | Single-record atomic ops; app-level sagas |
|
|
170
|
+
| **Scaling** | Vertical first; horizontal is complex | Horizontal by design |
|
|
171
|
+
| **Best for** | Financial systems, booking, inventory | Analytics, social, IoT, content delivery |
|
|
172
|
+
|
|
173
|
+
### When to Use Each
|
|
174
|
+
|
|
175
|
+
- **ACID**: Money movement, order processing, anything requiring rollback guarantees, regulatory compliance
|
|
176
|
+
- **BASE**: High-throughput writes, geographically distributed reads, systems where stale reads are acceptable for seconds
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Consistency Models
|
|
181
|
+
|
|
182
|
+
From strongest to weakest, choose the level your application actually needs:
|
|
183
|
+
|
|
184
|
+
| Model | Guarantee | Latency Cost | Use Case |
|
|
185
|
+
| :--- | :--- | :--- | :--- |
|
|
186
|
+
| **Strict / Linearizable** | Reads always see the latest write globally | Highest (cross-region coordination) | Distributed locks, leader election |
|
|
187
|
+
| **Sequential** | All nodes see operations in the same order | High | Replicated state machines |
|
|
188
|
+
| **Causal** | Causally related operations are seen in order | Medium | Chat applications, collaborative editing |
|
|
189
|
+
| **Read-your-writes** | A client always sees its own writes | Low-Medium | User profile updates, shopping carts |
|
|
190
|
+
| **Monotonic reads** | Once a value is seen, older values are never returned | Low | Dashboard displays, reporting |
|
|
191
|
+
| **Eventual** | All replicas converge given enough time | Lowest | DNS, CDN caches, social media likes |
|
|
192
|
+
|
|
193
|
+
Choose the weakest model your application can tolerate to maximize performance and availability.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Migration Safety
|
|
198
|
+
|
|
199
|
+
### Zero-Downtime Migration Pattern
|
|
200
|
+
|
|
201
|
+
Safe migrations follow a multi-phase approach that avoids locking tables or breaking running application code.
|
|
202
|
+
|
|
203
|
+
**Phase 1 - Expand**: Add new structures alongside old ones
|
|
204
|
+
**Phase 2 - Migrate**: Backfill data, dual-write to both structures
|
|
205
|
+
**Phase 3 - Contract**: Remove old structures after all consumers have switched
|
|
206
|
+
|
|
207
|
+
### Safe vs Unsafe Operations
|
|
208
|
+
|
|
209
|
+
| Operation | Safe? | Zero-Downtime Alternative |
|
|
210
|
+
| :--- | :--- | :--- |
|
|
211
|
+
| **Add nullable column** | Safe | N/A (already safe) |
|
|
212
|
+
| **Add column with default** | Safe (Postgres 11+) | For older versions, add nullable then backfill |
|
|
213
|
+
| **Drop column** | Unsafe | Stop reading column in code first, then drop in next deploy |
|
|
214
|
+
| **Rename column** | Unsafe | Add new column, dual-write, migrate reads, drop old |
|
|
215
|
+
| **Change column type** | Unsafe | Add new column with new type, backfill, swap reads |
|
|
216
|
+
| **Add NOT NULL constraint** | Unsafe | Add CHECK constraint as NOT VALID, then VALIDATE separately |
|
|
217
|
+
| **Add index** | Unsafe (locks table) | Use `CREATE INDEX CONCURRENTLY` (Postgres) |
|
|
218
|
+
| **Drop table** | Unsafe | Remove all references in code first, then drop |
|
|
219
|
+
|
|
220
|
+
### Backfill Pattern
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// Backfill in batches to avoid long-running transactions
|
|
224
|
+
async function backfillNewColumn(batchSize = 1000) {
|
|
225
|
+
let processed = 0;
|
|
226
|
+
let hasMore = true;
|
|
227
|
+
|
|
228
|
+
while (hasMore) {
|
|
229
|
+
const rows = await prisma.$executeRaw`
|
|
230
|
+
UPDATE users
|
|
231
|
+
SET display_name = first_name || ' ' || last_name
|
|
232
|
+
WHERE display_name IS NULL
|
|
233
|
+
LIMIT ${batchSize}
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
processed += rows;
|
|
237
|
+
hasMore = rows === batchSize;
|
|
238
|
+
|
|
239
|
+
// Yield to other operations between batches
|
|
240
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return processed;
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Connection Pooling
|
|
250
|
+
|
|
251
|
+
### Pool Size Guidance
|
|
252
|
+
|
|
253
|
+
| Environment | Pool Size | Rationale |
|
|
254
|
+
| :--- | :--- | :--- |
|
|
255
|
+
| **Development** | 2-5 | Single developer, minimal concurrency |
|
|
256
|
+
| **Production (server)** | 10-20 per instance | Balance between concurrency and DB connection limits |
|
|
257
|
+
| **Production (serverless)** | 1-2 per function | Functions scale horizontally; too many connections exhaust DB limits |
|
|
258
|
+
| **Staging / CI** | 3-5 | Mirrors production behavior without resource waste |
|
|
259
|
+
|
|
260
|
+
### Sizing Formula
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
max_pool_size = (db_max_connections - reserved_superuser_connections) / number_of_app_instances
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
For PostgreSQL with `max_connections = 100`, 3 superuser slots reserved, and 4 app instances:
|
|
267
|
+
`(100 - 3) / 4 = ~24 connections per instance`
|
|
268
|
+
|
|
269
|
+
### Tool Recommendations
|
|
270
|
+
|
|
271
|
+
| Tool | Best For | Notes |
|
|
272
|
+
| :--- | :--- | :--- |
|
|
273
|
+
| **PgBouncer** | External pooler for PostgreSQL | Transaction-mode pooling for serverless; sits between app and DB |
|
|
274
|
+
| **Prisma built-in pool** | Prisma ORM users | Configure via `connection_limit` in datasource URL |
|
|
275
|
+
| **Prisma Accelerate** | Serverless / edge | Managed connection pooling with global caching |
|
|
276
|
+
| **RDS Proxy** | AWS deployments | Managed pooler; supports IAM auth and failover |
|
|
277
|
+
| **Supabase Supavisor** | Supabase projects | Built-in pooler with transaction and session modes |
|
|
278
|
+
|
|
279
|
+
```prisma
|
|
280
|
+
// Prisma connection pool configuration
|
|
281
|
+
datasource db {
|
|
282
|
+
provider = "postgresql"
|
|
283
|
+
url = env("DATABASE_URL") // ?connection_limit=20&pool_timeout=10
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## Quick Reference
|
|
290
|
+
|
|
291
|
+
| Pattern | Usage |
|
|
292
|
+
| :------------- | :------------------ |
|
|
293
|
+
| UUID | Distributed systems |
|
|
294
|
+
| Auto-increment | Simple apps |
|
|
295
|
+
| Soft Delete | Audit requirements |
|
|
296
|
+
| Timestamps | Always include |
|
|
297
|
+
| Indexes | Frequent queries |
|
|
298
|
+
| Constraints | Data integrity |
|
|
299
|
+
| CAP trade-off | Distributed design |
|
|
300
|
+
| ACID | Transactional data |
|
|
301
|
+
| BASE | High-scale writes |
|
|
302
|
+
| Migrations | Zero-downtime deploys |
|
|
303
|
+
| Connection Pool | Right-size per env |
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: debugging-strategies
|
|
3
|
+
description: Systematic debugging approaches for complex problems
|
|
4
|
+
triggers: [context, debug, error, bug, fix]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Debugging Strategies Skill
|
|
8
|
+
|
|
9
|
+
> **Purpose**: Apply systematic debugging approaches
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
This skill provides structured methodologies for identifying and resolving bugs efficiently.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## The 5-Step Debugging Process
|
|
20
|
+
|
|
21
|
+
### 1. Reproduce
|
|
22
|
+
|
|
23
|
+
- Create minimal reproduction case
|
|
24
|
+
- Document exact steps to trigger
|
|
25
|
+
- Note environment details (OS, versions, config)
|
|
26
|
+
|
|
27
|
+
### 2. Isolate
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// Binary search approach
|
|
31
|
+
// Comment out half the code, see if issue persists
|
|
32
|
+
// Narrow down to smallest failing unit
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Identify
|
|
36
|
+
|
|
37
|
+
- Read error messages carefully
|
|
38
|
+
- Check stack traces
|
|
39
|
+
- Review recent changes
|
|
40
|
+
|
|
41
|
+
### 4. Fix
|
|
42
|
+
|
|
43
|
+
- Make minimal change
|
|
44
|
+
- One fix at a time
|
|
45
|
+
- Don't introduce new issues
|
|
46
|
+
|
|
47
|
+
### 5. Verify
|
|
48
|
+
|
|
49
|
+
- Confirm fix works
|
|
50
|
+
- Test edge cases
|
|
51
|
+
- Add regression test
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Debugging Tools
|
|
56
|
+
|
|
57
|
+
### Console Debugging
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Basic
|
|
61
|
+
console.log("value:", value);
|
|
62
|
+
|
|
63
|
+
// Better - with labels
|
|
64
|
+
console.log("[UserService.create]", { email, userId });
|
|
65
|
+
|
|
66
|
+
// Table format
|
|
67
|
+
console.table(users);
|
|
68
|
+
|
|
69
|
+
// Timing
|
|
70
|
+
console.time("api-call");
|
|
71
|
+
await fetchData();
|
|
72
|
+
console.timeEnd("api-call");
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Breakpoint Debugging
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
// VS Code / Chrome DevTools
|
|
79
|
+
debugger; // Programmatic breakpoint
|
|
80
|
+
|
|
81
|
+
// Conditional breakpoint in IDE:
|
|
82
|
+
// Right-click → Add Conditional Breakpoint
|
|
83
|
+
// user.email === 'test@example.com'
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Common Bug Patterns
|
|
89
|
+
|
|
90
|
+
### Async Issues
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// ❌ Missing await
|
|
94
|
+
const user = getUserById(id); // Returns Promise, not User
|
|
95
|
+
console.log(user.name); // undefined
|
|
96
|
+
|
|
97
|
+
// ✅ Fixed
|
|
98
|
+
const user = await getUserById(id);
|
|
99
|
+
console.log(user.name);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Reference vs Value
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// ❌ Mutating original
|
|
106
|
+
const sorted = items.sort(); // Modifies items!
|
|
107
|
+
|
|
108
|
+
// ✅ Copy first
|
|
109
|
+
const sorted = [...items].sort();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Closure Issues
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// ❌ Classic loop closure bug
|
|
116
|
+
for (var i = 0; i < 3; i++) {
|
|
117
|
+
setTimeout(() => console.log(i), 100); // 3, 3, 3
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ✅ Use let or closure
|
|
121
|
+
for (let i = 0; i < 3; i++) {
|
|
122
|
+
setTimeout(() => console.log(i), 100); // 0, 1, 2
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Error Investigation
|
|
129
|
+
|
|
130
|
+
### Read the Stack Trace
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
Error: Cannot read property 'name' of undefined
|
|
134
|
+
at UserService.getUser (user.service.ts:45:23) ← Start here
|
|
135
|
+
at UserController.show (user.controller.ts:28:15)
|
|
136
|
+
at processTicksAndRejections (internal/process/task_queues.js:93:5)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Check Recent Changes
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
git log --oneline -10
|
|
143
|
+
git diff HEAD~5..HEAD -- src/
|
|
144
|
+
git blame src/services/user.service.ts
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Quick Reference
|
|
150
|
+
|
|
151
|
+
| Symptom | Likely Cause |
|
|
152
|
+
| :------------------------- | :------------------ |
|
|
153
|
+
| undefined is not an object | Null reference |
|
|
154
|
+
| Maximum call stack | Infinite recursion |
|
|
155
|
+
| Cannot read property | Missing null check |
|
|
156
|
+
| CORS error | Backend config |
|
|
157
|
+
| 401 Unauthorized | Token expired |
|
|
158
|
+
| 500 Internal Error | Unhandled exception |
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deployment-procedures
|
|
3
|
+
description: Production deployment workflows, rollback strategies, and CI/CD best practices.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
allowed-tools: Read, Glob, Grep, Bash
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Deployment Procedures
|
|
9
|
+
|
|
10
|
+
> Every deployment is a risk. Minimize risk through preparation, not speed.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 1. Pre-Deployment Principles
|
|
15
|
+
|
|
16
|
+
### The 4 Verification Categories
|
|
17
|
+
|
|
18
|
+
| Category | What to Check |
|
|
19
|
+
| ---------------- | -------------------------------------- |
|
|
20
|
+
| **Code Quality** | Tests passing, linting clean, reviewed |
|
|
21
|
+
| **Build** | Production build works, no warnings |
|
|
22
|
+
| **Environment** | Env vars set, secrets current |
|
|
23
|
+
| **Safety** | Backup done, rollback plan ready |
|
|
24
|
+
|
|
25
|
+
### Pre-Deployment Checklist
|
|
26
|
+
|
|
27
|
+
- [ ] All tests passing
|
|
28
|
+
- [ ] Code reviewed and approved
|
|
29
|
+
- [ ] Production build successful
|
|
30
|
+
- [ ] Environment variables verified
|
|
31
|
+
- [ ] Database migrations ready (if any)
|
|
32
|
+
- [ ] Rollback plan documented
|
|
33
|
+
- [ ] Team notified
|
|
34
|
+
- [ ] Monitoring ready
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 2. The 5-Phase Deployment Process
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
1. PREPARE
|
|
42
|
+
└── Verify code, build, env vars
|
|
43
|
+
|
|
44
|
+
2. BACKUP
|
|
45
|
+
└── Save current state before changing
|
|
46
|
+
|
|
47
|
+
3. DEPLOY
|
|
48
|
+
└── Execute with monitoring open
|
|
49
|
+
|
|
50
|
+
4. VERIFY
|
|
51
|
+
└── Health check, logs, key flows
|
|
52
|
+
|
|
53
|
+
5. CONFIRM or ROLLBACK
|
|
54
|
+
└── All good? Confirm. Issues? Rollback.
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Phase Principles
|
|
58
|
+
|
|
59
|
+
| Phase | Principle |
|
|
60
|
+
| ----------- | -------------------------------- |
|
|
61
|
+
| **Prepare** | Never deploy untested code |
|
|
62
|
+
| **Backup** | Can't rollback without backup |
|
|
63
|
+
| **Deploy** | Watch it happen, don't walk away |
|
|
64
|
+
| **Verify** | Trust but verify |
|
|
65
|
+
| **Confirm** | Have rollback trigger ready |
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 3. Platform-Specific Procedures
|
|
70
|
+
|
|
71
|
+
### Vercel
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Preview deploy (automatic on PR)
|
|
75
|
+
git push origin feature-branch
|
|
76
|
+
|
|
77
|
+
# Production deploy
|
|
78
|
+
git push origin main
|
|
79
|
+
# or
|
|
80
|
+
vercel --prod
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Firebase
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Deploy hosting
|
|
87
|
+
firebase deploy --only hosting
|
|
88
|
+
|
|
89
|
+
# Deploy functions
|
|
90
|
+
firebase deploy --only functions
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Docker/VPS
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Build and push
|
|
97
|
+
docker build -t app:latest .
|
|
98
|
+
docker push registry/app:latest
|
|
99
|
+
|
|
100
|
+
# On server
|
|
101
|
+
docker pull registry/app:latest
|
|
102
|
+
docker-compose up -d
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 4. Rollback Strategies
|
|
108
|
+
|
|
109
|
+
### When to Rollback
|
|
110
|
+
|
|
111
|
+
| Symptom | Action |
|
|
112
|
+
| ----------------------- | --------------------- |
|
|
113
|
+
| 5xx errors | Rollback immediately |
|
|
114
|
+
| Critical feature broken | Rollback |
|
|
115
|
+
| Minor visual bug | Hotfix forward |
|
|
116
|
+
| Performance degradation | Evaluate, then decide |
|
|
117
|
+
|
|
118
|
+
### Rollback by Platform
|
|
119
|
+
|
|
120
|
+
| Platform | Method |
|
|
121
|
+
| -------- | ------------------------------------------ |
|
|
122
|
+
| Vercel | Redeploy previous commit, or use dashboard |
|
|
123
|
+
| Firebase | `firebase hosting:rollback` |
|
|
124
|
+
| Docker | Switch to previous image tag |
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 5. Zero-Downtime Strategies
|
|
129
|
+
|
|
130
|
+
| Strategy | When to Use |
|
|
131
|
+
| ---------- | ------------------------------ |
|
|
132
|
+
| Blue-Green | Multiple servers, quick switch |
|
|
133
|
+
| Rolling | Gradual, Kubernetes |
|
|
134
|
+
| Canary | Test with subset of users |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 6. Anti-Patterns
|
|
139
|
+
|
|
140
|
+
| ❌ Don't | ✅ Do |
|
|
141
|
+
| ------------------------ | -------------------- |
|
|
142
|
+
| Deploy on Friday | Deploy early in week |
|
|
143
|
+
| Rush deployment | Follow the process |
|
|
144
|
+
| Skip staging | Always test first |
|
|
145
|
+
| Deploy without backup | Backup before deploy |
|
|
146
|
+
| Walk away after deploy | Monitor for 15+ min |
|
|
147
|
+
| Multiple changes at once | One change at a time |
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 7. Decision Checklist
|
|
152
|
+
|
|
153
|
+
Before deploying:
|
|
154
|
+
|
|
155
|
+
- [ ] Platform-appropriate procedure?
|
|
156
|
+
- [ ] Backup strategy ready?
|
|
157
|
+
- [ ] Rollback plan documented?
|
|
158
|
+
- [ ] Monitoring configured?
|
|
159
|
+
- [ ] Team notified?
|
|
160
|
+
- [ ] Time to monitor after?
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 8. Best Practices
|
|
165
|
+
|
|
166
|
+
1. **Small, frequent deploys** over big releases
|
|
167
|
+
2. **Feature flags** for risky changes
|
|
168
|
+
3. **Automate** repetitive steps
|
|
169
|
+
4. **Document** every deployment
|
|
170
|
+
5. **Review** what went wrong after issues
|
|
171
|
+
6. **Test rollback** before you need it
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 9. Example Deployment Flow
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
develop → staging (auto) → main → production (auto)
|
|
179
|
+
│ │ │
|
|
180
|
+
└── PR ────┴── Review ────┴── Deploy
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Branch Protection
|
|
184
|
+
|
|
185
|
+
- `main` requires PR approval
|
|
186
|
+
- CI must pass before merge
|
|
187
|
+
- No force push allowed
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
> **Golden Rule:** If in doubt, don't deploy. Wait, prepare, then deploy.
|