Folder Structure for React Projects

Folder Structure for React Projects
October 06, 2023

In the past few years, React has become one of the most popular libraries for building the front end of a website. It is an open-source JavaScript library that makes it easy for developers to make user interfaces that are both complicated and easy to use.

As React apps get bigger and more complicated, it's important to have a well-organized folder hierarchy to make sure they can be maintained, scaled, and used again. This is where the structure of the React project folders comes into play.

In this blog, we'll talk about how important the folder structure of a React project is and how to make a good folder structure for small to large applications. We'll talk about the benefits of a well-organized folder structure and the different ways to set up a React project.

React Project Folder Structure:

my-react-app/
|-- public/
|   |-- index.html
|   |-- favicon.ico
|   |-- manifest.json
|
|-- src/
|   |-- components/
|   |   |-- Button/
|   |   |-- Header/
|   |   |-- ...
|   |
|   |-- containers/
|   |   |-- Home/
|   |   |-- About/
|   |   |-- ...
|   |
|   |-- hooks/
|   |   |-- useFetchData/
|   |   |-- useDebounce/
|   |   |-- ...
|   |
|   |-- contexts/
|   |   |-- ThemeContext.js
|   |   |-- UserContext.js
|   |   |-- ...
|   |
|   |-- utils/
|   |   |-- api.js
|   |   |-- helpers.js
|   |   |-- ...
|   |
|   |-- assets/
|   |   |-- images/
|   |   |-- styles/
|   |   |   |-- global.scss
|   |   |   |-- variables.scss
|   |   |   |-- ...
|   |   |-- fonts/
|   |
|   |-- tests/
|   |   |-- components/
|   |   |-- containers/
|   |   |-- ...
|   |
|   |-- config/
|   |   |-- index.js
|   |   |-- ...
|   |
|   |-- index.js
|   |-- App.js
|   |-- App.scss
|
|-- .gitignore
|-- package.json
|-- README.md


Let's see what is the use of each folder:

  1. public/: Contains the static files like index.html, favicon.ico, and manifest.json which are the starting point for your application.
  2. src/: Contains the source code of your React application.
  3. components/: Holds reusable UI components (e.g., Button, Header) that can be used across the application.
  4. containers/: Contains the container components or pages that are responsible for connecting components and managing application logic (e.g., Home, About).
  5. hooks/: Stores custom hooks that encapsulate logic for reusability throughout the application (e.g., useFetchData, useDebounce).
  6. contexts/: Contains the React context files for managing application-wide state (e.g., ThemeContext, UserContext).
  7. utils/: Holds utility files like API configuration, helper functions, and other shared utilities (e.g., api.js, helpers.js).
  8. assets/: Contains static assets like images, styles, and fonts. The styles/ folder should include global styles and SCSS variables.
  9. tests/: Stores the test files for your components, containers, and other application parts.
  10. config/: Contains configuration files for your application (e.g., index.js).
  11. .gitignore: Lists files and directories that should be ignored by Git.
  12. package.json: Contains information about the project and its dependencies.
  13. README.md: Provides an overview and instructions for your project.

Resources for You

ChatGPT Guide For Software Developers

Learn to use ChatGPT to stay ahead of competition

Front-End Developer Interview Kit

Today, Start preparing to get your dream job!

JavaScript Developer Kit

Start your JavaScript journey today!

Newsletter for Developers!

Join our newsletter to get important Web Development and Technology Updates