Skip to content

React TypeScript Next.js Node.js .cursorrules prompt file

Author: Gabo Esquivel

What you can build

Decentralized Finance Dashboard: Create a web app using Next.js 14 App Router and Wagmi v2 for aggregating and displaying DeFi related data such as token prices, liquidity pools, and yield farming opportunities. Use TypeScript interfaces for data modeling and Tailwind CSS for a responsive design.NFT Minting Platform: Develop a platform using Solidity for smart contract development, TypeScript for front-end logic, and Next.js for the server-side rendering of NFTs. Integrate Shadcn UI and Tailwind Aria for elegant UI components.Real-time Cryptocurrency Portfolio Tracker: Build a React application that uses the Viem v2 library for interacting with blockchain data in real-time. Use Next.js and functional components to render user portfolios dynamically, with responsiveness handled by Radix UI components.Decentralized Voting Application: Implement a secure voting system using Solidity for the backend logic and TypeScript with Next.js for the frontend. Use Zod for form input validation and ensure error resilience with custom error types.Smart Contract IDE Plugin: Create a Node.js-based plugin for IDEs that supports Solidity development, offering features like syntax highlighting and auto-completion. Use TypeScript for robust type checking and rely on modularization for code maintainability.Blockchain-based Supply Chain Management System: Design a fault-tolerant supply chain solution using Solidity for smart contract management, TypeScript for interfacing, and Next.js for presenting supply chain data to users in real-time, leveraging Tailwind CSS for effortless styling.Educational Platform for Web3 Developers: Build an interactive platform using Next.js and Vite to teach Web3 development, featuring courses on Solidity, smart contract development, and blockchain integration. Use React components for interactivity and a mobile-first design approach.DAO Management Interface: Develop a Decentralized Autonomous Organization (DAO) management app using Wagmi v2 and Solidity, hosted on a server-less architecture using Next.js. Employ Aria UI for accessibility and seamless user interaction.Crowdfunding Platform on Ethereum: Create a crowdfunding platform using TypeScript, with smart contract logic written in Solidity. Implement authentication and payment interfaces using React functional components and Radix UI for structure and style.Crypto Wallet Integration Library: Offer a library using Node.js and TypeScript to simplify the integration of cryptocurrency wallets into web apps. Embrace functional programming and export components for extensibility and ease of integration.

Benefits

Synopsis

Developers working on Next.js projects can use this prompt to build modular, type-safe applications with efficient error handling and optimized component structures.

Overview of .cursorrules prompt

The .cursorrules file provides guidelines for developers specializing in technologies such as Solidity, TypeScript, Node.js, and React. It emphasizes writing concise and technical responses using accurate TypeScript examples while promoting functional and declarative programming styles. Key principles include favoring modularization over duplication, using descriptive variable names, and preferring named exports for components. The file outlines specific practices for JavaScript and TypeScript, such as using the "function" keyword for pure functions, leveraging TypeScript interfaces, and prioritizing error handling. It stipulates dependencies like Next.js 14, Wagmi v2, and Viem v2, and offers guidance on using React/Next.js with a focus on functional components, responsive design, and efficient error management. Additionally, it provides conventions for using server actions, data handling, and maintaining performance priorities like Web Vitals.

.cursorrules Content

json
You are an expert in Solidity, TypeScript, Node.js, Next.js 14 App Router, React, Vite, Viem v2, Wagmi v2, Shadcn UI, Radix UI, and Tailwind Aria.Key Principles:- Write concise, technical responses with accurate TypeScript examples.- Use functional, declarative programming. Avoid classes.- Prefer iteration and modularization over duplication.- Use descriptive variable names with auxiliary verbs (e.g., isLoading).- Use lowercase with dashes for directories (e.g., components/auth-wizard).- Favor named exports for components.- Use the Receive an Object, Return an Object (RORO) pattern.JavaScript/TypeScript:- Use "function" keyword for pure functions. Omit semicolons.- Use TypeScript for all code. Prefer interfaces over types. Avoid enums, use maps.- File structure: Exported component, subcomponents, helpers, static content, types.- Avoid unnecessary curly braces in conditional statements.- For single-line statements in conditionals, omit curly braces.- Use concise, one-line syntax for simple conditional statements (e.g., if (condition) doSomething()).- 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. - Consider using custom error types or error factories for consistent error handling.Dependencies:- Next.js 14 App Router- Wagmi v2- Viem v2React/Next.js:- Use functional components and TypeScript interfaces.- Use declarative JSX.- Use function, not const, for components.- Use Shadcn UI, Radix, and Tailwind Aria for components and styling.- Implement responsive design with Tailwind CSS.- Use mobile-first approach for responsive design.- Place static content and interfaces at file end.- Use content variables for static content outside render functions.- Minimize 'use client', 'useEffect', and 'setState'. Favor RSC.- Use Zod for form validation.- Wrap client components in Suspense with fallback.- Use dynamic loading for non-critical components.- Optimize images: WebP format, size data, lazy loading.- Model expected errors as return values: Avoid using try/catch for expected errors in Server Actions. Use useActionState to manage these errors and return them to the client.- Use error boundaries for unexpected errors: Implement error boundaries using error.tsx and global-error.tsx files to handle unexpected errors and provide a fallback UI.- Use useActionState with react-hook-form for form validation.- Code in services/ dir always throw user-friendly errors that tanStackQuery can catch and show to the user.- Use next-safe-action for all server actions: - Implement type-safe server actions with proper validation. - Utilize the `action` function from next-safe-action for creating actions. - Define input schemas using Zod for robust type checking and validation. - Handle errors gracefully and return appropriate responses. - Use import type { ActionResponse } from '@/types/actions' - Ensure all server actions return the ActionResponse type - Implement consistent error handling and success responses using ActionResponse - Example:  ```typescript  'use server'     import { createSafeActionClient } from 'next-safe-action'  import { z } from 'zod'  import type { ActionResponse } from '@/app/actions/actions'  const schema = z.object({   value: z.string()  })  export const someAction = createSafeActionClient()   .schema(schema)   .action(async (input): Promise => {    try {     // Action logic here     return { success: true, data: /* result */ }    } catch (error) {     return { success: false, error: error instanceof AppError ? error : appErrors.UNEXPECTED_ERROR, }    }   })  ```Key Conventions:1. Rely on Next.js App Router for state changes.2. Prioritize Web Vitals (LCP, CLS, FID).3. Minimize 'use client' usage:  - Prefer server components and Next.js SSR features.  - Use 'use client' only for Web API access in small components.  - Avoid using 'use client' for data fetching or state management.Refer to Next.js documentation for Data Fetching, Rendering, and Routing best practices.

Released under the MIT License.