ShipKit Next.js Development Rules
Expert development rules for building Next.js applications with App Router, Shadcn UI, TypeScript, and modern React patterns. Optimized for the ShipKit stack including Payload CMS 3, NextAuth v5, Builder.io, and PNPM.
Instructions
You are an expert in TypeScript, Node.js, Next.js App Router, React, Shadcn UI, Radix UI and Tailwind.
Project Context Awareness
1. Check for `ai.mdx` file at the start of every session
- If it exists, read it to understand previous work and pick up where you left off
- Mark completed steps with checkboxes as you work
- Update the file continuously so another AI can continue your work
- If it doesn't exist, create it to document your plan
Key Principles
Write concise, technical TypeScript code with accurate examplesUse functional and declarative programming patterns; avoid classesPrefer iteration and modularization over code duplicationUse descriptive variable names with auxiliary verbs (e.g., `isLoading`, `hasError`)Structure files in this order: exported component, subcomponents, helpers, static content, typesPre-emptively ask questions if you are unsure about requirementsPre-emptively optimize code for productionPre-emptively add types to all functions and variablesPre-emptively fix any TypeScript errors or warningsNaming Conventions
Use lowercase with dashes for directories (e.g., `components/auth-wizard`)Use `hyphen-case.ext` over `CamelCase.ext` for file namesFavor named exports for componentsPrefer arrow functions for React components: - ✅ `export const Component = () => { ... }`
- ❌ `export function Component() { ... }`
- ❌ `export default function Component() { ... }`
TypeScript Usage
Use TypeScript for all codePrefer interfaces over typesAvoid enums; use maps insteadUse functional components with TypeScript interfacesAdd types to all functions and variablesFix all TypeScript errors and warnings before completing workSyntax and Formatting
Use the "function" keyword for pure functionsAvoid unnecessary curly braces in conditionals; use concise syntax for simple statementsUse declarative JSXUI and Styling
Use Shadcn UI, Radix, and Tailwind for components and stylingImplement responsive design with Tailwind CSS using a mobile-first approachFollow Tailwind CSS conventions for stylingEnsure responsive design for all componentsUse Shadcn/UI components for consistency in UI elementsPrioritize accessibility in UI designPerformance Optimization
Minimize 'use client', 'useEffect', and 'setState'; favor React Server Components (RSC)Wrap client components in Suspense with fallbackUse dynamic loading for non-critical componentsOptimize images: use WebP format, include size data, implement lazy loadingOptimize images and assets for faster load timesUse lazy loading for components and images where applicableMinimize the use of heavy libraries and dependenciesRegularly audit and improve performance metricsKey Conventions
Use 'nuqs' for URL search parameter state managementOptimize Web Vitals (LCP, CLS, FID)Limit 'use client': - Favor server components and Next.js SSR
- Use only for Web API access in small components
- Avoid for data fetching or state management
- Add `use client` to the top of the file if using client-side code like hooks
- Do not use `use client` in server components
Follow Next.js docs for Data Fetching, Rendering, and RoutingFile Structure
Use `@/server/actions` for all server actionsUse `@/server/services` for all internal servicesCritical Don'ts
**DO NOT** delete environment variables**DO NOT** nest server components in client components unless passed through props**DO NOT** forget to add `use client` to the top of the file if using client-side code like hooks**DO NOT** use `use client` in server components**DO NOT** fetch data with server actions (use Server Components instead)**DO NOT** use server actions to fetch data - use Server Components**DO NOT** use boolean values for database fields; use dates instead (e.g., `isActive: boolean` → `activeAt: Date`)Comments
Pre-emptively add comments to explain "why" behind the codeDo not modify comments or functionality unrelated to the prompt unless you have a very good reasonPreserve all existing comments unless specifically asked to modify themWhen showing code changes, use comments like `// ...` to indicate unchanged sectionsUse comments with callouts and examples:```typescript
/*
* Logging configuration
* @see https://nextjs.org/docs/app/api-reference/next-config-js/logging
*/
```
Comment any complex or hard-to-read codeReact Conventions
Use functional components and hooks for state managementEnsure components are reusable and maintainablePrefer server actions for internal API requestsMaintain a separation of concerns between client and server componentsNext.js Architecture
Server code belongs in services, server action code belongs in actions. If an action needs server-side code, it should call services:
Server components load data using servicesData manipulation uses server actionsServer actions call services for server-side operationsDatabase Interactions
1. Ensure all required fields are provided when interacting with the database
2. Check for potential undefined values and handle them appropriately
3. Use TypeScript's type system to enforce correct data structures
4. Implement error handling for database operations and API requests
5. Validate input data to prevent runtime errors and ensure data integrity
6. Add comments to explain complex logic or important decisions
7. Regularly review and test code to catch and fix errors early
8. Use the `db.transaction` method to ensure atomicity when performing multiple database operations
9. Don't use boolean values for anything; use dates instead (e.g., `isActive: boolean` → `activeAt: Date`)
API Integration
Use environment variables for sensitive data like API keysHandle API errors gracefully and provide user feedbackUse async/await for asynchronous operations to improve readabilityDocument API interactions and expected responsesDevelopment Workflow
1. Check for and read `ai.mdx` to understand project context
2. Ask clarifying questions if requirements are unclear
3. Write production-ready, type-safe code
4. Add comprehensive comments for complex logic
5. Fix all TypeScript errors and warnings
6. Test functionality thoroughly
7. Update `ai.mdx` with completed steps
8. Use open-source libraries when they enhance user/developer experience
Best Practices
Use best practices and write production-ready codeFix bugs and improve performance proactivelyBe aware of the latest versions of all librariesRegularly audit code quality and performanceExample Usage
Use this skill when:
Building Next.js applications with App RouterWorking with the ShipKit stack (Shadcn UI, Payload CMS 3, NextAuth v5)Implementing server components and server actionsCreating type-safe, production-ready React applicationsFollowing modern Next.js and React conventions