Patterns for Large Scale Vue.js Applications

Rate this content
Bookmark

What is the best way to structure a Vue.js application so that it can scale to meet all your users' needs? There are multiple patterns established by the Vue community and the programming community at large that can be adopted in order to make your codebases more predictable, maintainable, and extendable.

FAQ

Daniel Kelly is the lead instructor at the school and a full-stack developer with over 10 years of experience. He specializes in technologies such as Wearable on the backend and Vue.js on the front end.

In Vue.js, it is recommended to use Pascal case for component names, prefix base components with 'App' or 'Base', use multi-word names to avoid conflicts with existing HTML elements, and prefix single instance components with 'the'.

The Vue.js style guide suggests naming components in Pascal case, using prefixes like 'App' or 'Base' for general use components, and 'The' for components used once per page. It also recommends multi-word names to prevent conflicts with HTML elements.

Vue.js applications can maintain predictability by following the Vue.js style guide, using officially recommended tooling like Vite and Vuex, and considering frameworks like Nuxt3 for structured project setup.

Using officially recommended tooling in Vue.js ensures compatibility, better developer experience (DX), and familiarity for new team members, which simplifies project onboarding and maintenance.

Wrapping third-party code in Vue.js applications allows for easier maintenance, reduces the risk of dependency lock-in, and enables application-specific optimizations, making the codebase more adaptable and easier to manage.

Using an SDK in Vue.js projects helps prevent typos in API routes, allows for client-side data normalization, ensures type safety, and simplifies error handling, leading to more robust and maintainable code.

TypeScript enhances code quality in large-scale Vue.js projects by providing stronger type checks, reducing runtime errors, facilitating safer refactoring, and improving IDE auto-completion capabilities.

Daniel Kelly
Daniel Kelly
24 min
15 May, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

In this Talk, Daniel Kelly discusses patterns for large-scale Vue.js app development, emphasizing the importance of following standards and using officially recommended tooling. He highlights the Vue.js style guide as a valuable resource for styling standards and suggests using TypeScript and Nuxt 3 to enhance development capabilities. He also mentions the benefits of having a naming convention for routes and the concept of wrapping third-party dependencies for flexibility. Additionally, he mentions the app-icon component for a generic icon solution and the advantages of interacting with backends via an SDK.

1. Introduction to Large-Scale Vue.js App Development

Short description:

Hello! My name is Daniel Kelly, and I am the lead instructor at the school. Today, we will discuss patterns for large-scale Vue.js app development and the importance of structuring a maintainable and extendable application. One key tip is to make your code base predictable by following standards. The Vue.js style guide is the official resource for styling standards in the Vue.js community. It provides guidelines for component naming, such as using Pascal case and prefixing base components with 'app' or 'base'. Single instance components should be prefixed with 'the', and tightly coupled child components should have prefixed names. Following these standards helps ensure clarity and prevent conflicts. This is just a sample of the guidelines available in the style guide.

Hello! My name is Daniel Kelly, and I am the lead instructor at the school. I am so very excited to be with you all here today. I have been a full-stack developer for the past 10 plus years, worked with technologies like Wearable on the back end, and of course, Vue.js on the front end. But that's enough about me. I just wanted to quickly let you know who it is you're dealing with, but now let's get on to today's topic at hand, okay?

And that is looking at some patterns for large-scale Vue.js app development, right? So, our goal during this session is to answer this question, what is the best way to structure a Vue.js application so that it can continue to be maintainable and extendable, even as it gets to a very large size, right? Why is this question important? Because we've probably all been given a task for a particular app before and had this exact feeling. We just don't know where to begin, we don't even know how to approach the issue, maybe because things are a little bit messy. So, our goal is to eliminate this feeling here as much as humanly possible. All right, we all wanna enjoy our jobs and be less frustrated.

