Your project has grown organically and files are scattered everywhere — components mixed with utilities, business logic inside routes, no clear structure. It's hard to find anything.
Organize files by feature rather than type for larger projects, and always separate concerns into distinct layers.
src/
├── components/ # All React components
├── hooks/ # All custom hooks
├── services/ # All API services
├── utils/ # All utility functions
└── pages/ # All pages/routes
src/
├── features/
│ ├── auth/
│ │ ├── components/ # Auth-specific components
│ │ │ ├── LoginForm.jsx
│ │ │ └── RegisterForm.jsx
│ │ ├── hooks/
│ │ │ └── useAuth.js
│ │ ├── services/
│ │ │ └── auth.service.js
│ │ ├── store/
│ │ │ └── authSlice.js
│ │ └── index.js # Public API for this feature
│ │
│ ├── users/
│ │ ├── components/
│ │ ├── services/
│ │ └── index.js
│ │
│ └── products/
│ ├── components/
│ ├── services/
│ └── index.js
│
├── shared/ # Cross-feature utilities
│ ├── components/ # Button, Modal, Input
│ ├── hooks/ # useLocalStorage, useDebounce
│ └── utils/ # formatDate, generateId
│
├── pages/ # Route-level components only
│ ├── Home.jsx
│ ├── Profile.jsx
│ └── Products.jsx
│
└── app/ # App-level config
├── store.js
├── router.jsx
└── App.jsx
// features/auth/index.js — public API
export { LoginForm } from './components/LoginForm';
export { useAuth } from './hooks/useAuth';
export { login, logout } from './services/auth.service';
// Usage elsewhere (clean imports)
import { LoginForm, useAuth } from '@/features/auth';
// vs
import LoginForm from '@/features/auth/components/LoginForm';
import { useAuth } from '@/features/auth/hooks/useAuth';- Co-locate related files — if you change X and always change Y, they belong together
- One export per file for components (easier to find)
- Index files for public API of a feature
- Shared vs feature — if it's used by 3+ features, it's shared