ReactMedium

What is scalable architecture?

A scalable React architecture keeps the codebase easy to change as features, data and team size grow. It relies on clear module boundaries (feature folders with public APIs), separation of UI, state and data access, consistent patterns for server and client state, a shared design system, type safety and automated tests, plus performance practices such as code splitting.

Building blocks

  1. Feature-based structure with explicit boundaries; shared code does not depend on features.
  2. Server state vs client state: server data in TanStack Query, SWR, route loaders or Server Components; UI and app state in component state, context, or a small store (Zustand, Redux Toolkit).
  3. Data access layer: typed API clients (OpenAPI or tRPC generated types), validation with Zod at the boundary.
  4. Design system: accessible primitives and tokens (Radix, React Aria, shadcn/ui) used everywhere.
  5. Routing and framework: Next.js or React Router framework mode for code splitting, data loading and SSR conventions.
  6. TypeScript in strict mode across the codebase.
  7. Testing pyramid: unit tests for logic, component tests with Testing Library, E2E with Playwright.
  8. Tooling: ESLint (with eslint-plugin-react-hooks compiler rules), Prettier or Biome, CI checks, bundle budgets.
  9. Performance by default: React Compiler, lazy routes, virtualization, image optimization.
  10. Monorepo (Turborepo, Nx, pnpm workspaces) when several apps share packages.

Organizational aspects

  • Conventions documented in a README or ADRs.
  • Code owners per feature.
  • Feature flags for incremental releases.

Interview tip

Give concrete choices and the reason for each, rather than listing every tool.

Code example

tsx
1// lib/api/client.ts - one typed, validated access point to the backend
2import { z } from "zod";
3
4export async function api<T>(path: string, schema: z.ZodType<T>, init?: RequestInit): Promise<T> {
5 const res = await fetch(`${import.meta.env.VITE_API_URL}${path}`, {
6 ...init,
7 headers: { "Content-Type": "application/json", ...init?.headers },
8 credentials: "include",
9 });
10 if (!res.ok) throw new Error(`API ${res.status}: ${path}`);
11 return schema.parse(await res.json()); // fail fast on contract changes
12}
13
14// features/orders/api.ts - feature-level data access
15const Order = z.object({ id: z.string(), total: z.number(), status: z.enum(["pending", "paid", "shipped"]) });
16export const getOrders = () => api("/orders", z.array(Order));
17
18// features/orders/hooks/use-orders.ts - server state via TanStack Query
19import { useQuery } from "@tanstack/react-query";
20export const useOrders = () => useQuery({ queryKey: ["orders"], queryFn: getOrders, staleTime: 30_000 });

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.

Open in study app