Skip to content

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

  • .vue files and vue in package.json
  • src/main.ts calling createApp(App)
  • vue-router and pinia dependencies, vite.config.ts with @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 beforeEach for 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

  1. src/main.ts, to see installed plugins
  2. src/router/index.ts, for every screen and its guards
  3. The Pinia stores in src/stores/, for shared state and API calls

How a request moves through the code

  1. 1main.ts creates the app and installs the router and Pinia.
  2. 2The router resolves the URL, runs navigation guards, and renders a view inside <RouterView />.
  3. 3The view's <script setup> calls composables or store actions that fetch data.
  4. 4Reactive refs and store state update, and the template re-renders the affected parts.
  5. 5Child 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 storeToRefs or toRefs where 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.ts and Vite plugins.