@esreekarreddy/ai-prompts 1.0.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/LICENSE +21 -0
- package/README.md +361 -0
- package/chains/_index.md +33 -0
- package/chains/bug-fix.md +222 -0
- package/chains/new-feature.md +216 -0
- package/chains/production-launch.md +291 -0
- package/chains/refactor.md +210 -0
- package/chains/security-hardening.md +242 -0
- package/contexts/guides/api-design.md +229 -0
- package/contexts/guides/error-handling.md +219 -0
- package/contexts/patterns/agentic-coding.md +368 -0
- package/contexts/patterns/mcp-server-patterns.md +267 -0
- package/contexts/patterns/repository-pattern.md +163 -0
- package/contexts/patterns/service-layer.md +185 -0
- package/contexts/stacks/fastapi.md +187 -0
- package/contexts/stacks/nextjs-14.md +149 -0
- package/contexts/stacks/prisma.md +228 -0
- package/dist/index.d.ts +129 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +284 -0
- package/dist/index.js.map +1 -0
- package/examples/architecture-docs/sample-architecture.md +270 -0
- package/examples/code-reviews/sample-review.md +232 -0
- package/examples/prds/sample-prd.md +179 -0
- package/instructions/_index.md +57 -0
- package/instructions/personas/code-reviewer.md +83 -0
- package/instructions/personas/devops-engineer.md +90 -0
- package/instructions/personas/security-expert.md +69 -0
- package/instructions/personas/senior-engineer.md +243 -0
- package/instructions/personas/ux-engineer.md +88 -0
- package/instructions/standards/fastapi.md +241 -0
- package/instructions/standards/go.md +427 -0
- package/instructions/standards/nextjs.md +350 -0
- package/instructions/standards/nodejs.md +284 -0
- package/instructions/standards/python.md +245 -0
- package/instructions/standards/react.md +227 -0
- package/instructions/standards/rust.md +318 -0
- package/instructions/standards/typescript-react.md +822 -0
- package/instructions/standards/typescript.md +294 -0
- package/instructions/workflows/feature-development.md +222 -0
- package/instructions/workflows/incident-response.md +192 -0
- package/instructions/workflows/pr-review.md +149 -0
- package/instructions/workflows/tdd.md +160 -0
- package/package.json +84 -0
- package/prompts/_index.md +70 -0
- package/prompts/agentic/agentic-loop.md +83 -0
- package/prompts/agentic/context-manager.md +37 -0
- package/prompts/agentic/test-driven-fix.md +41 -0
- package/prompts/analysis/deep-debugger.md +488 -0
- package/prompts/design/design-system-extractor.md +147 -0
- package/prompts/development/code-cleaner.md +119 -0
- package/prompts/development/debugger.md +64 -0
- package/prompts/development/tech-debt-audit.md +88 -0
- package/prompts/planning/architecture-analyzer.md +72 -0
- package/prompts/planning/implementation-plan.md +98 -0
- package/prompts/planning/prd-generator.md +66 -0
- package/prompts/planning/scope-killer.md +74 -0
- package/prompts/quality/critical-path-tester.md +133 -0
- package/prompts/quality/pre-launch-checklist.md +137 -0
- package/prompts/quality/security-audit.md +115 -0
- package/prompts/quality/security-fixer.md +117 -0
- package/prompts/quality/security-hardening.md +157 -0
- package/prompts/system/master-system-prompt.md +252 -0
- package/skills/_index.md +60 -0
- package/skills/code-review-advanced.md +435 -0
- package/skills/code-review.md +86 -0
- package/skills/debugging.md +86 -0
- package/skills/documentation.md +97 -0
- package/skills/pr-description.md +116 -0
- package/skills/project-setup.md +123 -0
- package/skills/refactoring.md +93 -0
- package/skills/testing.md +134 -0
- package/snippets/_index.md +57 -0
- package/snippets/constraints/mvp-only.md +50 -0
- package/snippets/constraints/no-external-deps.md +45 -0
- package/snippets/constraints/read-only.md +45 -0
- package/snippets/constraints/security-first.md +50 -0
- package/snippets/modifiers/be-ruthless.md +52 -0
- package/snippets/modifiers/be-thorough.md +50 -0
- package/snippets/modifiers/effort-high.md +56 -0
- package/snippets/modifiers/explain-reasoning.md +50 -0
- package/snippets/modifiers/megathink.md +314 -0
- package/snippets/modifiers/meta-cot.md +101 -0
- package/snippets/modifiers/no-code-yet.md +55 -0
- package/snippets/modifiers/step-by-step.md +50 -0
- package/snippets/modifiers/ultrathink.md +359 -0
- package/snippets/output-formats/checklist.md +61 -0
- package/snippets/output-formats/json.md +53 -0
- package/snippets/output-formats/markdown-table.md +44 -0
- package/snippets/output-formats/numbered-list.md +44 -0
- package/templates/_index.md +101 -0
- package/templates/claude-md/auto-enhance.md +258 -0
- package/templates/claude-md/cli-tool.md +243 -0
- package/templates/claude-md/full.md +449 -0
- package/templates/claude-md/minimal.md +52 -0
- package/templates/claude-md/nextjs-app.md +207 -0
- package/templates/claude-md/nodejs-service.md +251 -0
- package/templates/claude-md/python-api.md +236 -0
- package/templates/copilot/instructions.md +33 -0
- package/templates/cursor-rules/fullstack.txt +98 -0
- package/templates/cursor-rules/minimal.txt +20 -0
- package/templates/cursor-rules/nextjs.txt +61 -0
- package/templates/cursor-rules/python.txt +79 -0
- package/templates/docs/adr-template.md +119 -0
- package/templates/docs/api-spec-template.md +277 -0
- package/templates/docs/prd-template.md +140 -0
- package/templates/docs/runbook-template.md +238 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Full CLAUDE.md Template
|
|
3
|
+
description: Production-ready CLAUDE.md that gives Claude all context needed for any codebase
|
|
4
|
+
tags: [template, claude-md, project-context, configuration]
|
|
5
|
+
aliases: [claude-md-full, project-setup, ai-context]
|
|
6
|
+
version: 2.0.0
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Full CLAUDE.md Template
|
|
10
|
+
|
|
11
|
+
> Copy this entire file to your project root as `CLAUDE.md` and fill in the sections. This gives Claude (and other AI tools) maximum context for working with your codebase.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
```markdown
|
|
16
|
+
# Project: [project_name]
|
|
17
|
+
|
|
18
|
+
> [one_line_description]
|
|
19
|
+
|
|
20
|
+
## Quick Reference
|
|
21
|
+
|
|
22
|
+
| Command | Purpose |
|
|
23
|
+
|---------|---------|
|
|
24
|
+
| `npm run dev` | Start development server |
|
|
25
|
+
| `npm run build` | Production build |
|
|
26
|
+
| `npm run test` | Run tests |
|
|
27
|
+
| `npm run lint` | Lint and format |
|
|
28
|
+
| `npm run typecheck` | TypeScript checks |
|
|
29
|
+
|
|
30
|
+
## Architecture Overview
|
|
31
|
+
|
|
32
|
+
### Tech Stack
|
|
33
|
+
- **Runtime:** Node.js 20 / Bun 1.x
|
|
34
|
+
- **Framework:** Next.js 14 (App Router)
|
|
35
|
+
- **Language:** TypeScript 5.x (strict mode)
|
|
36
|
+
- **Database:** PostgreSQL 15 + Prisma ORM
|
|
37
|
+
- **Cache:** Redis 7.x
|
|
38
|
+
- **Auth:** NextAuth.js v5
|
|
39
|
+
- **Styling:** Tailwind CSS + shadcn/ui
|
|
40
|
+
- **Testing:** Vitest + Playwright
|
|
41
|
+
|
|
42
|
+
### Directory Structure
|
|
43
|
+
```
|
|
44
|
+
├── app/ # Next.js App Router pages
|
|
45
|
+
│ ├── (auth)/ # Auth-required routes (grouped)
|
|
46
|
+
│ ├── (public)/ # Public routes
|
|
47
|
+
│ ├── api/ # API routes
|
|
48
|
+
│ └── layout.tsx # Root layout
|
|
49
|
+
├── components/ # React components
|
|
50
|
+
│ ├── ui/ # Base UI components (shadcn)
|
|
51
|
+
│ ├── features/ # Feature-specific components
|
|
52
|
+
│ └── layouts/ # Layout components
|
|
53
|
+
├── lib/ # Core utilities
|
|
54
|
+
│ ├── db/ # Database client and queries
|
|
55
|
+
│ ├── auth/ # Authentication utilities
|
|
56
|
+
│ ├── api/ # API client and helpers
|
|
57
|
+
│ └── utils/ # General utilities
|
|
58
|
+
├── services/ # Business logic layer
|
|
59
|
+
├── hooks/ # Custom React hooks
|
|
60
|
+
├── types/ # TypeScript type definitions
|
|
61
|
+
├── prisma/ # Database schema and migrations
|
|
62
|
+
└── tests/ # Test files
|
|
63
|
+
├── unit/ # Unit tests
|
|
64
|
+
├── integration/ # Integration tests
|
|
65
|
+
└── e2e/ # End-to-end tests
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Code Conventions
|
|
69
|
+
|
|
70
|
+
### TypeScript
|
|
71
|
+
- Strict mode enabled (`"strict": true`)
|
|
72
|
+
- No `any` types - use `unknown` with type guards
|
|
73
|
+
- Prefer `type` over `interface` unless extending
|
|
74
|
+
- Export types from the file that uses them
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
// GOOD
|
|
78
|
+
type User = {
|
|
79
|
+
id: string;
|
|
80
|
+
email: string;
|
|
81
|
+
createdAt: Date;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
async function getUser(id: string): Promise<User | null> {
|
|
85
|
+
// ...
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// BAD
|
|
89
|
+
async function getUser(id: any): Promise<any> {
|
|
90
|
+
// ...
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### React Components
|
|
95
|
+
- Functional components only
|
|
96
|
+
- Props type defined inline for simple components
|
|
97
|
+
- Separate types file for complex components
|
|
98
|
+
- Use `forwardRef` when exposing DOM elements
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
// Simple component
|
|
102
|
+
function Button({ children, onClick }: {
|
|
103
|
+
children: React.ReactNode;
|
|
104
|
+
onClick?: () => void;
|
|
105
|
+
}) {
|
|
106
|
+
return <button onClick={onClick}>{children}</button>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Complex component with separate types
|
|
110
|
+
// components/DataTable/types.ts
|
|
111
|
+
// components/DataTable/DataTable.tsx
|
|
112
|
+
// components/DataTable/index.ts
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### File Naming
|
|
116
|
+
- Components: `PascalCase.tsx`
|
|
117
|
+
- Hooks: `use-kebab-case.ts`
|
|
118
|
+
- Utilities: `kebab-case.ts`
|
|
119
|
+
- Types: `types.ts` (co-located) or `*.types.ts`
|
|
120
|
+
- Tests: `*.test.ts` or `*.spec.ts`
|
|
121
|
+
|
|
122
|
+
### Import Order
|
|
123
|
+
```typescript
|
|
124
|
+
// 1. React/Next.js
|
|
125
|
+
import { useState, useEffect } from 'react';
|
|
126
|
+
import { useRouter } from 'next/navigation';
|
|
127
|
+
|
|
128
|
+
// 2. External packages
|
|
129
|
+
import { z } from 'zod';
|
|
130
|
+
import { clsx } from 'clsx';
|
|
131
|
+
|
|
132
|
+
// 3. Internal aliases (@/)
|
|
133
|
+
import { Button } from '@/components/ui/button';
|
|
134
|
+
import { useAuth } from '@/hooks/use-auth';
|
|
135
|
+
|
|
136
|
+
// 4. Relative imports
|
|
137
|
+
import { UserAvatar } from './UserAvatar';
|
|
138
|
+
import type { UserCardProps } from './types';
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Error Handling
|
|
142
|
+
|
|
143
|
+
### API Routes
|
|
144
|
+
```typescript
|
|
145
|
+
// app/api/users/[id]/route.ts
|
|
146
|
+
import { NextResponse } from 'next/server';
|
|
147
|
+
import { z } from 'zod';
|
|
148
|
+
import { getUser } from '@/services/users';
|
|
149
|
+
import { AppError, handleApiError } from '@/lib/errors';
|
|
150
|
+
|
|
151
|
+
const paramsSchema = z.object({
|
|
152
|
+
id: z.string().uuid(),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export async function GET(
|
|
156
|
+
request: Request,
|
|
157
|
+
{ params }: { params: { id: string } }
|
|
158
|
+
) {
|
|
159
|
+
try {
|
|
160
|
+
const { id } = paramsSchema.parse(params);
|
|
161
|
+
const user = await getUser(id);
|
|
162
|
+
|
|
163
|
+
if (!user) {
|
|
164
|
+
throw new AppError('User not found', 404);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return NextResponse.json(user);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
return handleApiError(error);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Client-Side
|
|
175
|
+
```typescript
|
|
176
|
+
// Use React Query for data fetching
|
|
177
|
+
const { data, error, isLoading } = useQuery({
|
|
178
|
+
queryKey: ['user', userId],
|
|
179
|
+
queryFn: () => fetchUser(userId),
|
|
180
|
+
retry: 3,
|
|
181
|
+
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (error) {
|
|
185
|
+
return <ErrorDisplay error={error} />;
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Database Patterns
|
|
190
|
+
|
|
191
|
+
### Prisma Queries
|
|
192
|
+
```typescript
|
|
193
|
+
// lib/db/users.ts
|
|
194
|
+
import { prisma } from '@/lib/db/client';
|
|
195
|
+
import type { User, Prisma } from '@prisma/client';
|
|
196
|
+
|
|
197
|
+
export async function getUsers(
|
|
198
|
+
options: {
|
|
199
|
+
search?: string;
|
|
200
|
+
page?: number;
|
|
201
|
+
limit?: number;
|
|
202
|
+
} = {}
|
|
203
|
+
) {
|
|
204
|
+
const { search, page = 1, limit = 20 } = options;
|
|
205
|
+
|
|
206
|
+
const where: Prisma.UserWhereInput = search
|
|
207
|
+
? {
|
|
208
|
+
OR: [
|
|
209
|
+
{ name: { contains: search, mode: 'insensitive' } },
|
|
210
|
+
{ email: { contains: search, mode: 'insensitive' } },
|
|
211
|
+
],
|
|
212
|
+
}
|
|
213
|
+
: {};
|
|
214
|
+
|
|
215
|
+
const [users, total] = await Promise.all([
|
|
216
|
+
prisma.user.findMany({
|
|
217
|
+
where,
|
|
218
|
+
take: limit,
|
|
219
|
+
skip: (page - 1) * limit,
|
|
220
|
+
orderBy: { createdAt: 'desc' },
|
|
221
|
+
include: { profile: true },
|
|
222
|
+
}),
|
|
223
|
+
prisma.user.count({ where }),
|
|
224
|
+
]);
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
users,
|
|
228
|
+
pagination: {
|
|
229
|
+
page,
|
|
230
|
+
limit,
|
|
231
|
+
total,
|
|
232
|
+
pages: Math.ceil(total / limit),
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Migrations
|
|
239
|
+
```bash
|
|
240
|
+
# Create migration
|
|
241
|
+
npx prisma migrate dev --name add_user_profile
|
|
242
|
+
|
|
243
|
+
# Apply migrations (production)
|
|
244
|
+
npx prisma migrate deploy
|
|
245
|
+
|
|
246
|
+
# Reset database (development only)
|
|
247
|
+
npx prisma migrate reset
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Authentication
|
|
251
|
+
|
|
252
|
+
### Protected Routes
|
|
253
|
+
```typescript
|
|
254
|
+
// middleware.ts
|
|
255
|
+
import { auth } from '@/lib/auth';
|
|
256
|
+
|
|
257
|
+
export default auth((req) => {
|
|
258
|
+
const isLoggedIn = !!req.auth;
|
|
259
|
+
const isProtected = req.nextUrl.pathname.startsWith('/dashboard');
|
|
260
|
+
|
|
261
|
+
if (isProtected && !isLoggedIn) {
|
|
262
|
+
return Response.redirect(new URL('/login', req.url));
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
export const config = {
|
|
267
|
+
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
|
|
268
|
+
};
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Server Components
|
|
272
|
+
```typescript
|
|
273
|
+
// app/(auth)/dashboard/page.tsx
|
|
274
|
+
import { auth } from '@/lib/auth';
|
|
275
|
+
import { redirect } from 'next/navigation';
|
|
276
|
+
|
|
277
|
+
export default async function DashboardPage() {
|
|
278
|
+
const session = await auth();
|
|
279
|
+
|
|
280
|
+
if (!session?.user) {
|
|
281
|
+
redirect('/login');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return <Dashboard user={session.user} />;
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Testing
|
|
289
|
+
|
|
290
|
+
### Unit Tests
|
|
291
|
+
```typescript
|
|
292
|
+
// services/__tests__/pricing.test.ts
|
|
293
|
+
import { describe, it, expect } from 'vitest';
|
|
294
|
+
import { calculatePrice } from '../pricing';
|
|
295
|
+
|
|
296
|
+
describe('calculatePrice', () => {
|
|
297
|
+
it('applies discount for bulk orders', () => {
|
|
298
|
+
const result = calculatePrice({ quantity: 100, unitPrice: 10 });
|
|
299
|
+
expect(result.discount).toBe(0.1); // 10% bulk discount
|
|
300
|
+
expect(result.total).toBe(900);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('throws for negative quantities', () => {
|
|
304
|
+
expect(() =>
|
|
305
|
+
calculatePrice({ quantity: -1, unitPrice: 10 })
|
|
306
|
+
).toThrow('Quantity must be positive');
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### E2E Tests
|
|
312
|
+
```typescript
|
|
313
|
+
// tests/e2e/checkout.spec.ts
|
|
314
|
+
import { test, expect } from '@playwright/test';
|
|
315
|
+
|
|
316
|
+
test('complete checkout flow', async ({ page }) => {
|
|
317
|
+
await page.goto('/products');
|
|
318
|
+
await page.click('[data-testid="add-to-cart"]');
|
|
319
|
+
await page.click('[data-testid="checkout-button"]');
|
|
320
|
+
|
|
321
|
+
await page.fill('[name="email"]', 'test@example.com');
|
|
322
|
+
await page.fill('[name="card"]', '4242424242424242');
|
|
323
|
+
await page.click('[data-testid="place-order"]');
|
|
324
|
+
|
|
325
|
+
await expect(page).toHaveURL(/\/confirmation/);
|
|
326
|
+
await expect(page.getByText('Order Confirmed')).toBeVisible();
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Environment Variables
|
|
331
|
+
|
|
332
|
+
### Required Variables
|
|
333
|
+
```bash
|
|
334
|
+
# .env.local (development)
|
|
335
|
+
DATABASE_URL="postgresql://..."
|
|
336
|
+
NEXTAUTH_SECRET="generate-with-openssl-rand-base64-32"
|
|
337
|
+
NEXTAUTH_URL="http://localhost:3000"
|
|
338
|
+
STRIPE_SECRET_KEY="sk_test_..."
|
|
339
|
+
STRIPE_WEBHOOK_SECRET="whsec_..."
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Validation
|
|
343
|
+
```typescript
|
|
344
|
+
// lib/env.ts
|
|
345
|
+
import { z } from 'zod';
|
|
346
|
+
|
|
347
|
+
const envSchema = z.object({
|
|
348
|
+
DATABASE_URL: z.string().url(),
|
|
349
|
+
NEXTAUTH_SECRET: z.string().min(32),
|
|
350
|
+
STRIPE_SECRET_KEY: z.string().startsWith('sk_'),
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
export const env = envSchema.parse(process.env);
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## Common Tasks
|
|
357
|
+
|
|
358
|
+
### Adding a New Feature
|
|
359
|
+
1. Create database migration if needed
|
|
360
|
+
2. Add types in `types/`
|
|
361
|
+
3. Implement service layer in `services/`
|
|
362
|
+
4. Create API route in `app/api/`
|
|
363
|
+
5. Build UI components in `components/features/`
|
|
364
|
+
6. Add page in `app/`
|
|
365
|
+
7. Write tests
|
|
366
|
+
8. Update this file if new patterns introduced
|
|
367
|
+
|
|
368
|
+
### Adding a New API Endpoint
|
|
369
|
+
```typescript
|
|
370
|
+
// Template: app/api/[resource]/route.ts
|
|
371
|
+
import { NextResponse } from 'next/server';
|
|
372
|
+
import { z } from 'zod';
|
|
373
|
+
import { auth } from '@/lib/auth';
|
|
374
|
+
|
|
375
|
+
const schema = z.object({
|
|
376
|
+
// Define your schema
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
export async function POST(request: Request) {
|
|
380
|
+
const session = await auth();
|
|
381
|
+
if (!session) {
|
|
382
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
try {
|
|
386
|
+
const body = await request.json();
|
|
387
|
+
const data = schema.parse(body);
|
|
388
|
+
|
|
389
|
+
// Your logic here
|
|
390
|
+
|
|
391
|
+
return NextResponse.json({ success: true, data: result });
|
|
392
|
+
} catch (error) {
|
|
393
|
+
if (error instanceof z.ZodError) {
|
|
394
|
+
return NextResponse.json({ error: error.errors }, { status: 400 });
|
|
395
|
+
}
|
|
396
|
+
console.error('API Error:', error);
|
|
397
|
+
return NextResponse.json({ error: 'Internal error' }, { status: 500 });
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## AI Instructions
|
|
403
|
+
|
|
404
|
+
When working with this codebase:
|
|
405
|
+
|
|
406
|
+
1. **Follow existing patterns** - Look at similar code before creating new patterns
|
|
407
|
+
2. **Type everything** - No `any`, use proper TypeScript types
|
|
408
|
+
3. **Error handling** - Every API route needs try/catch, every async operation needs error handling
|
|
409
|
+
4. **Security first** - Validate all inputs, check auth on protected routes
|
|
410
|
+
5. **Test critical paths** - Business logic and API endpoints need tests
|
|
411
|
+
6. **Performance awareness** - Use React Query caching, avoid N+1 queries
|
|
412
|
+
|
|
413
|
+
### Don't
|
|
414
|
+
- Add `@ts-ignore` or `any` types
|
|
415
|
+
- Skip error handling "for now"
|
|
416
|
+
- Create god components (>300 lines)
|
|
417
|
+
- Put business logic in React components
|
|
418
|
+
- Commit secrets or environment variables
|
|
419
|
+
|
|
420
|
+
### Do
|
|
421
|
+
- Ask clarifying questions before big changes
|
|
422
|
+
- Run tests before considering work complete
|
|
423
|
+
- Explain trade-offs when making architectural decisions
|
|
424
|
+
- Update this file when adding new patterns
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## Customization Notes
|
|
430
|
+
|
|
431
|
+
### For Smaller Projects
|
|
432
|
+
Remove sections you don't need:
|
|
433
|
+
- Database patterns if no database
|
|
434
|
+
- Auth section if using simple auth
|
|
435
|
+
- E2E tests if only unit testing
|
|
436
|
+
|
|
437
|
+
### For Larger Projects
|
|
438
|
+
Add sections for:
|
|
439
|
+
- Microservices communication
|
|
440
|
+
- Feature flags
|
|
441
|
+
- A/B testing
|
|
442
|
+
- Analytics tracking
|
|
443
|
+
- Internationalization
|
|
444
|
+
|
|
445
|
+
### For Different Tech Stacks
|
|
446
|
+
Replace sections with your stack:
|
|
447
|
+
- Flask/FastAPI instead of Next.js
|
|
448
|
+
- MySQL/MongoDB instead of PostgreSQL
|
|
449
|
+
- Pytest instead of Vitest
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# CLAUDE.md - Minimal Template
|
|
2
|
+
|
|
3
|
+
> Lightweight project context for any codebase
|
|
4
|
+
|
|
5
|
+
Copy this file to your project root and customize.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Project Overview
|
|
10
|
+
|
|
11
|
+
Brief description of this project.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Install dependencies
|
|
17
|
+
npm install
|
|
18
|
+
|
|
19
|
+
# Run development server
|
|
20
|
+
npm run dev
|
|
21
|
+
|
|
22
|
+
# Run tests
|
|
23
|
+
npm test
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Tech Stack
|
|
27
|
+
|
|
28
|
+
- **Language**: TypeScript
|
|
29
|
+
- **Framework**: [Framework]
|
|
30
|
+
- **Database**: [Database]
|
|
31
|
+
|
|
32
|
+
## Project Structure
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
src/
|
|
36
|
+
├── components/ # UI components
|
|
37
|
+
├── lib/ # Shared utilities
|
|
38
|
+
├── pages/ # Routes/pages
|
|
39
|
+
└── types/ # TypeScript types
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Conventions
|
|
43
|
+
|
|
44
|
+
- Use TypeScript strict mode
|
|
45
|
+
- Follow existing patterns in the codebase
|
|
46
|
+
- Write tests for new features
|
|
47
|
+
|
|
48
|
+
## Important Files
|
|
49
|
+
|
|
50
|
+
- `src/lib/config.ts` - Configuration
|
|
51
|
+
- `src/lib/db.ts` - Database connection
|
|
52
|
+
- `src/types/index.ts` - Shared types
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# CLAUDE.md - Next.js App Template
|
|
2
|
+
|
|
3
|
+
> Project context for Next.js 14+ applications with App Router
|
|
4
|
+
|
|
5
|
+
Copy this file to your project root as `CLAUDE.md`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Project: [Project Name]
|
|
10
|
+
|
|
11
|
+
A Next.js application using the App Router.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install
|
|
17
|
+
npm run dev # http://localhost:3000
|
|
18
|
+
npm run build # Production build
|
|
19
|
+
npm run lint # ESLint
|
|
20
|
+
npm test # Run tests
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Tech Stack
|
|
24
|
+
|
|
25
|
+
- **Framework**: Next.js 14 (App Router)
|
|
26
|
+
- **Language**: TypeScript
|
|
27
|
+
- **Styling**: Tailwind CSS
|
|
28
|
+
- **Database**: [Prisma/Drizzle with PostgreSQL]
|
|
29
|
+
- **Auth**: [NextAuth.js / Clerk / Custom]
|
|
30
|
+
- **Testing**: Vitest + Testing Library
|
|
31
|
+
|
|
32
|
+
## Project Structure
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
.
|
|
36
|
+
├── app/
|
|
37
|
+
│ ├── (auth)/ # Auth route group
|
|
38
|
+
│ │ ├── login/
|
|
39
|
+
│ │ └── register/
|
|
40
|
+
│ ├── (dashboard)/ # Protected route group
|
|
41
|
+
│ │ └── dashboard/
|
|
42
|
+
│ ├── api/ # API routes
|
|
43
|
+
│ │ └── [resource]/
|
|
44
|
+
│ ├── layout.tsx # Root layout
|
|
45
|
+
│ ├── page.tsx # Home page
|
|
46
|
+
│ └── globals.css
|
|
47
|
+
├── components/
|
|
48
|
+
│ ├── ui/ # Reusable UI (buttons, inputs)
|
|
49
|
+
│ └── [feature]/ # Feature components
|
|
50
|
+
├── lib/
|
|
51
|
+
│ ├── actions/ # Server actions
|
|
52
|
+
│ ├── db/ # Database client & queries
|
|
53
|
+
│ ├── auth/ # Auth utilities
|
|
54
|
+
│ └── utils.ts # Helpers
|
|
55
|
+
├── hooks/ # Custom hooks
|
|
56
|
+
└── types/ # TypeScript types
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Next.js Conventions
|
|
60
|
+
|
|
61
|
+
### Server vs Client Components
|
|
62
|
+
```tsx
|
|
63
|
+
// Default: Server Component (no directive needed)
|
|
64
|
+
export default function ServerComponent() { ... }
|
|
65
|
+
|
|
66
|
+
// Client Component (when needed)
|
|
67
|
+
'use client';
|
|
68
|
+
export default function ClientComponent() { ... }
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Use Client Components when:**
|
|
72
|
+
- Using hooks (useState, useEffect, etc.)
|
|
73
|
+
- Browser APIs (window, document)
|
|
74
|
+
- Event handlers (onClick, onChange)
|
|
75
|
+
- Client-side libraries
|
|
76
|
+
|
|
77
|
+
### Server Actions
|
|
78
|
+
```tsx
|
|
79
|
+
// lib/actions/user.ts
|
|
80
|
+
'use server';
|
|
81
|
+
|
|
82
|
+
export async function createUser(formData: FormData) {
|
|
83
|
+
// Validate input
|
|
84
|
+
// Database operation
|
|
85
|
+
// Return result or revalidate
|
|
86
|
+
revalidatePath('/users');
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Data Fetching
|
|
91
|
+
```tsx
|
|
92
|
+
// In Server Components - fetch directly
|
|
93
|
+
async function Page() {
|
|
94
|
+
const data = await db.query.users.findMany();
|
|
95
|
+
return <UserList users={data} />;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// For mutations - use Server Actions
|
|
99
|
+
<form action={createUser}>
|
|
100
|
+
...
|
|
101
|
+
</form>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Route Handlers (API Routes)
|
|
105
|
+
```typescript
|
|
106
|
+
// app/api/users/route.ts
|
|
107
|
+
import { NextResponse } from 'next/server';
|
|
108
|
+
|
|
109
|
+
export async function GET() {
|
|
110
|
+
const users = await db.query.users.findMany();
|
|
111
|
+
return NextResponse.json(users);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function POST(request: Request) {
|
|
115
|
+
const body = await request.json();
|
|
116
|
+
// Validate and create
|
|
117
|
+
return NextResponse.json(user, { status: 201 });
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Coding Standards
|
|
122
|
+
|
|
123
|
+
### Component Pattern
|
|
124
|
+
```tsx
|
|
125
|
+
// components/feature/user-card.tsx
|
|
126
|
+
import { cn } from '@/lib/utils';
|
|
127
|
+
|
|
128
|
+
interface UserCardProps {
|
|
129
|
+
user: User;
|
|
130
|
+
className?: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function UserCard({ user, className }: UserCardProps) {
|
|
134
|
+
return (
|
|
135
|
+
<div className={cn('rounded-lg p-4', className)}>
|
|
136
|
+
{user.name}
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### File Naming
|
|
143
|
+
- Components: `kebab-case.tsx` → `user-card.tsx`
|
|
144
|
+
- Pages: `page.tsx` (Next.js convention)
|
|
145
|
+
- Layouts: `layout.tsx`
|
|
146
|
+
- API: `route.ts`
|
|
147
|
+
|
|
148
|
+
### Imports
|
|
149
|
+
```tsx
|
|
150
|
+
// Use path aliases
|
|
151
|
+
import { Button } from '@/components/ui/button';
|
|
152
|
+
import { db } from '@/lib/db';
|
|
153
|
+
import { cn } from '@/lib/utils';
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Important Files
|
|
157
|
+
|
|
158
|
+
| File | Purpose |
|
|
159
|
+
|------|---------|
|
|
160
|
+
| `app/layout.tsx` | Root layout, providers |
|
|
161
|
+
| `lib/db/index.ts` | Database client |
|
|
162
|
+
| `lib/auth/index.ts` | Auth utilities |
|
|
163
|
+
| `middleware.ts` | Route protection |
|
|
164
|
+
| `tailwind.config.ts` | Tailwind config |
|
|
165
|
+
|
|
166
|
+
## Common Patterns
|
|
167
|
+
|
|
168
|
+
### Protected Routes
|
|
169
|
+
```tsx
|
|
170
|
+
// middleware.ts
|
|
171
|
+
export function middleware(request: NextRequest) {
|
|
172
|
+
const session = await getSession();
|
|
173
|
+
if (!session && request.nextUrl.pathname.startsWith('/dashboard')) {
|
|
174
|
+
return NextResponse.redirect(new URL('/login', request.url));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Loading States
|
|
180
|
+
```tsx
|
|
181
|
+
// app/dashboard/loading.tsx
|
|
182
|
+
export default function Loading() {
|
|
183
|
+
return <Skeleton />;
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Error Handling
|
|
188
|
+
```tsx
|
|
189
|
+
// app/dashboard/error.tsx
|
|
190
|
+
'use client';
|
|
191
|
+
export default function Error({ error, reset }) {
|
|
192
|
+
return <ErrorBoundary error={error} onReset={reset} />;
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Environment Variables
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# .env.local (never commit)
|
|
200
|
+
DATABASE_URL=
|
|
201
|
+
NEXTAUTH_SECRET=
|
|
202
|
+
NEXTAUTH_URL=http://localhost:3000
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Required in `.env.example`:
|
|
206
|
+
- `DATABASE_URL` - Database connection string
|
|
207
|
+
- `NEXTAUTH_SECRET` - Auth secret (generate with `openssl rand -base64 32`)
|