React Architecture for Enterprise Application
Tags: react, javascript, webdev, beginners
Published: 2021-11-06 05:39:59

Structure and Organize React Components for Enterprise Application

React is the most popular Javascript library for building user interfaces. React does not have any standard folder structure to group the components and logic. React App can be structured in any way based on the project needs. 

But the improper structuring of the React App will lead to affect the app scalability and maintainability. As the App grows, We might add new and remove some old features, so each component needs to be loosely coupled with each other. Let see how to structure the React app to avoid such issues.

We need to group files based on the feature. That is, All files of a feature are in the same folder. Please check the below image for folder structure

![folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16xhaiebp6eyn19v40sm.png)

In the above image we can see the folders of the react app, let's break down each folder purpose.

## app

Global app setup and configuration used by the entire app are defined in app folder as below, which includes axiosClient, rootReducer, saga and store.

![app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kxcdw5kkpxgl9l4r279z.png)

## common

Reusable helpers, shared components, hooks, etc are defined in common folder.

![common](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzg6gj7olqmng75pbry7.png)

## features

Feature specific components, [Slice](https://redux-toolkit.js.org/tutorials/quick-start#create-a-redux-state-slice) (Redux reducer logic and associated actions - [Redux Toolkit](https://redux-toolkit.js.org/)), APIs and styles are placed in the features folder.

![features](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ii24liq9m1wt0zub7m0.png)

## routes

Components private, public routes are defined in routes folders. Route restriction based on authentication is handled here.

![routes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1nfihjuzs12e7b6g4mi.png)

## assets

Static assets like Images, files, icons are placed in the assets directory.

![assets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8kjucfba9d58jrkls8r.png)

## tests

Unit test cases and their mock goes to the tests directory. 

![tests](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71lwj4toslmdr8poje13.png)

## style

Global styles, theme configuration is placed in the style folder.

![style](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmwk88sgt7fatf681ynx.png)

Using the above feature folder structure, We can easily remove or add a feature related code without issues. The feature folder structure is recommended by the [redux style guide](https://redux.js.org/style-guide/style-guide#structure-files-as-feature-folders-with-single-file-logic). By using Redux Toolkit, We have avoided boilerplate code like actions and reducers.

> Need to know more about Redux ToolKit. Check out [my article related to the redux toolkit](https://dev.to/nilanth/redux-toolkit-the-standard-way-to-write-redux-2g32).

## Resources

1. [Ducks Proposal](https://github.com/erikras/ducks-modular-redux)
2. [File Structuring](https://reactjs.org/docs/faq-structure.html)
3. [Redux Toolkit](https://dev.to/nilanth/redux-toolkit-the-standard-way-to-write-redux-2g32)

## Conclusion

Feature folder based file structuring will make react app more maintainable, scalable and loosely coupled.

Thank you for reading.

Get more updates on [Twitter](https://twitter.com/Nilanth).

**You can support me [by buying me a coffee](https://buymeacoffee.com/nilanth) ☕**

## eBook

[Debugging ReactJS Issues with ChatGPT: 50 Essential Tips and Examples](https://nilanth.gumroad.com/l/ztehh)

[ReactJS Optimization Techniques and Development Resources](https://nilanth.gumroad.com/l/NYkdN)

## More Blogs
1. [Laravel Sanctum Authentication for React App Using Breeze
](https://dev.to/nilanth/laravel-sanctum-authentication-for-react-app-using-breeze-2l5f)
2. [Twitter Followers Tracker using Next.js, NextAuth and TailwindCSS](https://dev.to/nilanth/twitter-followers-tracker-using-nextjs-nextauth-and-tailwindcss-1em7)
3. [Don't Optimize Your React App, Use Preact Instead
](https://dev.to/nilanth/dont-optimize-your-react-app-use-preact-instead-30og)
4. [How to Reduce React App Loading Time By 70%](https://dev.to/nilanth/how-to-reduce-react-app-loading-time-by-70-1kmm)
5. [Build a Portfolio Using Next.js, Tailwind, and Vercel with Dark Mode Support](https://dev.to/nilanth/build-a-portfolio-using-next-js-tailwind-and-vercel-4dd8)
6. [No More ../../../ Import in React](https://dev.to/nilanth/no-more-import-in-react-2mbo)
7. [10 React Packages with 1K UI Components
](https://dev.to/nilanth/10-react-packages-with-1k-ui-components-2bf3)
8. [5 Packages to Optimize and Speed Up Your React App During Development](https://dev.to/nilanth/5-packages-to-optimize-and-speed-up-your-react-app-during-development-4h5f)
9. [How To Use Axios in an Optimized and Scalable Way With React](https://dev.to/nilanth/how-to-use-axios-in-an-optimized-and-scalable-way-with-react-518n)
10. [15 Custom Hooks to Make your React Component Lightweight](https://dev.to/nilanth/15-custom-hooks-to-make-your-react-component-lightweight-17cd)
11. [10 Ways to Host Your React App For Free](https://dev.to/nilanth/10-ways-to-host-your-react-app-for-free-27ga)
12. [How to Secure JWT in a Single-Page Application](https://dev.to/nilanth/how-to-secure-jwt-in-a-single-page-application-cko)