How should I structure the folders in a frontend project?
Organise folders by feature or domain rather than only by file type, so related code lives together. Keep shared, reusable code in a clearly separated place, and keep the structure consistent across the project.
Two common approaches
By type: Folders such as components, hooks, services, and styles group files by what they are. This is easy to start with, but as the project grows, a single feature is spread across many distant folders.
By feature: Folders such as cart, checkout, or user-profile contain everything that feature needs, including components, data-fetching code, and tests. This makes features easier to find, change, and remove.
For most projects, a feature-based structure scales better.
A practical layout
features/for domain-specific modules, each with its own components, logic, and tests.shared/orcommon/for generic, reusable pieces such as UI primitives, utilities, and API clients.app/orpages/for routing and top-level composition.- Keep configuration and build files at the root.
Rules that help
- Let features import from
shared, but avoid having features import from each other directly. If they must, expose a small public interface. - Keep a single, clear entry point for each feature.
- Write the rules down so the team follows the same pattern.
When to adjust
Small projects may not need much structure at all. Framework conventions also matter; follow them where they exist. The right layout depends on your team size and product, so review it with your team as the project grows.