Chapter 14. Application Structure for React.js
When building small hobby projects or trying a new concept or library, developers can start adding files to a folder without a plan or organizing structure. These could include CSS, helper components, images, and pages. A single folder for all resources becomes unmanageable as the project grows. Any respectably sized codebase should be organized into an application folder structure based on logical criteria. The decision on how to structure your files and application components could be a personal/team choice. It would also generally depend on the application domain and technology used.
This chapter mainly focuses on folder structures for React.js applications that could help in better management of our projects as they grow.
Introduction
React.js itself does not provide a guideline on structuring projects but does suggest a few commonly used approaches. Let’s look at these and understand their pros and cons before discussing folder structures for projects with added complexities and Next.js applications.
At the high level, you can group files in a React application in two ways:
- Group by feature
-
Create folders for every application module, feature, or route.
- Group by file type
-
Create folders for different types of files.
Let us look at this classification in detail.
Group by Module, Feature, or Route
In this case, the file structure would mirror the business model or the application flow. For example, if you have an ecommerce ...
Get Learning JavaScript Design Patterns, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.