| name | react-rules |
| description | React architecture rules for both auditing and development. Use when asked to "review components", "check architecture", "audit this react project", "does this follow react rules", "review my frontend structure", "add a new page", "add a new component", "add a new store domain", "implement this feature", or when starting any React development task. |
| version | 1.0.0 |
React Architecture Rules
This skill is the definitive source for React architecture rules. Any agent (architect, dev, or otherwise) should load this skill for authoritative rules on components, store, structure, and design style.
1. Stack
Expected stack: React 19 + Vite + TypeScript + Tailwind CSS v4 + shadcn/ui + Redux Toolkit + React Router
Key conventions:
- Path alias
@ → src/ — all imports use @/ paths
- All filenames use kebab-case — no exceptions:
my-component.tsx, login-form.tsx
- Missing shadcn primitive →
pnpm dlx shadcn@latest add <component> (installs into src/components/ui/)
2. Structure
src/pages/ — one file per route; no components defined here
src/store/{domain}/ — slice.ts + api.ts + index.ts per domain
src/lib/ — shared utilities only (api.ts, token.ts, utils.ts)
src/components/auth/ — PrivateRoute / PublicRoute guards only
src/components/ui/ — shadcn components only, never edited manually
src/components/{feature}/ — feature-specific components
src/components/common/ — cross-cutting utility components
- Path alias
@ → src/ — all imports use @/ paths
Naming Rules
Import Rules
3. Components
Body Ordering
Every component must follow this order — no interleaving:
- Declarations — all
const together: hooks (useParams, useState, useAppSelector, RTK Query), then derived values computed from them
- Effects —
useEffect and other side-effect hooks
- Render helpers —
const renderXxx = () => <JSX /> arrow functions for distinct sections
- Compose —
const renderMain = () => { ... } handles loading/error/empty branching
- Return —
return renderMain() or compose with render helpers; no early returns, no nested ternaries
const { id } = useParams()
const { data, isLoading, error } = useGetItemQuery(id)
const isEmpty = !data?.length
useEffect(() => { ... }, [])
const renderLoading = () => <LoadingSpinner />
const renderError = () => <ErrorMessage error={error} />
const renderContent = () => <MainContent data={data} />
const renderMain = () => {
if (isLoading) return renderLoading()
if (error) return renderError()
if (isEmpty) return null
return renderContent()
}
return <div>{renderMain()}</div>
Violations to flag:
- Multiple exported components in a single file
- Early returns or nested ternaries in JSX
- Utility functions defined inline in a component
useDispatch / useSelector used directly (must use useAppDispatch / useAppSelector)
4. Store
store/{domain}/index.ts pattern:
export * from './slice'
export * from './api'
Adding a domain (expected pattern)
- Types →
src/types.ts
src/store/{domain}/slice.ts → api.ts → index.ts
- Register in
src/store/index.ts
- Page →
src/pages/{domain}.tsx
- Route →
src/routes.tsx
5. Design Style
When a DESIGN.md is present, read it before building any UI and follow it strictly:
- Match the spacing, color, corner style, and component patterns defined there
- Use
cn() for all className merging
- Prefer shadcn primitives over custom-built UI elements
Auditing a project
These rules are the source of truth for auditing as well. When reviewing an existing project against them, use the react-architect skill — it defines the review process and report format and audits against the rules above.