ai-devx 1.0.0 → 1.0.1
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/package.json +1 -1
- package/templates/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/templates/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-313.pyc +0 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/templates/.agent/.shared/ui-ux-pro-max/scripts/search.py +106 -0
- package/templates/.agent/ARCHITECTURE.md +288 -0
- package/templates/.agent/agents/backend-specialist.md +251 -135
- package/templates/.agent/agents/code-archaeologist.md +106 -0
- package/templates/.agent/agents/database-architect.md +222 -160
- package/templates/.agent/agents/debugger.md +205 -108
- package/templates/.agent/agents/devops-engineer.md +226 -169
- package/templates/.agent/agents/documentation-writer.md +104 -0
- package/templates/.agent/agents/explorer-agent.md +73 -0
- package/templates/.agent/agents/frontend-specialist.md +587 -116
- package/templates/.agent/agents/game-developer.md +162 -0
- package/templates/.agent/agents/mobile-developer.md +377 -0
- package/templates/.agent/agents/orchestrator.md +412 -133
- package/templates/.agent/agents/penetration-tester.md +188 -0
- package/templates/.agent/agents/performance-optimizer.md +187 -0
- package/templates/.agent/agents/product-manager.md +112 -0
- package/templates/.agent/agents/product-owner.md +95 -0
- package/templates/.agent/agents/project-planner.md +390 -111
- package/templates/.agent/agents/qa-automation-engineer.md +103 -0
- package/templates/.agent/agents/security-auditor.md +158 -110
- package/templates/.agent/agents/seo-specialist.md +111 -0
- package/templates/.agent/agents/test-engineer.md +136 -154
- package/templates/.agent/mcp_config.json +24 -0
- package/templates/.agent/rules/GEMINI.md +273 -0
- package/templates/.agent/scripts/auto_preview.py +148 -0
- package/templates/.agent/scripts/checklist.py +217 -0
- package/templates/.agent/scripts/session_manager.py +120 -0
- package/templates/.agent/scripts/verify_all.py +327 -0
- package/templates/.agent/skills/api-patterns/SKILL.md +77 -232
- package/templates/.agent/skills/api-patterns/api-style.md +42 -0
- package/templates/.agent/skills/api-patterns/auth.md +24 -0
- package/templates/.agent/skills/api-patterns/documentation.md +26 -0
- package/templates/.agent/skills/api-patterns/graphql.md +41 -0
- package/templates/.agent/skills/api-patterns/rate-limiting.md +31 -0
- package/templates/.agent/skills/api-patterns/response.md +37 -0
- package/templates/.agent/skills/api-patterns/rest.md +40 -0
- package/templates/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
- package/templates/.agent/skills/api-patterns/security-testing.md +122 -0
- package/templates/.agent/skills/api-patterns/trpc.md +41 -0
- package/templates/.agent/skills/api-patterns/versioning.md +22 -0
- package/templates/.agent/skills/app-builder/SKILL.md +75 -0
- package/templates/.agent/skills/app-builder/agent-coordination.md +71 -0
- package/templates/.agent/skills/app-builder/feature-building.md +53 -0
- package/templates/.agent/skills/app-builder/project-detection.md +34 -0
- package/templates/.agent/skills/app-builder/scaffolding.md +118 -0
- package/templates/.agent/skills/app-builder/tech-stack.md +40 -0
- package/templates/.agent/skills/app-builder/templates/SKILL.md +39 -0
- package/templates/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
- package/templates/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
- package/templates/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/templates/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
- package/templates/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
- package/templates/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
- package/templates/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
- package/templates/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
- package/templates/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
- package/templates/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
- package/templates/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
- package/templates/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
- package/templates/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
- package/templates/.agent/skills/architecture/SKILL.md +55 -0
- package/templates/.agent/skills/architecture/context-discovery.md +43 -0
- package/templates/.agent/skills/architecture/examples.md +94 -0
- package/templates/.agent/skills/architecture/pattern-selection.md +68 -0
- package/templates/.agent/skills/architecture/patterns-reference.md +50 -0
- package/templates/.agent/skills/architecture/trade-off-analysis.md +77 -0
- package/templates/.agent/skills/bash-linux/SKILL.md +199 -0
- package/templates/.agent/skills/behavioral-modes/SKILL.md +242 -0
- package/templates/.agent/skills/brainstorming/SKILL.md +163 -0
- package/templates/.agent/skills/brainstorming/dynamic-questioning.md +350 -0
- package/templates/.agent/skills/clean-code/SKILL.md +201 -0
- package/templates/.agent/skills/code-review-checklist/SKILL.md +109 -0
- package/templates/.agent/skills/database-design/SKILL.md +34 -285
- package/templates/.agent/skills/database-design/database-selection.md +43 -0
- package/templates/.agent/skills/database-design/indexing.md +39 -0
- package/templates/.agent/skills/database-design/migrations.md +48 -0
- package/templates/.agent/skills/database-design/optimization.md +36 -0
- package/templates/.agent/skills/database-design/orm-selection.md +30 -0
- package/templates/.agent/skills/database-design/schema-design.md +56 -0
- package/templates/.agent/skills/database-design/scripts/schema_validator.py +172 -0
- package/templates/.agent/skills/deployment-procedures/SKILL.md +241 -0
- package/templates/.agent/skills/doc.md +177 -0
- package/templates/.agent/skills/documentation-templates/SKILL.md +194 -0
- package/templates/.agent/skills/frontend-design/SKILL.md +418 -0
- package/templates/.agent/skills/frontend-design/animation-guide.md +331 -0
- package/templates/.agent/skills/frontend-design/color-system.md +311 -0
- package/templates/.agent/skills/frontend-design/decision-trees.md +418 -0
- package/templates/.agent/skills/frontend-design/motion-graphics.md +306 -0
- package/templates/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/templates/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/templates/.agent/skills/frontend-design/typography-system.md +345 -0
- package/templates/.agent/skills/frontend-design/ux-psychology.md +1116 -0
- package/templates/.agent/skills/frontend-design/visual-effects.md +383 -0
- package/templates/.agent/skills/game-development/2d-games/SKILL.md +119 -0
- package/templates/.agent/skills/game-development/3d-games/SKILL.md +135 -0
- package/templates/.agent/skills/game-development/SKILL.md +167 -0
- package/templates/.agent/skills/game-development/game-art/SKILL.md +185 -0
- package/templates/.agent/skills/game-development/game-audio/SKILL.md +190 -0
- package/templates/.agent/skills/game-development/game-design/SKILL.md +129 -0
- package/templates/.agent/skills/game-development/mobile-games/SKILL.md +108 -0
- package/templates/.agent/skills/game-development/multiplayer/SKILL.md +132 -0
- package/templates/.agent/skills/game-development/pc-games/SKILL.md +144 -0
- package/templates/.agent/skills/game-development/vr-ar/SKILL.md +123 -0
- package/templates/.agent/skills/game-development/web-games/SKILL.md +150 -0
- package/templates/.agent/skills/geo-fundamentals/SKILL.md +156 -0
- package/templates/.agent/skills/geo-fundamentals/scripts/geo_checker.py +289 -0
- package/templates/.agent/skills/i18n-localization/SKILL.md +154 -0
- package/templates/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
- package/templates/.agent/skills/intelligent-routing/SKILL.md +335 -0
- package/templates/.agent/skills/lint-and-validate/SKILL.md +45 -0
- package/templates/.agent/skills/lint-and-validate/scripts/lint_runner.py +184 -0
- package/templates/.agent/skills/lint-and-validate/scripts/type_coverage.py +173 -0
- package/templates/.agent/skills/mcp-builder/SKILL.md +176 -0
- package/templates/.agent/skills/mobile-design/SKILL.md +394 -0
- package/templates/.agent/skills/mobile-design/decision-trees.md +516 -0
- package/templates/.agent/skills/mobile-design/mobile-backend.md +491 -0
- package/templates/.agent/skills/mobile-design/mobile-color-system.md +420 -0
- package/templates/.agent/skills/mobile-design/mobile-debugging.md +122 -0
- package/templates/.agent/skills/mobile-design/mobile-design-thinking.md +357 -0
- package/templates/.agent/skills/mobile-design/mobile-navigation.md +458 -0
- package/templates/.agent/skills/mobile-design/mobile-performance.md +767 -0
- package/templates/.agent/skills/mobile-design/mobile-testing.md +356 -0
- package/templates/.agent/skills/mobile-design/mobile-typography.md +433 -0
- package/templates/.agent/skills/mobile-design/platform-android.md +666 -0
- package/templates/.agent/skills/mobile-design/platform-ios.md +561 -0
- package/templates/.agent/skills/mobile-design/scripts/mobile_audit.py +670 -0
- package/templates/.agent/skills/mobile-design/touch-psychology.md +537 -0
- package/templates/.agent/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +312 -0
- package/templates/.agent/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +240 -0
- package/templates/.agent/skills/nextjs-react-expert/3-server-server-side-performance.md +490 -0
- package/templates/.agent/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +264 -0
- package/templates/.agent/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +581 -0
- package/templates/.agent/skills/nextjs-react-expert/6-rendering-rendering-performance.md +432 -0
- package/templates/.agent/skills/nextjs-react-expert/7-js-javascript-performance.md +684 -0
- package/templates/.agent/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +150 -0
- package/templates/.agent/skills/nextjs-react-expert/SKILL.md +286 -0
- package/templates/.agent/skills/nextjs-react-expert/scripts/convert_rules.py +222 -0
- package/templates/.agent/skills/nextjs-react-expert/scripts/react_performance_checker.py +252 -0
- package/templates/.agent/skills/nodejs-best-practices/SKILL.md +333 -0
- package/templates/.agent/skills/parallel-agents/SKILL.md +175 -0
- package/templates/.agent/skills/performance-profiling/SKILL.md +143 -0
- package/templates/.agent/skills/performance-profiling/scripts/lighthouse_audit.py +76 -0
- package/templates/.agent/skills/plan-writing/SKILL.md +152 -0
- package/templates/.agent/skills/powershell-windows/SKILL.md +167 -0
- package/templates/.agent/skills/python-patterns/SKILL.md +441 -0
- package/templates/.agent/skills/red-team-tactics/SKILL.md +199 -0
- package/templates/.agent/skills/rust-pro/SKILL.md +176 -0
- package/templates/.agent/skills/seo-fundamentals/SKILL.md +129 -0
- package/templates/.agent/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
- package/templates/.agent/skills/server-management/SKILL.md +161 -0
- package/templates/.agent/skills/systematic-debugging/SKILL.md +109 -0
- package/templates/.agent/skills/tailwind-patterns/SKILL.md +269 -0
- package/templates/.agent/skills/tdd-workflow/SKILL.md +149 -0
- package/templates/.agent/skills/testing-patterns/SKILL.md +156 -240
- package/templates/.agent/skills/testing-patterns/scripts/test_runner.py +219 -0
- package/templates/.agent/skills/vulnerability-scanner/SKILL.md +276 -0
- package/templates/.agent/skills/vulnerability-scanner/checklists.md +121 -0
- package/templates/.agent/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
- package/templates/.agent/skills/web-design-guidelines/SKILL.md +57 -0
- package/templates/.agent/skills/webapp-testing/SKILL.md +187 -0
- package/templates/.agent/skills/webapp-testing/scripts/playwright_runner.py +173 -0
- package/templates/.agent/workflows/brainstorm.md +113 -0
- package/templates/.agent/workflows/create.md +40 -112
- package/templates/.agent/workflows/debug.md +82 -117
- package/templates/.agent/workflows/deploy.md +142 -129
- package/templates/.agent/workflows/enhance.md +63 -0
- package/templates/.agent/workflows/orchestrate.md +237 -0
- package/templates/.agent/workflows/plan.md +74 -138
- package/templates/.agent/workflows/preview.md +81 -0
- package/templates/.agent/workflows/status.md +86 -0
- package/templates/.agent/workflows/test.md +109 -130
- package/templates/.agent/workflows/ui-ux-pro-max.md +296 -0
- package/templates/.agent/scripts/checklist.js +0 -260
- package/templates/.agent/scripts/security_scan.js +0 -251
- package/templates/.agent/skills/docker-expert/SKILL.md +0 -286
- package/templates/.agent/skills/react-best-practices/SKILL.md +0 -246
- package/templates/.agent/workflows/security.md +0 -181
|
@@ -1,303 +1,52 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: database-design
|
|
3
|
-
description: Database
|
|
4
|
-
|
|
5
|
-
requires: []
|
|
6
|
-
related:
|
|
7
|
-
- backend-specialist
|
|
8
|
-
- sql-optimization
|
|
3
|
+
description: Database design principles and decision-making. Schema design, indexing strategy, ORM selection, serverless databases.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep
|
|
9
5
|
---
|
|
10
6
|
|
|
11
|
-
# Database Design
|
|
7
|
+
# Database Design
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
> **Learn to THINK, not copy SQL patterns.**
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
- **Atomicity**: All operations succeed or fail together
|
|
17
|
-
- **Consistency**: Database remains in valid state
|
|
18
|
-
- **Isolation**: Concurrent transactions don't interfere
|
|
19
|
-
- **Durability**: Committed data persists
|
|
11
|
+
## 🎯 Selective Reading Rule
|
|
20
12
|
|
|
21
|
-
|
|
13
|
+
**Read ONLY files relevant to the request!** Check the content map, find what you need.
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
15
|
+
| File | Description | When to Read |
|
|
16
|
+
|------|-------------|--------------|
|
|
17
|
+
| `database-selection.md` | PostgreSQL vs Neon vs Turso vs SQLite | Choosing database |
|
|
18
|
+
| `orm-selection.md` | Drizzle vs Prisma vs Kysely | Choosing ORM |
|
|
19
|
+
| `schema-design.md` | Normalization, PKs, relationships | Designing schema |
|
|
20
|
+
| `indexing.md` | Index types, composite indexes | Performance tuning |
|
|
21
|
+
| `optimization.md` | N+1, EXPLAIN ANALYZE | Query optimization |
|
|
22
|
+
| `migrations.md` | Safe migrations, serverless DBs | Schema changes |
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
-- ❌ Not 1NF
|
|
29
|
-
CREATE TABLE orders (
|
|
30
|
-
id INT PRIMARY KEY,
|
|
31
|
-
items VARCHAR(255) -- "item1, item2, item3"
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
-- ✅ 1NF
|
|
35
|
-
CREATE TABLE order_items (
|
|
36
|
-
order_id INT,
|
|
37
|
-
item_name VARCHAR(255),
|
|
38
|
-
quantity INT
|
|
39
|
-
);
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
#### 2NF - Second Normal Form
|
|
43
|
-
- Must be in 1NF
|
|
44
|
-
- No partial dependencies (non-key columns depend on full PK)
|
|
45
|
-
|
|
46
|
-
```sql
|
|
47
|
-
-- ❌ Not 2NF (price depends only on product_id, not order_id)
|
|
48
|
-
CREATE TABLE order_items (
|
|
49
|
-
order_id INT,
|
|
50
|
-
product_id INT,
|
|
51
|
-
product_name VARCHAR(255),
|
|
52
|
-
product_price DECIMAL,
|
|
53
|
-
quantity INT,
|
|
54
|
-
PRIMARY KEY (order_id, product_id)
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
-- ✅ 2NF
|
|
58
|
-
CREATE TABLE products (
|
|
59
|
-
id INT PRIMARY KEY,
|
|
60
|
-
name VARCHAR(255),
|
|
61
|
-
price DECIMAL
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
CREATE TABLE order_items (
|
|
65
|
-
order_id INT,
|
|
66
|
-
product_id INT,
|
|
67
|
-
quantity INT,
|
|
68
|
-
PRIMARY KEY (order_id, product_id)
|
|
69
|
-
);
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
#### 3NF - Third Normal Form
|
|
73
|
-
- Must be in 2NF
|
|
74
|
-
- No transitive dependencies
|
|
75
|
-
|
|
76
|
-
```sql
|
|
77
|
-
-- ❌ Not 3NF (category_description depends on category, not directly on product)
|
|
78
|
-
CREATE TABLE products (
|
|
79
|
-
id INT PRIMARY KEY,
|
|
80
|
-
name VARCHAR(255),
|
|
81
|
-
category VARCHAR(255),
|
|
82
|
-
category_description TEXT
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
-- ✅ 3NF
|
|
86
|
-
CREATE TABLE categories (
|
|
87
|
-
id INT PRIMARY KEY,
|
|
88
|
-
name VARCHAR(255),
|
|
89
|
-
description TEXT
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
CREATE TABLE products (
|
|
93
|
-
id INT PRIMARY KEY,
|
|
94
|
-
name VARCHAR(255),
|
|
95
|
-
category_id INT,
|
|
96
|
-
FOREIGN KEY (category_id) REFERENCES categories(id)
|
|
97
|
-
);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## Schema Design Patterns
|
|
101
|
-
|
|
102
|
-
### User Management
|
|
103
|
-
```sql
|
|
104
|
-
CREATE TABLE users (
|
|
105
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
106
|
-
email VARCHAR(255) UNIQUE NOT NULL,
|
|
107
|
-
password_hash VARCHAR(255) NOT NULL,
|
|
108
|
-
name VARCHAR(255) NOT NULL,
|
|
109
|
-
role VARCHAR(50) DEFAULT 'user',
|
|
110
|
-
is_active BOOLEAN DEFAULT true,
|
|
111
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
112
|
-
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
CREATE TABLE user_profiles (
|
|
116
|
-
user_id UUID PRIMARY KEY,
|
|
117
|
-
bio TEXT,
|
|
118
|
-
avatar_url VARCHAR(500),
|
|
119
|
-
phone VARCHAR(20),
|
|
120
|
-
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
121
|
-
);
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### E-Commerce
|
|
125
|
-
```sql
|
|
126
|
-
CREATE TABLE products (
|
|
127
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
128
|
-
name VARCHAR(255) NOT NULL,
|
|
129
|
-
description TEXT,
|
|
130
|
-
price DECIMAL(10,2) NOT NULL,
|
|
131
|
-
stock_quantity INT DEFAULT 0,
|
|
132
|
-
category_id UUID,
|
|
133
|
-
is_active BOOLEAN DEFAULT true,
|
|
134
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
CREATE TABLE orders (
|
|
138
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
139
|
-
user_id UUID NOT NULL,
|
|
140
|
-
status VARCHAR(50) DEFAULT 'pending',
|
|
141
|
-
total_amount DECIMAL(10,2) NOT NULL,
|
|
142
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
143
|
-
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
CREATE TABLE order_items (
|
|
147
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
148
|
-
order_id UUID NOT NULL,
|
|
149
|
-
product_id UUID NOT NULL,
|
|
150
|
-
quantity INT NOT NULL,
|
|
151
|
-
unit_price DECIMAL(10,2) NOT NULL,
|
|
152
|
-
FOREIGN KEY (order_id) REFERENCES orders(id) ON DELETE CASCADE,
|
|
153
|
-
FOREIGN KEY (product_id) REFERENCES products(id)
|
|
154
|
-
);
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### Many-to-Many Relationships
|
|
158
|
-
```sql
|
|
159
|
-
-- Users and Roles (Many-to-Many)
|
|
160
|
-
CREATE TABLE roles (
|
|
161
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
162
|
-
name VARCHAR(100) UNIQUE NOT NULL,
|
|
163
|
-
permissions JSONB
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
CREATE TABLE user_roles (
|
|
167
|
-
user_id UUID,
|
|
168
|
-
role_id UUID,
|
|
169
|
-
assigned_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
170
|
-
PRIMARY KEY (user_id, role_id),
|
|
171
|
-
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
172
|
-
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE
|
|
173
|
-
);
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## Indexing Strategy
|
|
177
|
-
|
|
178
|
-
### When to Index
|
|
179
|
-
- Primary keys (automatic)
|
|
180
|
-
- Foreign keys
|
|
181
|
-
- Columns in WHERE clauses
|
|
182
|
-
- Columns in ORDER BY
|
|
183
|
-
- Columns in JOIN conditions
|
|
184
|
-
|
|
185
|
-
### Index Types
|
|
186
|
-
```sql
|
|
187
|
-
-- B-Tree Index (default)
|
|
188
|
-
CREATE INDEX idx_users_email ON users(email);
|
|
189
|
-
|
|
190
|
-
-- Unique Index
|
|
191
|
-
CREATE UNIQUE INDEX idx_users_email_unique ON users(email);
|
|
192
|
-
|
|
193
|
-
-- Composite Index
|
|
194
|
-
CREATE INDEX idx_orders_user_status ON orders(user_id, status);
|
|
195
|
-
|
|
196
|
-
-- Partial Index
|
|
197
|
-
CREATE INDEX idx_active_users ON users(email) WHERE is_active = true;
|
|
198
|
-
|
|
199
|
-
-- GIN Index (for JSONB, arrays)
|
|
200
|
-
CREATE INDEX idx_products_tags ON products USING GIN(tags);
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Index Best Practices
|
|
204
|
-
- Don't over-index (slows writes)
|
|
205
|
-
- Consider index selectivity
|
|
206
|
-
- Index order matters in composite indexes
|
|
207
|
-
- Regularly review and remove unused indexes
|
|
208
|
-
|
|
209
|
-
## Prisma Schema Example
|
|
210
|
-
|
|
211
|
-
```prisma
|
|
212
|
-
model User {
|
|
213
|
-
id String @id @default(uuid())
|
|
214
|
-
email String @unique
|
|
215
|
-
password String
|
|
216
|
-
name String
|
|
217
|
-
role Role @default(USER)
|
|
218
|
-
isActive Boolean @default(true)
|
|
219
|
-
createdAt DateTime @default(now()) @map("created_at")
|
|
220
|
-
updatedAt DateTime @updatedAt @map("updated_at")
|
|
221
|
-
|
|
222
|
-
profile Profile?
|
|
223
|
-
posts Post[]
|
|
224
|
-
orders Order[]
|
|
225
|
-
|
|
226
|
-
@@map("users")
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
model Profile {
|
|
230
|
-
id String @id @default(uuid())
|
|
231
|
-
bio String?
|
|
232
|
-
avatar String?
|
|
233
|
-
|
|
234
|
-
userId String @unique @map("user_id")
|
|
235
|
-
user User @relation(fields: [userId], references: [id])
|
|
236
|
-
|
|
237
|
-
@@map("profiles")
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
model Post {
|
|
241
|
-
id String @id @default(uuid())
|
|
242
|
-
title String
|
|
243
|
-
content String?
|
|
244
|
-
published Boolean @default(false)
|
|
245
|
-
createdAt DateTime @default(now()) @map("created_at")
|
|
246
|
-
|
|
247
|
-
authorId String @map("author_id")
|
|
248
|
-
author User @relation(fields: [authorId], references: [id])
|
|
249
|
-
|
|
250
|
-
@@index([authorId])
|
|
251
|
-
@@map("posts")
|
|
252
|
-
}
|
|
24
|
+
---
|
|
253
25
|
|
|
254
|
-
|
|
255
|
-
USER
|
|
256
|
-
ADMIN
|
|
257
|
-
MODERATOR
|
|
258
|
-
}
|
|
259
|
-
```
|
|
26
|
+
## ⚠️ Core Principle
|
|
260
27
|
|
|
261
|
-
|
|
28
|
+
- ASK user for database preferences when unclear
|
|
29
|
+
- Choose database/ORM based on CONTEXT
|
|
30
|
+
- Don't default to PostgreSQL for everything
|
|
262
31
|
|
|
263
|
-
|
|
264
|
-
1. Always create migrations for schema changes
|
|
265
|
-
2. Test migrations on staging first
|
|
266
|
-
3. Backup before major migrations
|
|
267
|
-
4. Keep migrations reversible
|
|
268
|
-
5. Document breaking changes
|
|
32
|
+
---
|
|
269
33
|
|
|
270
|
-
|
|
271
|
-
```sql
|
|
272
|
-
-- Up
|
|
273
|
-
CREATE TABLE new_feature (
|
|
274
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
275
|
-
name VARCHAR(255) NOT NULL
|
|
276
|
-
);
|
|
34
|
+
## Decision Checklist
|
|
277
35
|
|
|
278
|
-
|
|
279
|
-
DROP TABLE IF EXISTS new_feature;
|
|
280
|
-
```
|
|
36
|
+
Before designing schema:
|
|
281
37
|
|
|
282
|
-
|
|
38
|
+
- [ ] Asked user about database preference?
|
|
39
|
+
- [ ] Chosen database for THIS context?
|
|
40
|
+
- [ ] Considered deployment environment?
|
|
41
|
+
- [ ] Planned index strategy?
|
|
42
|
+
- [ ] Defined relationship types?
|
|
283
43
|
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
|
-
// ❌ N+1 queries
|
|
287
|
-
const users = await prisma.user.findMany();
|
|
288
|
-
for (const user of users) {
|
|
289
|
-
const posts = await prisma.post.findMany({
|
|
290
|
-
where: { authorId: user.id }
|
|
291
|
-
});
|
|
292
|
-
}
|
|
44
|
+
---
|
|
293
45
|
|
|
294
|
-
|
|
295
|
-
const users = await prisma.user.findMany({
|
|
296
|
-
include: { posts: true }
|
|
297
|
-
});
|
|
298
|
-
```
|
|
46
|
+
## Anti-Patterns
|
|
299
47
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
48
|
+
❌ Default to PostgreSQL for simple apps (SQLite may suffice)
|
|
49
|
+
❌ Skip indexing
|
|
50
|
+
❌ Use SELECT * in production
|
|
51
|
+
❌ Store JSON when structured data is better
|
|
52
|
+
❌ Ignore N+1 queries
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Database Selection (2025)
|
|
2
|
+
|
|
3
|
+
> Choose database based on context, not default.
|
|
4
|
+
|
|
5
|
+
## Decision Tree
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What are your requirements?
|
|
9
|
+
│
|
|
10
|
+
├── Full relational features needed
|
|
11
|
+
│ ├── Self-hosted → PostgreSQL
|
|
12
|
+
│ └── Serverless → Neon, Supabase
|
|
13
|
+
│
|
|
14
|
+
├── Edge deployment / Ultra-low latency
|
|
15
|
+
│ └── Turso (edge SQLite)
|
|
16
|
+
│
|
|
17
|
+
├── AI / Vector search
|
|
18
|
+
│ └── PostgreSQL + pgvector
|
|
19
|
+
│
|
|
20
|
+
├── Simple / Embedded / Local
|
|
21
|
+
│ └── SQLite
|
|
22
|
+
│
|
|
23
|
+
└── Global distribution
|
|
24
|
+
└── PlanetScale, CockroachDB, Turso
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Comparison
|
|
28
|
+
|
|
29
|
+
| Database | Best For | Trade-offs |
|
|
30
|
+
|----------|----------|------------|
|
|
31
|
+
| **PostgreSQL** | Full features, complex queries | Needs hosting |
|
|
32
|
+
| **Neon** | Serverless PG, branching | PG complexity |
|
|
33
|
+
| **Turso** | Edge, low latency | SQLite limitations |
|
|
34
|
+
| **SQLite** | Simple, embedded, local | Single-writer |
|
|
35
|
+
| **PlanetScale** | MySQL, global scale | No foreign keys |
|
|
36
|
+
|
|
37
|
+
## Questions to Ask
|
|
38
|
+
|
|
39
|
+
1. What's the deployment environment?
|
|
40
|
+
2. How complex are the queries?
|
|
41
|
+
3. Is edge/serverless important?
|
|
42
|
+
4. Vector search needed?
|
|
43
|
+
5. Global distribution required?
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Indexing Principles
|
|
2
|
+
|
|
3
|
+
> When and how to create indexes effectively.
|
|
4
|
+
|
|
5
|
+
## When to Create Indexes
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Index these:
|
|
9
|
+
├── Columns in WHERE clauses
|
|
10
|
+
├── Columns in JOIN conditions
|
|
11
|
+
├── Columns in ORDER BY
|
|
12
|
+
├── Foreign key columns
|
|
13
|
+
└── Unique constraints
|
|
14
|
+
|
|
15
|
+
Don't over-index:
|
|
16
|
+
├── Write-heavy tables (slower inserts)
|
|
17
|
+
├── Low-cardinality columns
|
|
18
|
+
├── Columns rarely queried
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Index Type Selection
|
|
22
|
+
|
|
23
|
+
| Type | Use For |
|
|
24
|
+
|------|---------|
|
|
25
|
+
| **B-tree** | General purpose, equality & range |
|
|
26
|
+
| **Hash** | Equality only, faster |
|
|
27
|
+
| **GIN** | JSONB, arrays, full-text |
|
|
28
|
+
| **GiST** | Geometric, range types |
|
|
29
|
+
| **HNSW/IVFFlat** | Vector similarity (pgvector) |
|
|
30
|
+
|
|
31
|
+
## Composite Index Principles
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Order matters for composite indexes:
|
|
35
|
+
├── Equality columns first
|
|
36
|
+
├── Range columns last
|
|
37
|
+
├── Most selective first
|
|
38
|
+
└── Match query pattern
|
|
39
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Migration Principles
|
|
2
|
+
|
|
3
|
+
> Safe migration strategy for zero-downtime changes.
|
|
4
|
+
|
|
5
|
+
## Safe Migration Strategy
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
For zero-downtime changes:
|
|
9
|
+
│
|
|
10
|
+
├── Adding column
|
|
11
|
+
│ └── Add as nullable → backfill → add NOT NULL
|
|
12
|
+
│
|
|
13
|
+
├── Removing column
|
|
14
|
+
│ └── Stop using → deploy → remove column
|
|
15
|
+
│
|
|
16
|
+
├── Adding index
|
|
17
|
+
│ └── CREATE INDEX CONCURRENTLY (non-blocking)
|
|
18
|
+
│
|
|
19
|
+
└── Renaming column
|
|
20
|
+
└── Add new → migrate data → deploy → drop old
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Migration Philosophy
|
|
24
|
+
|
|
25
|
+
- Never make breaking changes in one step
|
|
26
|
+
- Test migrations on data copy first
|
|
27
|
+
- Have rollback plan
|
|
28
|
+
- Run in transaction when possible
|
|
29
|
+
|
|
30
|
+
## Serverless Databases
|
|
31
|
+
|
|
32
|
+
### Neon (Serverless PostgreSQL)
|
|
33
|
+
|
|
34
|
+
| Feature | Benefit |
|
|
35
|
+
|---------|---------|
|
|
36
|
+
| Scale to zero | Cost savings |
|
|
37
|
+
| Instant branching | Dev/preview |
|
|
38
|
+
| Full PostgreSQL | Compatibility |
|
|
39
|
+
| Autoscaling | Traffic handling |
|
|
40
|
+
|
|
41
|
+
### Turso (Edge SQLite)
|
|
42
|
+
|
|
43
|
+
| Feature | Benefit |
|
|
44
|
+
|---------|---------|
|
|
45
|
+
| Edge locations | Ultra-low latency |
|
|
46
|
+
| SQLite compatible | Simple |
|
|
47
|
+
| Generous free tier | Cost |
|
|
48
|
+
| Global distribution | Performance |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Query Optimization
|
|
2
|
+
|
|
3
|
+
> N+1 problem, EXPLAIN ANALYZE, optimization priorities.
|
|
4
|
+
|
|
5
|
+
## N+1 Problem
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What is N+1?
|
|
9
|
+
├── 1 query to get parent records
|
|
10
|
+
├── N queries to get related records
|
|
11
|
+
└── Very slow!
|
|
12
|
+
|
|
13
|
+
Solutions:
|
|
14
|
+
├── JOIN → Single query with all data
|
|
15
|
+
├── Eager loading → ORM handles JOIN
|
|
16
|
+
├── DataLoader → Batch and cache (GraphQL)
|
|
17
|
+
└── Subquery → Fetch related in one query
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Query Analysis Mindset
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
Before optimizing:
|
|
24
|
+
├── EXPLAIN ANALYZE the query
|
|
25
|
+
├── Look for Seq Scan (full table scan)
|
|
26
|
+
├── Check actual vs estimated rows
|
|
27
|
+
└── Identify missing indexes
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Optimization Priorities
|
|
31
|
+
|
|
32
|
+
1. **Add missing indexes** (most common issue)
|
|
33
|
+
2. **Select only needed columns** (not SELECT *)
|
|
34
|
+
3. **Use proper JOINs** (avoid subqueries when possible)
|
|
35
|
+
4. **Limit early** (pagination at database level)
|
|
36
|
+
5. **Cache** (when appropriate)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ORM Selection (2025)
|
|
2
|
+
|
|
3
|
+
> Choose ORM based on deployment and DX needs.
|
|
4
|
+
|
|
5
|
+
## Decision Tree
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What's the context?
|
|
9
|
+
│
|
|
10
|
+
├── Edge deployment / Bundle size matters
|
|
11
|
+
│ └── Drizzle (smallest, SQL-like)
|
|
12
|
+
│
|
|
13
|
+
├── Best DX / Schema-first
|
|
14
|
+
│ └── Prisma (migrations, studio)
|
|
15
|
+
│
|
|
16
|
+
├── Maximum control
|
|
17
|
+
│ └── Raw SQL with query builder
|
|
18
|
+
│
|
|
19
|
+
└── Python ecosystem
|
|
20
|
+
└── SQLAlchemy 2.0 (async support)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Comparison
|
|
24
|
+
|
|
25
|
+
| ORM | Best For | Trade-offs |
|
|
26
|
+
|-----|----------|------------|
|
|
27
|
+
| **Drizzle** | Edge, TypeScript | Newer, less examples |
|
|
28
|
+
| **Prisma** | DX, schema management | Heavier, not edge-ready |
|
|
29
|
+
| **Kysely** | Type-safe SQL builder | Manual migrations |
|
|
30
|
+
| **Raw SQL** | Complex queries, control | Manual type safety |
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Schema Design Principles
|
|
2
|
+
|
|
3
|
+
> Normalization, primary keys, timestamps, relationships.
|
|
4
|
+
|
|
5
|
+
## Normalization Decision
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
When to normalize (separate tables):
|
|
9
|
+
├── Data is repeated across rows
|
|
10
|
+
├── Updates would need multiple changes
|
|
11
|
+
├── Relationships are clear
|
|
12
|
+
└── Query patterns benefit
|
|
13
|
+
|
|
14
|
+
When to denormalize (embed/duplicate):
|
|
15
|
+
├── Read performance critical
|
|
16
|
+
├── Data rarely changes
|
|
17
|
+
├── Always fetched together
|
|
18
|
+
└── Simpler queries needed
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Primary Key Selection
|
|
22
|
+
|
|
23
|
+
| Type | Use When |
|
|
24
|
+
|------|----------|
|
|
25
|
+
| **UUID** | Distributed systems, security |
|
|
26
|
+
| **ULID** | UUID + sortable by time |
|
|
27
|
+
| **Auto-increment** | Simple apps, single database |
|
|
28
|
+
| **Natural key** | Rarely (business meaning) |
|
|
29
|
+
|
|
30
|
+
## Timestamp Strategy
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
For every table:
|
|
34
|
+
├── created_at → When created
|
|
35
|
+
├── updated_at → Last modified
|
|
36
|
+
└── deleted_at → Soft delete (if needed)
|
|
37
|
+
|
|
38
|
+
Use TIMESTAMPTZ (with timezone) not TIMESTAMP
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Relationship Types
|
|
42
|
+
|
|
43
|
+
| Type | When | Implementation |
|
|
44
|
+
|------|------|----------------|
|
|
45
|
+
| **One-to-One** | Extension data | Separate table with FK |
|
|
46
|
+
| **One-to-Many** | Parent-children | FK on child table |
|
|
47
|
+
| **Many-to-Many** | Both sides have many | Junction table |
|
|
48
|
+
|
|
49
|
+
## Foreign Key ON DELETE
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
├── CASCADE → Delete children with parent
|
|
53
|
+
├── SET NULL → Children become orphans
|
|
54
|
+
├── RESTRICT → Prevent delete if children exist
|
|
55
|
+
└── SET DEFAULT → Children get default value
|
|
56
|
+
```
|