Monorepo Development
You are an expert in TypeScript, React and Next.js, Expo (React Native), Tamagui, Supabase, Zod, Turbo (Monorepo Management), i18next, Zustand, TanStack React Query, Solito, and Stripe.
Code Style and Structure
- Write concise, technical TypeScript code with accurate examples
- Use functional and declarative programming patterns; avoid classes
- Prefer iteration and modularization over code duplication
- Use descriptive variable names with auxiliary verbs (e.g.,
isLoading, hasError)
- Structure files with exported components, subcomponents, helpers, static content, and types
- Favor named exports for components and functions
- Use lowercase with dashes for directory names (e.g.,
components/auth-wizard)
TypeScript and Validation
- Use TypeScript for all code; prefer interfaces over types for object shapes
- Utilize Zod for schema validation and type inference
- Avoid enums; use literal types or maps instead
- Implement proper error handling with discriminated unions
State and Data Management
- Use Zustand for state management
- Use TanStack React Query for data fetching and caching
- Minimize
useEffect and setState; favor derived state
- Implement optimistic updates for better UX
Monorepo Structure
- Follow best practices using Turbo for monorepo management
- Use separate
apps and packages directories
- Keep shared configurations in the root
configs/ directory
- Use consistent naming conventions for workspaces
- Follow the standard Turborepo workspaces directory structure:
apps/ for application workspaces (Next.js, Expo apps)
packages/ for shared package workspaces (UI, utils, configs)
Internationalization
- Use i18next for web internationalization
- Use expo-localization for React Native internationalization
- Keep translation files organized by feature or domain
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
Performance Optimization
- Use dynamic imports for code splitting
- Implement lazy loading for non-critical components
- Optimize images: use WebP format, include size data, implement lazy loading
- Minimize the use of 'use client', 'useEffect', and 'setState'
Cross-Platform Development
- Use Solito for navigation across web and mobile
- Use
.native.tsx files for platform-specific code
- Share business logic and UI components through packages
Backend Integration
- Use Supabase for authentication and database
- Implement Row Level Security (RLS) policies
- Use Zod schemas for API validation
- Handle webhook events properly
Payments
- Implement Stripe integration with proper webhook handlers
- Handle subscription syncing between Stripe and your database
- Implement proper error handling for payment failures
1---2name: monorepo3description: Best practices for monorepo development with TypeScript, React, Next.js, Expo, Turbo, and related technologies4---5
6# Monorepo Development
7
8You are an expert in TypeScript, React and Next.js, Expo (React Native), Tamagui, Supabase, Zod, Turbo (Monorepo Management), i18next, Zustand, TanStack React Query, Solito, and Stripe.
9
10## Code Style and Structure
11
12- Write concise, technical TypeScript code with accurate examples
13- Use functional and declarative programming patterns; avoid classes
14- Prefer iteration and modularization over code duplication
15- Use descriptive variable names with auxiliary verbs (e.g., `isLoading`, `hasError`)
16- Structure files with exported components, subcomponents, helpers, static content, and types
17- Favor named exports for components and functions
18- Use lowercase with dashes for directory names (e.g., `components/auth-wizard`)
19
20## TypeScript and Validation
21
22- Use TypeScript for all code; prefer interfaces over types for object shapes
23- Utilize Zod for schema validation and type inference
24- Avoid enums; use literal types or maps instead
25- Implement proper error handling with discriminated unions
26
27## State and Data Management
28
29- Use Zustand for state management
30- Use TanStack React Query for data fetching and caching
31- Minimize `useEffect` and `setState`; favor derived state
32- Implement optimistic updates for better UX
33
34## Monorepo Structure
35
36- Follow best practices using Turbo for monorepo management
37- Use separate `apps` and `packages` directories
38- Keep shared configurations in the root `configs/` directory
39- Use consistent naming conventions for workspaces
40- Follow the standard Turborepo workspaces directory structure:
41 - `apps/` for application workspaces (Next.js, Expo apps)
42 - `packages/` for shared package workspaces (UI, utils, configs)
43
44## Internationalization
45
46- Use i18next for web internationalization
47- Use expo-localization for React Native internationalization
48- Keep translation files organized by feature or domain
49
50## Error Handling and Validation
51
52- Prioritize error handling and edge cases
53- Handle errors and edge cases at the beginning of functions
54- Use early returns for error conditions to avoid deeply nested if statements
55- Place the happy path last in the function for improved readability
56- Avoid unnecessary else statements; use if-return pattern instead
57- Use guard clauses to handle preconditions and invalid states early
58- Implement proper error logging and user-friendly error messages
59
60## Performance Optimization
61
62- Use dynamic imports for code splitting
63- Implement lazy loading for non-critical components
64- Optimize images: use WebP format, include size data, implement lazy loading
65- Minimize the use of 'use client', 'useEffect', and 'setState'
66
67## Cross-Platform Development
68
69- Use Solito for navigation across web and mobile
70- Use `.native.tsx` files for platform-specific code
71- Share business logic and UI components through packages
72
73## Backend Integration
74
75- Use Supabase for authentication and database
76- Implement Row Level Security (RLS) policies
77- Use Zod schemas for API validation
78- Handle webhook events properly
79
80## Payments
81
82- Implement Stripe integration with proper webhook handlers
83- Handle subscription syncing between Stripe and your database
84- Implement proper error handling for payment failures