File Naming Conventions
Comprehensive guidelines for file and folder naming conventions in the React Native project.
File Naming Conventions
Overview
This document establishes the official file and folder naming conventions for our React Native project. These conventions ensure consistency, readability, and maintainability across the codebase while aligning with React community best practices.
Purpose & Scope
These conventions apply to all files and folders in the project, covering:
- React components
- Custom hooks
- Domain files
- Utility functions
- Test files
- Configuration files
Following these conventions is mandatory for all team members to maintain code consistency.
General Principles
- Consistency: Apply conventions uniformly across the project
- Clarity: Names should be self-documenting
- Tool-friendly: Compatible with IDEs, linters, and build tools
- Community alignment: Follow React ecosystem standards
Component Files
Convention
Use PascalCase for React component files and folders.
Examples
Rules
- Component filename must match the component name
- Main component file should have the same name as its folder
- Always use
.tsxextension for components
Structure
Hook Files
Convention
Use camelCase starting with "use" for custom hooks.
Examples
Rules
- Hook names must start with "use"
- Single hook per file in shared hooks
- Multiple related hooks can be in domain
hooks.ts - Use
.tsextension (not.tsx) for hooks
Examples in Code
Domain Files
Convention
Use lowercase descriptive names for domain-specific files.
Standard Domain Files
Rules
- Keep names simple and descriptive
- Don't prefix with domain name (already in folder)
- Use consistent names across all domains
- Optional files only when needed
Utility Files
Convention
Use category-based lowercase names for utility functions.
Examples
Rules
- Group utilities by function type
- Keep names generic and descriptive
- Use plural for collection utilities
- No prefixes or suffixes
Feature Folders
Convention
Use kebab-case for feature folders.
Examples
Rules
- Use hyphens to separate words
- Keep names descriptive but concise
- Reflect user-facing functionality
- Avoid technical terms
Test Files
Convention
Use .test.ts or .test.tsx suffix for test files.
Examples
Rules
- Place tests next to the file being tested
- Or in
__tests__folder for organization - Match the name of the file being tested
- Use
.test.tsxfor component tests - Use
.test.tsfor non-component tests
Test Folder Structure
Index Files
Convention
Use index.ts for barrel exports.
Examples
Purpose
- Simplify imports
- Create public API for modules
- Re-export relevant items
Example Content
Multi-word Files
Rules by Type
- Components: PascalCase (
ProductCard.tsx) - Hooks: camelCase (
useLocalStorage.ts) - Domains: lowercase (
queryKeys.ts) - Features: kebab-case (
product-catalog/) - Utils: lowercase (
dateHelpers.tsordate.ts)
Examples
Platform-specific Files
Convention
Use platform suffixes when needed.
Examples
Rules
- Only use when platform differences exist
- Default file without suffix for shared code
- Platform files override default
Configuration Files
Convention
Follow tool-specific conventions.
Examples
Rules
- Use the format required by the tool
- Include tool name in filename when possible
- Place in project root by default
Special Cases
Private Files
Use underscore prefix for internal files:
Temporary Files
Use .temp suffix:
Generated Files
Use .generated suffix:
Do's and Don'ts
Component Naming
- (Do ✅)
ProductCard.tsx- PascalCase - (Don't ❌)
productCard.tsx- Wrong case - (Don't ❌)
product-card.tsx- Wrong convention
Hook Naming
- (Do ✅)
useAuth.ts- Starts with "use" - (Don't ❌)
authHook.ts- Missing "use" prefix - (Don't ❌)
UseAuth.ts- Wrong case
Feature Naming
- (Do ✅)
shopping-cart/- Kebab-case - (Don't ❌)
shoppingCart/- Wrong case - (Don't ❌)
shopping_cart/- Wrong separator
Test Naming
- (Do ✅)
Button.test.tsx- Clear test file - (Don't ❌)
Button.spec.tsx- Use .test instead - (Don't ❌)
ButtonTests.tsx- Use standard suffix
Directory Examples
Complete Feature Structure
Complete Domain Structure
Enforcement
ESLint Rules
Configure ESLint to enforce naming conventions:
Pre-commit Hooks
Use tools like lint-staged to check naming:
Migration Guide
When updating existing files:
-
Identify non-conforming files
-
Update imports
- Use IDE refactoring tools
- Update all import statements
- Update barrel exports
-
Update tests
- Rename test files
- Update test imports
-
Verify build
- Run full build
- Run all tests
- Check for broken imports
Summary
These naming conventions ensure:
- Consistency across the codebase
- Clarity in file purpose
- Compatibility with tools
- Scalability as project grows
All team members must follow these conventions for new files and when refactoring existing code.