mcpField
B
bulletproof-react-patterns

bulletproof-react-patterns

github.com/grahamcrackersDevelopment0153 installsUpdated 36w ago
Repository

About bulletproof-react-patterns

bulletproof-react-patterns is an architecture guide for React developers, based on bulletproof-react. It covers practices from project structure to testing, security, and performance.

Key features

  1. 01Organize projects by feature
  2. 02Define component and API layers
  3. 03Separate client and server state
  4. 04Plan error handling and testing
  5. 05Cover security and performance

Use cases

  1. 01Plan structure for a large React app
  2. 02Establish API, state, and error patterns
  3. 03Define component, integration, and end-to-end tests

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/grahamcrackers/skills --skill bulletproof-react-patterns

After installing, type/bulletproof-react-patternsin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
api-layer.md
components-and-styling.md
error-handling.md
performance.md
project-standards.md
project-structure.md
README.md
security.md
state-management.md
testing.md

Details

From the project README

Bulletproof React Patterns

Architecture patterns for building scalable, maintainable React applications. Based on bulletproof-react.

Core References

TopicDescriptionReference
Project StructureFeature-based organization, unidirectional architecture, ESLint enforcementproject-structure
Components & StylingComponent hierarchy, wrapping 3rd party libs, headless vs styled librariescomponents-and-styling
API LayerAPI client, request declarations, query/mutation hook patternsapi-layer
State ManagementComponent, application, server cache, form, and URL state categoriesstate-management
Error HandlingError boundaries, API errors, error tracking with Sentryerror-handling
TestingUnit, integration, e2e strategies with Vitest, Testing Library, Playwright, MSWtesting
Project StandardsESLint, Prettier, TypeScript, Husky, absolute imports, file namingproject-standards
SecurityAuthentication, token storage, XSS prevention, RBAC/PBAC authorizationsecurity
PerformanceCode splitting, data prefetching, state optimization, children patternperformance

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

// 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 TypeSolutionExamples
Server stateTanStack QueryUser data, posts, API responses
Client state (global)Zustand / JotaiTheme, sidebar open, user preferences
Client state (local)useState / useReducerForm inputs, toggles, modal open
URL stateURL search params / routerFilters, pagination, active tab
Form stateReact Hook FormMulti-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

LayerToolWhat to Test
ComponentsTesting LibraryRender output, user interactions, a11y
HooksrenderHookState changes, side effects
APIMSWRequest/response handling, error states
IntegrationTesting Library + MSWFull feature flows (render → interact → verify)
E2EPlaywrightCritical user journeys

Conventions

ItemConventionExample
ComponentsPascalCaseUserCard.tsx
HookscamelCase, use prefixuseUsers.ts
UtilitiescamelCaseformatDate.ts
TypesPascalCaseUser, CreateUserInput
ConstantsUPPER_SNAKE_CASEMAX_RETRIES
Directorieskebab-caseuser-settings/
Fileskebab-caseuser-card.tsx
Imports

Use path aliases to avoid deep relative imports:

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

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

Comments

Markdown supported