agentleFS
chohra-medchohra-med/expo_boilerplate/.cursor/rules/best_practices.mdc

expo_boilerplate / rules

Cursor rule34 starsChanged 5 months agoMITView on GitHub

Advanced Best Practices covering Error Handling, Environment Variables, Performance, and Accessibility rules

  • Reads credentials

The file

We split this best_practices.mdc into the rules it gives an agent

9 rules. About 0 are common, 3 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Never allow API failures to crash the app or fail silently.

    line 11
  2. Very specific:

    When calling RTK Query mutations, handle .unwrap() errors or isRejectedWithValue reliably.

    line 12
  3. Very specific:

    Use explicit try/catch and fire user-facing toasts (e.g., via react-native-toast-message) on failure.

    line 13
  4. Very specific:

    Never use process.env scattered across components.

    line 21
  5. Very specific:

    Never commit .env or credentials.

    line 23
  6. Distinctive:

    Avoid passing massive objects to worklets.

    line 29
  7. Very specific:

    Prefer Expo Image over standard React Native Image for aggressive caching and memory performance, especially in FlashList components.

    line 32
  8. Distinctive:

    All UI elements must be accessible.

    line 36
  9. Very specific:

    Use accessibilityState dynamically (e.g., selected, disabled) so screen readers announce correct context.

    line 39

≈ “Common” is an estimate: at least 1 in 5 of the 6,668 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
best_practices.mdc
---
description: Advanced Best Practices covering Error Handling, Environment Variables, Performance, and Accessibility rules
globs: **/*.ts, **/*.tsx
---

# Advanced Best Practices

## 🔴 Error Handling & Observability

### 1. API Error Handling
- Never allow API failures to crash the app or fail silently.
- When calling RTK Query mutations, handle `.unwrap()` errors or `isRejectedWithValue` reliably.
- Use explicit `try/catch` and fire user-facing toasts (e.g., via `react-native-toast-message`) on failure.

### 2. Global Error Boundaries
- Since `react-native-error-boundary` is installed, ensure that any major rendering block is wrapped where appropriate.
- Log fatal crashes to the logging service before presenting the fallback UI.

## 🟢 Environment Variables & Secrets

- Never use `process.env` scattered across components.
- Validate environment variables at startup. Use `zod` to schemas in a central config file (e.g., `src/config/env.ts`) so missing or invalid keys throw an immediate exception.
- Never commit `.env` or credentials. Use `Expo Secure Store` for user session tokens or keys, never `MMKV` for sensitive data.

## 🚀 Performance & Reanimated

### 1. Animations with Reanimated 4
- Differentiate between the UI thread and the JS Thread. Use `runOnJS` when invoking state changes from a worklet.
- Avoid passing massive objects to worklets; pick out primitive dependencies.

### 2. Image Loading
- Prefer `Expo Image` over standard React Native `Image` for aggressive caching and memory performance, especially in `FlashList` components.

## ♿ Accessibility (A11y)

All UI elements must be accessible.
- Pass `accessibilityRole="button"` and `accessibilityLabel` to all custom touchables.
- Account for scaling text. Since we use Restyle, configure typography variants to respect dynamic font types cleanly without breaking layout.
- Use `accessibilityState` dynamically (e.g., `selected`, `disabled`) so screen readers announce correct context.

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.