Okay, so I'm gonna start with this key tip for making a large-scale application, that is make your code base predictable. This first tip is really not that exciting, it's really not that flashy, but to be honest, this is one of the keys, in my opinion, to building a maintainable app. Make it as predictable as possible by following standards, so that everybody knows where to look and how certain things work. So, this begs the question, where do standards for the Vue.js community exist? Place number one that comes to mind for me is the Vue.js style guide. This is the official place for styling standards for the Vue framework. Here is an example of some standards designated within the document. When it comes to naming your components, first of all, it says that all of your components should be in the Pascal case. It also mentions you should prefix your base components with the word, app, or base. So, these are all those components that you're going to be using throughout your application, and they're a lot more general use case, right? These are things like AppButton, AppTable, AppModal, things like that. Things that accept props down and events up, and probably don't rely on any global state, okay? I actually prefer to use App in this instance because it always puts my base components at the very top of my components directory. It also mentions that you should have multi-worded names for your components. This is actually even more than just a style thing, it's also to prevent conflicts between existing or future HTML elements and your new components. Another standard is to prefix all your single instance components with the word, the. These are any components that are just going to be used on the page a single time. Now, they could absolutely be used on multiple pages, but they only appear on a single instance of a page at a time. So this is usually layout type components, things like the header, the footer, the sidebar, so on and so forth. It's also mentioned that you should prefix tightly coupled child components. For example, if you had a component for an item that always existed within a to-do list, you would prefix that component name with to-do list, and then item. A real-world application of this that I used in a codebase at my previous job was I had a job form component, and then there was a special field for choosing the location where a job should be advertised called job form location map field. Okay, so this tells any other developers within the project that this component is really only meant to ever be used in the context of the job form. And they can get that just by looking at the component name. Okay, this is great, and there are some other tips on styling your component names within the style guide as well, but this is just a good sampling, and there's certainly a lot more available in the style guide besides just component naming.

2. Standards, Tooling, and IDE

Short description:

Implementing standards in your project reduces cognitive load for new team members. The Vue.js style guide provides guidelines for component naming and other styling standards. The guide is currently outdated but still valuable. The officially recommended tooling for Vue.js, such as Vite and Opinion, provides useful resources. Avoid custom solutions when there are officially recommended ones. NUX3 is a reliable source of predictability due to its conventions and popularity. Taking full advantage of your IDE, installing Volar and ESLint, helps catch errors and improve development experience. IDE formatting, whether with ESLint or Prettier, ensures consistent code style.

But this is just a good sampling to kind of show you, hey, if you implement these standards, it's one less cognitive thing that people who are onboarded to your project have to think about, because they're standards that everybody already knows, okay?

By the way, just at the time of this talk, it is important to note this warning at the top of the style guide, and that is it's currently a bit outdated. Most of the examples are in the Options API only, and there are no rules regarding Script Setup and the Composition API. However, as you just saw, a lot of the things for styling don't even necessarily have to deal with one API or another. All of the component naming things could apply to either API. So this is still a great resource, but do expect it to be updated in the future, okay?

Another really great resource for standards is the officially recommended tooling for Vue.js, all right? That's found on the tooling page of the official Vue.js docs. It provides reference to things like Vite for your development server and Opinion for global state management. This might seem like it could go without saying, but maybe I've ignored some of my own advice in the past and I want to make sure you don't do the same. What do I mean? Well, one of the projects I was working on prior to joining Vue School, of course, needed global state management. Well, I wasn't thrilled about the DX that Vuex provided, and so I came up with my own global state management solution based around the Vue.Observable API in Vue 2. Long story short is, yes, there were some DX improvements. However, there were more downsides than upsides. There were caching issues that I didn't handle that Vuex would have already handled for me under the hood. There were onboarding issues when it came to moving new people to the project who I had to explain this custom solution to that if I just used Vuex they would have already been familiar with it or at least I could have just pointed them in the direction of the Vuex docs, right? So the key takeaway here is if there is an officially recommended solution for your problem, definitely think long and hard before you use anything else, okay?

So predictability from the style guide, predictability from the officially recommended tooling, and then finally another great source, I think, of predictability is the metaframework NUX3, okay? It makes a lot of opinionated decisions and it's such a huge player in the Vue.js community a lot of people are going to be familiar with the conventions that it provides. So definitely recommend taking cues from NUX3 when it comes to structuring your application or just using NUX3 to begin with. By the way, you will see NUX3 come up a few more times in this talk because I think it's such an excellent piece of software.

