Naming Conventions
Naming Conventions
Section titled “Naming Conventions”Introduction
Section titled “Introduction”Consistent naming makes code easier to read and find. When every file follows the same pattern, developers can predict where to find things.
File Naming
Section titled “File Naming”| Convention | Example | When to Use |
|---|---|---|
kebab-case | post-list.tsx | File names (all files) |
PascalCase | PostList.tsx | Component files |
camelCase | usePosts.ts | Hook files, utilities |
dot notation | posts.route.ts | Next.js special files |
Recommended Patterns
Section titled “Recommended Patterns”components/├── ui/│ ├── button.tsx # kebab-case│ ├── post-list.tsx # kebab-case│ ├── CreatePostForm.tsx # PascalCase (component)│ └── index.ts # Barrel exporthooks/├── use-posts.ts # kebab-case├── use-user.tslib/├── api-client.ts # kebab-case├── utils.tsComponent Naming
Section titled “Component Naming”// ✅ Descriptive component namesexport function PostList() { }export function UserAvatar() { }export function CreatePostForm() { }
// ❌ Generic namesexport function List() { }export function Avatar() { }export function Form() { }Variable & Function Naming
Section titled “Variable & Function Naming”// ✅ Descriptiveconst isLoading = trueconst sortedPosts = posts.sort()async function fetchUser(id: string) { }
// ❌ Unclearconst flag = trueconst data = posts.sort()async function get(id: string) { }Folder Naming
Section titled “Folder Naming”features/├── auth/ # kebab-case├── user-profile/ # kebab-case — use full words├── billing/ # kebab-case└── src/ # ❌ avoid abbreviations like 'src' in feature foldersCommon Mistakes
Section titled “Common Mistakes”- Mixed casing — Pick one convention and use it everywhere. Mixing
snake_caseandcamelCaseis confusing. - Abbreviations —
usr,btn,cfgare unclear. Use full words:user,button,config. - Generic names —
index.tsxeverywhere loses meaning. Use descriptive component names.
Best Practices
Section titled “Best Practices”- Use
kebab-casefor all files (except components which arePascalCase) - Use descriptive, full-word names
- Be consistent across the entire project — use linting to enforce
- Group related files with consistent prefixes (
use-for hooks)
Summary
Section titled “Summary”Consistent naming conventions make codebases predictable and easy to navigate. Use kebab-case for files, PascalCase for components, and descriptive names everywhere. Enforce conventions with linting.