All skills
🖥️

Frontend Review

Best Practices

Comprehensive audit of your app's interface. Reviews how it's built, how fast it loads, accessibility, and file sizes. Helps catch the issues that make apps feel slow or bloated.

Skill prompt

Frontend Audit Skill

Perform a comprehensive audit of React and Next.js applications covering component architecture, performance, accessibility, state management, and framework-specific best practices.

1. Component Architecture

Component Size and Complexity:

bash
# Find large component files (over 300 lines)
find . -name "*.tsx" -not -path "*/node_modules/*" | xargs wc -l | sort -rn | head -30

# Find components with excessive JSX return blocks
grep -rn "return\s*(" . --include="*.tsx" -l | while read f; do
  count=$(grep -c "<" "$f" 2>/dev/null)
  if [ "$count" -gt 100 ]; then
    echo "$f: $count JSX elements"
  fi
done

Prop Drilling Detection:

bash
# Find components passing many props (potential prop drilling)
grep -rn "props\.\|{.*,.*,.*,.*,.*}" . --include="*.tsx" | grep -v "node_modules" | head -30

# Find deeply nested prop passing (same prop name across multiple files)
for prop in $(grep -roh '\b\w*Id\b' . --include="*.tsx" -h | sort | uniq -c | sort -rn | head -10 | awk '{print $2}'); do
  echo "=== Prop: $prop ==="
  grep -rn "$prop" . --include="*.tsx" --include="*.ts" | grep -v "node_modules" | head -5
done

Single Responsibility Violations:

bash
# Find components with multiple useEffect hooks (may do too much)
grep -rl "useEffect" . --include="*.tsx" | while read f; do
  count=$(grep -c "useEffect" "$f")
  if [ "$count" -gt 3 ]; then
    echo "$f: $count useEffect calls"
  fi
done

# Find components mixing data fetching with UI logic
grep -rln "fetch\|axios\|useSWR\|useQuery" . --include="*.tsx" | while read f; do
  if grep -q "return.*<" "$f"; then
    echo "Mixed concerns: $f"
  fi
done

Colocation Check:

bash
# Find component directories missing colocated test files
find . -name "*.tsx" -not -name "*.test.*" -not -name "*.spec.*" -not -path "*/node_modules/*" | while read f; do
  dir=$(dirname "$f")
  base=$(basename "$f" .tsx)
  if [ ! -f "$dir/$base.test.tsx" ] && [ ! -f "$dir/$base.spec.tsx" ] && [ ! -f "$dir/__tests__/$base.test.tsx" ]; then
    echo "Missing test: $f"
  fi
done

2. React Patterns

Hook Rules Violations:

bash
# Find hooks called conditionally (inside if/for/while blocks)
grep -rn "if\s*(.*)\s*{" . --include="*.tsx" --include="*.ts" -A10 | grep "use[A-Z]\w*("

# Find hooks called after early returns
grep -rn "return\s" . --include="*.tsx" -A20 | grep "use[A-Z]\w*("

Missing Dependency Arrays:

bash
# Find useEffect/useMemo/useCallback without dependency arrays
grep -rn "useEffect(\s*(" . --include="*.tsx" --include="*.ts" | grep -v "\[" | grep -v "node_modules"
grep -rn "useMemo(\s*(" . --include="*.tsx" --include="*.ts" | grep -v "\[" | grep -v "node_modules"
grep -rn "useCallback(\s*(" . --include="*.tsx" --include="*.ts" | grep -v "\[" | grep -v "node_modules"

# Find useEffect with empty dependency arrays that reference outer variables
grep -rn "useEffect" . --include="*.tsx" -A10 | grep "\[\]" | head -20

Stale Closures and References:

bash
# Find state used inside setTimeout/setInterval without refs
grep -rn "setTimeout\|setInterval" . --include="*.tsx" --include="*.ts" -B5 -A5 | grep -v "node_modules"

# Find event handlers referencing state that may be stale
grep -rn "addEventListener" . --include="*.tsx" -A5 | grep "useState\|state\." | grep -v "node_modules"

Unnecessary Re-renders:

bash
# Find inline object/array creation in JSX props (causes re-renders)
grep -rn 'style={{' . --include="*.tsx" | grep -v "node_modules"
grep -rn '={{\s*\w' . --include="*.tsx" | grep -v "style=" | grep -v "node_modules" | head -20

# Find inline arrow functions in JSX event handlers
grep -rn 'on\w\+={() =>' . --include="*.tsx" | grep -v "node_modules" | head -20

