frontend-rules

A set of frontend development rules for React 18+, TypeScript, Tailwind CSS, React Router, and React Query or SWR.

In plain words
What is it for?
Use it when organizing React components, defining props and state, choosing local or global state, and structuring frontend test files.
Why use it?
It gives a shared structure for components, types, styling, routing, data fetching, and state management, reducing inconsistent frontend code.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/ddr187/cursor-howto/frontend-rules
Clone the repo
git clone --depth 1 https://github.com/DDR187/cursor-howto
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,411 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01411
Opus 5 $0.00000 $0.00705
Sonnet 5 $0.00000 $0.00282
Haiku 4.5 $0.00000 $0.00141

Measured 2d ago against content hash 8cc983d0657b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

frontend-rules scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

02-rules/frontend-rules.mdc · 321 lines

How it starts

The opening of the file, as written. The whole thing — 321 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Frontend Development Rules

Tech Stack

  • React 18+
  • TypeScript 5+
  • Tailwind CSS
  • React Router v6
  • React Query / SWR

Component Standards

Component Structure

ComponentName/
├── index.tsx          # Component entry
├── ComponentName.tsx  # Component implementation
├── styles.css         # Style file
├── types.ts           # Type definitions
├── hooks.ts           # Component Hooks
└── __tests__/         # Test files
    └── ComponentName.test.tsx

Component Template

import { FC } from 'react';

interface ComponentNameProps {
  title: string;
  onClick?: () => void;
}

export const ComponentName: FC<ComponentNameProps> = ({
  title,
  onClick
}) => {
  return (
    <div className="component-container" onClick={onClick}>
      <h1>{title}</h1>
    </div>
  );
};

Component Principles

  • Single responsibility principle
  • Appropriate component granularity
  • Clear Props types
  • Reasonable default values

State Management

Local State

// Simple state
const [count, setCount] = useState(0);

// Complex state
const [state, dispatch] = useReducer(reducer, initialState);

Global State

  • Use Zustand for global state
  • Use React Query for server state
  • Avoid overusing global state

State Selectors

// Use selectors for performance optimization
const user = useUserStore(state => state.user);
const isLoading = useUserStore(state => state.isLoading);

Style Standards

Tailwind CSS

// Recommended approach
<div className="flex items-center justify-between p-4 bg-white rounded-lg shadow-md">
  {/* content */}
</div>

// Extract complex styles as components
const Card = ({ children }) => (
  <div className="p-4 bg-white rounded-lg shadow-md">
    {children}
  </div>
);

CSS Variables

:root {
  --color-primary: #3b82f6;
  --color-secondary: #64748b;
  --spacing-md: 1rem;
}

Responsive Design

// Mobile-first principle
<div className="w-full md:w-1/2 lg:w-1/3">
  {/* content */}
</div>

Read the full file on GitHub · 321 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 321 lines · 0 tokens per session scan A 8cc983d0657b

Subscribe to this mod's changes

frontend-rules is a cursor rule published in the GitHub repository DDR187/cursor-howto (2 stars, last pushed 5mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,411 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.