Vuex on large projects: How to structure it ?

Mustafa Dalga
heybooster
Published in
2 min readNov 21, 2021

If you are using vuex in a small project, you can keep state, mutation, getters, and actions in a single file.

On the other hand, when developing a large project, we can divide vuex into modules based on categories, thereby keeping file sizes down, keeping the code cleaner, and increasing the chances of more than one developer being able to work on the project at the same time.

We can also separate state, mutation, getters, and actions within these modules. By using vuex modules, we want to increase manageability and understandability.

I will explain and show how to create modules per categories in this blog post. I will divide this blog post into two parts and explain how to exchange data between these modules in the second post, so as not to prolong it.

Modules

  1. auth: This module stores and processes data about user accounts.
  2. movies: This module stores and processes data about movies.
  3. notifications: This module stores and processes data about warnings, errors, etc.
Vuex modules
Vuex modules

Every module has its own state, mutations, getters, and actions files.

Module files

In each module, we create an index.js file that collects state, mutations, getters, and actions.

store/modules/movies/index.js

We import these modules and define them in the main store file index.js.

store/index.js

main.js uses it as follows:

main.js

As a result, vuex needs to be used more accurately to provide a more manageable and clean project.

The sample project is on my github account and the demo is on netlify.

Originally published at heybooster.

--

--

Mustafa Dalga
heybooster

Software Developer | Nature and Animal Photographer