As applications grow, managing shared code across projects becomes increasingly difficult. Teams often face problems like:
- Duplicated logic across repositories
- Inconsistent project structure
- Hard-to-maintain design systems
- Repeated configuration setup
This is where Nuxt Layers become extremely useful.
In this article, weβll explore:
- What Nuxt Layers are
- How they work
- How to use them to reuse code across projects
- How they help build scalable architecture
- Potential tradeoffs and when to avoid them
Letβs dive in.
π€ What Are Nuxt Layers?
Nuxt Layers allow one Nuxt project to extend another using the extends feature.
In practice, this means you can create a base layer containing shared logic, and multiple applications can build on top of it.
A layer can include:
- Components
- Composables
- Pages
- Layouts
- Middleware
- Configuration
- Modules
Think of layers as reusable Nuxt building blocks.
Example architecture:
base-layer/
components/
composables/
layouts/
nuxt.config.ts
app/
pages/
nuxt.config.ts
The application extends the base layer.
π’ Creating a Nuxt Layer
A layer is essentially a Nuxt project that other projects can extend.
Example layer structure:
ui-layer/
components/
AppButton.vue
composables/
useTheme.ts
nuxt.config.ts
Then in your application:
export default defineNuxtConfig({
extends: ['../ui-layer']
})
Now everything inside the layer becomes available inside your app.
For example, the AppButton component can be used directly:
<AppButton>
Click me
</AppButton>
No additional imports required. This makes sharing UI systems across multiple apps much easier.
π’ Reusing Code Across Multiple Projects
One of the biggest benefits of Nuxt Layers is code reuse across multiple repositories.
For example, you may create layers for:
- UI components
- Authentication logic
- Analytics integrations
- Design systems
- API composables
Example layered architecture:
core-layer
composables/
utils/
ui-layer
components/
layouts/
marketing-app
admin-app
dashboard-app
Each application extends the shared layers.
Example configuration:
export default defineNuxtConfig({
extends: [
'../core-layer',
'../ui-layer'
]
})
This ensures that:
- Shared code lives in one place
- Updates propagate across projects
- Teams maintain consistent patterns
Itβs particularly useful for large organizations managing multiple applications.
π’ Using Layers for Scalable Architecture
Nuxt Layers also help structure large applications.
Instead of a single large codebase, you can divide your system into logical layers.
Example architecture:
design-system-layer
business-logic-layer
feature-layer
app-layer
Each layer builds on top of the previous one.
Example:
design-system-layer
components/
styles/
business-layer
composables/
feature-layer
pages/
components/
app-layer
pages/
Then your main application config:
export default defineNuxtConfig({
extends: [
'../design-system-layer',
'../business-layer',
'../feature-layer'
]
})
This approach:
- Improves maintainability
- Encourages separation of concerns
- Helps teams scale development
It becomes easier to reason about the architecture of large Nuxt projects.
π’ Layer Overrides and Merging
One powerful aspect of Nuxt Layers is that later layers override earlier ones.
For example:
base-layer/components/Header.vue
app/components/Header.vue
The application version overrides the base layer component.
This allows you to:
- Provide defaults in layers
- Customize behavior in applications
Configuration is also merged automatically.
Example:
export default defineNuxtConfig({
runtimeConfig: {
apiBase: '/api'
}
})
If multiple layers define runtimeConfig, Nuxt merges them.
This merging behavior makes layers flexible and customizable.
β οΈ Tradeoffs of Nuxt Layers
While layers are powerful, they introduce some complexity.
Increased Architectural Complexity
When many layers are involved, it can become harder to understand:
- Where components come from
- Which layer overrides which
- How configuration is merged
This can slow onboarding for new developers.
Debugging Can Be Harder
If a component behaves unexpectedly, you may need to check multiple layers.
Example problem:
Component defined in:
- layer A
- layer B
- application
Understanding which one is active requires careful inspection.
Tooling and IDE Navigation
Depending on your editor setup, navigating across layers may be less straightforward than working within a single project.
Although modern Nuxt tooling is improving, it still requires good project organization.
Overengineering Risk
For small projects, layers may be unnecessary.
If you only have one application, layers may introduce more complexity than value.
They shine most when:
- Managing multiple applications
- Building reusable systems
- Maintaining design systems
π Learn more
If you would like to learn more about Vue, Nuxt, JavaScript or other useful technologies, checkout VueSchool by clicking this link or by clicking the image below:
It covers most important concepts while building modern Vue or Nuxt applications that can help you in your daily work or side projects π
π§ͺ Advance skills
A certification boosts your skills, builds credibility, and opens doors to new opportunities. Whether you're advancing your career or switching paths, it's a smart step toward success.
Check out Certificates.dev by clicking this link or by clicking the image below:
Invest in yourselfβget certified in Vue.js, JavaScript, Nuxt, Angular, React, and more!
β Summary
Nuxt Layers introduce a powerful way to structure and reuse code across applications. When used correctly, layers can transform a collection of applications into a well-organized ecosystem of reusable building blocks.
But like any architectural tool, they should be applied thoughtfully and only when they truly provide value.
Take care!
And happy coding as always π₯οΈ


Top comments (0)