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.

referencesapi-layer.md

≈829 tokens on demand. Your agent reads this file only when SKILL.md points to it.

API Layer

Single API Client Instance

Use a single, pre-configured API client instance throughout the application. This can be built with the native fetch API or libraries like axios, graphql-request, or apollo-client.

// src/lib/api-client.ts
import axios from "axios";

const api = axios.create({
    baseURL: import.meta.env.VITE_API_URL,
    headers: { "Content-Type": "application/json" },
});

api.interceptors.response.use(
    (response) => response.data,
    (error) => {
        const message = error.response?.data?.message || error.message;
        // Trigger notification toast
        // Log out on 401
        return Promise.reject(error);
    },
);

export { api };

Request Declaration Pattern

Every API request declaration consists of:

  1. Types and validation schemas for request and response data
  2. A fetcher function that calls an endpoint using the API client
  3. A hook that consumes the fetcher via react-query, swr, etc.

Query Example

// features/discussions/api/get-discussions.ts
import { useQuery, type QueryConfig } from "@tanstack/react-query";
import { api } from "@/lib/api-client";

type Discussion = {
    id: string;
    title: string;
    body: string;
    createdAt: string;
};

type GetDiscussionsParams = {
    teamId: string;
};

function getDiscussions(params: GetDiscussionsParams): Promise<Discussion[]> {
    return api.get("/discussions", { params });
}

type UseDiscussionsOptions = {
    params: GetDiscussionsParams;
    queryConfig?: QueryConfig<typeof getDiscussions>;
};

export function useDiscussions({ params, queryConfig }: UseDiscussionsOptions) {
    return useQuery({
        queryKey: ["discussions", params],
        queryFn: () => getDiscussions(params),
        ...queryConfig,
    });
}

Mutation Example

// features/discussions/api/create-discussion.ts
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { api } from "@/lib/api-client";

type CreateDiscussionInput = {
    title: string;
    body: string;
    teamId: string;
};

function createDiscussion(data: CreateDiscussionInput): Promise<Discussion> {
    return api.post("/discussions", data);
}

export function useCreateDiscussion() {
    const queryClient = useQueryClient();

    return useMutation({
        mutationFn: createDiscussion,
        onSuccess: () => {
            queryClient.invalidateQueries({ queryKey: ["discussions"] });
        },
    });
}

File Organization

features/users/api/
├── get-users.ts       # useUsers query hook + API function
├── get-user.ts        # useUser query hook + API function
├── create-user.ts     # useCreateUser mutation hook + API function
├── update-user.ts     # useUpdateUser mutation hook + API function
└── index.ts           # re-exports all hooks

In some cases it may be more practical to keep shared API calls in a dedicated top-level api/ folder rather than inside features.

Key Principles

  • Keep API functions pure — they return promises with no framework dependencies.
  • Type all responses and infer types down the application for type safety.
  • Handle errors centrally in the API client via interceptors.
  • Colocate API declarations with the features that use them.

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