Alright, so tip number two is to take full advantage of your IDE. This is after all the software that you're going to be using most in order to develop your application. Number one, that means make sure to install Volar, that's probably pretty obvious. However, number two is also make sure you have ESLint installed on all your projects. I've had projects that I've worked on before where we didn't do this. Let me tell you, it was an absolute pain because ESLint is going to help you catch items directly inside of your IDE without having to wait to find out about them at runtime. In fact, it's gonna show you errors in your IDE that you might not even get hard errors for within the browser, all right?

So, for example, in this little piece of code, we're using a V4 to loop over item in items but we have left off the key. This would not error in the browser but my IDE knows now because of ESLint I should really add this key to my V4. And then the same thing down here for this Hello World component. It's being imported and registered. However, it's not actually being used anywhere inside of my template. And so ESLint is saving my end user from having to download this extra code that's never even used. Right, I get this essentially for free just by installing ESLint, okay?

Similar to this is making sure your IDE's formatting is set up appropriately. Okay, this could be the formatting that is built in with ESLint or it could be a more opinionated formatter like Prettier.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Everything Beyond State Management in Stores with Pinia
Vue.js London Live 2021Vue.js London Live 2021
34 min
Everything Beyond State Management in Stores with Pinia
Top Content
When we think about Vuex, Pinia, or stores in general we often think about state management and the Flux patterns but not only do stores not always follow the Flux pattern, there is so much more about stores that make them worth using! Plugins, Devtools, server-side rendering, TypeScript integrations... Let's dive into everything beyond state management with Pinia with practical examples about plugins and Devtools to get the most out of your stores.
Welcome to Nuxt 3
Vue.js London Live 2021Vue.js London Live 2021
29 min
Welcome to Nuxt 3
Top Content
Explain about NuxtJS codebase refactor and challenges facing to implement Vue 3, Vite and other packages.
One Year Into Vue 3
Vue.js London Live 2021Vue.js London Live 2021
20 min
One Year Into Vue 3
Top Content
Vue 3 may still sound new to many users, but it's actually been released for over a year already. How did Vue 3 evolve during this period? Why did it take so long for the ecosystem to catch up? What did we learn from this process? What's coming next? We will discuss these questions in this talk!
Utilising Rust from Vue with WebAssembly
Vue.js London Live 2021Vue.js London Live 2021
8 min
Utilising Rust from Vue with WebAssembly
Top Content
Rust is a new language for writing high-performance code, that can be compiled to WebAssembly, and run within the browser. In this talk you will be taken through how you can integrate Rust, within a Vue application, in a way that's painless and easy. With examples on how to interact with Rust from JavaScript, and some of the gotchas to be aware of.
Vue: Feature Updates
Vue.js London 2023Vue.js London 2023
44 min
Vue: Feature Updates
Top Content
The creator of Vue js gives an update on the new features of the technology.
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.

Workshops on related topic

Vue3: Modern Frontend App Development
Vue.js London Live 2021Vue.js London Live 2021
169 min
Vue3: Modern Frontend App Development
Top Content
Featured WorkshopFree
Mikhail Kuznetcov
Mikhail Kuznetcov
The Vue3 has been released in mid-2020. Besides many improvements and optimizations, the main feature of Vue3 brings is the Composition API – a new way to write and reuse reactive code. Let's learn more about how to use Composition API efficiently.

Besides core Vue3 features we'll explain examples of how to use popular libraries with Vue3.

Table of contents:
- Introduction to Vue3
- Composition API
- Core libraries
- Vue3 ecosystem

