How to understand a Qwik codebase
Qwik is built around resumability: the server renders HTML and serialises state so the browser can continue without re-running the app. The `$` suffix marks code the optimizer can split into lazily loaded chunks, which changes how you read the code: almost every handler is its own entry point.
How to tell it's Qwik
@builder.io/qwikor@qwik.dev/coreinpackage.jsoncomponent$,useSignal,useTask$andonClick$throughout- Qwik City routes under
src/routes/withindex.tsxandlayout.tsx
Where things usually live
- src/routes/**/index.tsx
- Pages; the folder path is the URL.
- src/routes/**/layout.tsx
- Shared layouts and route-level loaders.
- src/components/
- Components declared with
component$. - src/entry.ssr.tsx
- Server rendering entry.
- src/root.tsx
- The document root.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
src/routes/for the page you care aboutrouteLoader$androuteAction$exports, which hold server-side data logicsrc/root.tsxfor global setup
How a request moves through the code
- The server matches a route and runs its
routeLoader$functions. - Components render to HTML with state serialised into the page.
- In the browser, nothing runs until the user interacts.
- An
onClick$handler's chunk downloads on demand and runs with the resumed state. - Form posts call
routeAction$on the server, and loaders re-run to refresh data.
Questions to ask about the repository
- Which data is loaded on the server for this route, and where?
- What state is serialised into the page, and is any of it sensitive?
- Which server functions (
server$) can the browser call?
What trips people up
- Values captured inside a
$closure must be serialisable, so some patterns that work in React fail here. - Debugging requires thinking in lazily loaded chunks; a handler's code may not exist in the browser until it runs.