Start with routes and boundaries
Map the routes before building components. Each route should have an obvious page component and a clear data requirement. Shared layout belongs in a layout component; page-specific composition stays with the page.
Decide where a feature begins and ends. A feature can own its components, hooks and types. Shared primitives such as buttons, fields and cards live outside features so they can be reused without creating circular dependencies.
- One page component per route
- Layout separated from page content
- Feature folders for domain-specific code
- Shared UI primitives kept independent
Components, hooks and state
Keep components focused on rendering. Move reusable behaviour into hooks, but do not turn every piece of logic into an abstraction. State should live close to where it is used; lift it only when another part of the tree genuinely needs it.
Separate server state from interface state. Data fetched from an API is not the same as whether a menu is open. Treating them as one store is a common source of bugs and unnecessary re-renders.
- Local state by default, lifted only when needed
- Server data and UI state kept distinct
- Effects reserved for external synchronisation
- Derived values computed rather than stored twice
Data fetching and API contracts
Type the API response at the boundary and validate it before the UI trusts it. Handle loading, empty, error and success states explicitly. A spinner that never resolves is usually a missing error path, not a styling problem.
Keep request functions in one place so the components do not each invent their own fetch logic. When the API changes, the contract and its consumers should be easy to find.
- Typed request and response shapes
- Explicit loading, empty, error and success states
- Centralised API functions
- No secrets or privileged calls in the browser
Testing and review
Test the behaviour that would be expensive to break: authentication, permissions, forms, payments and critical navigation. Component tests are useful for interaction patterns; end-to-end tests cover the journeys that cross pages.
Review the structure as the product grows. If a feature folder becomes a second application, split it. If shared code changes for every page, it may not be shared after all.
- Critical flows covered by tests
- Accessibility checked with keyboard and screen reader
- Build and bundle size reviewed regularly
- Structure revisited when features grow
Key takeaways
- Plan routes and feature boundaries before components multiply.
- Keep server state and interface state separate.
- Handle loading, empty and error states as part of the feature.
- Test the flows that would be expensive to break.
Need help
Related services.
React Development
React front-ends built with TypeScript, clear component boundaries and accessibility in mind.
Frontend Development
Responsive, accessible front ends built with React, TypeScript and modern CSS, connected cleanly to real data.
Web Application Development
Custom web applications that replace fragile spreadsheets, manual handoffs and disconnected tools.
Questions
About this guide.
Should every component have its own folder?
No. A folder per component creates a lot of noise. Group by feature, keep small components beside their parent, and extract shared primitives when reuse is real.
Do I need a state management library?
Not by default. Local state and a small amount of context cover many applications. Add a library when the state is genuinely shared, complex and difficult to reason about without one.
How do you decide between client and server rendering?
It depends on the product. Server rendering helps with first paint and search visibility; client rendering suits application interfaces behind authentication. The choice is made before the build, not after.