agentleFS
wataru-maedawataru-maeda/react-native-boilerplate/.cursor/rules/coding-guidelines.mdc

react-native-boilerplate / rules

Cursor rule517 starsChanged 15 months agoMITView on GitHub

React Native Expo SDK 54 project with TypeScript, Expo Router v6, Redux Toolkit, and modern development practices.

  • Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.

    Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

Show its rules and text

We split this coding-guidelines.mdc into the rules it gives an agent

25 rules. About 0 are common, 22 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈22

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never hardcode environment values, always go through config

    line 18
  2. Very specific:

    Use @/theme/colors: instead of hardcoded color values

    line 23
  3. Distinctive:

    Keep local state minimal, prefer global state for shared data

    line 38
  4. Distinctive:

    Never make direct API calls from components

    line 43
  5. Distinctive:

    Use the services layer for data transformation

    line 44
  6. Distinctive:

    Use function declarations, not arrow functions for components

    line 80
  7. Distinctive:

    Keep hooks at the top of components

    line 81
  8. Distinctive:

    Use early returns for conditional rendering

    line 82
  9. Very specific:

    Always use StyleSheet.create for performance

    line 87
  10. Distinctive:

    Import colors from theme, never hardcode

    line 88
  11. Distinctive:

    Use platform-specific styles when needed

    line 89
  12. Distinctive:

    Keep styles at component bottom

    line 90
  13. Distinctive:

    Test component behavior, not implementation

    line 95
  14. Distinctive:

    Use descriptive test names

    line 96
  15. Very specific:

    Use utils/config.ts for all config access

    line 138
  16. Distinctive:

    Always handle loading and error states

    line 163
  17. Distinctive:

    Keep functions focused and small

    line 165
  18. Distinctive:

    Always check existing components before creating new ones

    line 169
  19. Distinctive:

    Use built-in utilities instead of reinventing

    line 170
  20. Distinctive:

    Follow established patterns in the codebase

    line 172
  21. Distinctive:

    Write tests for all new components

    line 176
  22. Distinctive:

    Ensure tests pass before committing

    line 177
  23. Distinctive:

    Test both happy path and error scenarios

    line 178
  24. Distinctive:

    Use React Native Testing Library patterns

    line 179
  25. Distinctive:

    Reuse existing built-in features: before creating new ones

    line 190

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
coding-guidelines.mdc
---
description: 
globs: 
alwaysApply: true
---
# React Native Expo Project - Coding Guidelines

## Project Overview

React Native Expo SDK 54 project with TypeScript, Expo Router v6, Redux Toolkit, and modern development practices.

## Built-in Features to Always Use

### Configuration Management

- **Use `utils/config.ts`** for all environment variables and app configuration
- **Use `utils/deviceInfo.ts`** for platform detection and device dimensions
- Never hardcode environment values, always go through config

### Theme System

- **Always import from `@/theme`** for colors, fonts, and images
- **Use `@/theme/colors`** instead of hardcoded color values
- **Use theme system** for consistent dark/light mode support
- **Load assets through `@/theme/images` and `@/theme/fonts`**

### Custom Hooks

- **Use `useColorScheme` from `@/hooks`** for theme detection
- **Use `useDataPersist` from `@/hooks`** for local storage operations
- **Use `useKeyboard` from `@/hooks`** for keyboard state management
- **Use `useAppSlice` from `@/slices`** for global state management

### State Management

- **Use Redux Toolkit slices** in `@/slices` for global state
- **Import from `@/slices`** for all state operations
- Keep local state minimal, prefer global state for shared data

### Services Layer

- **Use `@/services`** for all API calls and external integrations
- Never make direct API calls from components
- Use the services layer for data transformation

### Type Safety

- **Use types from `@/types`** for all interfaces
- **Define component props interfaces** for all components
- **Use TypeScript strict mode** - project is configured for it

## Directory Structure Rules

### Component Organization

- **`components/elements`** - Reusable UI components (Button, Image, etc.)
- **`components/layouts`** - Layout-specific components (headers, navigation)
- **`scenes`** - Screen components (renamed from pages)
- **`app`** - Expo Router routes only, delegate to scenes

### File Naming

- **Components**: PascalCase (`Button.tsx`, `NavigationHeader.tsx`)
- **Hooks**: camelCase with "use" prefix (`useColorScheme.ts`)
- **Utils**: camelCase (`deviceInfo.ts`, `config.ts`)
- **Types**: PascalCase (`User.ts`, `ApiResponse.ts`)

## Code Standards

### Import Organization

1. React and React Native imports first
2. Third-party library imports
3. Internal imports using `@/` paths
4. Relative imports last

### Component Structure

- Define TypeScript interfaces for all props
- Use function declarations, not arrow functions for components
- Keep hooks at the top of components
- Use early returns for conditional rendering
- Export default at the bottom

### Styling Rules

- Always use `StyleSheet.create` for performance
- Import colors from theme, never hardcode
- Use platform-specific styles when needed
- Keep styles at component bottom

### Testing Requirements

- One test file per component
- Test component behavior, not implementation
- Use descriptive test names
- Mock external dependencies

### SafeAreaView Usage

- **Import from `react-native-safe-area-context`**, not React Native
- React Native's SafeAreaView is deprecated as of SDK 54

### Required Peer Dependencies

- **@expo/metro-runtime** - Required for Expo Router
- **react-native-worklets** - Required for React Native Reanimated

## Built-in Architecture Patterns

### Navigation (Expo Router v5)

- **Use flat config format** as project is configured
- **Keep route files minimal** - delegate to scene components
- **Use `<Redirect>` for programmatic navigation**
- **Handle deep linking through router**

### Error Handling

- **Use try-catch for async operations**
- **Provide user-friendly error messages**
- **Log errors appropriately for debugging**
- **Implement fallback UI states**

### Performance

- **Use React.memo for expensive components**
- **Implement proper useCallback/useMemo**
- **Optimize lists with proper keys**
- **Lazy load components when possible**

## Project-Specific Features

### Environment Configuration

- Project uses `expo-constants` for environment variables
- Configuration is typed and validated
- Use `utils/config.ts` for all config access

### Theme and Styling

- Dark/light mode support built-in
- Theme colors are centralized and typed
- Responsive design utilities available

### Data Persistence

- Custom hook for local data storage
- Redux Toolkit for global state management
- Proper data flow architecture

### Platform Support

- iOS, Android, and Web platform support
- Platform-specific utilities available
- Responsive design considerations

## Development Rules

### Code Quality

- No `console.log` in production code
- Always handle loading and error states
- Write self-documenting code
- Keep functions focused and small

### Reusability Focus

- Always check existing components before creating new ones
- Use built-in utilities instead of reinventing
- Extend existing components rather than duplicating
- Follow established patterns in the codebase

### Testing

- Write tests for all new components
- Ensure tests pass before committing
- Test both happy path and error scenarios
- Use React Native Testing Library patterns

## Migration and Updates

- Currently on Expo SDK 54 with React 19.1
- ESLint 9 with flat config
- Modern React Native 0.81.4
- TypeScript strict mode enabled (v5.9.2)

## Key Principles

1. **Reuse existing built-in features** before creating new ones
2. **Follow established patterns** in the codebase
3. **Use TypeScript strictly** for better code quality
4. **Test all components** for reliability
5. **Keep components focused** and single-purpose
6. **Use the theme system** for consistent UI
7. **Leverage built-in hooks** for common functionality
8. **Follow import/export conventions** for maintainability

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.