Organize frontend code around features. Each feature provides a starting point for finding its components, hooks, state, helpers, and API requests. Shared code lives outside individual features so the rest of the application can reuse it.
Drawing on Bulletproof React’s project structure, this layout separates shared code from feature-specific code:
src/
├── components/
│ └── ui/
│ ├── Button.jsx
│ └── Modal.jsx
├── hooks/
│ └── useDebounce.js
├── stores/
│ └── useSessionStore.js
├── lib/
│ └── apiClient.js
├── utils/
│ ├── formatCurrency.js
│ └── formatDate.js
├── constants/
│ └── dateFormats.js
└── features/
├── notifications/
│ ├── components/
│ │ ├── NotificationPanel.jsx
│ │ └── NotificationItem.jsx
│ ├── hooks/
│ │ └── useNotifications.js
│ ├── stores/
│ │ └── useNotificationStore.js
│ ├── helpers/
│ │ └── groupNotificationsByDate.js
│ └── api/
│ ├── getNotifications.js
│ └── markNotificationRead.js
└── payments/
├── components/
│ ├── PaymentForm.jsx
│ └── PaymentSummary.jsx
├── hooks/
│ └── usePaymentForm.js
├── stores/
│ └── usePaymentStore.js
├── helpers/
│ └── calculatePaymentTotal.js
└── api/
├── getPayments.js
└── createPayment.jsA developer changing payments starts in features/payments. Its directories separate the main responsibilities:
- Components: render the UI and connect user actions to behavior.
- Hooks: manage React behavior, such as form interactions and fetching data.
- Stores: hold client state shared by multiple components, such as selected payments or active filters.
- Helpers: perform calculations and data transformations without depending on React.
- API requests: call backend endpoints through the shared client in
src/lib/apiClient.js.
Keep state as close as possible to the components that need it. A value used by one component can stay in that component. State shared within a feature can live in its store. Application-wide state, such as the active session, belongs in a shared store. Server data should generally be managed through a query cache rather than copied into a client store.
Keep feature-specific code within its feature. Move code into shared directories when multiple features need it: reusable hooks in src/hooks, application-wide stores in src/stores, general utilities in src/utils, and common constants in src/constants. Create these directories as needed; every feature does not need every folder.