
Frontend Dev Guidelines
- 37 installs
- 16 repo stars
- Updated November 20, 2025
- jackspace/claudeskillz
This is a copy of frontend-dev-guidelines by davila7 - installs and ranking accrue to the original listing.
Helps with frontend development tasks.
About
frontend-dev-guidelines is a Claude Code skill for frontend development. It helps solo builders move faster with AI-assisted coding.
- frontend-dev-guidelines
- Frontend Development
- AI-coding skill
Frontend Dev Guidelines by the numbers
- 37 all-time installs (skills.sh)
- Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/jackspace/claudeskillz --skill frontend-dev-guidelinesAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 37 |
|---|---|
| repo stars | ★ 16 |
| Last updated | November 20, 2025 |
| Repository | jackspace/claudeskillz ↗ |
What it does
Helps with frontend development tasks.
Files
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
- Creating new components or pages
- Building new features
- Fetching data with TanStack Query
- Setting up routing with TanStack Router
- Styling components with MUI v7
- Performance optimization
- Organizing frontend code
- TypeScript best practices
---
Quick Start
New Component Checklist
Creating a component? Follow this checklist:
- [ ] Use
React.FC<Props>pattern with TypeScript - [ ] Lazy load if heavy component:
React.lazy(() => import()) - [ ] Wrap in
<SuspenseLoader>for loading states - [ ] Use
useSuspenseQueryfor data fetching - [ ] Import aliases:
@/,~types,~components,~features - [ ] Styles: Inline if <100 lines, separate file if >100 lines
- [ ] Use
useCallbackfor event handlers passed to children - [ ] Default export at bottom
- [ ] No early returns with loading spinners
- [ ] Use
useMuiSnackbarfor user notifications
New Feature Checklist
Creating a feature? Set up this structure:
- [ ] Create
features/{feature-name}/directory - [ ] Create subdirectories:
api/,components/,hooks/,helpers/,types/ - [ ] Create API service file:
api/{feature}Api.ts - [ ] Set up TypeScript types in
types/ - [ ] Create route in
routes/{feature-name}/index.tsx - [ ] Lazy load feature components
- [ ] Use Suspense boundaries
- [ ] Export public API from feature
index.ts
---
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:
React.FC<Props>for type safetyReact.lazy()for code splittingSuspenseLoaderfor loading states- Named const + default export pattern
Key Concepts:
- Lazy load heavy components (DataGrid, charts, editors)
- Always wrap lazy components in Suspense
- Use SuspenseLoader component (with fade animation)
- Component structure: Props → Hooks → Handlers → Render → Export
[📖 Complete Guide: resources/component-patterns.md](resources/component-patterns.md)
---
📊 Data Fetching
PRIMARY PATTERN: useSuspenseQuery
- Use with Suspense boundaries
- Cache-first strategy (check grid cache before API)
- Replaces
isLoadingchecks - Type-safe with generics
API Service Layer:
- Create
features/{feature}/api/{feature}Api.ts - Use
apiClientaxios instance - Centralized methods per feature
- Route format:
/form/route(NOT/api/form/route)
[📖 Complete Guide: resources/data-fetching.md](resources/data-fetching.md)
---
📁 File Organization
features/ vs components/:
features/: Domain-specific (posts, comments, auth)components/: Truly reusable (SuspenseLoader, CustomAppBar)
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](resources/file-organization.md)
---
🎨 Styling
Inline vs Separate:
- <100 lines: Inline
const styles: Record<string, SxProps<Theme>> - >100 lines: Separate
.styles.tsfile
Primary Method:
- Use
sxprop for MUI components - Type-safe with
SxProps<Theme> - Theme access:
(theme) => theme.palette.primary.main
MUI v7 Grid:
<Grid size={{ xs: 12, md: 6 }}> // ✅ v7 syntax
<Grid xs={12} md={6}> // ❌ Old syntax[📖 Complete Guide: resources/styling-guide.md](resources/styling-guide.md)
---
🛣️ Routing
TanStack Router - Folder-Based:
- Directory:
routes/my-route/index.tsx - Lazy load components
- Use
createFileRoute - Breadcrumb data in loader
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](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:
- Use
useMuiSnackbarfor user feedback - NEVER
react-toastify - TanStack Query
onErrorcallbacks
[📖 Complete Guide: resources/loading-and-error-states.md](resources/loading-and-error-states.md)
---
⚡ Performance
Optimization Patterns:
useMemo: Expensive computations (filter, sort, map)useCallback: Event handlers passed to childrenReact.memo: Expensive components- Debounced search (300-500ms)
- Memory leak prevention (cleanup in useEffect)
[📖 Complete Guide: resources/performance.md](resources/performance.md)
---
📘 TypeScript
Standards:
- Strict mode, no
anytype - Explicit return types on functions
- Type imports:
import type { User } from '~types/user' - Component prop interfaces with JSDoc
[📖 Complete Guide: resources/typescript-standards.md](resources/typescript-standards.md)
---
🔧 Common Patterns
Covered Topics:
- React Hook Form with Zod validation
- DataGrid wrapper contracts
- Dialog component standards
useAuthhook for current user- Mutation patterns with cache invalidation
[📖 Complete Guide: resources/common-patterns.md](resources/common-patterns.md)
---
📚 Complete Examples
Full working examples:
- Modern component with all patterns
- Complete feature structure
- API service layer
- Route with lazy loading
- Suspense + useSuspenseQuery
- Form with validation
[📖 Complete Guide: resources/complete-examples.md](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
- error-tracking: Error tracking with Sentry (applies to frontend too)
- backend-dev-guidelines: Backend API patterns that frontend consumes
---
Skill Status: Modular structure with progressive loading for optimal context management
{
"sections": {
"Common Imports Cheatsheet": "```typescript\r\n// React & Lazy Loading\r\nimport React, { useState, useCallback, useMemo } from 'react';\r\nconst Heavy = React.lazy(() => import('./Heavy'));\r\n\r\n// MUI Components\r\nimport { Box, Paper, Typography, Button, Grid } from '@mui/material';\r\nimport type { SxProps, Theme } from '@mui/material';\r\n\r\n// TanStack Query (Suspense)\r\nimport { useSuspenseQuery, useQueryClient } from '@tanstack/react-query';\r\n\r\n// TanStack Router\r\nimport { createFileRoute } from '@tanstack/react-router';\r\n\r\n// Project Components\r\nimport { SuspenseLoader } from '~components/SuspenseLoader';\r\n\r\n// Hooks\r\nimport { useAuth } from '@/hooks/useAuth';\r\nimport { useMuiSnackbar } from '@/hooks/useMuiSnackbar';\r\n\r\n// Types\r\nimport type { Post } from '~types/post';\r\n```\r\n\r\n---",
"Core Principles": "1. **Lazy Load Everything Heavy**: Routes, DataGrid, charts, editors\r\n2. **Suspense for Loading**: Use SuspenseLoader, not early returns\r\n3. **useSuspenseQuery**: Primary data fetching pattern for new code\r\n4. **Features are Organized**: api/, components/, hooks/, helpers/ subdirs\r\n5. **Styles Based on Size**: <100 inline, >100 separate\r\n6. **Import Aliases**: Use @/, ~types, ~components, ~features\r\n7. **No Early Returns**: Prevents layout shift\r\n8. **useMuiSnackbar**: For all user notifications\r\n\r\n---",
"Topic Guides": "### 🎨 Component Patterns\r\n\r\n**Modern React components use:**\r\n- `React.FC<Props>` for type safety\r\n- `React.lazy()` for code splitting\r\n- `SuspenseLoader` for loading states\r\n- Named const + default export pattern\r\n\r\n**Key Concepts:**\r\n- Lazy load heavy components (DataGrid, charts, editors)\r\n- Always wrap lazy components in Suspense\r\n- Use SuspenseLoader component (with fade animation)\r\n- Component structure: Props → Hooks → Handlers → Render → Export\r\n\r\n**[📖 Complete Guide: resources/component-patterns.md](resources/component-patterns.md)**\r\n\r\n---\r\n\r\n### 📊 Data Fetching\r\n\r\n**PRIMARY PATTERN: useSuspenseQuery**\r\n- Use with Suspense boundaries\r\n- Cache-first strategy (check grid cache before API)\r\n- Replaces `isLoading` checks\r\n- Type-safe with generics\r\n\r\n**API Service Layer:**\r\n- Create `features/{feature}/api/{feature}Api.ts`\r\n- Use `apiClient` axios instance\r\n- Centralized methods per feature\r\n- Route format: `/form/route` (NOT `/api/form/route`)\r\n\r\n**[📖 Complete Guide: resources/data-fetching.md](resources/data-fetching.md)**\r\n\r\n---\r\n\r\n### 📁 File Organization\r\n\r\n**features/ vs components/:**\r\n- `features/`: Domain-specific (posts, comments, auth)\r\n- `components/`: Truly reusable (SuspenseLoader, CustomAppBar)\r\n\r\n**Feature Subdirectories:**\r\n```\r\nfeatures/\r\n my-feature/\r\n api/ # API service layer\r\n components/ # Feature components\r\n hooks/ # Custom hooks\r\n helpers/ # Utility functions\r\n types/ # TypeScript types\r\n```\r\n\r\n**[📖 Complete Guide: resources/file-organization.md](resources/file-organization.md)**\r\n\r\n---\r\n\r\n### 🎨 Styling\r\n\r\n**Inline vs Separate:**\r\n- <100 lines: Inline `const styles: Record<string, SxProps<Theme>>`\r\n- >100 lines: Separate `.styles.ts` file\r\n\r\n**Primary Method:**\r\n- Use `sx` prop for MUI components\r\n- Type-safe with `SxProps<Theme>`\r\n- Theme access: `(theme) => theme.palette.primary.main`\r\n\r\n**MUI v7 Grid:**\r\n```typescript\r\n<Grid size={{ xs: 12, md: 6 }}> // ✅ v7 syntax\r\n<Grid xs={12} md={6}> // ❌ Old syntax\r\n```\r\n\r\n**[📖 Complete Guide: resources/styling-guide.md](resources/styling-guide.md)**\r\n\r\n---\r\n\r\n### 🛣️ Routing\r\n\r\n**TanStack Router - Folder-Based:**\r\n- Directory: `routes/my-route/index.tsx`\r\n- Lazy load components\r\n- Use `createFileRoute`\r\n- Breadcrumb data in loader\r\n\r\n**Example:**\r\n```typescript\r\nimport { createFileRoute } from '@tanstack/react-router';\r\nimport { lazy } from 'react';\r\n\r\nconst MyPage = lazy(() => import('@/features/my-feature/components/MyPage'));\r\n\r\nexport const Route = createFileRoute('/my-route/')({\r\n component: MyPage,\r\n loader: () => ({ crumb: 'My Route' }),\r\n});\r\n```\r\n\r\n**[📖 Complete Guide: resources/routing-guide.md](resources/routing-guide.md)**\r\n\r\n---\r\n\r\n### ⏳ Loading & Error States\r\n\r\n**CRITICAL RULE: No Early Returns**\r\n\r\n```typescript\r\n// ❌ NEVER - Causes layout shift\r\nif (isLoading) {\r\n return <LoadingSpinner />;\r\n}\r\n\r\n// ✅ ALWAYS - Consistent layout\r\n<SuspenseLoader>\r\n <Content />\r\n</SuspenseLoader>\r\n```\r\n\r\n**Why:** Prevents Cumulative Layout Shift (CLS), better UX\r\n\r\n**Error Handling:**\r\n- Use `useMuiSnackbar` for user feedback\r\n- NEVER `react-toastify`\r\n- TanStack Query `onError` callbacks\r\n\r\n**[📖 Complete Guide: resources/loading-and-error-states.md](resources/loading-and-error-states.md)**\r\n\r\n---\r\n\r\n### ⚡ Performance\r\n\r\n**Optimization Patterns:**\r\n- `useMemo`: Expensive computations (filter, sort, map)\r\n- `useCallback`: Event handlers passed to children\r\n- `React.memo`: Expensive components\r\n- Debounced search (300-500ms)\r\n- Memory leak prevention (cleanup in useEffect)\r\n\r\n**[📖 Complete Guide: resources/performance.md](resources/performance.md)**\r\n\r\n---\r\n\r\n### 📘 TypeScript\r\n\r\n**Standards:**\r\n- Strict mode, no `any` type\r\n- Explicit return types on functions\r\n- Type imports: `import type { User } from '~types/user'`\r\n- Component prop interfaces with JSDoc\r\n\r\n**[📖 Complete Guide: resources/typescript-standards.md](resources/typescript-standards.md)**\r\n\r\n---\r\n\r\n### 🔧 Common Patterns\r\n\r\n**Covered Topics:**\r\n- React Hook Form with Zod validation\r\n- DataGrid wrapper contracts\r\n- Dialog component standards\r\n- `useAuth` hook for current user\r\n- Mutation patterns with cache invalidation\r\n\r\n**[📖 Complete Guide: resources/common-patterns.md](resources/common-patterns.md)**\r\n\r\n---\r\n\r\n### 📚 Complete Examples\r\n\r\n**Full working examples:**\r\n- Modern component with all patterns\r\n- Complete feature structure\r\n- API service layer\r\n- Route with lazy loading\r\n- Suspense + useSuspenseQuery\r\n- Form with validation\r\n\r\n**[📖 Complete Guide: resources/complete-examples.md](resources/complete-examples.md)**\r\n\r\n---",
"Import Aliases Quick Reference": "| Alias | Resolves To | Example |\r\n|-------|-------------|---------|\r\n| `@/` | `src/` | `import { apiClient } from '@/lib/apiClient'` |\r\n| `~types` | `src/types` | `import type { User } from '~types/user'` |\r\n| `~components` | `src/components` | `import { SuspenseLoader } from '~components/SuspenseLoader'` |\r\n| `~features` | `src/features` | `import { authApi } from '~features/auth'` |\r\n\r\nDefined in: [vite.config.ts](../../vite.config.ts) lines 180-185\r\n\r\n---",
"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": "- Creating new components or pages\r\n- Building new features\r\n- Fetching data with TanStack Query\r\n- Setting up routing with TanStack Router\r\n- Styling components with MUI v7\r\n- Performance optimization\r\n- Organizing frontend code\r\n- TypeScript best practices\r\n\r\n---",
"Navigation Guide": "| Need to... | Read this resource |\r\n|------------|-------------------|\r\n| Create a component | [component-patterns.md](resources/component-patterns.md) |\r\n| Fetch data | [data-fetching.md](resources/data-fetching.md) |\r\n| Organize files/folders | [file-organization.md](resources/file-organization.md) |\r\n| Style components | [styling-guide.md](resources/styling-guide.md) |\r\n| Set up routing | [routing-guide.md](resources/routing-guide.md) |\r\n| Handle loading/errors | [loading-and-error-states.md](resources/loading-and-error-states.md) |\r\n| Optimize performance | [performance.md](resources/performance.md) |\r\n| TypeScript types | [typescript-standards.md](resources/typescript-standards.md) |\r\n| Forms/Auth/DataGrid | [common-patterns.md](resources/common-patterns.md) |\r\n| See full examples | [complete-examples.md](resources/complete-examples.md) |\r\n\r\n---",
"Quick Reference: File Structure": "```\r\nsrc/\r\n features/\r\n my-feature/\r\n api/\r\n myFeatureApi.ts # API service\r\n components/\r\n MyFeature.tsx # Main component\r\n SubComponent.tsx # Related components\r\n hooks/\r\n useMyFeature.ts # Custom hooks\r\n useSuspenseMyFeature.ts # Suspense hooks\r\n helpers/\r\n myFeatureHelpers.ts # Utilities\r\n types/\r\n index.ts # TypeScript types\r\n index.ts # Public exports\r\n\r\n components/\r\n SuspenseLoader/\r\n SuspenseLoader.tsx # Reusable loader\r\n CustomAppBar/\r\n CustomAppBar.tsx # Reusable app bar\r\n\r\n routes/\r\n my-route/\r\n index.tsx # Route component\r\n create/\r\n index.tsx # Nested route\r\n```\r\n\r\n---",
"Modern Component Template (Quick Copy)": "```typescript\r\nimport React, { useState, useCallback } from 'react';\r\nimport { Box, Paper } from '@mui/material';\r\nimport { useSuspenseQuery } from '@tanstack/react-query';\r\nimport { featureApi } from '../api/featureApi';\r\nimport type { FeatureData } from '~types/feature';\r\n\r\ninterface MyComponentProps {\r\n id: number;\r\n onAction?: () => void;\r\n}\r\n\r\nexport const MyComponent: React.FC<MyComponentProps> = ({ id, onAction }) => {\r\n const [state, setState] = useState<string>('');\r\n\r\n const { data } = useSuspenseQuery({\r\n queryKey: ['feature', id],\r\n queryFn: () => featureApi.getFeature(id),\r\n });\r\n\r\n const handleAction = useCallback(() => {\r\n setState('updated');\r\n onAction?.();\r\n }, [onAction]);\r\n\r\n return (\r\n <Box sx={{ p: 2 }}>\r\n <Paper sx={{ p: 3 }}>\r\n {/* Content */}\r\n </Paper>\r\n </Box>\r\n );\r\n};\r\n\r\nexport default MyComponent;\r\n```\r\n\r\nFor complete examples, see [resources/complete-examples.md](resources/complete-examples.md)\r\n\r\n---",
"Related Skills": "- **error-tracking**: Error tracking with Sentry (applies to frontend too)\r\n- **backend-dev-guidelines**: Backend API patterns that frontend consumes\r\n\r\n---\r\n\r\n**Skill Status**: Modular structure with progressive loading for optimal context management",
"Quick Start": "### New Component Checklist\r\n\r\nCreating a component? Follow this checklist:\r\n\r\n- [ ] Use `React.FC<Props>` pattern with TypeScript\r\n- [ ] Lazy load if heavy component: `React.lazy(() => import())`\r\n- [ ] Wrap in `<SuspenseLoader>` for loading states\r\n- [ ] Use `useSuspenseQuery` for data fetching\r\n- [ ] Import aliases: `@/`, `~types`, `~components`, `~features`\r\n- [ ] Styles: Inline if <100 lines, separate file if >100 lines\r\n- [ ] Use `useCallback` for event handlers passed to children\r\n- [ ] Default export at bottom\r\n- [ ] No early returns with loading spinners\r\n- [ ] Use `useMuiSnackbar` for user notifications\r\n\r\n### New Feature Checklist\r\n\r\nCreating a feature? Set up this structure:\r\n\r\n- [ ] Create `features/{feature-name}/` directory\r\n- [ ] Create subdirectories: `api/`, `components/`, `hooks/`, `helpers/`, `types/`\r\n- [ ] Create API service file: `api/{feature}Api.ts`\r\n- [ ] Set up TypeScript types in `types/`\r\n- [ ] Create route in `routes/{feature-name}/index.tsx`\r\n- [ ] Lazy load feature components\r\n- [ ] Use Suspense boundaries\r\n- [ ] Export public API from feature `index.ts`\r\n\r\n---"
},
"id": "frontend-dev-guidelines_diet103",
"name": "frontend-dev-guidelines",
"description": "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, pages, features, fetching data, styling, routing, or working with frontend code."
}---
name: frontend-dev-guidelines
description: 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, pages, features, fetching data, styling, routing, or working with frontend code.
---
# 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
- Creating new components or pages
- Building new features
- Fetching data with TanStack Query
- Setting up routing with TanStack Router
- Styling components with MUI v7
- Performance optimization
- Organizing frontend code
- TypeScript best practices
---
## Quick Start
### New Component Checklist
Creating a component? Follow this checklist:
- [ ] Use `React.FC<Props>` pattern with TypeScript
- [ ] Lazy load if heavy component: `React.lazy(() => import())`
- [ ] Wrap in `<SuspenseLoader>` for loading states
- [ ] Use `useSuspenseQuery` for data fetching
- [ ] Import aliases: `@/`, `~types`, `~components`, `~features`
- [ ] Styles: Inline if <100 lines, separate file if >100 lines
- [ ] Use `useCallback` for event handlers passed to children
- [ ] Default export at bottom
- [ ] No early returns with loading spinners
- [ ] Use `useMuiSnackbar` for user notifications
### New Feature Checklist
Creating a feature? Set up this structure:
- [ ] Create `features/{feature-name}/` directory
- [ ] Create subdirectories: `api/`, `components/`, `hooks/`, `helpers/`, `types/`
- [ ] Create API service file: `api/{feature}Api.ts`
- [ ] Set up TypeScript types in `types/`
- [ ] Create route in `routes/{feature-name}/index.tsx`
- [ ] Lazy load feature components
- [ ] Use Suspense boundaries
- [ ] Export public API from feature `index.ts`
---
## 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](../../vite.config.ts) lines 180-185
---
## Common Imports Cheatsheet
```typescript
// 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:**
- `React.FC<Props>` for type safety
- `React.lazy()` for code splitting
- `SuspenseLoader` for loading states
- Named const + default export pattern
**Key Concepts:**
- Lazy load heavy components (DataGrid, charts, editors)
- Always wrap lazy components in Suspense
- Use SuspenseLoader component (with fade animation)
- Component structure: Props → Hooks → Handlers → Render → Export
**[📖 Complete Guide: resources/component-patterns.md](resources/component-patterns.md)**
---
### 📊 Data Fetching
**PRIMARY PATTERN: useSuspenseQuery**
- Use with Suspense boundaries
- Cache-first strategy (check grid cache before API)
- Replaces `isLoading` checks
- Type-safe with generics
**API Service Layer:**
- Create `features/{feature}/api/{feature}Api.ts`
- Use `apiClient` axios instance
- Centralized methods per feature
- Route format: `/form/route` (NOT `/api/form/route`)
**[📖 Complete Guide: resources/data-fetching.md](resources/data-fetching.md)**
---
### 📁 File Organization
**features/ vs components/:**
- `features/`: Domain-specific (posts, comments, auth)
- `components/`: Truly reusable (SuspenseLoader, CustomAppBar)
**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](resources/file-organization.md)**
---
### 🎨 Styling
**Inline vs Separate:**
- <100 lines: Inline `const styles: Record<string, SxProps<Theme>>`
- >100 lines: Separate `.styles.ts` file
**Primary Method:**
- Use `sx` prop for MUI components
- Type-safe with `SxProps<Theme>`
- Theme access: `(theme) => theme.palette.primary.main`
**MUI v7 Grid:**
```typescript
<Grid size={{ xs: 12, md: 6 }}> // ✅ v7 syntax
<Grid xs={12} md={6}> // ❌ Old syntax
```
**[📖 Complete Guide: resources/styling-guide.md](resources/styling-guide.md)**
---
### 🛣️ Routing
**TanStack Router - Folder-Based:**
- Directory: `routes/my-route/index.tsx`
- Lazy load components
- Use `createFileRoute`
- Breadcrumb data in loader
**Example:**
```typescript
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](resources/routing-guide.md)**
---
### ⏳ Loading & Error States
**CRITICAL RULE: No Early Returns**
```typescript
// ❌ NEVER - Causes layout shift
if (isLoading) {
return <LoadingSpinner />;
}
// ✅ ALWAYS - Consistent layout
<SuspenseLoader>
<Content />
</SuspenseLoader>
```
**Why:** Prevents Cumulative Layout Shift (CLS), better UX
**Error Handling:**
- Use `useMuiSnackbar` for user feedback
- NEVER `react-toastify`
- TanStack Query `onError` callbacks
**[📖 Complete Guide: resources/loading-and-error-states.md](resources/loading-and-error-states.md)**
---
### ⚡ Performance
**Optimization Patterns:**
- `useMemo`: Expensive computations (filter, sort, map)
- `useCallback`: Event handlers passed to children
- `React.memo`: Expensive components
- Debounced search (300-500ms)
- Memory leak prevention (cleanup in useEffect)
**[📖 Complete Guide: resources/performance.md](resources/performance.md)**
---
### 📘 TypeScript
**Standards:**
- Strict mode, no `any` type
- Explicit return types on functions
- Type imports: `import type { User } from '~types/user'`
- Component prop interfaces with JSDoc
**[📖 Complete Guide: resources/typescript-standards.md](resources/typescript-standards.md)**
---
### 🔧 Common Patterns
**Covered Topics:**
- React Hook Form with Zod validation
- DataGrid wrapper contracts
- Dialog component standards
- `useAuth` hook for current user
- Mutation patterns with cache invalidation
**[📖 Complete Guide: resources/common-patterns.md](resources/common-patterns.md)**
---
### 📚 Complete Examples
**Full working examples:**
- Modern component with all patterns
- Complete feature structure
- API service layer
- Route with lazy loading
- Suspense + useSuspenseQuery
- Form with validation
**[📖 Complete Guide: resources/complete-examples.md](resources/complete-examples.md)**
---
## Navigation Guide
| Need to... | Read this resource |
|------------|-------------------|
| Create a component | [component-patterns.md](resources/component-patterns.md) |
| Fetch data | [data-fetching.md](resources/data-fetching.md) |
| Organize files/folders | [file-organization.md](resources/file-organization.md) |
| Style components | [styling-guide.md](resources/styling-guide.md) |
| Set up routing | [routing-guide.md](resources/routing-guide.md) |
| Handle loading/errors | [loading-and-error-states.md](resources/loading-and-error-states.md) |
| Optimize performance | [performance.md](resources/performance.md) |
| TypeScript types | [typescript-standards.md](resources/typescript-standards.md) |
| Forms/Auth/DataGrid | [common-patterns.md](resources/common-patterns.md) |
| See full examples | [complete-examples.md](resources/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)
```typescript
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](resources/complete-examples.md)
---
## Related Skills
- **error-tracking**: Error tracking with Sentry (applies to frontend too)
- **backend-dev-guidelines**: Backend API patterns that frontend consumes
---
**Skill Status**: Modular structure with progressive loading for optimal context management