Most folder-structure debates go in circles because people argue personal taste instead of asking what jobs folder names do. In practice, folder names act as navigation hints when you are trying to answer everyday questions: where does a new component go, do we already have one like it, what is in this repo, or how do I target a lint rule or test run?
Six kinds of folders you see in real repos
- Framework folders (
/pages,/app,/__tests__): Required or treated specially by Next.js or test runners. - Higher-order classification folders (
/assets,/_infra,/bin): Buckets that separate deploy configs, scripts, and images from app code. - Third-party code folders (
/graphql): Directories expected or suggested by specific libraries and gems. - Architecture hint folders (
/domains,/services,/policies,/decorators): Labels tied to a design pattern. Over a few years, different architectural eras tend to leave overlapping folders behind. - Code proximity folders (
/features/*): Grouping everything for one feature together. Handy locally, though it often hides reusable pieces as the app grows. - Usage-intent folders (
/shared): Folders meant to signal code that is shared across features or ready to extract into a package.
Two ways to keep it intentional
- Option 1 - Flat composition: Stick to top-level framework and classification folders (
app/,components/,lib/,_infra/,bin/). Keepcomponents/shallow since React components are functional and built for composition, and use architecture folders sparingly underlib/(fetch/,queries/,mappers/,test_fixtures/,test_utils/). - Option 2 - Feature-grouped under
lib/: Keep Next.js routing thin underapp/orpages/, group API code by domain (fetchers/,mappers/,operations/) and UI pieces by tier (blocks/,layouts/,templates/) insidelib/, and keep each component's spec and story files right next to it (Component.jsx,Component.spec.jsx,Component.stories.jsx).
Either approach works as long as you are deliberate about what kind of hint each folder name gives, instead of mixing patterns by accident.