Skip to content

Project Structure & Best Practices

A well-organized project structure is essential for React applications to remain maintainable as they grow. This guide covers practical folder organization patterns and naming conventions.

Every React project should start with this foundational structure:

  • Directorysrc/
    • Directorycomponents/
    • Directoryhooks/
    • Directorycontexts/
    • Directoryservices/
    • Directorypages/
    • Directoryassets/
    • Directoryutils/
    • App.js
    • index.js
  • components/: Reusable UI components
  • hooks/: Custom React hooks
  • contexts/: React Context providers
  • services/: API calls and external service integrations
  • pages/: Top-level page components (for routing)
  • assets/: Images, icons, fonts, and static files
  • utils/: Helper functions and utilities

Organize by technical layers (recommended for most projects):

  • Directorysrc/
    • Directorycomponents/
      • Directoryui/
        • Button.jsx
        • Input.jsx
        • Modal.jsx
      • Directorylayout/
        • Header.jsx
        • Sidebar.jsx
        • Footer.jsx
      • Directoryforms/
        • LoginForm.jsx
        • SignupForm.jsx
    • Directoryhooks/
      • useAuth.js
      • useLocalStorage.js
    • Directoryservices/
      • api.js
      • authService.js
    • Directorycontexts/
      • AuthContext.js
      • ThemeContext.js

Organize by business features (for complex applications):

  • Directorysrc/
    • Directoryfeatures/
      • Directoryauth/
        • Directorycomponents/
          • DirectoryLoginForm/
          • DirectorySignupForm/
        • Directoryhooks/
          • useAuth.js
        • Directoryservices/
          • authService.js
        • index.js
      • Directorydashboard/
        • Directorycomponents/
          • DirectoryDashboardCard/
          • DirectoryStatsWidget/
        • Directoryhooks/
          • useDashboard.js
        • Directoryservices/
          • dashboardService.js
      • Directoryprofile/
        • Directorycomponents/
          • DirectoryProfileForm/
          • DirectoryAvatarUpload/
        • Directoryhooks/
          • useProfile.js
    • Directoryshared/
      • Directorycomponents/
        • Button.jsx
        • Input.jsx
      • Directoryhooks/
      • Directoryutils/
Terminal window
# PascalCase for component files
UserProfile.jsx
NavigationMenu.jsx
ProductCard.jsx
# Include component type in folder structure
components/forms/LoginForm.jsx
components/ui/Button.jsx
components/layout/Header.jsx
// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@components': path.resolve(__dirname, './src/components'),
'@hooks': path.resolve(__dirname, './src/hooks'),
'@services': path.resolve(__dirname, './src/services'),
'@utils': path.resolve(__dirname, './src/utils'),
'@assets': path.resolve(__dirname, './src/assets'),
'@pages': path.resolve(__dirname, './src/pages')
}
}
});
// Without aliases
import Button from '../../../components/ui/Button/Button';
import { useAuth } from '../../../hooks/useAuth';
import { userService } from '../../../services/userService';
// With aliases
import Button from '@components/ui/Button';
import { useAuth } from '@hooks/useAuth';
import { userService } from '@services/userService';
  1. Import Paths Getting Long: ../../../components/ui/Button
  2. Hard to Find Components: Spending time looking for files
  3. Naming Conflicts: Multiple components with similar names
  4. Large Folders: More than 10-15 files in a single folder
  5. Feature Coupling: Changes in one area break unrelated features
  1. Start Small: Begin with one feature or component type
  2. Update Imports: Use find/replace for import paths
  3. Setup Aliases: Configure path aliases before big moves
  4. Test Thoroughly: Ensure nothing breaks during restructuring
  5. Document Changes: Update team on new conventions
  1. One Component Per File: Keep components focused and testable
  2. Colocate Related Files: Keep component, styles, and tests together
  3. Use Index Files: Simplify imports with index.js exports
  4. Consistent Naming: Stick to naming conventions across the project
  1. Start Simple: Begin with flat structure, refactor as needed
  2. Feature Boundaries: Group related functionality together
  3. Shared Components: Extract reusable components to shared folder
  4. Regular Cleanup: Remove unused files and refactor regularly