---
name: bulletproof-react-patterns
description: Bulletproof React architecture patterns for scalable, maintainable applications. Covers feature-based project structure, component patterns, state management boundaries, API layer design, error handling, security, and testing strategies. Use when structuring a React project, designing application architecture, organizing features, or when the user asks about React project structure or scalable patterns.
title: bulletproof-react-patterns
canonical_url: https://skilld.dev/gh/grahamcrackers/skills/bulletproof-react-patterns
last_updated: 2026-10-07T02:20:44.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/api-layer.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/api-layer.md), [references/components-and-styling.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/components-and-styling.md), [references/error-handling.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/error-handling.md), [references/performance.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/performance.md), [references/project-standards.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/project-standards.md), [references/project-structure.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/project-structure.md), [references/README.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/README.md), [references/security.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/security.md), [references/state-management.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/state-management.md), [references/testing.md](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/testing.md).
>
> If the user asked to install this Skill, run `npx skilld install grahamcrackers/skills/bulletproof-react-patterns`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/bulletproof-react-patterns`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/grahamcrackers/skills/bulletproof-react-patterns) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/bulletproof-react-patterns`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/bulletproof-react-patterns --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/bulletproof-react-patterns --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Bulletproof React Patterns

Architecture patterns for building scalable, maintainable React applications. Based on [bulletproof-react](https://github.com/alan2207/bulletproof-react).

## Core References

| Topic                | Description                                                                     | Reference                                                      |
| -------------------- | ------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| Project Structure    | Feature-based organization, unidirectional architecture, ESLint enforcement     | [project-structure](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/project-structure.md)           |
| Components & Styling | Component hierarchy, wrapping 3rd party libs, headless vs styled libraries      | [components-and-styling](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/components-and-styling.md) |
| API Layer            | API client, request declarations, query/mutation hook patterns                  | [api-layer](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/api-layer.md)                           |
| State Management     | Component, application, server cache, form, and URL state categories            | [state-management](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/state-management.md)             |
| Error Handling       | Error boundaries, API errors, error tracking with Sentry                        | [error-handling](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/error-handling.md)                 |
| Testing              | Unit, integration, e2e strategies with Vitest, Testing Library, Playwright, MSW | [testing](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/testing.md)                               |
| Project Standards    | ESLint, Prettier, TypeScript, Husky, absolute imports, file naming              | [project-standards](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/project-standards.md)           |
| Security             | Authentication, token storage, XSS prevention, RBAC/PBAC authorization          | [security](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/security.md)                             |
| Performance          | Code splitting, data prefetching, state optimization, children pattern          | [performance](https://skilld.dev/api/skills-raw/grahamcrackers/skills/bulletproof-react-patterns/references/performance.md)                       |

## Project Structure

Organize by feature, not by file type:

```
src/
├── app/                # Application shell (routes, providers, router)
├── assets/             # Static files (images, fonts)
├── components/         # Shared, reusable UI components
├── config/             # Environment variables, constants
├── features/           # Feature-based modules
├── hooks/              # Shared custom hooks
├── lib/                # Pre-configured library wrappers
├── stores/             # Global client state
├── testing/            # Test utilities, MSW handlers, factories
├── types/              # Shared TypeScript types
└── utils/              # Pure utility functions
```

### Feature Modules

```
features/users/
├── api/            # API functions and query hooks
├── components/     # Feature-specific components
├── hooks/          # Feature-specific hooks
├── types/          # Feature-specific types
└── utils/          # Feature-specific utilities
```

**Rules:**

- Features should not import from other features. Compose at the app level.
- Code flows one direction: **shared → features → app**.
- Promote to shared directories only when reused by 2+ features.
- Prefer direct imports over barrel re-exports for Vite tree-shaking.

## Component Hierarchy

```
Page Components          → route-level, compose features, handle layout
  └── Feature Components → feature-specific, business logic
        └── UI Components      → shared primitives, no business logic
```

## API Layer Pattern

```typescript
// Pure API function
function getUsers(params?: GetUsersParams): Promise<UsersResponse> {
    return api.get("/users", { params });
}

// Query hook wrapping the API function
function useUsers(params?: GetUsersParams) {
    return useQuery({
        queryKey: ["users", params],
        queryFn: () => getUsers(params),
    });
}
```

## State Management Boundaries

| State Type            | Solution                   | Examples                              |
| --------------------- | -------------------------- | ------------------------------------- |
| Server state          | TanStack Query             | User data, posts, API responses       |
| Client state (global) | Zustand / Jotai            | Theme, sidebar open, user preferences |
| Client state (local)  | useState / useReducer      | Form inputs, toggles, modal open      |
| URL state             | URL search params / router | Filters, pagination, active tab       |
| Form state            | React Hook Form            | Multi-step forms, validation          |

**Don't mix server and client state.** Never copy query data into `useState`.

## Error Hierarchy

```
App Error Boundary          → catches unrecoverable crashes
  └── Route Error Boundary     → catches route-level failures, shows retry
        └── Feature Error Boundary   → catches feature-specific errors
```

## Testing Strategy

| Layer       | Tool                  | What to Test                                    |
| ----------- | --------------------- | ----------------------------------------------- |
| Components  | Testing Library       | Render output, user interactions, a11y          |
| Hooks       | renderHook            | State changes, side effects                     |
| API         | MSW                   | Request/response handling, error states         |
| Integration | Testing Library + MSW | Full feature flows (render → interact → verify) |
| E2E         | Playwright            | Critical user journeys                          |

## Conventions

| Item        | Convention              | Example                   |
| ----------- | ----------------------- | ------------------------- |
| Components  | PascalCase              | `UserCard.tsx`            |
| Hooks       | camelCase, `use` prefix | `useUsers.ts`             |
| Utilities   | camelCase               | `formatDate.ts`           |
| Types       | PascalCase              | `User`, `CreateUserInput` |
| Constants   | UPPER_SNAKE_CASE        | `MAX_RETRIES`             |
| Directories | kebab-case              | `user-settings/`          |
| Files       | kebab-case              | `user-card.tsx`           |

### Imports

Use path aliases to avoid deep relative imports:

```typescript
import { Button } from "@/components/ui/button";
import { useUsers } from "@/features/users/api";
```

Configure `@/` as the `src/` alias in `tsconfig.json`.
