SkillCharged
React

How to Structure a React Project in 2024

Alex Dev
Mar 15, 2024
8 min read

Why Structure Matters

A logical folder structure makes a project easier to navigate and scale. As your app grows from a few components to hundreds, finding files quickly becomes crucial for developer productivity.

๐Ÿ’ก Pro Tip: Don't over-engineer your structure early on. Start simple and refactor to feature folders when your components folder gets too crowded.

The Features Folder Pattern

Instead of grouping by file type (e.g., all components together, all hooks together), group by feature. This keeps related code co-located.

src/
โ”œโ”€โ”€ features/
โ”‚   โ”œโ”€โ”€ auth/
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/
โ”‚   โ”‚   โ””โ”€โ”€ api/
โ”‚   โ””โ”€โ”€ dashboard/
โ”œโ”€โ”€ components/ # Global shared components
โ”œโ”€โ”€ hooks/      # Global shared hooks
โ””โ”€โ”€ lib/        # Third-party setups

Guidelines

Here are some golden rules to keep in mind:

  1. Keep it flat: Avoid deep nesting. 3-4 levels should be the maximum.
  2. Co-locate tests: Put test files next to the implementation files.
  3. Index exports: Use index.ts files to expose a public API for each feature.

Want to dive deeper?

Check out our full-length courses with hands-on projects and highly-edited videos.

View Courses