# Find components creating new arrays/objects each render
grep -rn "const.*=\s*\[" . --include="*.tsx" | grep -v "useState\|useMemo\|useRef" | grep -v "node_modules" | head -20

Missing Keys:

bash
# Find .map() calls in JSX that may lack proper keys
grep -rn "\.map(" . --include="*.tsx" -A3 | grep -v "key=" | grep "<" | grep -v "node_modules" | head -20

Direct DOM Manipulation:

bash
# Find direct DOM manipulation (anti-pattern in React)
grep -rn "document\.getElementById\|document\.querySelector\|document\.getElement" . --include="*.tsx" --include="*.ts" | grep -v "node_modules"
grep -rn "\.innerHTML\|\.outerHTML\|\.insertAdjacentHTML" . --include="*.tsx" --include="*.ts" | grep -v "node_modules"

3. Next.js Specifics

Server vs Client Components:

bash
# Find all 'use client' directives
grep -rln "'use client'\|\"use client\"" . --include="*.tsx" --include="*.ts" | grep -v "node_modules"

# Count ratio of client to server components
total=$(find . -name "*.tsx" -not -path "*/node_modules/*" | wc -l)
client=$(grep -rln "'use client'" . --include="*.tsx" | grep -v "node_modules" | wc -l)
echo "Total components: $total, Client components: $client, Server components: $((total - client))"

# Find 'use client' files that do not use any client features
grep -rln "'use client'" . --include="*.tsx" | grep -v "node_modules" | while read f; do
  if ! grep -q "useState\|useEffect\|useRef\|useCallback\|useMemo\|useReducer\|useContext\|onClick\|onChange\|onSubmit\|onKeyDown\|addEventListener" "$f"; then
    echo "Unnecessary 'use client': $f"
  fi
done

Route Organization:

bash
# Check for proper App Router structure
find . -path "*/app/*" -name "page.tsx" -not -path "*/node_modules/*" | sort
find . -path "*/app/*" -name "layout.tsx" -not -path "*/node_modules/*" | sort

# Check for missing loading/error/not-found boundaries
find . -path "*/app/*" -name "page.tsx" -not -path "*/node_modules/*" | while read f; do
  dir=$(dirname "$f")
  missing=""
  [ ! -f "$dir/loading.tsx" ] && missing="$missing loading.tsx"
  [ ! -f "$dir/error.tsx" ] && missing="$missing error.tsx"
  [ ! -f "$dir/not-found.tsx" ] && missing="$missing not-found.tsx"
  if [ -n "$missing" ]; then
    echo "$dir: missing$missing"
  fi
done

Metadata and SEO:

bash
# Find pages without metadata exports
find . -path "*/app/*" -name "page.tsx" -not -path "*/node_modules/*" | while read f; do
  if ! grep -q "export.*metadata\|generateMetadata" "$f"; then
    layout=$(dirname "$f")/layout.tsx
    if [ ! -f "$layout" ] || ! grep -q "export.*metadata\|generateMetadata" "$layout"; then
      echo "Missing metadata: $f"
    fi
  fi
done

# Check for missing OpenGraph images
find . -path "*/app/*" -name "opengraph-image.*" -not -path "*/node_modules/*" | head -10

Image Component Usage:

bash
# Find <img> tags that should use next/image
grep -rn "<img " . --include="*.tsx" --include="*.jsx" | grep -v "node_modules" | grep -v "next/image"

# Find next/image without width/height or fill
grep -rn "<Image" . --include="*.tsx" -A5 | grep -v "width=\|height=\|fill" | grep "<Image" | grep -v "node_modules"

# Find images without alt text
grep -rn "<Image\|<img" . --include="*.tsx" | grep -v "alt=" | grep -v "node_modules"

Font Optimization:

bash
# Check for Google Fonts loaded via <link> instead of next/font
grep -rn "fonts.googleapis.com\|fonts.gstatic.com" . --include="*.tsx" --include="*.html" --include="*.ts" | grep -v "node_modules"

# Verify next/font usage
grep -rn "next/font" . --include="*.tsx" --include="*.ts" | grep -v "node_modules"

4. State Management

Prop Drilling That Should Be Context or Store:

bash
# Find props passed through 3+ component levels (same prop name in parent-child chain)
grep -rn "interface.*Props" . --include="*.tsx" --include="*.ts" -A20 | grep -v "node_modules" | grep ":\s*\w" | awk -F: '{print $NF}' | sort | uniq -c | sort -rn | head -20

# Find components receiving more than 8 props
grep -rn "interface.*Props" . --include="*.tsx" -A30 | grep -v "node_modules" | grep "}" -m1 | head -20

