React · Lesson 81 of 120
Project Structure
Folders and files.
React doesn't force a folder layout. But a clear structure makes a growing app easy to find your way around. A simple, common approach is to group files by feature.
- No fixed layout
- Clear structure
- Group by feature
A typical layout
The source folder holds everything. Components shared across the app live in components. Each feature, like the cart or products, gets its own folder, with its components, hooks, and logic together. Main dot j s x starts the app.
tree.txttext
src/
main.jsx starts the app
App.jsx routes
components/ shared: Button, Modal, Layout
features/
products/ ProductList.jsx, ProductCard.jsx, api.js
cart/ CartContext.jsx, cartReducer.js, CartPanel.jsx
checkout/ Checkout.jsx, validate.js
hooks/ useLocalStorage.js, useFetch.js
styles/ global.cssHabits
One component per file, named after the component. Keep files that change together close together. Don't nest folders too deep. And move things when the structure stops fitting, it's fine to change it.
| key | value |
|---|---|
| Files | one component each |
| Group | what changes together |
| Depth | keep it shallow |
| Change | when it stops fitting |
Summary
Group files by feature, and keep shared pieces in components. Next, testing components.
Key takeaways- features/
- components/
- Shallow
Next up: Testing Components — what to test