How to understand a Vue 3 codebase
Vue 3 apps are built from single-file components (`.vue` files) that hold a template, a script and styles together. Modern projects use `<script setup>` with the Composition API, share logic through composables, and keep shared state in Pinia stores.
How to tell it's Vue 3
.vuefiles andvueinpackage.jsonsrc/main.tscallingcreateApp(App)vue-routerandpiniadependencies,vite.config.tswith@vitejs/plugin-vue
Where things usually live
- src/main.ts
- Creates the app, installs the router, Pinia and plugins, then mounts.
- src/App.vue
- Root component, usually containing
<RouterView />. - src/router/index.ts
- Route table, navigation guards such as
beforeEachfor auth. - src/views/ or src/pages/
- Route-level components.
- src/components/
- Reusable components.
- src/composables/
useX()functions sharing reactive logic.- src/stores/
- Pinia stores defined with
defineStore.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
src/main.ts, to see installed pluginssrc/router/index.ts, for every screen and its guards- The Pinia stores in
src/stores/, for shared state and API calls
How a request moves through the code
main.tscreates the app and installs the router and Pinia.- The router resolves the URL, runs navigation guards, and renders a view inside
<RouterView />. - The view's
<script setup>calls composables or store actions that fetch data. - Reactive refs and store state update, and the template re-renders the affected parts.
- Child components receive props and send changes back with emitted events or
v-model.
Questions to ask about the repository
- Which navigation guards run before each route, and what do they check?
- Where is this piece of state defined, and which components change it?
- List the composables and what each one is responsible for.
- How do components talk to the backend: through stores, composables or direct calls?
What trips people up
- Destructuring a reactive object or store loses reactivity; look for
storeToRefsortoRefswhere values seem not to update. - Options API and Composition API can coexist in one codebase, so the same idea may be written two different ways.
- Globally registered components and auto-import plugins mean a component can be used without an import line; check
main.tsand Vite plugins.