The layers/ directory contains reusable Nuxt 4 layer packages that power apps within this monorepo. Each layer encapsulates domain-specific functionality (routing, composables, server handlers, UI components) so apps can opt into a consistent feature set by extending the layer in nuxt.config.ts.
- Install or link the layers – development workspaces created with
couchfusionclone this directory alongsideapps/. When running an app locally, Nuxt can resolve layers via workspace-relative aliases (#<layer_name>). - Reference the layer in
nuxt.config.ts– add entries to theextendsarray so Nuxt merges the layer’s configuration, plugins, and components into the app build. - Review the layer docs – each layer has a
docs/folder with setup notes, API references, and change history. Some layers require environment variables or companion services. - Run the app – the standard
bun run devbootstraps Nuxt with hot reload unless overridden in the app’s dev script.
export default defineNuxtConfig({
extends: [
// layers are two levels up from the app folder
'../../layers/auth',
'../../layers/content',
'../../layers/imagekit'
],
runtimeConfig: {
public: {
authEndpoint: process.env.NUXT_PUBLIC_AUTH_ENDPOINT
}
}
})When couchfusion create_app finishes, it writes docs/module_setup.json inside the new app directory. That JSON file lists the precise extends values and any follow-up steps (for example, adding environment variables). Use it as the source of truth when wiring layers into a freshly cloned app.
| Layer | Folder | Summary |
|---|---|---|
| Analytics | layers/analytics |
Integrates Umami analytics tracking, handles excluded paths, and ships composables for anonymous event capture. |
| Auth | layers/auth |
Provides CouchDB-backed authentication flows, session middleware, and websocket token support for real-time features. |
| Content | layers/content |
Implements the content workbench, inline editor, component registry, and page configuration tooling for Nuxt CMS experiences. |
| Database | layers/database |
Supplies shared CouchDB utilities, initialization helpers, and logout/session management helpers used across apps. |
| ImageKit | layers/imagekit |
Adds ImageKit asset helpers, Nuxt image directives, library pagination, and editor integrations for media management. |
| Lightning | layers/lightning |
Connects to Lightning/Strike APIs for payment handling, subscriptions, and BTC conversion utilities. |
| Orders | layers/orders |
Offers server endpoints and utilities for managing orders and purchase flows in commerce-focused apps. |
Each layer follows a similar structure:
app/orplugins/– Nuxt resources merged into the consuming app.server/– API routes, middleware, or Nitro handlers provided by the layer.utils/ortypes/– shared helpers available to apps.docs/– setup guides, API contracts, and release notes.
Consult individual layer READMEs or docs for feature-specific guidance and environment requirements.
- Document changes in the layer’s
docs/directory (or add entries underdocs/implementation_results/) whenever you update functionality. - Notify app owners when breaking changes occur, especially if new runtime config or environment variables are introduced.
- When creating new layers, mirror this directory structure, add documentation, and update any bootstrap tooling (
couchfusionconfig) so the layer is selectable during app scaffolding.
For more detail on the CLI bootstrap process, review couchfusion/docs/specs/cli_bootstrap_prd.md and the sample configuration in couchfusion/README.md.
Automated suites live inside content/tests, powered by Vitest and a shared CouchDB harness. Follow these steps to execute them locally:
-
Create a
.envfile in thelayers/directory with CouchDB credentials and URL. Example:COUCHDB_URL=http://localhost:5984 COUCHDB_ADMIN_AUTH=$(printf 'admin:password' | base64)
Ensure the referenced CouchDB instance is reachable and allows the configured admin user.
-
Start CouchDB (if you don’t already have one running). A quick option is Docker:
docker run --rm -p 5984:5984 -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password couchdb:3
-
Install dependencies in the
layers/workspace (if not already done):bun install
-
Run the Vitest suite from the
layers/directory:bunx vitest --run
Without
--run, Vitest stays in watch mode. The config atlayers/vitest.config.tsautomatically loads.env, sets up the CouchDB harness, and discovers tests undercontent/tests. Optionally you can use--uito open the Vitest UI.
- Missing env vars → The harness throws “CouchDB admin credentials missing.” Double-check your
.env. - Connection failures (
fetch failed/EPERM) → Ensure CouchDB is running and accessible atCOUCHDB_URL. - Port conflicts during tests → Investigate the CouchDB logs; each test run creates temporary databases prefixed with
test-content-*and drops them during teardown.
This library is used by: