Search⌘ K
AI Features

Feature-Based Folder Structures

Explore how to organize React applications using a feature-based folder structure that groups components, hooks, and APIs by feature rather than by file type. Understand the benefits of this approach, such as better code cohesion, easier refactoring, and clearer ownership. Apply best practices to manage state within features, avoid cross-feature dependencies, and maintain clean public surfaces for scalable React apps.

As React applications scale, codebases organized by file type rather than by feature become harder to maintain. A type-based structure spreads related logic across multiple folders, which complicates refactoring and introduces hidden dependencies that only surface at scale. Many React projects start with a structure that groups files by type. For example, a common structure looks like this:

src/
├── components/ # All buttons, cards, forms go here
├── pages/ # All top-level page components
├── hooks/ # All custom hooks
└── services/ # All API calls, utility functions
Traditional react application

Type-based structure pitfalls

This approach introduces the following challenges when code is organized by file type rather than by feature:

  • Difficulty scaling: In a large app, modifying the “User Profile” feature requires jumping between components/UserProfileCard.js, pages/UserProfilePage.js, and hooks/useFetchProfile.js.

  • Poor cohesion: Files related to a single feature are scattered, making it hard to quickly understand the feature’s complete logic.

  • Refactoring risk: Deleting or refactoring a feature involves manually searching for all related files across multiple top-level directories.

Feature-first architecture

A feature-first architecture solves these problems by grouping each domain, such as Auth, Tasks, or User Profile, into a self-contained unit with its own components, hooks, and API utilities, allowing teams to work independently and confidently. Instead of placing components, hooks, and utilities in separate top-level directories, each feature encapsulates them internally, making ownership clear and helping eliminate accidental cross-feature imports. Large teams benefit from this structure because it transforms each feature into a portable, maintainable module with its own logic, UI, and state, while exposing only the public APIs defined in its index.js ...