Prerequisites:
IDE of choice (Inellij or VSC) installed
Nodejs + NPM
Using Nitro – Building an App with the Latest Nuxt Rendering Engine
Vue.js London Live 2021Vue.js London Live 2021
117 min
Using Nitro – Building an App with the Latest Nuxt Rendering Engine
Top Content
Workshop
Daniel Roe
Daniel Roe
We'll build a Nuxt project together from scratch using Nitro, the new Nuxt rendering engine, and Nuxt Bridge. We'll explore some of the ways that you can use and deploy Nitro, whilst building a application together with some of the real-world constraints you'd face when deploying an app for your enterprise. Along the way, fire your questions at me and I'll do my best to answer them.
Going on an adventure with Nuxt 3, Motion UI and Azure
JSNation 2022JSNation 2022
141 min
Going on an adventure with Nuxt 3, Motion UI and Azure
WorkshopFree
Melanie de Leeuw
Melanie de Leeuw
We love easily created and deployed web applications! So, let’s see what a very current tech stack like Nuxt 3, Motion UI and Azure Static Web Apps can do for us. It could very well be a golden trio in modern day web development. Or it could be a fire pit of bugs and errors. Either way it will be a learning adventure for us all. Nuxt 3 has been released just a few months ago, and we cannot wait any longer to explore its new features like its acceptance of Vue 3 and the Nitro Engine. We add a bit of pizzazz to our application with the Sass library Motion UI, because static design is out, and animations are in again.Our driving power of the stack will be Azure. Azure static web apps are new, close to production and a nifty and quick way for developers to deploy their websites. So of course, we must try this out.With some sprinkled Azure Functions on top, we will explore what web development in 2022 can do.
TresJS create 3D experiences declaratively with Vue Components
Vue.js London 2023Vue.js London 2023
137 min
TresJS create 3D experiences declaratively with Vue Components
Workshop
Alvaro Saburido
Alvaro Saburido
- Intro 3D - Intro WebGL- ThreeJS- Why TresJS- Installation or Stackblitz setup - Core Basics- Setting up the Canvas- Scene- Camera- Adding an object- Geometries- Arguments- Props- Slots- The Loop- UseRenderLoop composable- Before and After rendering callbacks- Basic Animations- Materials- Basic Material- Normal Material- Toon Material- Lambert Material- Standard and Physical Material- Metalness, roughness - Lights- AmbientLight- DirectionalLight- PointLights- Shadows- Textures- Loading textures with useTextures- Tips and tricks- Misc- Orbit Controls- Loading models with Cientos- Debugging your scene- Performance
Building Vue forms with VeeValidate
Vue.js London Live 2021Vue.js London Live 2021
176 min
Building Vue forms with VeeValidate
Workshop
Abdelrahman Awad
Abdelrahman Awad
In this workshop, you will learn how to use vee-validate to handle form validation, manage form values and handle submissions effectively. We will start from the basics with a simple login form all the way to using the composition API and building repeatable and multistep forms.

Table of contents:
- Introduction to vee-validate
- Building a basic form with vee-validate components
- Handling validation and form submissions
- Building validatable input components with the composition API
- Field Arrays and repeatable inputs
- Building a multistep form
Prerequisites:
VSCode setup and an empty Vite + Vue project.
Building full-stack GraphQL applications with Hasura and Vue 3
Vue.js London Live 2021Vue.js London Live 2021
115 min
Building full-stack GraphQL applications with Hasura and Vue 3
WorkshopFree
Gavin Ray
Gavin Ray
The frontend ecosystem moves at a breakneck pace. This workshop is intended to equip participants with an understanding of the state of the Vue 3 + GraphQL ecosystem, exploring that ecosystem – hands on, and through the lens of full-stack application development.

Table of contents
- Participants will use Hasura to build out a realtime GraphQL API backed Postgres. Together we'll walk through consuming it from a frontend and making the front-end reactive, subscribed to data changes.
- Additionally, we will look at commonly-used tools in the Vue GraphQL stack (such as Apollo Client and Urql), discuss some lesser-known alternatives, and touch on problems frequently encountered when starting out.
- Multiple patterns for managing stateful data and their tradeoffs will be outlined during the workshop, and a basic implementation for each pattern discussed will be shown.
Workshop level

NOTE: No prior experience with GraphQL is necessary, but may be helpful to aid understanding. The fundamentals will be covered.