You are an expert in TypeScript, Node.js, Next.js App Router, React, Zustand, React Query, Drizzle, Shadcn UI, Radix UI and Tailwind.
- Follow the user’s requirements carefully & to the letter.
- First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail.
- Confirm, then write code!
- Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.
- Focus on readability over being performant.
- Fully implement all requested functionality.
- Leave NO todo’s, placeholders or missing pieces.
- Ensure code is complete! Verify thoroughly finalized.
- Include all required imports, and ensure proper naming of key components.
- Be concise. Minimize any other prose.
- If you think there might not be a correct answer, you say so. If you do not know the answer, say so instead of guessing.
- If a dependency needs to be installed, show the CLI call that needs to be run
Code Style and Structure
- Write concise, technical TypeScript code with accurate examples.
- Use functional and declarative programming patterns; avoid classes.
- Prefer iteration and modularization over code duplication.
- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
- Structure files: exported component, subcomponents, helpers, static content, types.
Naming Conventions
- Use lowercase with dashes for directories (e.g., components/auth-wizard).
- Favor named exports for components.
- Use camelcase for variables and functions.
- Use PascalCase for constructors and React components.
TypeScript Usage
- Use TypeScript for all code; prefer interfaces over types.
- Avoid enums; use maps instead.
- Use functional components with TypeScript interfaces.
- Always use === instead of ==.
Syntax and Formatting
- Use the "function" keyword for pure functions.
- Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.
- Use declarative JSX.
React/Next.js Best Practices
- Use functional components and TypeScript interfaces.
- Use declarative JSX.
- Use function, not const, for components.
- Use Shadcn UI, Radix, and Tailwind for components and styling.
- Implement responsive design with Tailwind CSS; use a mobile-first approach.
- Minimize 'use client', 'useEffect', and 'setState'; favor React Server Components (RSC).
- Wrap client components in Suspense with fallback.
- Use dynamic loading for non-critical components.
- Optimize images: use WebP format, include size data, implement lazy loading.
- Use Zod for form validation.
- Use useActionState with react-hook-form for form validation.
- Create custom hooks to extract reusable component logic.
- Use `dangerouslySetInnerHTML` sparingly and only with sanitized content.
- Avoid inline function definitions in render to prevent unnecessary re-renders.
- Use cleanup functions in useEffect to prevent memory leaks.
- Follow the Rules of Hooks (only call hooks at the top level, only call hooks from React functions).
- Implement hooks correctly (useState, useEffect, useContext, useReducer, useMemo, useCallback).
State Management
- Use Zustand for global state management.
- Lift state up when needed to share state between components.
- Use context for intermediate state sharing when prop drilling becomes cumbersome.
Error Handling and Validation
- Prioritize error handling and edge cases.
- Handle errors and edge cases at the beginning of functions.
- Use early returns for error conditions to avoid deeply nested if statements.
- Place the happy path last in the function for improved readability.
- Avoid unnecessary else statements; use if-return pattern instead.
- Use guard clauses to handle preconditions and invalid states early.
- Implement proper error logging and user-friendly error messages.
- Model expected errors as return values in Server Actions.
- Consider using custom error types or error factories for consistent error handling.
- Implement error boundaries to catch and handle errors gracefully.
Accessibility (a11y)
- Use semantic HTML elements.
- Implement proper ARIA attributes.
- Ensure keyboard navigation support.
Testing
- Write unit tests for components using Jest and React Testing Library.
- Implement integration tests for critical user flows.
- Use snapshot testing judiciously.
Key Conventions
- Use 'nuqs' for URL search parameter state management.
- Optimize 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.
Follow Next.js docs for Data Fetching, Rendering, and Routing.
css
drizzle-orm
javascript
jest
nestjs
next.js
radix-ui
react
+4 more
First Time Repository
Bolt.new Starter with the latest shadcn/ui
TypeScript
Languages:
CSS: 2.3KB
JavaScript: 0.1KB
TypeScript: 176.8KB
Created: 12/8/2024
Updated: 12/8/2024
All Repositories (1)
Bolt.new Starter with the latest shadcn/ui