AI Hints
Home›React Tutorial›Quality
React · Lesson 81 of 120

Project Structure

Folders and files.

⏱ 2 min read▶ Video at 1:08:48🎓 Free
Watch this lesson in the React courseWatch on YouTube ↗Full React course

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.css

Habits

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.

keyvalue
Filesone component each
Groupwhat changes together
Depthkeep it shallow
Changewhen 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