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.

referencessecurity.md

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

Security

Authentication

Client-side authentication enhances UX and complements server-side security — both are essential.

Token Storage

Method Pros Cons
Application state Most secure Lost on refresh
HttpOnly cookies Inaccessible to JS, XSS-resistant Requires server-side setup
localStorage Persists across sessions Vulnerable to XSS

Recommended: Store tokens in HttpOnly cookies configured by the server. The client should not have direct access to the token.

XSS Prevention

Sanitize all user inputs before displaying them:

import DOMPurify from "dompurify";

function MarkdownPreview({ content }: { content: string }) {
    const sanitized = DOMPurify.sanitize(content);
    return <div dangerouslySetInnerHTML={{ __html: sanitized }} />;
}

Avoid dangerouslySetInnerHTML unless content is sanitized. React escapes JSX by default, but raw HTML insertion bypasses this.

User Data Management

Treat user info as global state accessible throughout the application. Options:

  • TanStack Query (if already using it) — via react-query-auth
  • React Context + hooks
  • Third-party state management (Zustand, Redux)

The application assumes the user is authenticated if a user object is present.

Authorization

RBAC (Role-Based Access Control)

Restrict access based on user roles (ADMIN, USER, etc.):

function RBACGuard({ allowedRoles, children }: { allowedRoles: Role[]; children: React.ReactNode }) {
    const { user } = useAuth();
    if (!user || !allowedRoles.includes(user.role)) return null;
    return children;
}

// Usage
<RBACGuard allowedRoles={["ADMIN"]}>
    <AdminPanel />
</RBACGuard>;

PBAC (Permission-Based Access Control)

For finer-grained control where access depends on resource ownership:

function PBACGuard({ check, children }: { check: boolean; children: React.ReactNode }) {
    if (!check) return null;
    return children;
}

// Only the comment author can delete it
<PBACGuard check={comment.authorId === currentUser.id}>
    <DeleteCommentButton commentId={comment.id} />
</PBACGuard>;

Combined Usage

Use the same guard component with either role-based or policy-based checks:

// Role-based
<Authorization allowedRoles={["ADMIN"]}>
  <DeleteUserButton />
</Authorization>

// Policy-based
<Authorization policyCheck={comment.authorId === user.id}>
  <DeleteCommentButton />
</Authorization>

Use RBAC for broad role-level access. Use PBAC for resource-level ownership checks.

Security Resources

For a full list of client-side security risks, see OWASP Top 10 Client-Side Security Risks.

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