DEV Community

Cover image for Reusable Architecture for Large Applications with Nuxt Layers
Jakub Andrzejewski
Jakub Andrzejewski

Posted on

Reusable Architecture for Large Applications with Nuxt Layers

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Then in your application:

export default defineNuxtConfig({
  extends: ['../ui-layer']
})
Enter fullscreen mode Exit fullscreen mode

Now everything inside the layer becomes available inside your app.

For example, the AppButton component can be used directly:

<AppButton>
  Click me
</AppButton>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Each application extends the shared layers.

Example configuration:

export default defineNuxtConfig({
  extends: [
    '../core-layer',
    '../ui-layer'
  ]
})
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

Then your main application config:

export default defineNuxtConfig({
  extends: [
    '../design-system-layer',
    '../business-layer',
    '../feature-layer'
  ]
})
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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'
  }
})
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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:

Vue School Link

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:

Certificates.dev Link

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)