Skip to content

πŸ–₯️ 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.ts

Component 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 typeWhere to put itTool
UI stateComponent (local)useState
Form stateForm libraryReact Hook Form, Formik
Server stateCache layerTanStack Query, SWR
Global UIContext or storeZustand, Jotai
URL stateRouterSearch 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 all div)
  • Alt text on images
  • Keyboard navigation support
  • Sufficient color contrast
  • ARIA labels when semantics aren't enough

Pergame Knowledge Base