agentleFS
bybren-llcbybren-llc/safe-agentic-workflow/.agents/skills/frontend-patterns/SKILL.md

frontend-patterns

Skill419 starsChanged 4 months agoMITView on GitHub

Frontend patterns for modern web frameworks, component libraries, auth flows, and analytics. Use when building UI components, creating pages, implementing auth flows, adding analytics events, or working with component libraries. Do NOT use for API-only or backend-only changes.

  • Reads credentials

46 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use kotlin-testing, configure-ecc and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • tpavanipradeepSkill

    kotlin-testing

    Kotlin testing patterns with Kotest, MockK, coroutine testing, property-based testing, and Kover coverage. Follows TDD methodology with idiomatic Kotlin practices.

    Also in 6 projects that use this

  • saxon-ySkill

    configure-ecc

    Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.

    Also in 12 projects that use this

  • mryeastcodeSkill

    nuxt4-patterns

    Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.

    Also in 5 projects that use this

  • InfopibeSkill

    content-hash-cache-pattern

    Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.

    Also in 11 projects that use this

  • InfopibeSkill

    ralphinho-rfc-pipeline

    RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.

    Also in 9 projects that use this

  • WorldFlowAISkill

    project-guidelines-example

    Also in 18 projects that use this

  • +3 more from Infopibe

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Ensure consistent frontend development using established patterns for your framework (Next.js App Router, React, etc.), authentication …

    line 16
  2. Distinctive:

    CRITICAL: Always use forced dynamic rendering for authenticated pages:

    line 57
  3. Distinctive:

    Use snake_case with category prefix:

    line 216

“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Frontend Patterns Skill

TEMPLATE: This skill uses {{PLACEHOLDER}} tokens. Replace with your project values before use.

Purpose

Ensure consistent frontend development using established patterns for your framework (Next.js App Router, React, etc.), authentication provider, UI component library, and analytics platform.

When This Skill Applies

  • Building new UI components or pages
  • Implementing authentication flows
  • Adding forms with validation
  • Integrating analytics events
  • Creating protected/authenticated routes
  • Working with component libraries (shadcn/ui, Radix, etc.)

Server vs Client Components

// SERVER COMPONENT (default) - Use for:
// - Data fetching
// - Auth checks
// - SEO-critical content
import { auth } from "{{AUTH_SERVER_IMPORT}}";

export default async function DashboardPage() {
  const { userId } = await auth();
  // Fetch data server-side...
}

// CLIENT COMPONENT - Use for:
// - Interactivity (onClick, onChange)
// - Browser APIs (localStorage, window)
// - Hooks (useState, useEffect)
"use client";

import { useState } from "react";

export function InteractiveWidget() {
  const [count, setCount] = useState(0);
  // Interactive logic...
}

Protected Pages

CRITICAL: Always use forced dynamic rendering for authenticated pages:

import { auth } from "{{AUTH_SERVER_IMPORT}}";
import { redirect } from "next/navigation";

// REQUIRED - Auth context unavailable at build time
export const dynamic = "force-dynamic";

export default async function ProtectedPage() {
  const { userId } = await auth();

  if (!userId) {
    redirect("/sign-in");
  }

  // Render protected content...
}

Route Organization

app/
+-- (auth)/                    # Auth routes (sign-in, sign-up)
+-- (marketing)/               # Public marketing pages
|   +-- page.tsx               # Homepage
|   +-- pricing/page.tsx
+-- dashboard/                 # Protected user area
|   +-- page.tsx
|   +-- _components/           # Page-specific components
+-- admin/                     # Admin-only area
    +-- page.tsx

Authentication Patterns

Server Component Auth

import { auth } from "{{AUTH_SERVER_IMPORT}}";

export default async function Page() {
  const { userId } = await auth();
  // userId is string | null
}

Client Component Auth

"use client";
import { useUser, useAuth } from "{{AUTH_CLIENT_IMPORT}}";

export function UserProfile() {
  const { user, isLoaded, isSignedIn } = useUser();
  const { signOut } = useAuth();

  if (!isLoaded) return <Skeleton />;
  if (!isSignedIn) return <SignInPrompt />;

  return <div>Welcome, {user.firstName}!</div>;
}

Admin Verification

import { auth } from "{{AUTH_SERVER_IMPORT}}";
import { redirect } from "next/navigation";

export const dynamic = "force-dynamic";

