Explaining the Code Architecture of React Apps

When we create a React application using either Create React App or Vite, it initializes several default folders, including src, public, node_modules, and build/dist. Our primary focus is on the src directory, where we will explain its contents and the architecture of the files and folders within it.

The /src directory includes some of the directories which we explore in one by one.

/src

1. /common

Purpose: This directory is often used to store shared components that can be reused throughout the application.

Typical Files:

2. /components

Purpose: This directory contains reusable UI components that can be utilized throughout the application.

Typical Files:

3. /hooks

Purpose: This directory is for custom React hooks that encapsulate reusable logic.

Typical Files:

4. /layout

Purpose: This directory is used to define the overall layout components of the application, which can include shared layouts across different pages.

Typical Files:

5. /pages

Purpose: This directory contains components that represent different pages of the application, often mapped to routes in a router.

Typical Files:

6. /reducers

Purpose: This directory is for Redux reducers if the application uses Redux for state management. Reducers handle state changes based on dispatched actions.

Typical Files:

7. /store

Purpose: This directory usually contains files related to the Redux store configuration.

Typical Files:

8. /utils

Purpose: This directory is for utility functions that provide common functionalities and can be used throughout the application. utils can have many directories inside it like CommonFunctions , Settings , Constants and ValidatonSchema.

Typical Files:

9. /assets

The /assets directory in a React application is typically used to store static files that are not code but are needed for the application to function or for enhancing the user interface. Here’s an overview of what can be included in the /assets directory:

  1. Images
  2. Fonts

Table of Contents