π₯οΈ Frontend Architecture β
Structuring frontend applications for scalability and maintainability.
Project structure (feature-based) β
src/
βββ features/
β βββ auth/
β β βββ components/
β β βββ hooks/
β β βββ api.ts
β β βββ types.ts
β βββ dashboard/
β βββ settings/
βββ shared/
β βββ components/
β βββ hooks/
β βββ utils/
β βββ types/
βββ app/
β βββ routes.tsx
β βββ layout.tsx
βββ lib/
βββ api-client.ts
βββ config.tsComponent principles β
- Single responsibility β One component, one job
- Composition over inheritance β Build complex UIs from simple pieces
- Props down, events up β Data flows one direction
- Dumb components β Most components should be presentational
- Smart containers β Few components handle data fetching and state
State management guide β
| State type | Where to put it | Tool |
|---|---|---|
| UI state | Component (local) | useState |
| Form state | Form library | React Hook Form, Formik |
| Server state | Cache layer | TanStack Query, SWR |
| Global UI | Context or store | Zustand, Jotai |
| URL state | Router | Search params |
Performance rules β
- Avoid unnecessary re-renders (
React.memo,useMemo,useCallback) - Lazy load routes and heavy components
- Virtualize long lists (TanStack Virtual)
- Debounce user input (search, resize)
- Optimize images and fonts
Accessibility basics β
- Semantic HTML (
button,nav,main, not alldiv) - Alt text on images
- Keyboard navigation support
- Sufficient color contrast
- ARIA labels when semantics aren't enough