export default async function AdminPage() {
  const { userId, orgId, orgRole } = await auth();

  if (!userId) {
    redirect("/sign-in");
  }

  // Verify admin role
  const ADMIN_ORG_ID = process.env.{{ADMIN_ORG_ENV_VAR}};
  const ADMIN_ROLE = "org:admin";

  if (orgId !== ADMIN_ORG_ID || orgRole !== ADMIN_ROLE) {
    redirect("/admin-denied");
  }

  // Render admin content...
}

Component Library Patterns

Import Convention

// Always use path alias for components
import { Button } from "{{UI_COMPONENTS_PATH}}/button";
import { Card, CardHeader, CardTitle, CardContent } from "{{UI_COMPONENTS_PATH}}/card";
import { Input } from "{{UI_COMPONENTS_PATH}}/input";

Form Pattern (React Hook Form + Zod)

"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { Button } from "{{UI_COMPONENTS_PATH}}/button";
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "{{UI_COMPONENTS_PATH}}/form";
import { Input } from "{{UI_COMPONENTS_PATH}}/input";

const FormSchema = z.object({
  email: z.string().email("Invalid email"),
  name: z.string().min(1, "Name is required"),
});

type FormData = z.infer<typeof FormSchema>;

export function MyForm() {
  const form = useForm<FormData>({
    resolver: zodResolver(FormSchema),
    defaultValues: { email: "", name: "" },
  });

  async function onSubmit(data: FormData) {
    // Handle submission...
  }

  return (
    <Form {...form}>
      <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
        <FormField
          control={form.control}
          name="name"
          render={({ field }) => (
            <FormItem>
              <FormLabel>Name</FormLabel>
              <FormControl>
                <Input {...field} />
              </FormControl>
              <FormMessage />
            </FormItem>
          )}
        />
        <Button type="submit">Submit</Button>
      </form>
    </Form>
  );
}

Analytics Patterns

Event Naming Convention

Use snake_case with category prefix:

user_signed_up, user_signed_in, user_profile_updated
feature_dark_mode_toggled, feature_export_clicked
payment_checkout_started, payment_completed, subscription_upgraded
page_viewed, cta_clicked

Event Tracking

"use client";

import { usePostHog } from "{{ANALYTICS_IMPORT}}";

export function TrackableButton() {
  const posthog = usePostHog();

  function handleClick() {
    posthog?.capture("cta_clicked", {
      button_text: "Get Started",
      page: "/pricing",
      variant: "primary",
    });
  }

  return <Button onClick={handleClick}>Get Started</Button>;
}

Feature Flags

"use client";

import { useFeatureFlagEnabled } from "{{ANALYTICS_IMPORT}}";

export function FeatureFlaggedComponent() {
  const showNewFeature = useFeatureFlagEnabled("new-checkout-flow");

  if (showNewFeature) {
    return <NewCheckoutFlow />;
  }

  return <LegacyCheckoutFlow />;
}

Accessibility Checklist

Required for all components:

  • Keyboard Navigation: All interactive elements focusable via Tab
  • Focus Indicators: Visible focus ring
  • Color Contrast: 4.5:1 minimum for text
  • Alt Text: All images have descriptive alt text
  • ARIA Labels: Form inputs have labels or aria-label
  • Error States: Form errors announced to screen readers

Responsive Design Patterns

// Mobile-first approach (Tailwind)
<div className="px-4 md:px-6 lg:px-8">

// Responsive grid
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">

// Hide/show at breakpoints
<div className="hidden md:block">Desktop only</div>
<div className="md:hidden">Mobile only</div>

Common Mistakes to Avoid

// WRONG: Missing 'use client' for interactive components
import { useState } from "react"; // Will error!

// WRONG: Using hooks in server components
export default async function Page() {
  const [state, setState] = useState(); // Will error!
}

// WRONG: Missing force-dynamic on auth pages
export default async function ProtectedPage() {
  const { userId } = await auth(); // May fail at build!
}

// WRONG: Inline styles (use Tailwind or CSS modules)
<div style={{ marginTop: "20px" }}>  // Use className="mt-5"

Authoritative References

  • UI Patterns: patterns_library/ui/
  • Component Library: {{UI_COMPONENTS_PATH}}
  • Analytics Setup: {{ANALYTICS_CONFIG_PATH}}
  • Feature Flags: {{FEATURE_FLAGS_CONFIG}}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.