Skip to content

Upgrade to the Layer Architecture

Move a project built on the Turborepo version of the kit to the new layer architecture.

This guide is for projects built on the previous version of the starter kit: Nuxt layers as workspace packages in packages/layer-*, run with Turborepo. The new version keeps the features and the database schema but changes the folder structure, the scripts and some environment variables.

The repository contains the same guide as MIGRATION.md.

What stays the same: page and API URLs, the database schema and its migrations, the better-auth and Polar setup, and the components and pages (only their location changed). End users of your app won't notice the update.

What breaks: your deployment, until you rename one environment variable, and every import or path that points into packages/layer-*.

Choose a path

  • You barely changed the kit: start from the new version and copy your few changes over.
  • You changed a lot: still start from the new version and move your code in with the tables below. A git merge of the new version into your fork works in theory, but almost every file was moved, so expect conflicts in every file you touched.

Either way, do it on a branch and deploy to a staging environment first.

1. Environment variables

The .env file moves from the repository root to apps/web/.env (compare it with apps/web/.env.example).

BeforeAfter
BETTER_AUTH_SECRETNUXT_BETTER_AUTH_SECRET
BETTER_AUTH_URLremoved: the base URL comes from NUXT_PUBLIC_BASE_URL
DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORDremoved: only NUXT_PRIVATE_DATABASE_URL is used
NODE_ENV in .envremoved: the Nuxt CLI sets it
–new, optional: NUXT_PRIVATE_EMAIL_RESEND_API_TOKEN (when NUXT_PRIVATE_EMAIL_PROVIDER=resend)

The values are now declared as Zod schemas in the runtimeConfig of each layer's nuxt.config.ts, which replaces apps/web/validate-env.ts. The server doesn't start when a required value is missing and lists the missing ones (error NUXT_E8014). See Setup for the required values.

NUXT_PRIVATE_POLAR_SERVER now defaults to sandbox. Set it to production in production.

Docker and Coolify: rename BETTER_AUTH_SECRET to NUXT_BETTER_AUTH_SECRET both as a runtime variable and as a build secret. Remove the build secrets the Dockerfile no longer reads (BETTER_AUTH_URL, DATABASE_*, POLAR_ACCESS_TOKEN, POLAR_SERVER). Without the new name the server doesn't start.

2. Scripts and tooling

Turborepo and dotenv-cli are gone. Run the scripts from the repository root as before:

BeforeAfter
pnpm dev:webpnpm dev
pnpm preview:webpnpm preview
pnpm dev:prepareruns automatically on pnpm install (nuxt prepare in apps/web)
pnpm build, lint, typecheck, test:e2e, db:*unchanged
  • Delete turbo.json and .turbo/ if you still have them.
  • The shared ESLint config (packages/eslint-config) is inlined in apps/web/eslint.config.mjs. The layers no longer have their own package.json, ESLint config, tsconfig.json or .nuxtrc.
  • All npm dependencies of the app and its layers are in apps/web/package.json. If you added dependencies to a layer's package.json, move them there. Versions still go into the catalog: of pnpm-workspace.yaml.

3. Folder structure

Layers live in apps/web/layers/<name> and are registered automatically. There is no extends in nuxt.config.ts any more.

BeforeAfter
packages/layer-<name>/…apps/web/layers/<name>/…
packages/layer-auth/server/db/migrations/apps/web/layers/auth/server/db/migrations/ (all migrations, unchanged)
packages/layer-auth/server/db/drizzle.config.tsapps/web/layers/auth/server/db/drizzle.config.ts
packages/layer-auth/server/db/schema/<table>.tsapps/web/layers/<feature>/server/db/schema/<table>.ts (see below)
.env, .env.exampleapps/web/.env, apps/web/.env.example

Most files moved 1:1. These moved into the layer of their feature:

