grassrootseconomics sarafu.network .cursorrules file for TypeScript (stars: 3)


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()).

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.
  - Consider using custom error types or error factories for consistent error handling.

React/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.

RainbowKit v2 & Wagmi Integration
- Setup RainbowKit v2 with Wagmi v2 using `configureChains` and `createClient` from Wagmi.
- Initialize chains and providers within a `RainbowKitProvider` wrapper.
- Store mnemonics in `expo-secure-store` or other secure storage solutions.
- Use React hooks like `useAccount`, `useConnect`, `useDisconnect` from Wagmi for wallet actions.
- Favor the use of hooks over directly accessing global state.

tRPC v11 Integration
- Use `@trpc/react-query` and define tRPC routers on the server.
- Set up queries and mutations using `trpc.useQuery` and `trpc.useMutation` on the client.
- Use Zod for input validation at both client and server levels.
- Handle optimistic updates in React Query using the `onMutate` and `onSuccess` methods.
- For error handling, ensure tRPC procedures return a consistent error structure.

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.
css
dockerfile
java
javascript
nestjs
next.js
radix-ui
react
+5 more

First Time Repository

Sarafu Network dApp

TypeScript

Languages:

CSS: 15.3KB
Dockerfile: 2.3KB
JavaScript: 5.7KB
Shell: 1.4KB
TypeScript: 1592.7KB
Created: 6/6/2023
Updated: 1/23/2025

All Repositories (1)