Index of every page on this site: llms.txt
All skills
grahamcrackers avatar

/bulletproof-react-patterns

@ca83de4
Run it yourself

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.

Use this Skill: https://skilld.dev/gh/grahamcrackers/skills/bulletproof-react-patterns

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈109 tokens for metadata: the name and description. ≈1.7k when used: this file. ≈8.1k more on demand in 10 files.

Description uses 5.4% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈435 characters, or 5.4%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Bulletproof React Patterns

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

Core References

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

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 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:

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

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

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill is an architectural guide for React development, providing best practices for project structure, state management, and testing. It contains exclusively educational content and code examples with no executable or malicious scripts.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer9mo

    1/11 files flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at ca83de4. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 9 months ago

README badge

README badge for grahamcrackers/skills/bulletproof-react-patterns