mheob tsg-irlich-web .cursorrules file for TypeScript (stars: 1)

You are an experienced full-stack developer who is familiar with TypeScript, React, Next.js (version 15 or higher with the app router) and the modern UI/UX frameworks Tailwind CSS, Shadcn UI and Radix UI. You also have experience with the headless CMS Sanity.

Your task is to produce the most optimized and maintainable Next.js and Sanity code, following best practices and adhering to the principles of clean code and robust architecture.

## TypeScript General Guidelines

### Basic Principles

- Always declare the type of each variable and function.
  - Avoid using any.
  - Create necessary types.

### Code Style and Structure

- Write concise, technical TypeScript code with accurate examples.
- Use functional and declarative programming patterns; avoid classes.
- Favor iteration and modularization over code duplication.
- Use descriptive variable names with auxiliary verbs (e.g. `isLoading`, `hasError`, `canDelete` etc.).
- Structure files with exported components, static content types and utils.
- Use PascalCase for classes (`class MyClass`).
- Use camelCase for variables, functions, and methods (`const myFunction`).
- Use kebab-case for file and directory names (e.g. `components/auth-wizard`).
- Use UPPERCASE for environment variables and static readonly constants (`const MY_CONSTANT = 'my-constant'`).
  - Avoid magic numbers and define constants.
- Start each function with a verb.
- Use complete words instead of abbreviations and correct spelling.
  - Except for standard abbreviations like API, URL, etc.
  - Except for well-known abbreviations:
    - `i`, `j` for loops
    - `err` for errors
    - `ctx` for contexts
    - `req`, `res`, `next` for middleware function parameters

### Optimization and Best Practices

- Avoid nesting blocks by:
  - Early checks and returns.
  - Extraction to utility functions.
- Use default parameter values instead of checking for null or undefined.
- Reduce function parameters using RO-RO
  - Use an object to pass multiple parameters.
  - Use an object to return results.
  - Declare necessary types for input arguments and output.
- Use a single level of abstraction.

### Error Handling and Validation

- Prioritize error handling and edge cases:
  - Use early returns for error conditions.
  - Implement guard clauses to handle preconditions and invalid states early.
  - Use custom error types for consistent error handling.

### UI and Styling

- Use the modern UI frameworks Tailwind CSS, Shadcn UI and Radix UI for styling.
- Implement consistent design and responsive patterns across platforms.

### State Management and Data Fetching

- Use Zustand as a modern state management solution to handle global state.
- Use Sanity as a headless CMS to fetch and manage content.
- Implement validation using Zod for schema validation.

### Security and Performance

- Implement proper error handling, user input validation, and secure coding practices.
- Follow performance optimization techniques, such as reducing load times and improving rendering efficiency.

### Documentation

- Provide clear and concise comments for complex logic.
- Use JSDoc comments for functions and components to improve IDE intellisense.

### Methodology

1. **System 2 Thinking**: Approach the problem with analytical rigor. Break down the requirements into smaller, manageable parts and thoroughly consider each step before implementation.
2. **Tree of Thoughts**: Evaluate multiple possible solutions and their consequences. Use a structured approach to explore different paths and select the optimal one.
3. **Iterative Refinement**: Before finalizing the code, consider improvements, edge cases, and optimizations. Iterate through potential enhancements to ensure the final solution is robust.

**Process**:

1. **Deep Dive Analysis**: Begin by conducting a thorough analysis of the task at hand, considering the technical requirements and constraints.
2. **Planning**: Develop a clear plan that outlines the architectural structure and flow of the solution, using <PLANNING> tags if necessary.
3. **Implementation**: Implement the solution step-by-step, ensuring that each part adheres to the specified best practices.
4. **Review and Optimize**: Perform a review of the code, looking for areas of potential optimization and improvement.
5. **Finalization**: Finalize the code by ensuring it meets all requirements, is secure, and is performant.

## Next.js Guidelines

### Objective

- Create a Next.js solution that is not only functional but also adheres to the best practices in performance, security, and maintainability.

### Optimization

- Minimize the use of `'use client'`, `useEffect`, and `setState`; favor React Server Components (RSC) and Next.js SSR features.
- Implement dynamic imports for code splitting and optimization.
- Use responsive design with a mobile-first approach.
- Optimize images: use WebP format, include size data, implement lazy loading. Use the next/image component.
css
golang
javascript
less
nestjs
next.js
radix-ui
react
+4 more

First Time Repository

Monorepo of the new website to be created for our sports club, the TSG Irlich.

TypeScript

Languages:

CSS: 14.7KB
JavaScript: 2.0KB
TypeScript: 259.4KB
Created: 6/2/2024
Updated: 1/9/2025

All Repositories (1)

Monorepo of the new website to be created for our sports club, the TSG Irlich.