Core Principles for React 19 SPA Development
Production-ready best practices for building modern React applications with TypeScript, Vite, and TanStack ecosystem.
Stack Overview
- React 19 with React Compiler (auto-memoization)
- TypeScript (strict mode)
- Vite (bundler)
- Biome (formatting + linting)
- TanStack Query (server state)
- TanStack Router (file-based routing)
- Vitest (testing with jsdom)
- Apidog MCP (API spec source of truth)
Project Structure
/src
/app/ # App shell, providers, global styles
/routes/ # TanStack Router file-based routes
/components/ # Reusable, pure UI components (no data-fetch)
/features/ # Feature folders (UI + hooks local to a feature)
/api/ # Generated API types & client (from OpenAPI)
/lib/ # Utilities (zod schemas, date, formatting, etc.)
/test/ # Test utilities
Key Principles:
- One responsibility per file
- UI components don't fetch server data
- Put queries/mutations in feature hooks
- Co-locate tests next to files
Agent Execution Rules
Always do this when you add or modify code:
API Spec: Fetch latest via Apidog MCP and regenerate /src/api types if changed
Data Access: Wire only through feature hooks that wrap TanStack Query. Never fetch inside UI components.
New Routes:
- Create file under
/src/routes/** (file-based routing)
- If needs data at navigation, add loader that prefetches with Query
Server Mutations:
- Use React 19 Actions OR TanStack Query
useMutation (choose one per feature)
- Use optimistic UI via
useOptimistic (Actions) or Query's optimistic updates
- Invalidate/selectively update cache on success
Compiler-Friendly:
- Keep code pure (pure components, minimal effects)
- If compiler flags something, fix it or add
"use no memo" temporarily
Tests:
- Add Vitest tests for new logic
- Component tests use RTL
- Stub network with msw
Before Committing:
- Run
biome check --write
- Ensure Vite build passes
"Done" Checklist per PR
Authoritative Sources
React 19 & Compiler:
- React v19 overview
- React Compiler: overview + installation + verification
<form action> / Actions API; useOptimistic; use
- CRA deprecation & guidance
Vite:
- Getting started; env & modes; TypeScript targets
TypeScript:
moduleResolution: "bundler" (for bundlers like Vite)
Biome:
- Formatter/Linter configuration & CLI usage
TanStack Query:
- Caching & important defaults; v5 migration notes; devtools/persisting cache
TanStack Router:
- Install with Vite plugin; file-based routing; search params; devtools
Vitest:
- Getting started & config (jsdom)
Apidog + MCP:
- Apidog docs (import/export, OpenAPI); MCP server usage
Final Notes
- Favor compile-friendly React patterns
- Let the compiler and Query/Router handle perf and data orchestration
- Treat Apidog's OpenAPI (via MCP) as the single source of truth for network shapes
- Keep this doc as your "contract"—don't add heavy frameworks or configs beyond what's here unless explicitly requested
Related Skills
- tooling-setup - Vite, TypeScript, Biome configuration
- react-patterns - React 19 specific patterns (compiler, actions, forms)
- tanstack-router - Routing patterns
- tanstack-query - Server state management with Query v5
- router-query-integration - Integrating Router with Query
- api-integration - Apidog + MCP patterns
- performance-security - Performance, accessibility, security
1---2name: core-principles3description: Use when planning new projects, onboarding, or reviewing architectural decisions. Core principles and project structure for React 19 SPA development. Covers stack overview, project organization, agent execution rules, and authoritative sources.4updated: 2026-01-205keywords: react-19, spa, project-structure, architecture, vite, typescript, tanstack, biome6---78# Core Principles for React 19 SPA Development910Production-ready best practices for building modern React applications with TypeScript, Vite, and TanStack ecosystem.1112## Stack Overview1314- **React 19** with React Compiler (auto-memoization)15- **TypeScript** (strict mode)16- **Vite** (bundler)17- **Biome** (formatting + linting)18- **TanStack Query** (server state)19- **TanStack Router** (file-based routing)20- **Vitest** (testing with jsdom)21- **Apidog MCP** (API spec source of truth)2223## Project Structure2425```26/src27 /app/ # App shell, providers, global styles28 /routes/ # TanStack Router file-based routes29 /components/ # Reusable, pure UI components (no data-fetch)30 /features/ # Feature folders (UI + hooks local to a feature)31 /api/ # Generated API types & client (from OpenAPI)32 /lib/ # Utilities (zod schemas, date, formatting, etc.)33 /test/ # Test utilities34```3536**Key Principles:**37- One responsibility per file38- UI components don't fetch server data39- Put queries/mutations in feature hooks40- Co-locate tests next to files4142## Agent Execution Rules4344**Always do this when you add or modify code:**45461. **API Spec:** Fetch latest via Apidog MCP and regenerate `/src/api` types if changed47482. **Data Access:** Wire only through feature hooks that wrap TanStack Query. Never fetch inside UI components.49503. **New Routes:**51 - Create file under `/src/routes/**` (file-based routing)52 - If needs data at navigation, add loader that prefetches with Query53544. **Server Mutations:**55 - Use React 19 Actions OR TanStack Query `useMutation` (choose one per feature)56 - Use optimistic UI via `useOptimistic` (Actions) or Query's optimistic updates57 - Invalidate/selectively update cache on success58595. **Compiler-Friendly:**60 - Keep code pure (pure components, minimal effects)61 - If compiler flags something, fix it or add `"use no memo"` temporarily62636. **Tests:**64 - Add Vitest tests for new logic65 - Component tests use RTL66 - Stub network with msw67687. **Before Committing:**69 - Run `biome check --write`70 - Ensure Vite build passes7172## "Done" Checklist per PR7374- [ ] Route file added/updated; loader prefetch (if needed) present75- [ ] Query keys are stable (`as const`), `staleTime`/`gcTime` tuned76- [ ] Component remains pure; no unnecessary effects; compiler ✨ visible77- [ ] API calls typed from `/src/api`; inputs/outputs validated at boundaries78- [ ] Tests cover new logic; Vitest jsdom setup passes79- [ ] `biome check --write` clean; Vite build ok8081## Authoritative Sources8283- **React 19 & Compiler:**84 - React v19 overview85 - React Compiler: overview + installation + verification86 - `<form action>` / Actions API; `useOptimistic`; `use`87 - CRA deprecation & guidance8889- **Vite:**90 - Getting started; env & modes; TypeScript targets9192- **TypeScript:**93 - `moduleResolution: "bundler"` (for bundlers like Vite)9495- **Biome:**96 - Formatter/Linter configuration & CLI usage9798- **TanStack Query:**99 - Caching & important defaults; v5 migration notes; devtools/persisting cache100101- **TanStack Router:**102 - Install with Vite plugin; file-based routing; search params; devtools103104- **Vitest:**105 - Getting started & config (jsdom)106107- **Apidog + MCP:**108 - Apidog docs (import/export, OpenAPI); MCP server usage109110## Final Notes111112- Favor compile-friendly React patterns113- Let the compiler and Query/Router handle perf and data orchestration114- Treat Apidog's OpenAPI (via MCP) as the single source of truth for network shapes115- Keep this doc as your "contract"—don't add heavy frameworks or configs beyond what's here unless explicitly requested116117## Related Skills118119- **tooling-setup** - Vite, TypeScript, Biome configuration120- **react-patterns** - React 19 specific patterns (compiler, actions, forms)121- **tanstack-router** - Routing patterns122- **tanstack-query** - Server state management with Query v5123- **router-query-integration** - Integrating Router with Query124- **api-integration** - Apidog + MCP patterns125- **performance-security** - Performance, accessibility, security