cursor-handbook / frontend
Cursor rule31 starsChanged 3 months agoMITView on GitHub
Frontend component architecture and patterns. Apply when creating or editing UI components.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository30 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/architecture/core-principles.mdcCursor rule
- .cursor/rules/architecture/dependency-management.mdcCursor rule
- .cursor/rules/architecture/token-efficiency.mdcCursor rule
- .cursor/rules/backend/api-design.mdcCursor rule
- .cursor/rules/backend/code-organization.mdcCursor rule
- .cursor/rules/backend/error-handling.mdcCursor rule
- .cursor/rules/backend/handler-patterns.mdcCursor rule
- .cursor/rules/backend/nodejs.mdcCursor rule
- .cursor/rules/backend/typescript.mdcCursor rule
- .cursor/rules/cloud/containerization.mdcCursor rule
- .cursor/rules/cloud/infrastructure.mdcCursor rule
- .cursor/rules/cloud/serverless.mdcCursor rule
- .cursor/rules/database/migration-rules.mdcCursor rule
- .cursor/rules/database/query-patterns.mdcCursor rule
- .cursor/rules/database/schema-design.mdcCursor rule
- .cursor/rules/devops/ci-cd.mdcCursor rule
- .cursor/rules/devops/documentation-standards.mdcCursor rule
- .cursor/rules/devops/monitoring.mdcCursor rule
- .cursor/rules/frontend/accessibility.mdcCursor rule
- .cursor/rules/frontend/performance.mdcCursor rule
- .cursor/rules/frontend/state-management.mdcCursor rule
- .cursor/rules/main-rules.mdcCursor rule
- .cursor/rules/security/guardrails.mdcCursor rule
- .cursor/rules/security/secrets-rules.mdcCursor rule
- .cursor/rules/security/security-compliance.mdcCursor rule
- .cursor/rules/testing/integration-testing.mdcCursor rule
- .cursor/rules/testing/mock-patterns.mdcCursor rule
- .cursor/rules/testing/testing-standards.mdcCursor rule
The file
Show its rules and text
We split this component-patterns.mdc into the rules it gives an agent
15 rules. About 0 are common, 11 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 37
Use functional components with hooks — no class components
- Very specific: line 38
Use React.FC or explicit return types
- Distinctive: line 43
Use descriptive prop names
- Distinctive: line 45
Document complex props with JSDoc comments
- Very specific: line 87
Use React.memo for pure presentational components
- Distinctive: line 92
Use CSS Modules, Tailwind CSS, or styled-components — pick one, be consistent
- Distinctive: line 93
No inline styles except for dynamic values
- Distinctive: line 94
Follow design system tokens for colors, spacing, typography
- Very specific: line 99
Don't use any for props — define explicit interface
- Distinctive: line 108
Don't fetch in useEffect without cleanup — cancel on unmount
- Distinctive: line 109
Don't put server data in global state — use React Query
- Distinctive: line 110
Don't use index as key when list can reorder — use stable id
- Distinctive: line 111
Don't inline object/array in JSX — causes unnecessary re-renders
- Distinctive: line 126
List virtualization: Use when >100 items; set item height for scroll
- Very specific: line 129
Use @component-creation skill for new components
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Frontend component architecture and patterns. Apply when creating or editing UI components."
alwaysApply: false
globs: "**/*.tsx,**/*.jsx,**/components/**/*,**/Components/**/*"
---
# Frontend Component Patterns
## Component Structure
```
src/components/
├── ui/ # Atomic/base components
│ ├── Button/
│ │ ├── Button.tsx
│ │ ├── Button.test.tsx
│ │ ├── Button.stories.tsx
│ │ └── index.ts
│ ├── Input/
│ └── Modal/
├── features/ # Feature-specific components
│ ├── Auth/
│ ├── Dashboard/
│ └── Settings/
├── layout/ # Layout components
│ ├── Header/
│ ├── Sidebar/
│ └── Footer/
└── shared/ # Shared/utility components
├── ErrorBoundary/
├── LoadingSpinner/
└── ProtectedRoute/
```
## Component Guidelines
### Functional Components Only
- Use functional components with hooks — no class components
- Use `React.FC` or explicit return types
- Destructure props at the function signature level
### Props
- Define props interface above the component
- Use descriptive prop names
- Provide default values where appropriate
- Document complex props with JSDoc comments
```tsx
interface ButtonProps {
/** Button label text */
label: string;
/** Visual style variant */
variant?: 'primary' | 'secondary' | 'danger';
/** Disabled state */
disabled?: boolean;
/** Click handler */
onClick: () => void;
}
export const Button: React.FC<ButtonProps> = ({
label,
variant = 'primary',
disabled = false,
onClick,
}) => {
return (
<button
className={`btn btn-${variant}`}
disabled={disabled}
onClick={onClick}
>
{label}
</button>
);
};
```
### State Management
- Local state: `useState` for component-scoped state
- Shared state: Context API or state library (Zustand, Redux Toolkit)
- Server state: React Query / TanStack Query
- Form state: React Hook Form or Formik
- **NEVER** prop-drill more than 2 levels — use context or state management
### Performance
- Memoize expensive computations with `useMemo`
- Memoize callbacks with `useCallback` when passing to child components
- Use `React.memo` for pure presentational components
- Lazy load routes and heavy components with `React.lazy`
- Virtualize long lists (react-window or react-virtuoso)
## Styling Rules
- Use CSS Modules, Tailwind CSS, or styled-components — pick one, be consistent
- No inline styles except for dynamic values
- Follow design system tokens for colors, spacing, typography
- Mobile-first responsive design
- Support dark mode via CSS variables or theme context
## Anti-patterns
- Don't use `any` for props — define explicit interface
```tsx
// BAD
const Button = (props: any) => ...
// GOOD
interface ButtonProps { label: string; onClick: () => void; }
```
- Don't fetch in useEffect without cleanup — cancel on unmount
- Don't put server data in global state — use React Query
- Don't use index as key when list can reorder — use stable id
- Don't inline object/array in JSX — causes unnecessary re-renders
## Examples
```tsx
// BAD: New object every render
<Child onClick={() => ({})} />
// GOOD: Stable callback
const noop = useCallback(() => {}, []);
<Child onClick={noop} />
```
## Edge Cases
- **Loading states**: Skeleton > spinner > empty; handle error state
- **Form validation**: Show errors on blur or submit; don't block typing
- **List virtualization**: Use when >100 items; set item height for scroll
## Related
- Use `@component-creation` skill for new components
- See `@accessibility` for a11y requirements
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
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.

