Frontend dev guidelines

From davila7/claude-code-templates · View interactive version

Frontend dev guidelines is an AI agent skill from the GitHub repository davila7/claude-code-templates. Frontend development guidelines for React/TypeScript applications. Modern patterns including Suspense, lazy loading, useSuspenseQuery, file organization with features directory, MUI v7 styling, TanStack Router, performance optimization, and TypeScript best practices. Use when creating components, pa

How to use this skill

Skill file

Frontend Development Guidelines

Purpose

Comprehensive guide for modern React development, emphasizing Suspense-based data fetching, lazy loading, proper file organization, and performance optimization.

When to Use This Skill


Quick Start

New Component Checklist

Creating a component? Follow this checklist:

New Feature Checklist

Creating a feature? Set up this structure:


Import Aliases Quick Reference

| Alias | Resolves To | Example |

|-------|-------------|---------|

| @/ | src/ | import { apiClient } from '@/lib/apiClient' |

| ~types | src/types | import type { User } from '~types/user' |

| ~components | src/components | import { SuspenseLoader } from '~components/SuspenseLoader' |

| ~features | src/features | import { authApi } from '~features/auth' |

Defined in: vite.config.ts lines 180-185


Common Imports Cheatsheet

// React & Lazy Loading
import React, { useState, useCallback, useMemo } from 'react';
const Heavy = React.lazy(() => import('./Heavy'));

// MUI Components
import { Box, Paper, Typography, Button, Grid } from '@mui/material';
import type { SxProps, Theme } from '@mui/material';

// TanStack Query (Suspense)
import { useSuspenseQuery, useQueryClient } from '@tanstack/react-query';

// TanStack Router
import { createFileRoute } from '@tanstack/react-router';

// Project Components
import { SuspenseLoader } from '~components/SuspenseLoader';

// Hooks
import { useAuth } from '@/hooks/useAuth';
import { useMuiSnackbar } from '@/hooks/useMuiSnackbar';

// Types
import type { Post } from '~types/post';

Topic Guides

🎨 Component Patterns

Modern React components use:

Key Concepts:

📖 Complete Guide: resources/component-patterns.md


📊 Data Fetching

PRIMARY PATTERN: useSuspenseQuery

API Service Layer:

📖 Complete Guide: resources/data-fetching.md


📁 File Organization

features/ vs components/:

Feature Subdirectories:

features/
  my-feature/
    api/          # API service layer
    components/   # Feature components
    hooks/        # Custom hooks
    helpers/      # Utility functions
    types/        # TypeScript types

📖 Complete Guide: resources/file-organization.md


🎨 Styling

Inline vs Separate:

Primary Method:

MUI v7 Grid:

<Grid size={{ xs: 12, md: 6 }}>  // ✅ v7 syntax
<Grid xs={12} md={6}>             // ❌ Old syntax

📖 Complete Guide: resources/styling-guide.md


🛣️ Routing

TanStack Router - Folder-Based:

Example:

import { createFileRoute } from '@tanstack/react-router';
import { lazy } from 'react';

const MyPage = lazy(() => import('@/features/my-feature/components/MyPage'));

export const Route = createFileRoute('/my-route/')({
    component: MyPage,
    loader: () => ({ crumb: 'My Route' }),
});

📖 Complete Guide: resources/routing-guide.md


⏳ Loading & Error States

CRITICAL RULE: No Early Returns

// ❌ NEVER - Causes layout shift
if (isLoading) {
    return <LoadingSpinner />;
}

// ✅ ALWAYS - Consistent layout
<SuspenseLoader>
    <Content />
</SuspenseLoader>

Why: Prevents Cumulative Layout Shift (CLS), better UX

Error Handling:

📖 Complete Guide: resources/loading-and-error-states.md


⚡ Performance

Optimization Patterns:

📖 Complete Guide: resources/performance.md


📘 TypeScript

Standards:

📖 Complete Guide: resources/typescript-standards.md


🔧 Common Patterns

Covered Topics:

📖 Complete Guide: resources/common-patterns.md


📚 Complete Examples

Full working examples:

📖 Complete Guide: resources/complete-examples.md


Navigation Guide

| Need to... | Read this resource |

|------------|-------------------|

| Create a component | component-patterns.md |

| Fetch data | data-fetching.md |

| Organize files/folders | file-organization.md |

| Style components | styling-guide.md |

| Set up routing | routing-guide.md |

| Handle loading/errors | loading-and-error-states.md |

| Optimize performance | performance.md |

| TypeScript types | typescript-standards.md |

| Forms/Auth/DataGrid | common-patterns.md |

| See full examples | complete-examples.md |


Core Principles

  1. Lazy Load Everything Heavy: Routes, DataGrid, charts, editors
  2. Suspense for Loading: Use SuspenseLoader, not early returns
  3. useSuspenseQuery: Primary data fetching pattern for new code
  4. Features are Organized: api/, components/, hooks/, helpers/ subdirs
  5. Styles Based on Size: <100 inline, >100 separate
  6. Import Aliases: Use @/, ~types, ~components, ~features
  7. No Early Returns: Prevents layout shift
  8. useMuiSnackbar: For all user notifications

Quick Reference: File Structure

src/
  features/
    my-feature/
      api/
        myFeatureApi.ts       # API service
      components/
        MyFeature.tsx         # Main component
        SubComponent.tsx      # Related components
      hooks/
        useMyFeature.ts       # Custom hooks
        useSuspenseMyFeature.ts  # Suspense hooks
      helpers/
        myFeatureHelpers.ts   # Utilities
      types/
        index.ts              # TypeScript types
      index.ts                # Public exports

  components/
    SuspenseLoader/
      SuspenseLoader.tsx      # Reusable loader
    CustomAppBar/
      CustomAppBar.tsx        # Reusable app bar

  routes/
    my-route/
      index.tsx               # Route component
      create/
        index.tsx             # Nested route

Modern Component Template (Quick Copy)

import React, { useState, useCallback } from 'react';
import { Box, Paper } from '@mui/material';
import { useSuspenseQuery } from '@tanstack/react-query';
import { featureApi } from '../api/featureApi';
import type { FeatureData } from '~types/feature';

interface MyComponentProps {
    id: number;
    onAction?: () => void;
}

export const MyComponent: React.FC<MyComponentProps> = ({ id, onAction }) => {
    const [state, setState] = useState<string>('');

    const { data } = useSuspenseQuery({
        queryKey: ['feature', id],
        queryFn: () => featureApi.getFeature(id),
    });

    const handleAction = useCallback(() => {
        setState('updated');
        onAction?.();
    }, [onAction]);

    return (
        <Box sx={{ p: 2 }}>
            <Paper sx={{ p: 3 }}>
                {/* Content */}
            </Paper>
        </Box>
    );
};

export default MyComponent;

For complete examples, see resources/complete-examples.md


Related Skills


Skill Status: Modular structure with progressive loading for optimal context management

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.