How to understand a React with Vite codebase
A Vite React app is a single-page application: `index.html` loads one script, React mounts into a root element, and a client-side router decides what to show. Everything runs in the browser, so the interesting structure is the router, the data-fetching layer and where state lives.
How to tell it's React with Vite
vite.config.tswith@vitejs/plugin-reactor@vitejs/plugin-react-swcindex.htmlat the project root with<script type="module" src="/src/main.tsx">- Environment variables read as
import.meta.env.VITE_*
Where things usually live
- index.html
- The real entry point. Vite starts from the script tag here.
- src/main.tsx
- Calls
createRoot(...).render(<App />)and usually wraps providers. - src/App.tsx
- Top-level component; often defines routes or layout.
- src/routes/ or src/pages/
- Screen components, wired up by React Router, TanStack Router or similar.
- src/components/
- Reusable UI.
- src/hooks/
- Custom hooks: data fetching, subscriptions, shared behaviour.
- src/api/ or src/services/
- HTTP client and functions that call the backend.
- vite.config.ts
- Aliases such as
@/, dev-server proxy to the API, build options.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
src/main.tsx, to see providers (router, query client, store, theme)- The router definition, to list every screen
- The API client in
src/api/, to see which backend the app talks to
How a request moves through the code
- The browser loads
index.html, which loadssrc/main.tsx. main.tsxmounts<App />inside providers such as a router and a data-fetching client.- The router matches the URL and renders a screen component.
- The screen calls hooks that fetch data from the API client, often via TanStack Query or a custom hook.
- User actions update local state or a store, or send mutations to the backend and refetch.
Questions to ask about the repository
- List every route and the component that renders it.
- How does the app authenticate requests to the backend, and where is the token stored?
- Where does global state live, and which components read from it?
- Which environment variables does the app expect?
- What does the dev-server proxy in
vite.config.tsforward, and to where?
What trips people up
- Anything in
import.meta.env.VITE_*is bundled into public JavaScript, so it is not a secret. - Path aliases like
@/componentsare defined in bothvite.config.tsandtsconfig.json; if they disagree, editors and builds resolve differently. - There is no server: features that look like backend logic usually call an API defined in another repository.