Empty React App
Pre-configured and ready to use React Application. To save time in setting things up for new project. Almost everything needed is already configured. Either you can use create-react-app followed by --template empty-react-app or you can just clone and start developing without wasting time in doing same stuffs for every project. With create-react-app the command will be as below.
npx create-react-app <app-name> --template empty-react-app
or
yarn create react-app <app-name> --template empty-react-app
Overview
Things included in this empty react app
- Folder Structure
- Axios Interceptor
- Redux with Redux-Thunk
- Router with Private Route
- Confugured for SCSS/SASS
- Eslint & Prettier
- Pre-commit Hook
- Absolute Imports
- Auth0 authenticator
- Preconfigured webpack setup
- Preconfigured Progressive Web App
Folder Structure
Those applications which are big and/or complex needs to have have well planned, organized folder structure. Best way is to use a mix of strategies to achieve better results as I am going to describe next.
Top level project architecture (which is under src/ folder) should be organized by type. No files should be here, just folders. This way it will be clear and understandable. Having files in here adding mess. We should keep it clear like this:
- src/
- library/
- main/
- modules/
- resources/
Library Folder : This folder will keep all our helpers and common files which will be shared across the application. We have 2 major folder in this common
and utilities
. If you want to create some api services you can keep it in api
folder inside library
folder.
- src/library/
- common
- actions
- AuthActions.js
- components
- Header
- index.jsx
- styles.scss
- Dropdown
- index.jsx
- styles.scss
- constants
- StoreConstant.js
- ImagesConstants.js
- URLConstants.js
- hooks
- dataFetchHook.js
- reducers
- AuthReducer.js
- utilities
- Storage.js
- Validators.js
- api - (optional folder as per requirement create this)
- AuthApiService.js
Main Folder : This folder is for main configurations such as Redux Create Store, Axios Instance and Routes
- src/main/
- axios/
- index.js
- routes
- index.jsx
- PrivateRoute.jsx
- store/
- index.js
- mainReducer.ts
Modules Folder : This folder is for Modules/Features of our app, we can treat this as containers. Each module/feature will have all its related files in same folder. We may have some module related components which we will be placing inside frames
folder and components which are used in more than one module we will keep in common/components to share across the application. Reason for keeping all related files in same folder to increase maintainability and searchability.
- src/modules/
- Dashboard/
- index.jsx
- dashboard.scss
- dashboardActions.js
- dashboardConstants.js
- dashboardReducer.js
- frames/
- HeaderFrame/
- index.jsx
- headerFrame.scss
- Home
- index.jsx
- Home.scss
- homeActions.js
- homeConstants.js
- homeReducer.js
- frames/
- HomeFrame/
- index.jsx
- homeFrame.scss
Resources Folder : This folder will be used to keep all our static resources such as images
, styles (mixins, variable etc)
, seeds
, fonts
etc. You can add seed, fonts if needed.
- src/resources/
- fonts/
- OpenSans-Regular.ttf
- images/
- logo.svg
- styles/
- variables.scss
- mixins.scss
- seed/
- country.json
Imports Style
Order should be as below
Imports packages / functions / variables from node_modules
Absolute Imports
Relative Imports
example:
import React from 'react';
import { uniqBy } from 'lodash';
import AppNavbar from 'library/common/components/AppNavbar';
import './style.scss';
NPM or YARN Commands
npm start - To start the application
npm build - To build the application
npm test - To test the application
npm lint - To check the lint errors in the application
npm lint:fix - To check the lint errors and fix the code from the application
npm format - To format the code in nicer way using prettier
npm isReady - This is the combination of format and lint:fix