Oversized Context Causing Re-renders:

bash
# Find large context providers (many values bundled together)
grep -rn "createContext\|React\.createContext" . --include="*.tsx" --include="*.ts" -l | grep -v "node_modules" | while read f; do
  echo "=== $f ==="
  grep -A30 "Provider value=" "$f" | head -35
done

# Find contexts without value splitting
grep -rn "Provider value={{" . --include="*.tsx" | grep -v "node_modules"

Client State That Should Be Server State:

bash
# Find useState for data that looks like it should be fetched server-side
grep -rn "useState.*\[\])\|useState.*null)" . --include="*.tsx" | grep -v "node_modules" -A3 | grep "fetch\|axios\|api"

# Find client-side data fetching in components that could be Server Components
grep -rln "useEffect" . --include="*.tsx" | grep -v "node_modules" | while read f; do
  if grep -q "fetch\|axios" "$f" && ! grep -q "'use client'" "$f"; then
    echo "Fetch in effect without 'use client': $f"
  fi
done

URL State Underuse:

bash
# Find filter/sort/search state stored in useState instead of URL params
grep -rn "useState.*filter\|useState.*sort\|useState.*search\|useState.*query\|useState.*page\b\|useState.*tab" . --include="*.tsx" -i | grep -v "node_modules"

# Check for missing useSearchParams usage
grep -rln "useSearchParams" . --include="*.tsx" --include="*.ts" | grep -v "node_modules" | wc -l

5. Performance

Missing Memoization Where Measurably Needed:

bash
# Find expensive computations in render without useMemo
grep -rn "\.filter(\|\.sort(\|\.reduce(\|\.map(" . --include="*.tsx" | grep -v "useMemo\|useCallback" | grep -v "node_modules" | head -20

# Find components receiving object/array props without React.memo
grep -rn "export default function\|export function\|export const" . --include="*.tsx" | grep -v "React\.memo\|memo(" | grep -v "node_modules" | head -20

# Find large list renders without virtualization
grep -rn "\.map(" . --include="*.tsx" -B5 | grep "items\|list\|data\|results\|rows" | grep -v "node_modules" | head -20

Missing Suspense Boundaries:

bash
# Find lazy-loaded components without Suspense wrappers
grep -rn "React\.lazy\|lazy(" . --include="*.tsx" --include="*.ts" | grep -v "node_modules"
grep -rn "<Suspense" . --include="*.tsx" | grep -v "node_modules"

# Compare counts
lazy_count=$(grep -rn "React\.lazy\|lazy(" . --include="*.tsx" --include="*.ts" | grep -v "node_modules" | wc -l)
suspense_count=$(grep -rn "<Suspense" . --include="*.tsx" | grep -v "node_modules" | wc -l)
echo "Lazy components: $lazy_count, Suspense boundaries: $suspense_count"

Missing Lazy Loading:

bash
# Find heavy components imported statically that could be lazy loaded
grep -rn "import.*Modal\|import.*Dialog\|import.*Drawer\|import.*Chart\|import.*Editor\|import.*Map" . --include="*.tsx" | grep -v "lazy\|dynamic" | grep -v "node_modules"

# Check for next/dynamic usage
grep -rn "next/dynamic" . --include="*.tsx" --include="*.ts" | grep -v "node_modules"

Excessive Client-Side JavaScript:

bash
# Find large client component files
grep -rln "'use client'" . --include="*.tsx" | grep -v "node_modules" | while read f; do
  lines=$(wc -l < "$f")
  if [ "$lines" -gt 200 ]; then
    echo "$f: $lines lines"
  fi
done

# Check for heavy libraries imported in client components
grep -rln "'use client'" . --include="*.tsx" | grep -v "node_modules" | while read f; do
  if grep -q "import.*moment\|import.*lodash\b\|import.*d3\b\|import.*chart" "$f"; then
    echo "Heavy import in client component: $f"
  fi
done

6. Styling

Inconsistent Styling Patterns:

bash
# Detect mixed styling approaches
css_modules=$(find . -name "*.module.css" -o -name "*.module.scss" | grep -v "node_modules" | wc -l)
tailwind=$(grep -rln "className=\".*\(flex\|grid\|p-\|m-\|text-\|bg-\)" . --include="*.tsx" | grep -v "node_modules" | wc -l)
styled=$(grep -rln "styled\.\|styled(" . --include="*.tsx" --include="*.ts" | grep -v "node_modules" | wc -l)
inline=$(grep -rn "style={{" . --include="*.tsx" | grep -v "node_modules" | wc -l)
echo "CSS Modules: $css_modules, Tailwind: $tailwind, Styled Components: $styled, Inline styles: $inline"

