ateschh-kit 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +4 -1
- package/CHANGELOG.md +15 -0
- package/CLAUDE.md +16 -16
- package/package.json +1 -2
- package/skills/build/SKILL.md +642 -0
- package/skills/cloudflare-workers-expert/SKILL.md +89 -0
- package/skills/docker-expert/SKILL.md +413 -0
- package/skills/electron-development/SKILL.md +856 -0
- package/skills/expo-api-routes/SKILL.md +368 -0
- package/skills/expo-deployment/SKILL.md +73 -0
- package/skills/fastapi-pro/SKILL.md +190 -0
- package/skills/flutter-expert/SKILL.md +197 -0
- package/skills/llm-app-patterns/SKILL.md +763 -0
- package/skills/nextjs-app-router-patterns/SKILL.md +36 -0
- package/skills/nextjs-best-practices/SKILL.md +208 -0
- package/skills/nodejs-backend-patterns/SKILL.md +38 -0
- package/skills/postgres-best-practices/SKILL.md +59 -0
- package/skills/prisma-expert/SKILL.md +361 -0
- package/skills/prompt-engineering/SKILL.md +177 -0
- package/skills/rag-implementation/SKILL.md +196 -0
- package/skills/react-best-practices/SKILL.md +127 -0
- package/skills/react-native-architecture/SKILL.md +36 -0
- package/skills/shadcn/SKILL.md +250 -0
- package/skills/supabase-automation/SKILL.md +240 -0
- package/skills/tailwind-design-system/SKILL.md +36 -0
- package/skills/typescript-expert/SKILL.md +426 -0
- package/skills/vercel-deployment/SKILL.md +80 -0
- /package/{workflows → .claude/commands}/_TEMPLATE.md +0 -0
- /package/{workflows → .claude/commands}/brainstorm.md +0 -0
- /package/{workflows → .claude/commands}/build.md +0 -0
- /package/{workflows → .claude/commands}/deploy.md +0 -0
- /package/{workflows → .claude/commands}/design.md +0 -0
- /package/{workflows → .claude/commands}/finish.md +0 -0
- /package/{workflows → .claude/commands}/map-codebase.md +0 -0
- /package/{workflows → .claude/commands}/new-project.md +0 -0
- /package/{workflows → .claude/commands}/next.md +0 -0
- /package/{workflows → .claude/commands}/quick.md +0 -0
- /package/{workflows → .claude/commands}/requirements.md +0 -0
- /package/{workflows → .claude/commands}/resume.md +0 -0
- /package/{workflows → .claude/commands}/save.md +0 -0
- /package/{workflows → .claude/commands}/settings.md +0 -0
- /package/{workflows → .claude/commands}/status.md +0 -0
- /package/{workflows → .claude/commands}/test.md +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nextjs-app-router-patterns
|
|
3
|
+
description: "Master Next.js 14+ App Router with Server Components, streaming, parallel routes, and advanced data fetching. Use when building Next.js applications, implementing SSR/SSG, or optimizing React Serve..."
|
|
4
|
+
risk: unknown
|
|
5
|
+
source: community
|
|
6
|
+
date_added: "2026-02-27"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Next.js App Router Patterns
|
|
10
|
+
|
|
11
|
+
Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.
|
|
12
|
+
|
|
13
|
+
## Use this skill when
|
|
14
|
+
|
|
15
|
+
- Building new Next.js applications with App Router
|
|
16
|
+
- Migrating from Pages Router to App Router
|
|
17
|
+
- Implementing Server Components and streaming
|
|
18
|
+
- Setting up parallel and intercepting routes
|
|
19
|
+
- Optimizing data fetching and caching
|
|
20
|
+
- Building full-stack features with Server Actions
|
|
21
|
+
|
|
22
|
+
## Do not use this skill when
|
|
23
|
+
|
|
24
|
+
- The task is unrelated to next.js app router patterns
|
|
25
|
+
- You need a different domain or tool outside this scope
|
|
26
|
+
|
|
27
|
+
## Instructions
|
|
28
|
+
|
|
29
|
+
- Clarify goals, constraints, and required inputs.
|
|
30
|
+
- Apply relevant best practices and validate outcomes.
|
|
31
|
+
- Provide actionable steps and verification.
|
|
32
|
+
- If detailed examples are required, open `resources/implementation-playbook.md`.
|
|
33
|
+
|
|
34
|
+
## Resources
|
|
35
|
+
|
|
36
|
+
- `resources/implementation-playbook.md` for detailed patterns and examples.
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nextjs-best-practices
|
|
3
|
+
description: "Next.js App Router principles. Server Components, data fetching, routing patterns."
|
|
4
|
+
risk: unknown
|
|
5
|
+
source: community
|
|
6
|
+
date_added: "2026-02-27"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Next.js Best Practices
|
|
10
|
+
|
|
11
|
+
> Principles for Next.js App Router development.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 1. Server vs Client Components
|
|
16
|
+
|
|
17
|
+
### Decision Tree
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
Does it need...?
|
|
21
|
+
│
|
|
22
|
+
├── useState, useEffect, event handlers
|
|
23
|
+
│ └── Client Component ('use client')
|
|
24
|
+
│
|
|
25
|
+
├── Direct data fetching, no interactivity
|
|
26
|
+
│ └── Server Component (default)
|
|
27
|
+
│
|
|
28
|
+
└── Both?
|
|
29
|
+
└── Split: Server parent + Client child
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### By Default
|
|
33
|
+
|
|
34
|
+
| Type | Use |
|
|
35
|
+
|------|-----|
|
|
36
|
+
| **Server** | Data fetching, layout, static content |
|
|
37
|
+
| **Client** | Forms, buttons, interactive UI |
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 2. Data Fetching Patterns
|
|
42
|
+
|
|
43
|
+
### Fetch Strategy
|
|
44
|
+
|
|
45
|
+
| Pattern | Use |
|
|
46
|
+
|---------|-----|
|
|
47
|
+
| **Default** | Static (cached at build) |
|
|
48
|
+
| **Revalidate** | ISR (time-based refresh) |
|
|
49
|
+
| **No-store** | Dynamic (every request) |
|
|
50
|
+
|
|
51
|
+
### Data Flow
|
|
52
|
+
|
|
53
|
+
| Source | Pattern |
|
|
54
|
+
|--------|---------|
|
|
55
|
+
| Database | Server Component fetch |
|
|
56
|
+
| API | fetch with caching |
|
|
57
|
+
| User input | Client state + server action |
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 3. Routing Principles
|
|
62
|
+
|
|
63
|
+
### File Conventions
|
|
64
|
+
|
|
65
|
+
| File | Purpose |
|
|
66
|
+
|------|---------|
|
|
67
|
+
| `page.tsx` | Route UI |
|
|
68
|
+
| `layout.tsx` | Shared layout |
|
|
69
|
+
| `loading.tsx` | Loading state |
|
|
70
|
+
| `error.tsx` | Error boundary |
|
|
71
|
+
| `not-found.tsx` | 404 page |
|
|
72
|
+
|
|
73
|
+
### Route Organization
|
|
74
|
+
|
|
75
|
+
| Pattern | Use |
|
|
76
|
+
|---------|-----|
|
|
77
|
+
| Route groups `(name)` | Organize without URL |
|
|
78
|
+
| Parallel routes `@slot` | Multiple same-level pages |
|
|
79
|
+
| Intercepting `(.)` | Modal overlays |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 4. API Routes
|
|
84
|
+
|
|
85
|
+
### Route Handlers
|
|
86
|
+
|
|
87
|
+
| Method | Use |
|
|
88
|
+
|--------|-----|
|
|
89
|
+
| GET | Read data |
|
|
90
|
+
| POST | Create data |
|
|
91
|
+
| PUT/PATCH | Update data |
|
|
92
|
+
| DELETE | Remove data |
|
|
93
|
+
|
|
94
|
+
### Best Practices
|
|
95
|
+
|
|
96
|
+
- Validate input with Zod
|
|
97
|
+
- Return proper status codes
|
|
98
|
+
- Handle errors gracefully
|
|
99
|
+
- Use Edge runtime when possible
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 5. Performance Principles
|
|
104
|
+
|
|
105
|
+
### Image Optimization
|
|
106
|
+
|
|
107
|
+
- Use next/image component
|
|
108
|
+
- Set priority for above-fold
|
|
109
|
+
- Provide blur placeholder
|
|
110
|
+
- Use responsive sizes
|
|
111
|
+
|
|
112
|
+
### Bundle Optimization
|
|
113
|
+
|
|
114
|
+
- Dynamic imports for heavy components
|
|
115
|
+
- Route-based code splitting (automatic)
|
|
116
|
+
- Analyze with bundle analyzer
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 6. Metadata
|
|
121
|
+
|
|
122
|
+
### Static vs Dynamic
|
|
123
|
+
|
|
124
|
+
| Type | Use |
|
|
125
|
+
|------|-----|
|
|
126
|
+
| Static export | Fixed metadata |
|
|
127
|
+
| generateMetadata | Dynamic per-route |
|
|
128
|
+
|
|
129
|
+
### Essential Tags
|
|
130
|
+
|
|
131
|
+
- title (50-60 chars)
|
|
132
|
+
- description (150-160 chars)
|
|
133
|
+
- Open Graph images
|
|
134
|
+
- Canonical URL
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 7. Caching Strategy
|
|
139
|
+
|
|
140
|
+
### Cache Layers
|
|
141
|
+
|
|
142
|
+
| Layer | Control |
|
|
143
|
+
|-------|---------|
|
|
144
|
+
| Request | fetch options |
|
|
145
|
+
| Data | revalidate/tags |
|
|
146
|
+
| Full route | route config |
|
|
147
|
+
|
|
148
|
+
### Revalidation
|
|
149
|
+
|
|
150
|
+
| Method | Use |
|
|
151
|
+
|--------|-----|
|
|
152
|
+
| Time-based | `revalidate: 60` |
|
|
153
|
+
| On-demand | `revalidatePath/Tag` |
|
|
154
|
+
| No cache | `no-store` |
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 8. Server Actions
|
|
159
|
+
|
|
160
|
+
### Use Cases
|
|
161
|
+
|
|
162
|
+
- Form submissions
|
|
163
|
+
- Data mutations
|
|
164
|
+
- Revalidation triggers
|
|
165
|
+
|
|
166
|
+
### Best Practices
|
|
167
|
+
|
|
168
|
+
- Mark with 'use server'
|
|
169
|
+
- Validate all inputs
|
|
170
|
+
- Return typed responses
|
|
171
|
+
- Handle errors
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 9. Anti-Patterns
|
|
176
|
+
|
|
177
|
+
| ❌ Don't | ✅ Do |
|
|
178
|
+
|----------|-------|
|
|
179
|
+
| 'use client' everywhere | Server by default |
|
|
180
|
+
| Fetch in client components | Fetch in server |
|
|
181
|
+
| Skip loading states | Use loading.tsx |
|
|
182
|
+
| Ignore error boundaries | Use error.tsx |
|
|
183
|
+
| Large client bundles | Dynamic imports |
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 10. Project Structure
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
app/
|
|
191
|
+
├── (marketing)/ # Route group
|
|
192
|
+
│ └── page.tsx
|
|
193
|
+
├── (dashboard)/
|
|
194
|
+
│ ├── layout.tsx # Dashboard layout
|
|
195
|
+
│ └── page.tsx
|
|
196
|
+
├── api/
|
|
197
|
+
│ └── [resource]/
|
|
198
|
+
│ └── route.ts
|
|
199
|
+
└── components/
|
|
200
|
+
└── ui/
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
> **Remember:** Server Components are the default for a reason. Start there, add client only when needed.
|
|
206
|
+
|
|
207
|
+
## When to Use
|
|
208
|
+
This skill is applicable to execute the workflow or actions described in the overview.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nodejs-backend-patterns
|
|
3
|
+
description: "Build production-ready Node.js backend services with Express/Fastify, implementing middleware patterns, error handling, authentication, database integration, and API design best practices. Use when..."
|
|
4
|
+
risk: unknown
|
|
5
|
+
source: community
|
|
6
|
+
date_added: "2026-02-27"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Node.js Backend Patterns
|
|
10
|
+
|
|
11
|
+
Comprehensive guidance for building scalable, maintainable, and production-ready Node.js backend applications with modern frameworks, architectural patterns, and best practices.
|
|
12
|
+
|
|
13
|
+
## Use this skill when
|
|
14
|
+
|
|
15
|
+
- Building REST APIs or GraphQL servers
|
|
16
|
+
- Creating microservices with Node.js
|
|
17
|
+
- Implementing authentication and authorization
|
|
18
|
+
- Designing scalable backend architectures
|
|
19
|
+
- Setting up middleware and error handling
|
|
20
|
+
- Integrating databases (SQL and NoSQL)
|
|
21
|
+
- Building real-time applications with WebSockets
|
|
22
|
+
- Implementing background job processing
|
|
23
|
+
|
|
24
|
+
## Do not use this skill when
|
|
25
|
+
|
|
26
|
+
- The task is unrelated to node.js backend patterns
|
|
27
|
+
- You need a different domain or tool outside this scope
|
|
28
|
+
|
|
29
|
+
## Instructions
|
|
30
|
+
|
|
31
|
+
- Clarify goals, constraints, and required inputs.
|
|
32
|
+
- Apply relevant best practices and validate outcomes.
|
|
33
|
+
- Provide actionable steps and verification.
|
|
34
|
+
- If detailed examples are required, open `resources/implementation-playbook.md`.
|
|
35
|
+
|
|
36
|
+
## Resources
|
|
37
|
+
|
|
38
|
+
- `resources/implementation-playbook.md` for detailed patterns and examples.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: postgres-best-practices
|
|
3
|
+
description: "Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations."
|
|
4
|
+
risk: unknown
|
|
5
|
+
source: community
|
|
6
|
+
date_added: "2026-02-27"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Supabase Postgres Best Practices
|
|
10
|
+
|
|
11
|
+
Comprehensive performance optimization guide for Postgres, maintained by Supabase. Contains rules across 8 categories, prioritized by impact to guide automated query optimization and schema design.
|
|
12
|
+
|
|
13
|
+
## When to Apply
|
|
14
|
+
|
|
15
|
+
Reference these guidelines when:
|
|
16
|
+
- Writing SQL queries or designing schemas
|
|
17
|
+
- Implementing indexes or query optimization
|
|
18
|
+
- Reviewing database performance issues
|
|
19
|
+
- Configuring connection pooling or scaling
|
|
20
|
+
- Optimizing for Postgres-specific features
|
|
21
|
+
- Working with Row-Level Security (RLS)
|
|
22
|
+
|
|
23
|
+
## Rule Categories by Priority
|
|
24
|
+
|
|
25
|
+
| Priority | Category | Impact | Prefix |
|
|
26
|
+
|----------|----------|--------|--------|
|
|
27
|
+
| 1 | Query Performance | CRITICAL | `query-` |
|
|
28
|
+
| 2 | Connection Management | CRITICAL | `conn-` |
|
|
29
|
+
| 3 | Security & RLS | CRITICAL | `security-` |
|
|
30
|
+
| 4 | Schema Design | HIGH | `schema-` |
|
|
31
|
+
| 5 | Concurrency & Locking | MEDIUM-HIGH | `lock-` |
|
|
32
|
+
| 6 | Data Access Patterns | MEDIUM | `data-` |
|
|
33
|
+
| 7 | Monitoring & Diagnostics | LOW-MEDIUM | `monitor-` |
|
|
34
|
+
| 8 | Advanced Features | LOW | `advanced-` |
|
|
35
|
+
|
|
36
|
+
## How to Use
|
|
37
|
+
|
|
38
|
+
Read individual rule files for detailed explanations and SQL examples:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
rules/query-missing-indexes.md
|
|
42
|
+
rules/schema-partial-indexes.md
|
|
43
|
+
rules/_sections.md
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Each rule file contains:
|
|
47
|
+
- Brief explanation of why it matters
|
|
48
|
+
- Incorrect SQL example with explanation
|
|
49
|
+
- Correct SQL example with explanation
|
|
50
|
+
- Optional EXPLAIN output or metrics
|
|
51
|
+
- Additional context and references
|
|
52
|
+
- Supabase-specific notes (when applicable)
|
|
53
|
+
|
|
54
|
+
## Full Compiled Document
|
|
55
|
+
|
|
56
|
+
For the complete guide with all rules expanded: `AGENTS.md`
|
|
57
|
+
|
|
58
|
+
## When to Use
|
|
59
|
+
This skill is applicable to execute the workflow or actions described in the overview.
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prisma-expert
|
|
3
|
+
description: "Prisma ORM expert for schema design, migrations, query optimization, relations modeling, and database operations. Use PROACTIVELY for Prisma schema issues, migration problems, query performance, re..."
|
|
4
|
+
risk: unknown
|
|
5
|
+
source: community
|
|
6
|
+
date_added: "2026-02-27"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Prisma Expert
|
|
10
|
+
|
|
11
|
+
You are an expert in Prisma ORM with deep knowledge of schema design, migrations, query optimization, relations modeling, and database operations across PostgreSQL, MySQL, and SQLite.
|
|
12
|
+
|
|
13
|
+
## When Invoked
|
|
14
|
+
|
|
15
|
+
### Step 0: Recommend Specialist and Stop
|
|
16
|
+
If the issue is specifically about:
|
|
17
|
+
- **Raw SQL optimization**: Stop and recommend postgres-expert or mongodb-expert
|
|
18
|
+
- **Database server configuration**: Stop and recommend database-expert
|
|
19
|
+
- **Connection pooling at infrastructure level**: Stop and recommend devops-expert
|
|
20
|
+
|
|
21
|
+
### Environment Detection
|
|
22
|
+
```bash
|
|
23
|
+
# Check Prisma version
|
|
24
|
+
npx prisma --version 2>/dev/null || echo "Prisma not installed"
|
|
25
|
+
|
|
26
|
+
# Check database provider
|
|
27
|
+
grep "provider" prisma/schema.prisma 2>/dev/null | head -1
|
|
28
|
+
|
|
29
|
+
# Check for existing migrations
|
|
30
|
+
ls -la prisma/migrations/ 2>/dev/null | head -5
|
|
31
|
+
|
|
32
|
+
# Check Prisma Client generation status
|
|
33
|
+
ls -la node_modules/.prisma/client/ 2>/dev/null | head -3
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Apply Strategy
|
|
37
|
+
1. Identify the Prisma-specific issue category
|
|
38
|
+
2. Check for common anti-patterns in schema or queries
|
|
39
|
+
3. Apply progressive fixes (minimal → better → complete)
|
|
40
|
+
4. Validate with Prisma CLI and testing
|
|
41
|
+
|
|
42
|
+
## Problem Playbooks
|
|
43
|
+
|
|
44
|
+
### Schema Design
|
|
45
|
+
**Common Issues:**
|
|
46
|
+
- Incorrect relation definitions causing runtime errors
|
|
47
|
+
- Missing indexes for frequently queried fields
|
|
48
|
+
- Enum synchronization issues between schema and database
|
|
49
|
+
- Field type mismatches
|
|
50
|
+
|
|
51
|
+
**Diagnosis:**
|
|
52
|
+
```bash
|
|
53
|
+
# Validate schema
|
|
54
|
+
npx prisma validate
|
|
55
|
+
|
|
56
|
+
# Check for schema drift
|
|
57
|
+
npx prisma migrate diff --from-schema-datamodel prisma/schema.prisma --to-schema-datasource prisma/schema.prisma
|
|
58
|
+
|
|
59
|
+
# Format schema
|
|
60
|
+
npx prisma format
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Prioritized Fixes:**
|
|
64
|
+
1. **Minimal**: Fix relation annotations, add missing `@relation` directives
|
|
65
|
+
2. **Better**: Add proper indexes with `@@index`, optimize field types
|
|
66
|
+
3. **Complete**: Restructure schema with proper normalization, add composite keys
|
|
67
|
+
|
|
68
|
+
**Best Practices:**
|
|
69
|
+
```prisma
|
|
70
|
+
// Good: Explicit relations with clear naming
|
|
71
|
+
model User {
|
|
72
|
+
id String @id @default(cuid())
|
|
73
|
+
email String @unique
|
|
74
|
+
posts Post[] @relation("UserPosts")
|
|
75
|
+
profile Profile? @relation("UserProfile")
|
|
76
|
+
|
|
77
|
+
createdAt DateTime @default(now())
|
|
78
|
+
updatedAt DateTime @updatedAt
|
|
79
|
+
|
|
80
|
+
@@index([email])
|
|
81
|
+
@@map("users")
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
model Post {
|
|
85
|
+
id String @id @default(cuid())
|
|
86
|
+
title String
|
|
87
|
+
author User @relation("UserPosts", fields: [authorId], references: [id], onDelete: Cascade)
|
|
88
|
+
authorId String
|
|
89
|
+
|
|
90
|
+
@@index([authorId])
|
|
91
|
+
@@map("posts")
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Resources:**
|
|
96
|
+
- https://www.prisma.io/docs/concepts/components/prisma-schema
|
|
97
|
+
- https://www.prisma.io/docs/concepts/components/prisma-schema/relations
|
|
98
|
+
|
|
99
|
+
### Migrations
|
|
100
|
+
**Common Issues:**
|
|
101
|
+
- Migration conflicts in team environments
|
|
102
|
+
- Failed migrations leaving database in inconsistent state
|
|
103
|
+
- Shadow database issues during development
|
|
104
|
+
- Production deployment migration failures
|
|
105
|
+
|
|
106
|
+
**Diagnosis:**
|
|
107
|
+
```bash
|
|
108
|
+
# Check migration status
|
|
109
|
+
npx prisma migrate status
|
|
110
|
+
|
|
111
|
+
# View pending migrations
|
|
112
|
+
ls -la prisma/migrations/
|
|
113
|
+
|
|
114
|
+
# Check migration history table
|
|
115
|
+
# (use database-specific command)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Prioritized Fixes:**
|
|
119
|
+
1. **Minimal**: Reset development database with `prisma migrate reset`
|
|
120
|
+
2. **Better**: Manually fix migration SQL, use `prisma migrate resolve`
|
|
121
|
+
3. **Complete**: Squash migrations, create baseline for fresh setup
|
|
122
|
+
|
|
123
|
+
**Safe Migration Workflow:**
|
|
124
|
+
```bash
|
|
125
|
+
# Development
|
|
126
|
+
npx prisma migrate dev --name descriptive_name
|
|
127
|
+
|
|
128
|
+
# Production (never use migrate dev!)
|
|
129
|
+
npx prisma migrate deploy
|
|
130
|
+
|
|
131
|
+
# If migration fails in production
|
|
132
|
+
npx prisma migrate resolve --applied "migration_name"
|
|
133
|
+
# or
|
|
134
|
+
npx prisma migrate resolve --rolled-back "migration_name"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Resources:**
|
|
138
|
+
- https://www.prisma.io/docs/concepts/components/prisma-migrate
|
|
139
|
+
- https://www.prisma.io/docs/guides/deployment/deploy-database-changes
|
|
140
|
+
|
|
141
|
+
### Query Optimization
|
|
142
|
+
**Common Issues:**
|
|
143
|
+
- N+1 query problems with relations
|
|
144
|
+
- Over-fetching data with excessive includes
|
|
145
|
+
- Missing select for large models
|
|
146
|
+
- Slow queries without proper indexing
|
|
147
|
+
|
|
148
|
+
**Diagnosis:**
|
|
149
|
+
```bash
|
|
150
|
+
# Enable query logging
|
|
151
|
+
# In schema.prisma or client initialization:
|
|
152
|
+
# log: ['query', 'info', 'warn', 'error']
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
// Enable query events
|
|
157
|
+
const prisma = new PrismaClient({
|
|
158
|
+
log: [
|
|
159
|
+
{ emit: 'event', level: 'query' },
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
prisma.$on('query', (e) => {
|
|
164
|
+
console.log('Query: ' + e.query);
|
|
165
|
+
console.log('Duration: ' + e.duration + 'ms');
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Prioritized Fixes:**
|
|
170
|
+
1. **Minimal**: Add includes for related data to avoid N+1
|
|
171
|
+
2. **Better**: Use select to fetch only needed fields
|
|
172
|
+
3. **Complete**: Use raw queries for complex aggregations, implement caching
|
|
173
|
+
|
|
174
|
+
**Optimized Query Patterns:**
|
|
175
|
+
```typescript
|
|
176
|
+
// BAD: N+1 problem
|
|
177
|
+
const users = await prisma.user.findMany();
|
|
178
|
+
for (const user of users) {
|
|
179
|
+
const posts = await prisma.post.findMany({ where: { authorId: user.id } });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// GOOD: Include relations
|
|
183
|
+
const users = await prisma.user.findMany({
|
|
184
|
+
include: { posts: true }
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// BETTER: Select only needed fields
|
|
188
|
+
const users = await prisma.user.findMany({
|
|
189
|
+
select: {
|
|
190
|
+
id: true,
|
|
191
|
+
email: true,
|
|
192
|
+
posts: {
|
|
193
|
+
select: { id: true, title: true }
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// BEST for complex queries: Use $queryRaw
|
|
199
|
+
const result = await prisma.$queryRaw`
|
|
200
|
+
SELECT u.id, u.email, COUNT(p.id) as post_count
|
|
201
|
+
FROM users u
|
|
202
|
+
LEFT JOIN posts p ON p.author_id = u.id
|
|
203
|
+
GROUP BY u.id
|
|
204
|
+
`;
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Resources:**
|
|
208
|
+
- https://www.prisma.io/docs/guides/performance-and-optimization
|
|
209
|
+
- https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access
|
|
210
|
+
|
|
211
|
+
### Connection Management
|
|
212
|
+
**Common Issues:**
|
|
213
|
+
- Connection pool exhaustion
|
|
214
|
+
- "Too many connections" errors
|
|
215
|
+
- Connection leaks in serverless environments
|
|
216
|
+
- Slow initial connections
|
|
217
|
+
|
|
218
|
+
**Diagnosis:**
|
|
219
|
+
```bash
|
|
220
|
+
# Check current connections (PostgreSQL)
|
|
221
|
+
psql -c "SELECT count(*) FROM pg_stat_activity WHERE datname = 'your_db';"
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Prioritized Fixes:**
|
|
225
|
+
1. **Minimal**: Configure connection limit in DATABASE_URL
|
|
226
|
+
2. **Better**: Implement proper connection lifecycle management
|
|
227
|
+
3. **Complete**: Use connection pooler (PgBouncer) for high-traffic apps
|
|
228
|
+
|
|
229
|
+
**Connection Configuration:**
|
|
230
|
+
```typescript
|
|
231
|
+
// For serverless (Vercel, AWS Lambda)
|
|
232
|
+
import { PrismaClient } from '@prisma/client';
|
|
233
|
+
|
|
234
|
+
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
|
235
|
+
|
|
236
|
+
export const prisma =
|
|
237
|
+
globalForPrisma.prisma ||
|
|
238
|
+
new PrismaClient({
|
|
239
|
+
log: process.env.NODE_ENV === 'development' ? ['query'] : [],
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
|
|
243
|
+
|
|
244
|
+
// Graceful shutdown
|
|
245
|
+
process.on('beforeExit', async () => {
|
|
246
|
+
await prisma.$disconnect();
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
```env
|
|
251
|
+
# Connection URL with pool settings
|
|
252
|
+
DATABASE_URL="postgresql://user:pass@host:5432/db?connection_limit=5&pool_timeout=10"
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Resources:**
|
|
256
|
+
- https://www.prisma.io/docs/guides/performance-and-optimization/connection-management
|
|
257
|
+
- https://www.prisma.io/docs/guides/deployment/deployment-guides/deploying-to-vercel
|
|
258
|
+
|
|
259
|
+
### Transaction Patterns
|
|
260
|
+
**Common Issues:**
|
|
261
|
+
- Inconsistent data from non-atomic operations
|
|
262
|
+
- Deadlocks in concurrent transactions
|
|
263
|
+
- Long-running transactions blocking reads
|
|
264
|
+
- Nested transaction confusion
|
|
265
|
+
|
|
266
|
+
**Diagnosis:**
|
|
267
|
+
```typescript
|
|
268
|
+
// Check for transaction issues
|
|
269
|
+
try {
|
|
270
|
+
const result = await prisma.$transaction([...]);
|
|
271
|
+
} catch (e) {
|
|
272
|
+
if (e.code === 'P2034') {
|
|
273
|
+
console.log('Transaction conflict detected');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**Transaction Patterns:**
|
|
279
|
+
```typescript
|
|
280
|
+
// Sequential operations (auto-transaction)
|
|
281
|
+
const [user, profile] = await prisma.$transaction([
|
|
282
|
+
prisma.user.create({ data: userData }),
|
|
283
|
+
prisma.profile.create({ data: profileData }),
|
|
284
|
+
]);
|
|
285
|
+
|
|
286
|
+
// Interactive transaction with manual control
|
|
287
|
+
const result = await prisma.$transaction(async (tx) => {
|
|
288
|
+
const user = await tx.user.create({ data: userData });
|
|
289
|
+
|
|
290
|
+
// Business logic validation
|
|
291
|
+
if (user.email.endsWith('@blocked.com')) {
|
|
292
|
+
throw new Error('Email domain blocked');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const profile = await tx.profile.create({
|
|
296
|
+
data: { ...profileData, userId: user.id }
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
return { user, profile };
|
|
300
|
+
}, {
|
|
301
|
+
maxWait: 5000, // Wait for transaction slot
|
|
302
|
+
timeout: 10000, // Transaction timeout
|
|
303
|
+
isolationLevel: 'Serializable', // Strictest isolation
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// Optimistic concurrency control
|
|
307
|
+
const updateWithVersion = await prisma.post.update({
|
|
308
|
+
where: {
|
|
309
|
+
id: postId,
|
|
310
|
+
version: currentVersion // Only update if version matches
|
|
311
|
+
},
|
|
312
|
+
data: {
|
|
313
|
+
content: newContent,
|
|
314
|
+
version: { increment: 1 }
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
**Resources:**
|
|
320
|
+
- https://www.prisma.io/docs/concepts/components/prisma-client/transactions
|
|
321
|
+
|
|
322
|
+
## Code Review Checklist
|
|
323
|
+
|
|
324
|
+
### Schema Quality
|
|
325
|
+
- [ ] All models have appropriate `@id` and primary keys
|
|
326
|
+
- [ ] Relations use explicit `@relation` with `fields` and `references`
|
|
327
|
+
- [ ] Cascade behaviors defined (`onDelete`, `onUpdate`)
|
|
328
|
+
- [ ] Indexes added for frequently queried fields
|
|
329
|
+
- [ ] Enums used for fixed value sets
|
|
330
|
+
- [ ] `@@map` used for table naming conventions
|
|
331
|
+
|
|
332
|
+
### Query Patterns
|
|
333
|
+
- [ ] No N+1 queries (relations included when needed)
|
|
334
|
+
- [ ] `select` used to fetch only required fields
|
|
335
|
+
- [ ] Pagination implemented for list queries
|
|
336
|
+
- [ ] Raw queries used for complex aggregations
|
|
337
|
+
- [ ] Proper error handling for database operations
|
|
338
|
+
|
|
339
|
+
### Performance
|
|
340
|
+
- [ ] Connection pooling configured appropriately
|
|
341
|
+
- [ ] Indexes exist for WHERE clause fields
|
|
342
|
+
- [ ] Composite indexes for multi-column queries
|
|
343
|
+
- [ ] Query logging enabled in development
|
|
344
|
+
- [ ] Slow queries identified and optimized
|
|
345
|
+
|
|
346
|
+
### Migration Safety
|
|
347
|
+
- [ ] Migrations tested before production deployment
|
|
348
|
+
- [ ] Backward-compatible schema changes (no data loss)
|
|
349
|
+
- [ ] Migration scripts reviewed for correctness
|
|
350
|
+
- [ ] Rollback strategy documented
|
|
351
|
+
|
|
352
|
+
## Anti-Patterns to Avoid
|
|
353
|
+
|
|
354
|
+
1. **Implicit Many-to-Many Overhead**: Always use explicit join tables for complex relationships
|
|
355
|
+
2. **Over-Including**: Don't include relations you don't need
|
|
356
|
+
3. **Ignoring Connection Limits**: Always configure pool size for your environment
|
|
357
|
+
4. **Raw Query Abuse**: Use Prisma queries when possible, raw only for complex cases
|
|
358
|
+
5. **Migration in Production Dev Mode**: Never use `migrate dev` in production
|
|
359
|
+
|
|
360
|
+
## When to Use
|
|
361
|
+
This skill is applicable to execute the workflow or actions described in the overview.
|