DEV Community

Tahir Rafique
Tahir Rafique

Posted on

๐Ÿง  Clean folder structure = Clean code = Happy developer's

๐Ÿ—‚๏ธ โ€œ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฅ๐—ฒ๐—ฎ๐—ฐ๐˜ ๐—ฃ๐—ฟ๐—ผ๐—ท๐—ฒ๐—ฐ๐˜ ๐—ฆ๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ ๐—Ÿ๐—ถ๐—ธ๐—ฒ ๐—ฎ ๐—ฃ๐—ฟ๐—ผ!โ€ ๐Ÿ’ป

When your app grows ๐Ÿ“ˆ, a messy structure slows you down ๐ŸŒ. Thatโ€™s why using a clean, scalable folder structure is the secret to high-performance React development!

Check out this modern React JS project layout๐Ÿ‘‡

โœจ Highlights of this structure:

Feature-Based Modules โ€“ Keep code modular with features/ like products/ and users/

๐Ÿ“ src/ โ€“ React JS Project Structure




src/
โ”‚
โ”œโ”€โ”€ assets/ # Static files (images, fonts, icons)
โ”‚ โ”œโ”€โ”€ images/
โ”‚ โ”œโ”€โ”€ fonts/
โ”‚ โ””โ”€โ”€ icons/
โ”‚
โ”œโ”€โ”€ components/ # Shared/reusable UI components
โ”‚ โ””โ”€โ”€ common/
โ”‚ โ”œโ”€โ”€ Button/
โ”‚ โ”‚ โ”œโ”€โ”€ Button.js
โ”‚ โ”‚ โ”œโ”€โ”€ Button.module.css
โ”‚ โ”‚ โ””โ”€โ”€ index.js
โ”‚ โ””โ”€โ”€ Modal/
โ”‚ โ”œโ”€โ”€ Modal.js
โ”‚ โ”œโ”€โ”€ Modal.module.css
โ”‚ โ””โ”€โ”€ index.js
โ”‚
โ”œโ”€โ”€ layouts/ # Layouts for different pages
โ”‚ โ”œโ”€โ”€ MainLayout/
โ”‚ โ”‚ โ”œโ”€โ”€ MainLayout.js
โ”‚ โ”‚ โ””โ”€โ”€ MainLayout.module.css
โ”‚ โ”œโ”€โ”€ AuthLayout/
โ”‚ โ”‚ โ”œโ”€โ”€ AuthLayout.js
โ”‚ โ”‚ โ””โ”€โ”€ AuthLayout.module.css
โ”‚ โ””โ”€โ”€ index.js
โ”‚
โ”œโ”€โ”€ features/ # Feature-specific modules
โ”‚ โ”œโ”€โ”€ products/
โ”‚ โ”‚ โ”œโ”€โ”€ components/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ProductList.js
โ”‚ โ”‚ โ”œโ”€โ”€ hooks/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ useProducts.js
โ”‚ โ”‚ โ”œโ”€โ”€ services/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ productService.js
โ”‚ โ”‚ โ””โ”€โ”€ types/
โ”‚ โ”‚ โ””โ”€โ”€ product.js
โ”‚ โ”‚
โ”‚ โ””โ”€โ”€ users/
โ”‚ โ”œโ”€โ”€ components/
โ”‚ โ”‚ โ””โ”€โ”€ UserProfile.js
โ”‚ โ”œโ”€โ”€ hooks/
โ”‚ โ”‚ โ””โ”€โ”€ useUser.js
โ”‚ โ”œโ”€โ”€ services/
โ”‚ โ”‚ โ””โ”€โ”€ userService.js
โ”‚ โ””โ”€โ”€ types/
โ”‚ โ””โ”€โ”€ user.js
โ”‚
โ”œโ”€โ”€ hooks/ # Global custom hooks
โ”‚ โ”œโ”€โ”€ useAuth.js
โ”‚ โ”œโ”€โ”€ useDebounce.js
โ”‚ โ””โ”€โ”€ index.js
โ”‚
โ”œโ”€โ”€ routes/ # Route and navigation configs
โ”‚ โ”œโ”€โ”€ AppRoutes.js
โ”‚ โ”œโ”€โ”€ ProtectedRoute.js
โ”‚ โ””โ”€โ”€ index.js
โ”‚
โ”œโ”€โ”€ services/ # Global service files (e.g., axios client)
โ”‚ โ”œโ”€โ”€ apiClient.js
โ”‚ โ””โ”€โ”€ errorHandler.js
โ”‚
โ”œโ”€โ”€ store/ # Redux or context-based store
โ”‚ โ”œโ”€โ”€ slices/
โ”‚ โ”‚ โ”œโ”€โ”€ authSlice.js
โ”‚ โ”‚ โ””โ”€โ”€ productSlice.js
โ”‚ โ”œโ”€โ”€ hooks.js
โ”‚ โ””โ”€โ”€ store.js
โ”‚
โ”œโ”€โ”€ styles/ # Global CSS or SCSS files
โ”‚ โ”œโ”€โ”€ variables.css
โ”‚ โ”œโ”€โ”€ global.css
โ”‚ โ””โ”€โ”€ mixins.css
โ”‚
โ”œโ”€โ”€ utils/ # Utility/helper functions
โ”‚ โ”œโ”€โ”€ constants.js
โ”‚ โ”œโ”€โ”€ formatters.js
 |
โ”‚
โ”œโ”€โ”€ pages/ # Page components for routing
โ”‚ โ”œโ”€โ”€ HomePage.js
โ”‚ โ”œโ”€โ”€ LoginPage.js
 |
โ”‚
โ””โ”€โ”€ App.js # Main app component


Enter fullscreen mode Exit fullscreen mode

๐Ÿ”ธ Reusable Components โ€“ Organized in components/common/ for easy UI reuse ๐Ÿ”

๐Ÿ”ธ Layouts & Routes โ€“ Centralized layouts and routing logic for better navigation ๐Ÿ”

๐Ÿ”ธ Hooks & Services โ€“ Smart separation of custom logic and API calls ๐Ÿคฏ

๐Ÿ”ธ State Management โ€“ Scalable structure with store/ and slices/ for Redux ๐Ÿ’พ

๐Ÿ”ธ Assets, Utils, Styles โ€“ Clean up the mess and boost your productivity ๐Ÿงน

Top comments (0)