How to run the project
npm i
and
npm start
Before using This project install latest versions of following packages
- Axios
- Bootstrap - React Strap - MUI - AntD - Tailwind
- React Icons
- React Router Dom Latest React Router v6
- Other Required packages
In the project I have just set Up most used folder structure:
React JS Advanced Folder Structure
.
├── public
| └── index.html
├── src
├── assets
| ├── audios
| ├── icons
| ├── images
| └── videos
├── components
| ├── Button
| | ├── index.jsx
| | └── button.module.css
| ├── inputs
| | ├── index.jsx
| | └── inputs.module.css
| ├── Modal
| | ├── index.jsx
| | └── modal.module.css
| └── Tooltip
| ├── index.jsx
| └── tooltip.module.css
| └── index.js
├── db
| ├── productsData.js
| └── userData.js
├── layout
| ├── Header
| | ├── index.jsx
| | └── header.module.css
| ├── Navbar.jsx
| | ├── index.jsx
| | └── navbar.module.css
| ├── Breadcrumbs.jsx
| | ├── index.jsx
| | └── breadcrumbs.module.css
| └── Footer.jsx
| ├── index.jsx
| └── footer.module.css
| └── index.js
├── pages
| ├── Home
| | ├── index.jsx
| | └── home.module.css
| ├── Login
| | ├── index.jsx
| | └── login.module.css
| ├── Signup
| | ├── index.jsx
| | └── signup.module.css
| └── About
| ├── index.jsx
| └── about.module.css
| └── index.js
├── Routers
| └── Routers.js
├── store
| ├── action.js
| ├── reducers.js
| └── store.js
├── services
| ├── api.js // API request functions
| └── dataUtils.js // Data manipulation functions
├── utils
| ├── constants
| | ├── Strapi.js
| | └── Firebase.js
| ├── helpers
| | ├── arrays.js
| | └── helpers.js
| └── hooks
| └── useIsMobile.js
├── .env
├── app.js
├── index.css
├── index.js
|
├── .gitignore
├── package-lock.json
├── package.json
└── README.md
Public
Assests
Components
db
layout
Pages
Routes
services
store
utils
Constants
helpers
hooks
.env.example
/.env.development
.eslintrc.cjs
.prettierrc.cjs
.jsonconfig.json
.gitignore
package.json
.vite.config.js
Public mainly contain root file index.html
which help to run react project.
In Assets folder you can put following things.
- Images
- Video
- Icons
- CSS
Component will have all the components which are reuseable anywhere in website. Like - Button - Cards - DropDownBtn - inputs - Modal - Popups - Toast - Tooltip - Text/Heading/Title - Skeleton - Spiner/Loader
Constants folder have Tokens, logins, and those details which we don't want to share with public. Like Env files are used to store sensitive credentials such as API keys. An environment variable supports storing the API link at one location so that we do not need to change the Link in each file manually.
const API_BASE_URL = 'https://api.example.com';
const MAX_ITEMS_PER_PAGE = 10;
Here we provide JSON Formate of data in frontend in React APP.
- products data
- users data
Helpers used to store utility functions and modules that provide various helper functionalities. These functions are usually small, reusable, and not directly tied to the main business logic of your application.
- Array to Object
- Object to Array
- Date Formatting
- Number Formatting
- Validation
- Api Request
This is just a special folder for placing any layout based components.
- Header
- Footer
- Breadcrumbs
- Navbar
- Sidebar
Pages will have all the pages which we will use in website.
Router will have all the Routes in website. Where we are going and where we want to go.
In Services we put configuration file, like when you are using google firebase then your firebase config file will be in services folder.
The "services" folder is often used to contain code related to making *API
requests and managing data from external sources. This folder helps separate the concerns of your application by isolating data fetching and manipulation logic from the components that render the UI.
// services/apiService.js
import axios from 'axios';
export function fetchUserData(userId) {
return axios.get(`/api/users/${userId}`);
}
"store" folder in a React application typically refers to a directory where you manage your application's state using state management libraries like
- Redux
- Redux Toolkit
- Zustand
- Context Api
- Mobx
|-- store/
| |-- actions.js // Redux action creators
| |-- reducers.js // Redux reducers
| |-- store.js // Redux store configuration
Utils
folder is a common convention in many software projects, including React applications, for storing utility functions and helper modules that provide general-purpose functionality across different parts of the application.
- constants
- helpers
- hooks
Example:
// utils/stringUtils.js
export function capitalizeFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
// utils/dateUtils.js
export function formatDate(date) {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return new Date(date).toLocaleDateString(undefined, options);
}
Env files are used to store sensitive credentials such as API keys.
REACT_APP_API_URL=http://localhost:3001
REACT_APP_DEBUG_MODE=true
Env files are used to store sensitive credentials such as API keys.
REACT_APP_API_KEY=
REACT_APP_API_URL=
ESLint, which is a popular tool for linting and enforcing coding style and best practices in JavaScript code. The .eslintrc.cjs file is written in CommonJS module format and is used to configure ESLint for your project.
.gitignore file contain all those files,folders name which user want to skip to push online. If you don't want to push any specific file/folder then you should put their name in .gitignore
.prettierrc.cjs
file is a configuration file used for Prettier, which is a widely used code formatting tool. Prettier helps ensure consistent and automatic code formatting across your codebase. The .prettierrc.cjs
file is written in CommonJS module format and is used to configure Prettier's behavior for your project.
- File Format & Naming
- Configuration Setup
- Export Configuration
module.exports = {
printWidth: 80,
tabWidth: 2,
singleQuote: true,
trailingComma: 'es5',
};
- File Purpose
- Configuration Setup:
- JSON Format
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
}
}
package.json file is core to the Nodejs ecosystem and is a fundamental part of understanding and working with Node. js , npm , and even modern JavaScript . This file is used as a manifest, storing information about applications, modules, packages, and more.
-
File Purpose: The vite.config.js file allows you to customize various aspects of your Vite project, including configuration options for the development server, build process, and plugin settings.
-
Configuration Setup: Inside the vite.config.js file, you export an object containing the configuration options for your Vite project. This object can include settings related to the development server, build process, plugins, and more.
-
JavaScript Format: The vite.config.js file is written in JavaScript, and it's named vite.config.js. It should be placed in the root directory of your Vite project.
// vite.config.js
export default {
server: {
port: 3000
},
build: {
minify: true
},
plugins: [/* your plugins here */]
};
@import
export default defineConfig({
resolve: {
alias: {
'@': '/src',
'@page': '/src/page'
}
},
plugins: [react()],
})
2nd Method
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path';
const alias = {
// eslint-disable-next-line no-undef
'@': resolve(__dirname, './src'),
};
export default defineConfig({
plugins: [react()],
resolve: {
alias,
},
})