Skip to content

TypeScript Shadcn UI Next.js .cursorrules prompt file

Author: Pontus Abrahamsson

What you can build

Code Snippet Generator with TypeScript Focus - Create a tool that generates concise, functional TypeScript code snippets based on user requirements. It will incorporate patterns like iteration, modularization, and use of interfaces.React Component Design System - Develop a design system using functional React components, integrated with Shadcn UI and Tailwind CSS, providing examples with TypeScript interfaces and declarative JSX.Error Handling SDK - Provide a library focused on error handling and validation using TypeScript and Zod. It can model expected errors, implement error boundaries, and return user-friendly messages.Responsive Design Toolkit - Offer a service to automatically generate mobile-first responsive designs using Tailwind CSS, focusing on performance optimization with features like image lazy loading and dynamic component loading.Next.js Performance Optimizer - A tool that analyzes Next.js projects for optimization opportunities focusing on 'use client', 'useEffect', React Server Components, image optimization, and Web Vitals improvement.Zod Validation Studio - Create an application where developers can design and test form validations with Zod, getting real-time feedback on expected error models and integration with functional components.Search Parameter State Manager - Develop a utility library for managing URL search parameters using 'nuqs', ensuring optimal state persistence in Next.js applications.TypeScript Interface Converter - A service that converts JavaScript objects and types into TypeScript interfaces, encouraging type safety and better integration with functional programming patterns.Functional Programming Playground - An interactive platform for practicing TypeScript functional patterns, enforcing modularization and avoidance of class-based components through challenges and examples.Shadcn UI Component Library - Provide a collection of pre-built React components styled with Tailwind and Radix UI, optimized for server-side rendering with bare minimum client-side code usage.

Benefits

Synopsis

Front-end developers building scalable React and Next.js applications will benefit by implementing TypeScript-driven architecture and enhancing performance, error handling, and UI styling standards.

Overview of .cursorrules prompt

The .cursorrules file provides guidelines for writing TypeScript code focusing on style, structure, and best practices. It emphasizes concise, functional, and declarative programming, discouraging the use of classes and code duplication. Developers are advised to use descriptive naming conventions and to structure files systematically, preferring interfaces over types and avoiding enums by using maps. The file outlines syntax preferences, advocating for pure functions and clean conditionals. Error handling is prioritized with suggestions for early returns, proper logging, and user-friendly messages. For UI and styling, the file recommends using Shadcn UI, Radix, and Tailwind CSS, emphasizing responsive design and performance optimization through dynamic loading and React Server Components. Key conventions include managing URL state with 'nuqs' and adhering to Next.js best practices for data fetching and rendering, while optimizing Web Vitals.

.cursorrules Content

json
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, typesNaming Conventions:- Use lowercase with dashes for directories (e.g., components/auth-wizard)- Favor named exports for componentsTypeScript Usage:- Use TypeScript for all code; prefer interfaces over types- Avoid enums; use maps instead- Use functional components with TypeScript interfacesSyntax and Formatting:- Use the "function" keyword for pure functions- Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements- Use declarative JSXError Handling and Validation:- Prioritize error handling: handle errors and edge cases early- Use early returns and guard clauses- Implement proper error logging and user-friendly messages- Use Zod for form validation- Model expected errors as return values in Server Actions- Use error boundaries for unexpected errorsUI and Styling:- Use Shadcn UI, Radix, and Tailwind Aria for components and styling- Implement responsive design with Tailwind CSS; use a mobile-first approachPerformance Optimization:- 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 loadingKey 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 managementFollow Next.js docs for Data Fetching, Rendering, and Routing

Released under the MIT License.