Focus
rules builder
Clean `src` architecture, glass UI, and export-ready instructions for Claude, Cursor, Copilot, or any coding agent.
focus
Rules Builder
CLAUDE.md
157 lines# CLAUDE.md
<!-- This file is read by Claude as project-level instructions -->
<!-- Place this file at the root of your project -->
# my-project
> Clean Next.js agent rules with a src-first architecture
> Version: 1.0.0
---
## ๐๏ธ Project Overview
This is a **Next.js** project using the **App Router**.
Language: **TypeScript** (strict mode)
Styling: **tailwind**
## ๐ Folder Structure
```
my-project
โโโ src
โโโ app
โ โโโ main
โ โโโ layout.tsx
โ โโโ page.tsx
โโโ components
โ โโโ ui
โ โโโ common
โ โโโ navbar.tsx
โ โโโ footer.tsx
โโโ features
โโโ shared
โโโ hooks
โโโ lib
โโโ types
```
**Component organization:** feature-based
- Keep type definitions in dedicated `types/` files
- Custom hooks live in `hooks/` directory, prefixed with `use`
- Utility functions in `utils/` โ pure functions only, no side effects
- Constants in `constants/` โ never inline magic strings or numbers
## โ๏ธ Naming Conventions
| Entity | Convention | Example |
|--------|-----------|---------|
| Components | `PascalCase` | `UserProfile` |
| Files | `kebab-case` | `user-profile.tsx` |
| Functions | `camelCase` | `getUserData()` |
| Variables | `camelCase` | `userData` |
| Constants | `SCREAMING_SNAKE` | `USER_DATA` |
| CSS Classes | `kebab-case` | `.user-profile` |
| API Routes | `kebab-case` | `/api/user-profile` |
| React Hooks | prefix `use` | `useUserProfile()` |
| Interfaces | prefix `I` | `IUserProps` |
## ๐จ Code Style
```json
{
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"printWidth": 100,
"trailingComma": "es5",
"arrowParens": "always"
}
```
**Rules:**
- Prefer arrow functions over `function` declarations for callbacks
- Use `const` by default, `let` only when reassignment is necessary, never `var`
- Prefer named exports over default exports for better refactoring support
- Use `async/await` over `.then()/.catch()` chains
- Use early returns to reduce nesting depth โ avoid deeply nested conditionals
- Max line length: **100** characters
- Indent size: **2** spaces
## โ๏ธ Component Guidelines
- **Always use functional components** โ class components are not permitted
- Define a props interface for every component: `IComponentNameProps`
- Destructure props in the function signature
- Default to **Server Components** โ add `'use client'` directive only when necessary (event handlers, hooks, browser APIs)
- **Memoization strategy:** selective
- Use `React.memo` for components that re-render frequently with same props
- Use `useMemo` for expensive computations
- Use `useCallback` for callbacks passed as props
**State Management:**
- `useState` โ Local component state
- `zustand` โ Global client state โ keep stores small and focused
## ๐ฆ Import Rules
- Use absolute imports with alias `@` for all internal modules
- โ
`import { Button } from '@/components/Button'`
- โ `import { Button } from '../../../components/Button'`
- Do not use barrel `index.ts` files that re-export everything โ import directly from the file
**Import order (with blank line between groups):**
1. react
2. next
3. external
4. internal
5. relative
6. types
7. styles
## ๐งช Testing
- **Framework:** vitest
- **Testing Library:** @testing-library/react
- **Coverage threshold:** 80%
- **Test files:** In `__tests__/` directory
- **Naming:** `*.test.ts`
**Guidelines:**
- Test behavior, not implementation details
- One describe block per component/function
- Use descriptive test names: `it('should show error when email is invalid')`
## โก Performance
- Add `priority` prop to above-the-fold `<Image>` components
- Lazy load images and components below the fold
- Use `next/dynamic` for large client-side components to reduce initial bundle
- Leverage Next.js caching: `fetch` with `cache` and `revalidate` options in Server Components
## ๐ฆ Package Manager & Dependencies
**Package Manager:** `npm`
### Dependencies
- `next@latest` โ The React Framework
- `react@latest` โ React is a JavaScript library for building user interfaces
- `react-dom@latest` โ React package for working with the DOM
### Dev Dependencies
- `typescript@latest` โ TypeScript is a language for application-scale JavaScript
- `tailwindcss@latest` โ A utility-first CSS framework
### Install Commands
```bash
npm install next react react-dom
npm install --save-dev typescript tailwindcss
```
---
*Generated by [Next.js Rules Builder](https://github.com) โ 2026-06-15*