BeforeAfter
layer-auth/server/db/schema/{banner,file,testimonial,waitlist}.tslayers/{banner,storage,testimonials,waitlist}/server/db/schema/
layer-dashboard/app/components/admin/{Banner,Testimonial*,Waitlist}*.vuelayers/{banner,testimonials,waitlist}/app/components/admin/
layer-dashboard/app/pages/dashboard/admin/index/{banner,testimonials,waitlist}.vuesame path inside layers/{banner,testimonials,waitlist}/app/pages/
layer-dashboard/server/api/dashboard/admin/{banner,testimonials,waitlist}/same path inside layers/{banner,testimonials,waitlist}/server/api/
layer-dashboard/shared/utils/banner.tslayers/banner/server/utils/useBanner.ts
apps/web/server/api/banner.get.tslayers/banner/server/api/banner.get.ts
layer-dashboard/app/components/DashboardAvatarUploader.vuelayers/storage/app/components/StorageAvatarUploader.global.vue
layer-dashboard/app/pages/dashboard/storage-test.vuelayers/storage/app/pages/dashboard/storage-test.vue
layer-core/server/utils/useCache.tslayers/storage/server/utils/useCache.ts
layer-emails/app/emails/WaitlistConfirmation.vuelayers/waitlist/app/emails/WaitlistConfirmation.vue
i18n keys of a feature in layer-core/i18n/locales/*.jsonlayers/<feature>/i18n/locales/{en,de}.json

banner is a new layer. Before, its code was spread over layer-auth, layer-dashboard and apps/web.

4. Code changes

Imports between layers

Package imports such as layer-auth/server/db/schema no longer exist, and neither does the barrel file server/db/schema/index.ts. Import the table file directly with a relative path, because drizzle-kit doesn't resolve aliases:

// before
import { user } from 'layer-auth/server/db/schema'

// after (from apps/web/layers/<layer>/server/api/…)
import { user } from '../../../auth/server/db/schema/auth'

User and Session stay auto-imported (layers/auth/shared/types/db.ts). The types of each feature are now in layers/<feature>/shared/types/ and are auto-imported too.

Required code (apps/web, core, auth, emails, payment, dashboard) no longer references optional features. If you added links or sections for your own features, register them in your layer's app/app.config.ts. See Layers.

Emails

useEmail() keeps sendContactSubmissionEmail, sendPasswordResetEmail and sendVerificationEmail. New: sendTemplate({ template, props, subject, to }) sends any component from an app/emails/ folder of any layer. sendWaitlistVerificationEmail moved to the waitlist layer as a server util with the same signature.

Loggers and server errors

useLogger() and useServerLogger() return a consola instance and take an optional tag: useServerLogger('billing'). They no longer call consola.wrapConsole(), so console.* isn't redirected any more (ESLint forbids it anyway).

A Nitro plugin (layers/core/server/plugins/error-logger.ts) logs every 5xx response. You can remove try/catch blocks that only log and rethrow. Throw createError({ statusCode, statusMessage }) as before.

Auth

useAuth() returns the same API. It now creates one better-auth client per app and loads the session only once. After that, better-auth's session store keeps it up to date, also across tabs: when a user signs out in one tab, the other tabs go to the login page on their next navigation. If your code called fetchSession() on every navigation, you can drop that. The unused user.stripeCustomerId default is gone.

Admin API handlers

Every handler under server/api/dashboard/admin/ now starts with await requireAdmin(event) (401 without a session, 403 without the admin role), in addition to the admin middleware. Add the same line to your own admin handlers; the unit test layers/dashboard/test/admin-handlers.test.ts fails for handlers without it. hasAdminRole moved to layers/auth/server/lib/roles.ts.

Removed dependencies

If your own code used one of these, add it back to apps/web/package.json or switch to the replacement:

RemovedReplacement
@vueuse/nuxt (VueUse auto-imports)Import composables explicitly: import { refDebounced } from '@vueuse/core'. @vueuse/core stays.
uuidimport { randomUUIDv7 } from 'node:crypto' (server only)
nanoidimport { randomUUID } from 'node:crypto' (server only)
@unovis/vue, @unovis/tsThe dashboard revenue chart (HomeChart.client.vue) is now a plain SVG component
better-sqlite3Nuxt Content uses Node's built-in node:sqlite. The Docker build no longer installs python3, make and g++.
tsx, happy-dom, @vue/test-utils, playwright-coreUnused, or already installed by other packages

SEO and LLM files

The skew-protection and AI-ready modules of @nuxtjs/seo are disabled in layers/core/nuxt.config.ts. /llms.txt and /llms-full.txt come from nuxt-llms. The Markdown copies of every page (/pricing.md, …) and their Link headers are gone; the docs and blog posts are available as Markdown under /raw/….

Docs routes

/docs is now a redirect route rule to /docs/getting-started. pages/docs/index.vue and the docs-redirect server middleware were removed.

Uploads (breaking)

The upload API detects the file type from the file content and no longer trusts the MIME type or file name sent by the client. The stored MIME type and extension come from the detected type.

  • Only PNG, JPEG, GIF, WebP, AVIF and PDF can be uploaded. SVG, HTML, CSV and every other type return 415, even if NUXT_PRIVATE_STORAGE_ALLOWED_MIME_TYPES lists them.
  • Without NUXT_PRIVATE_STORAGE_ALLOWED_MIME_TYPES, only the image types are allowed (before: every type). Add application/pdf to allow PDFs.
  • Without NUXT_PRIVATE_STORAGE_MAX_FILE_SIZE, the limit is 10 MB (before: no limit).

Files uploaded before stay as they are.

5. Database

No schema change and no new migration. The migrations only moved folders, so pnpm db:migrate on an existing database has nothing to apply. drizzle-kit now collects the schema from apps/web/layers/*/server/db/schema/*.ts.

If you added your own tables, put them into server/db/schema/ of the layer they belong to, run pnpm db:generate and check that the generated migration is empty. If it isn't, a table is missing from the new paths.

6. Check the result

pnpm install
pnpm lint
pnpm typecheck
pnpm build
pnpm test:e2e

Then start the build with your real apps/web/.env and click through login, billing and the admin pages before you deploy.

New in this version: you can delete the optional features you don't need (blog, docs, waitlist, testimonials, banner, storage). See Layers.