Unused Styles:

bash
# Find CSS module classes that may be unused
find . -name "*.module.css" -not -path "*/node_modules/*" | while read css; do
  component="${css%.module.css}.tsx"
  if [ -f "$component" ]; then
    grep -oP '\.\K[a-zA-Z_][a-zA-Z0-9_-]*' "$css" | while read class; do
      if ! grep -q "$class" "$component"; then
        echo "Possibly unused class .$class in $css"
      fi
    done
  fi
done

!important Abuse:

bash
# Find !important declarations
grep -rn "!important" . --include="*.css" --include="*.scss" --include="*.module.css" | grep -v "node_modules"

Magic Values:

bash
# Find hardcoded pixel values that should be design tokens
grep -rn "[0-9]\+px" . --include="*.css" --include="*.scss" --include="*.module.css" | grep -v "node_modules" | grep -v "0px\|1px" | head -30

# Find hardcoded colors that should be tokens
grep -rn "#[0-9a-fA-F]\{3,8\}" . --include="*.tsx" --include="*.css" --include="*.scss" | grep -v "node_modules" | head -20

7. Accessibility

Missing ARIA Labels:

bash
# Find interactive elements without accessible labels
grep -rn "<button\|<a \|<input\|<select\|<textarea" . --include="*.tsx" | grep -v "aria-label\|aria-labelledby\|title=\|<button>.*<\/button>" | grep -v "node_modules" | head -20

# Find icon-only buttons without labels
grep -rn "<button" . --include="*.tsx" -A3 | grep "Icon\|icon\|svg" | grep -v "aria-label\|sr-only\|visually-hidden" | grep -v "node_modules" | head -20

Non-Semantic HTML:

bash
# Find div/span used where semantic elements should be
grep -rn '<div.*onClick\|<span.*onClick' . --include="*.tsx" | grep -v "role=" | grep -v "node_modules" | head -20

# Find missing landmark elements
grep -rn "<header\|<main\|<nav\|<footer\|<aside\|<section\|<article" . --include="*.tsx" | grep -v "node_modules" | wc -l

Keyboard Navigation:

bash
# Find elements with onClick but no onKeyDown/onKeyUp
grep -rn "onClick" . --include="*.tsx" | grep -v "button\|<a \|<input\|<select\|Link\|Button\|onKeyDown\|onKeyUp\|role=" | grep -v "node_modules" | head -20

# Find custom components with tabIndex but missing keyboard handlers
grep -rn "tabIndex" . --include="*.tsx" | grep -v "onKeyDown\|onKeyUp" | grep -v "node_modules"

Color Contrast and Focus Management:

bash
# Find focus-related styles being removed
grep -rn "outline:\s*none\|outline:\s*0\|:focus.*outline" . --include="*.css" --include="*.scss" --include="*.tsx" | grep -v "focus-visible\|focus-within" | grep -v "node_modules"

# Find missing focus-visible styles
grep -rn "focus-visible" . --include="*.css" --include="*.scss" --include="*.tsx" | grep -v "node_modules" | wc -l

8. Data Fetching

Waterfall Requests:

bash
# Find sequential awaits that could be parallelized
grep -rn "await" . --include="*.tsx" --include="*.ts" -A1 | grep -v "node_modules" | grep -A1 "await" | grep "await" | head -20

# Find nested data fetching (fetch inside fetch callback)
grep -rn "\.then(.*fetch\|await.*await" . --include="*.tsx" --include="*.ts" | grep -v "node_modules" | head -20

Missing Error and Loading States:

bash
# Find data fetching without error handling
grep -rn "useQuery\|useSWR\|fetch(" . --include="*.tsx" | grep -v "error\|Error\|catch\|isError" | grep -v "node_modules" | head -20

# Find components with loading state but no error handling
grep -rln "isLoading\|loading" . --include="*.tsx" | grep -v "node_modules" | while read f; do
  if ! grep -q "error\|Error\|isError" "$f"; then
    echo "Loading without error state: $f"
  fi
done

Over-Fetching:

bash
# Find API calls fetching all fields when only some are needed
grep -rn "fetch\|axios\.get\|useQuery" . --include="*.tsx" --include="*.ts" -A5 | grep -v "select\|fields\|pick\|pluck" | grep "\/api\/" | grep -v "node_modules" | head -20

Caching Strategy:

