---
title: "How it works"
description: "How the Convex client, the Nuxt server and the same-origin auth proxy fit together, which component each capability runs on, and who owns what between the backend component, your app and the providers."
canonical_url: "https://nuxt-backend.dev/docs/start/concepts/how-it-works"
---
# How it works

> How the Convex client, the Nuxt server and the same-origin auth proxy fit together, which component each capability runs on, and who owns what between the backend component, your app and the providers.

Version: nuxt-backend 0.6.x · Tab: Start · Kind: concept · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

The package ships two halves in one install: a Nuxt module for your app, and one Convex component for your backend. The [capabilities](https://nuxt-backend.dev/docs/start/concepts/capabilities) are what they give your app. This page is how the halves fit together, and which request takes which path. It is one module in `modules`, never a Nuxt layer in `extends` ([Principles](https://nuxt-backend.dev/docs/start/concepts/principles#one-module-not-a-nuxt-layer)).

<table>
<thead>
  <tr>
    <th>
      Half
    </th>
    
    <th>
      What it does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        Nuxt module
      </strong>
      
       (<code>
        nuxt-backend
      </code>
      
      )
    </td>
    
    <td>
      Registers plugins, composables, components, server utilities and the auth proxy, mounts the ready-made pages, and loads the CSS of the capabilities it detects
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Convex component
      </strong>
      
       (<code>
        nuxt-backend/convex.config
      </code>
      
      )
    </td>
    
    <td>
      Defines the all-in-one <code>
        backend
      </code>
      
       component: the Better Auth adapter and auth tables, transactional email (Resend's component nested inside), the billing entitlement cache, gifts, AI metering records, the webhook delivery log, the activity trail and feature flags
    </td>
  </tr>
</tbody>
</table>

The scaffolded `convex.config.ts` mounts the `backend` component and the official `@convex-dev/*` components its setup helpers use, one explicit `app.use` each. A component your own code needs, such as an aggregate, your app mounts beside them ([the component tree](#one-backend-component-beside-the-official-ones)).

## Request flows

Three transports run side by side, each with its own path through the stack:

<card-group>
<card icon="i-lucide-zap" title="Real-time">

`Browser ⇄ Convex deployment` over a WebSocket (`ConvexVueClient`): queries subscribe, and the deployment pushes live updates.

</card>

<card icon="i-lucide-server" title="SSR">

`Browser → Nuxt → Convex` over HTTP (`ConvexHttpClient`): the server renders the HTML and ships a hydration payload.

</card>

<card icon="i-lucide-shield-check" title="Auth">

`Browser → /api/auth/* → Nuxt proxy → Better Auth → Convex`: the session token and `Set-Cookie` come back same-origin.

</card>
</card-group>

### Real-time data

The client, `ConvexVueClient`, keeps one WebSocket open to the deployment. `useQuery`, `useMutation`, `useAction` and pagination go through it, and every subscribed query updates live, in every open tab ([Query and update data](https://nuxt-backend.dev/docs/build/data/read-write)).

<demo-connection>



</demo-connection>

### SSR

During the server render, `useAsyncQuery` fetches a query over HTTP as the signed-in person and hands the result to the browser, which goes live without fetching it again. Nuxt server routes call the deployment with `fetchQuery`, `fetchMutation` and `fetchAction`, or as the signed-in person through `backendAuth(event)` ([Render data on the server](https://nuxt-backend.dev/docs/build/data/read-write/server-rendering)).

### Authentication

`/api/auth/*` is proxied from Nuxt to the deployment's site URL, so cookies stay on your domain. Better Auth keeps users and sessions through the adapter inside the `backend` component, and issues a session token the client authenticates its WebSocket with ([Auth](https://nuxt-backend.dev/docs/build/auth)).

### Inbound webhooks

One more path ends in the backend without a browser in front: `Provider → <site URL>/billing/events | /email/events → Convex HTTP router`. `registerBackendRoutes` in the scaffolded `http.ts` mounts both, beside the metered AI stream at `/ai/stream` and the health check. Every delivery is verified once with Standard Webhooks, deduplicated and logged, and the route answers `503` until its secret is set ([Register webhooks](https://nuxt-backend.dev/docs/ship/security/webhooks)).

<note>

This mirrors the official Convex and Better Auth integration: realtime over a WebSocket, server rendering over HTTP, and a same-origin auth proxy that keeps cookies on your domain.

</note>

## What it mounts

`nuxt-backend` ships one [Convex component](https://www.convex.dev/components) of its own, the all-in-one `backend` component, and sets up the official components its helpers build on. Each capability is set up by one helper in one scaffold file: [Setup helpers](https://nuxt-backend.dev/docs/reference/backend) lists every helper with its file, and [Ecosystem](https://nuxt-backend.dev/docs/reference/ecosystem) the components that work beside these.

<table>
<thead>
  <tr>
    <th>
      Capability
    </th>
    
    <th>
      Component
    </th>
    
    <th>
      Entrypoint
    </th>
    
    <th>
      Setup helper
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Auth
    </td>
    
    <td>
      <code>
        backend
      </code>
      
       (the Better Auth tables and adapter)
    </td>
    
    <td>
      <code>
        nuxt-backend/auth
      </code>
    </td>
    
    <td>
      <code>
        setupAuth
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Access tiers and errors
    </td>
    
    <td>
      None: function builders over your own <code>
        query
      </code>
      
      , <code>
        mutation
      </code>
      
       and <code>
        action
      </code>
    </td>
    
    <td>
      <code>
        nuxt-backend/functions
      </code>
    </td>
    
    <td>
      <code>
        createFunctions
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Launch access and the waitlist
    </td>
    
    <td>
      <code>
        backend
      </code>
    </td>
    
    <td>
      <code>
        nuxt-backend/access
      </code>
    </td>
    
    <td>
      <code>
        setupAccess
      </code>
      
      , <code>
        setupWaitlist
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Account export, deletion and consents
    </td>
    
    <td>
      <code>
        backend
      </code>
    </td>
    
    <td>
      <code>
        nuxt-backend/account
      </code>
    </td>
    
    <td>
      <code>
        setupAccount
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Admin console
    </td>
    
    <td>
      <code>
        backend
      </code>
    </td>
    
    <td>
      <code>
        nuxt-backend/admin
      </code>
    </td>
    
    <td>
      <code>
        setupAdmin
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Activity trail
    </td>
    
    <td>
      <code>
        backend
      </code>
    </td>
    
    <td>
      <code>
        nuxt-backend/audit
      </code>
    </td>
    
    <td>
      <code>
        setupAudit
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Feature flags
    </td>
    
    <td>
      <code>
        backend
      </code>
    </td>
    
    <td>
      <code>
        nuxt-backend/flags
      </code>
    </td>
    
    <td>
      <code>
        defineFlags
      </code>
      
      , <code>
        setupFlags
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Email
    </td>
    
    <td>
      <code>
        backend
      </code>
      
       (nests <a href="https://www.convex.dev/components/resend" rel="nofollow">
        <code>
          @convex-dev/resend
        </code>
      </a>
      
      )
    </td>
    
    <td>
      <code>
        nuxt-backend/email
      </code>
    </td>
    
    <td>
      <code>
        setupEmail
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Notifications
    </td>
    
    <td>
      <code>
        backend
      </code>
    </td>
    
    <td>
      <code>
        nuxt-backend/notifications
      </code>
    </td>
    
    <td>
      <code>
        setupNotifications
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Billing
    </td>
    
    <td>
      <a href="https://www.convex.dev/components/polar" rel="nofollow">
        <code>
          @convex-dev/polar
        </code>
      </a>
      
      , <a href="https://www.convex.dev/components/sharded-counter" rel="nofollow">
        <code>
          @convex-dev/sharded-counter
        </code>
      </a>
      
       (plan quotas) and <code>
        backend
      </code>
      
       (the entitlement and credit cache, gifts)
    </td>
    
    <td>
      <code>
        nuxt-backend/billing
      </code>
    </td>
    
    <td>
      <code>
        setupBilling
      </code>
      
      , <code>
        defineBillingCatalog
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Files
    </td>
    
    <td>
      <code>
        backend
      </code>
      
      , over Convex file storage
    </td>
    
    <td>
      <code>
        nuxt-backend/storage
      </code>
    </td>
    
    <td>
      <code>
        setupStorage
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Webhooks and routes
    </td>
    
    <td>
      None: HTTP routes over auth, billing, email and AI
    </td>
    
    <td>
      <code>
        nuxt-backend/http
      </code>
    </td>
    
    <td>
      <code>
        registerBackendRoutes
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Monitoring
    </td>
    
    <td>
      None: actions post to the DSN
    </td>
    
    <td>
      <code>
        nuxt-backend/monitoring
      </code>
    </td>
    
    <td>
      <code>
        reportError
      </code>
      
      , <code>
        checkIn
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Rate limiting
    </td>
    
    <td>
      <a href="https://www.convex.dev/components/rate-limiter" rel="nofollow">
        <code>
          @convex-dev/rate-limiter
        </code>
      </a>
    </td>
    
    <td>
      <code>
        nuxt-backend/rate-limit
      </code>
    </td>
    
    <td>
      <code>
        setupRateLimiter
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Metered AI and generation jobs
    </td>
    
    <td>
      <a href="https://www.convex.dev/components/persistent-text-streaming" rel="nofollow">
        <code>
          @convex-dev/persistent-text-streaming
        </code>
      </a>
      
      , <a href="https://www.convex.dev/components/workpool" rel="nofollow">
        <code>
          @convex-dev/workpool
        </code>
      </a>
      
       and <code>
        backend
      </code>
      
       (the request records)
    </td>
    
    <td>
      <code>
        nuxt-backend/ai
      </code>
    </td>
    
    <td>
      <code>
        setupAi
      </code>
      
      , <code>
        defineJobQueue
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Workflows and email sequences
    </td>
    
    <td>
      <a href="https://www.convex.dev/components/workflow" rel="nofollow">
        <code>
          @convex-dev/workflow
        </code>
      </a>
    </td>
    
    <td>
      <code>
        nuxt-backend/workflows
      </code>
    </td>
    
    <td>
      <code>
        setupWorkflows
      </code>
      
      , <code>
        defineEmailSequence
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Search
    </td>
    
    <td>
      Convex's native full-text search
    </td>
    
    <td>
      <code>
        nuxt-backend/search
      </code>
    </td>
    
    <td>
      <code>
        defineSearch
      </code>
    </td>
  </tr>
</tbody>
</table>

Your own counters, aggregates, cached actions, queues and migrations come straight from their official components: [`@convex-dev/sharded-counter`](https://www.convex.dev/components/sharded-counter) (the scaffold already mounts it for plan quotas), [`@convex-dev/aggregate`](https://www.convex.dev/components/aggregate), [`@convex-dev/action-cache`](https://www.convex.dev/components/action-cache), [`@convex-dev/workpool`](https://www.convex.dev/components/workpool) and [`@convex-dev/migrations`](https://www.convex.dev/components/migrations). Your app mounts the one it needs and imports it directly, as the [Data](https://nuxt-backend.dev/docs/build/data) recipes show. The package's own maintenance runs inside its component, so your app registers no cron for it.

### The scaffolded `convex.config.ts`

`npx nuxt-backend init` writes `backend/convex.config.ts`. It mounts the `backend` component and the official components the setup helpers use, and declares the typed env contract (`backendEnv` from `nuxt-backend/app`: `AUTH_SECRET` and `SITE_URL` required, the rest optional). It also forwards the variables the `backend` component reads, so setting them on the deployment is all the sign-in codes, invitations and cron check-ins need:

```ts [backend/convex.config.ts]
import { defineApp } from 'convex/server'
import { backendEnv } from 'nuxt-backend/app'
import backend from 'nuxt-backend/convex.config'
import persistentTextStreaming from '@convex-dev/persistent-text-streaming/convex.config'
import polar from '@convex-dev/polar/convex.config'
import rateLimiter from '@convex-dev/rate-limiter/convex.config'
import shardedCounter from '@convex-dev/sharded-counter/convex.config'
import workflow from '@convex-dev/workflow/convex.config'
import workpool from '@convex-dev/workpool/convex.config'

const app = defineApp({ env: backendEnv })

// Components are isolated from the app's env: forward what backend reads.
app.use(backend, {
  env: {
    BACKEND_ENVIRONMENT: app.env.BACKEND_ENVIRONMENT,
    EMAIL_API_KEY: app.env.EMAIL_API_KEY,
    EMAIL_FROM: app.env.EMAIL_FROM,
    EMAIL_WEBHOOK_SECRET: app.env.EMAIL_WEBHOOK_SECRET,
    MONITORING_DSN: app.env.MONITORING_DSN,
  },
})
app.use(persistentTextStreaming)
app.use(polar)
app.use(rateLimiter)
app.use(shardedCounter)
app.use(workflow)
app.use(workpool)

export default app
```

<note>

**Why not a one-call helper?** Convex discovers components from the `convex.config` imports it meets while bundling this file. Current Convex backends refuse the push (`start_push 500`) when such an import is reached through an intermediate module, or when `app.use` runs in a loop. So the definition is explicit on purpose: every component imported and mounted in the root file, one `app.use` each, which also keeps the component tree in plain sight.

</note>

To read an env var of your own, extend the contract, and mount a component of your own after the package's:

```ts [backend/convex.config.ts]
import aggregate from '@convex-dev/aggregate/convex.config'
import { v } from 'convex/values'

const app = defineApp({
  env: { ...backendEnv, STORY_STYLE: v.optional(v.string()) },
})
// … the package's components, as above
app.use(aggregate)
```

`backend` is the package's core: keep it mounted, with the official components its helpers name. `setupAuth` uses `rateLimiter`, `setupAi` needs `persistentTextStreaming` and `rateLimiter`, `setupBilling` needs `polar`, plus `shardedCounter` for plan quotas, and `setupWorkflows` needs `workflow`. The env proxy throws on an undeclared variable, so declare every one you read.

### One `backend` component, beside the official ones

The package ships one Convex component of its own, its functions split into modules by concern. Your code reaches them through the setup helpers; [The backend component](https://nuxt-backend.dev/docs/reference/backend/component) lists every function and table:

<table>
<thead>
  <tr>
    <th>
      Module
    </th>
    
    <th>
      What it holds
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        adapter
      </code>
    </td>
    
    <td>
      The Better Auth tables and adapter. Better Auth itself runs as app-level code over it, not as a component
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        account
      </code>
    </td>
    
    <td>
      An account's export and its erasure across every participant
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        audit
      </code>
    </td>
    
    <td>
      The activity trail: one row per event, and the hand-off to your <code>
        onEvent
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        email
      </code>
    </td>
    
    <td>
      Transactional email, with <a href="https://www.convex.dev/components/resend" rel="nofollow">
        <code>
          @convex-dev/resend
        </code>
      </a>
      
       nested inside; it owns the <code>
        EMAIL_*
      </code>
      
       env
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        billing
      </code>
      
       and <code>
        gifts
      </code>
    </td>
    
    <td>
      The live entitlement and credit cache, and gift purchases
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ai
      </code>
    </td>
    
    <td>
      The records of metered AI requests, from the reservation to settlement or release
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        flags
      </code>
    </td>
    
    <td>
      The overrides an administrator set; a flag without one holds its default from code
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        webhooks
      </code>
    </td>
    
    <td>
      The delivery log of <code>
        /billing/events
      </code>
      
       and <code>
        /email/events
      </code>
      
      , which dedupes redeliveries and feeds DevTools (<a href="https://nuxt-backend.dev/docs/ship/security/webhooks#the-delivery-log">
        the delivery log
      </a>
      
      )
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        maintenance
      </code>
      
       and <code>
        monitoring
      </code>
    </td>
    
    <td>
      The hourly housekeeping of every table above, and its cron check-ins (<a href="https://nuxt-backend.dev/docs/build/data/jobs#what-the-component-already-runs">
        Background work
      </a>
      
      )
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        migrations
      </code>
      
       and <code>
        posture
      </code>
    </td>
    
    <td>
      Internal: the package's own data migrations, which <a href="https://nuxt-backend.dev/docs/reference/cli#upgrade">
        <code>
          nuxt-backend upgrade
        </code>
      </a>
      
       runs, and what the deployment reports of its email to <code>
        doctor --prod
      </code>
    </td>
  </tr>
</tbody>
</table>

Two components are nested **inside** `backend`: Resend's, which is self-contained, so `backend` re-exposes it through its `email` functions, and a migrations component of its own, which runs the package's data migrations over `backend`'s tables when `nuxt-backend upgrade` asks. The official components mount at the app level: a nested component is sandboxed from the parent app, and Polar's, the rate limiter, the sharded counter, workflows and the workpool all work over your own tables, functions, auth and HTTP routes.

The dashboard component tree looks like this:

```text
app
├─ backend
│  ├─ backend/resend
│  └─ backend/migrations
├─ persistentTextStreaming
├─ polar
├─ rateLimiter
├─ shardedCounter
├─ workflow
│  └─ workflow/workpool
└─ workpool
```

### Server helpers and composables, two halves of one feature

The `nuxt-backend/*` entrypoints are server code: you import them inside your Convex functions to set up each capability with the package's defaults, such as the auth rate limits or the workflow retries. The auto-imported composables, such as `useSearch`, `useBilling` and `useWorkflowStatus`, are client code: reactive wrappers over `useQuery` that subscribe to the queries those functions expose. The helper builds the server endpoint, and the composable reads it reactively in your components.

<note>

Each helper lives on its own entrypoint rather than one barrel, so a Convex function bundles only what it imports: the reason the official `@convex-dev/*` packages are split too, and what keeps `better-auth` out of a file that only does rate limiting.

</note>

## Who owns what

<table>
<thead>
  <tr>
    <th>
      
    </th>
    
    <th>
      Owns
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The <code>
        backend
      </code>
      
       component
    </td>
    
    <td>
      Its own tables (accounts, sessions, passkeys, workspaces, the billing cache, gifts, AI requests, email records, the webhook log, the activity trail and flags), the operations on them, their hourly maintenance, and erasing what it holds about an account
    </td>
  </tr>
  
  <tr>
    <td>
      Your app's <code>
        backend/
      </code>
    </td>
    
    <td>
      Identity and authorization (Better Auth runs there, over the component's tables, and <code>
        functions.ts
      </code>
      
       decides who may call what), every call to a provider, made by the setup helpers, and your own tables and files
    </td>
  </tr>
  
  <tr>
    <td>
      The providers
    </td>
    
    <td>
      Money (Polar's customers, orders, invoices and meters), delivery (Resend's messages and events) and model calls
    </td>
  </tr>
</tbody>
</table>

The split is why the component can be upgraded and migrated on its own (`npx nuxt-backend upgrade`), while nothing it does needs a provider key: those stay in your app's functions.

## One path for what happens

A sign-in, a workspace change, a subscription or order, or an administrator's action is a [backend event](https://nuxt-backend.dev/docs/reference/backend/events#backend-events), written once to the activity trail by the code that made it happen. Everything that reacts reads it there: the [activity](https://nuxt-backend.dev/docs/build/auth/admin/audit-log) the account, its workspace and administrators see, your own `onEvent` hook, and the [in-app notifications](https://nuxt-backend.dev/docs/build/email/notifications) an event derives in the same transaction, for the people it is about. An administrator acts inside someone else's account only by [impersonating](https://nuxt-backend.dev/docs/build/auth/admin/impersonation) it, which is an event of its own.

## What this means for you

- [Capabilities](https://nuxt-backend.dev/docs/start/concepts/capabilities): the parts this composes, and how each one's state is detected.
- [What you got](https://nuxt-backend.dev/docs/start/what-you-got): the files, pages and routes this left in your app.
- [Environments and deployments](https://nuxt-backend.dev/docs/start/concepts/environments): which deployment each path talks to.
- [Record your own events](https://nuxt-backend.dev/docs/build/auth/admin/audit-log#record-your-own-events) on the same path, and [Webhooks](https://nuxt-backend.dev/docs/ship/security/webhooks) for the inbound one.
- [Glossary](https://nuxt-backend.dev/docs/reference/glossary): each of the package's words, with the name its provider uses.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
