Expo AI Coding Rules

Expo AI rules help engineering teams get better results from AI coding assistants like Cursor, Windsurf, and GitHub Copilot. By defining clear conventions for code style, architecture patterns, error handling, and module organisation, Expo AI rules ensure that generated code is consistent, maintainable, and production-ready. Whether you are working on a side project or a large-scale enterprise system, community-curated rules on AI Rules Hub provide a solid foundation you can adopt instantly and customise to fit your team's standards.

Why Use AI Rules for Expo?

  • Ensure AI-generated Expo code follows your team's conventions
  • Prevent common anti-patterns that degrade maintainability
  • Reduce code review cycles by getting AI output right the first time
  • Standardise error handling, logging, and module structure
  • Make AI assistants produce secure and performance-conscious code

Best Practices for Expo AI Coding

Define a Consistent Code Style

Specify formatting preferences (indentation, quotes, trailing commas) for Expo so AI output matches your linter configuration without manual edits.

Enforce Error Handling Patterns

Instruct AI to always handle errors explicitly, use structured logging, and avoid swallowing exceptions silently.

Set Module Organisation Rules

Define how Expo modules should be organised — feature folders, barrel exports, and separation of concerns — so AI keeps the project structure clean.

Require Security-Conscious Patterns

Add rules that enforce input validation, sanitisation, and safe dependency usage so AI never introduces obvious security vulnerabilities.

Common Patterns & Standards

#01

Separation of Concerns

Keep business logic, data access, and presentation layers separate in Expo projects so each layer is independently testable.

#02

Dependency Injection

Pass dependencies explicitly through constructors or function parameters — avoiding global state that makes testing difficult.

#03

Consistent Naming Conventions

Rule AI to follow Expo community naming standards for files, classes, functions, and constants.

#04

Automated Testing Standards

Define what test types are required (unit, integration) and where test files should live so AI generates tests alongside implementation code.

Top Expo Rules on AI Rules Hub

No description provided.

# Expo React Native + TypeScript Development Rules

## Project Stack

-   Framework: Expo (React Native)
-   Language: TypeScript
-   Navigation: Expo Router or React Navigation
-   State Management: Prefer React Context or Zustand
-   Styling: React Native StyleSheet or Tailwind (NativeWind)

------------------------------------------------------------------------

## File Structure

src/ components/ screens/ hooks/ services/ utils/ types/ constants/

Rules: - Components must live in `components/` - Screens must live in
`screens/` - Business logic should be inside `services/` - Reusable
hooks should be inside `hooks/` - Type definitions must live in `types/`

------------------------------------------------------------------------

## TypeScript Rules

Always follow strict TypeScript rules.

Required: - Avoid `any` - Prefer `type` or `interface` - Always type
props - Always type API responses

Example:

``` ts
type User = {
  id: string
  name: string
  email: string
}
```

Component example:

``` ts
type Props = {
  title: string
}

export function Header({ title }: Props) {
  return <Text>{title}</Text>
}
```

------------------------------------------------------------------------

## Component Rules

Preferred component style:

-   Functional components only
-   Use hooks
-   Avoid class components

Example:

``` tsx
export const Button = () => {
  return <Pressable></Pressable>
}
```

Rules: - One component per file - Component name must match file name

Example:

components/Button.tsx

------------------------------------------------------------------------

## Styling Rules

Preferred order:

1.  StyleSheet
2.  NativeWind (if enabled)

Example:

``` ts
const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 16
  }
})
```

Rules: - Do not inline large styles - Shared styles go in `/styles`

------------------------------------------------------------------------

## Hooks Rules

Custom hooks must start with `use`.

Example:

useAuth.ts\
useUser.ts\
useLocation.ts

Example implementation:

``` ts
export function useUser() {
  const [user, setUser] = useState<User | null>(null)
  return { user, setUser }
}
```

------------------------------------------------------------------------

## API Rules

All API calls must live in:

services/api/

Example:

services/api/userService.ts

Example:

``` ts
export async function getUsers(): Promise<User[]> {
  const res = await fetch("/users")
  return res.json()
}
```

Rules: - No API calls inside UI components - Always type API responses

------------------------------------------------------------------------

## Performance Rules

Always:

-   Use React.memo for heavy components
-   Use useCallback for handlers
-   Use useMemo for computed values
-   Avoid unnecessary re-renders

------------------------------------------------------------------------

## Expo Rules

Always prefer Expo APIs:

Examples:

expo-location\
expo-camera\
expo-secure-store\
expo-image-picker

Rules: - Do not install native packages if Expo already provides them -
Keep compatibility with Expo managed workflow

------------------------------------------------------------------------

## Error Handling

All async code must handle errors.

Example:

``` ts
try {
  const users = await getUsers()
} catch (error) {
  console.error(error)
}
```

------------------------------------------------------------------------

## Naming Conventions

Components → PascalCase\
Hooks → camelCase starting with `use`\
Files → PascalCase for components

Example:

UserCard.tsx\
useAuth.ts\
userService.ts

------------------------------------------------------------------------

## Testing

Preferred tools:

-   Jest
-   React Native Testing Library

Test files:

ComponentName.test.tsx

------------------------------------------------------------------------

## Code Quality Rules

Never:

-   Use `any`
-   Put business logic in UI
-   Duplicate code
-   Ignore TypeScript errors

Always:

-   Write readable code
-   Use proper types
-   Split large components
9 views

Share Your Expo AI Rules

Have rules that improved your Expo workflow? Submit them to AI Rules Hub and help the community get better results from AI coding assistants.

Frequently Asked Questions

Expo AI rules are context files (like `.cursorrules` or `AGENTS.md`) that instruct AI coding assistants to follow Expo best practices — covering code style, architecture, error handling, and testing conventions.

Command Palette

Search for a command to run...