bash
# Check for missing cache/revalidation in Next.js fetch
grep -rn "fetch(" . --include="*.tsx" --include="*.ts" | grep -v "cache\|revalidate\|next:" | grep -v "node_modules" | grep -v "'use client'" | head -20

# Check React Query/SWR stale time configuration
grep -rn "staleTime\|cacheTime\|revalidateOnFocus\|dedupingInterval" . --include="*.tsx" --include="*.ts" | grep -v "node_modules"

9. Bundle Analysis

Large Dependencies With Lighter Alternatives:

bash
# Check for heavy libraries
grep -rn "\"moment\"\|'moment'" package.json
grep -rn "\"lodash\"\|'lodash'" package.json
grep -rn "\"date-fns\"\|'date-fns'" package.json
grep -rn "\"classnames\"\|'classnames'" package.json

# Check for full lodash import instead of specific functions
grep -rn "import.*from ['\"]lodash['\"]" . --include="*.tsx" --include="*.ts" | grep -v "lodash/" | grep -v "node_modules"

# Check for moment.js (should use date-fns or dayjs)
grep -rn "import.*moment\|require.*moment" . --include="*.tsx" --include="*.ts" | grep -v "node_modules"

Barrel File Import Costs:

bash
# Find barrel files (index.ts exporting everything)
find . -name "index.ts" -not -path "*/node_modules/*" | while read f; do
  exports=$(grep -c "export" "$f")
  if [ "$exports" -gt 10 ]; then
    echo "Large barrel file ($exports exports): $f"
  fi
done

# Find imports from barrel files
grep -rn "from ['\"]\.\.\/\.\.\/" . --include="*.tsx" --include="*.ts" | grep -v "node_modules" | head -20

Dynamic Import Opportunities:

bash
# Find large static imports that could be dynamic
grep -rn "import.*from" . --include="*.tsx" --include="*.ts" | grep -v "node_modules\|type " | grep "Chart\|Editor\|Modal\|Map\|PDF\|Markdown\|CodeMirror\|Monaco" | grep -v "dynamic\|lazy"

10. Audit Report Format

Generate findings in this structure:

markdown
# Frontend Audit Report

## Summary

- Files audited: X
- Critical issues: X
- Warnings: X
- Suggestions: X
- Passing checks: X

## Critical (must fix)

| #   | Category      | Issue                     | File:Line                 | Impact                                |
| --- | ------------- | ------------------------- | ------------------------- | ------------------------------------- |
| 1   | Accessibility | Button missing aria-label | src/components/Nav.tsx:45 | Screen readers cannot identify action |
| 2   | Performance   | Unoptimized image in LCP  | src/app/page.tsx:12       | Core Web Vitals regression            |

## Warnings (should fix)

| #   | Category       | Issue                          | File:Line                 | Impact                 |
| --- | -------------- | ------------------------------ | ------------------------- | ---------------------- |
| 1   | React Patterns | Missing useEffect dependencies | src/hooks/useAuth.tsx:23  | Stale closure bug risk |
| 2   | Next.js        | Unnecessary 'use client'       | src/components/Card.tsx:1 | Larger client bundle   |

## Suggestions (nice to have)

| #   | Category | Issue                              | File:Line                    | Impact                   |
| --- | -------- | ---------------------------------- | ---------------------------- | ------------------------ |
| 1   | State    | Filter state should use URL params | src/app/products/page.tsx:18 | Non-shareable page state |
| 2   | Bundle   | Replace moment with dayjs          | package.json:15              | ~65KB bundle reduction   |

## Positive Observations

- Consistent use of next/image for optimized images
- Good Suspense boundary coverage on route segments
- Proper use of Server Components for data fetching

## Recommended Next Steps

1. Address all Critical accessibility issues first
2. Add missing error/loading boundaries to route segments
3. Audit 'use client' directives and convert eligible components to Server Components
4. Set up bundle analysis in CI to prevent regressions

Severity Guidelines

  • Critical: Accessibility violations blocking users, security issues, data loss risks, broken functionality
  • Warning: Performance regressions, stale closures, missing error states, unnecessary client components, React anti-patterns
  • Suggestion: Bundle size optimizations, code organization improvements, pattern inconsistencies, missing but non-blocking best practices

When to Use This Skill

Use /frontend-audit when:

  • Reviewing a React or Next.js codebase for quality issues
  • Preparing for a production launch
  • Investigating rendering performance problems
  • Checking accessibility compliance
  • Evaluating component architecture before a refactor
  • Auditing bundle size and client-side JavaScript footprint
  • Verifying proper use of Next.js App Router patterns