Data, files and jobs

Try live
Your own tables and functions beside the backend component: live queries in Vue, data rendered on the server, typed refusals, search, counts, checked uploads, share links, retention and background work, on Convex.

This is the part of the backend you build on. Your tables sit in your own schema, beside the ones the backend component keeps, and your functions guard them with an access tier. Pages read them live, render them on the server first, and learn why a call was refused. Around them come what a client app needs next: search, counts, uploads, share links, retention and work that runs in the background. It is two of the package's capabilities: data, the database and what reads it, and jobs, the work that runs outside a request. New here? Start with Your data, then Query and update data.

It runs on Convex: the database, its realtime queries, search indexes, file storage and scheduler, and the official Convex components. The package adds the access tiers, typed refusals, checked uploads with EXIF stripping and byte quotas, expiring private URLs, share links and retention rules, and composables that follow one set of conventions. Nothing here hides Convex: a plain query, mutation or action is always a valid choice, and counters, caches, queues and migrations come straight from their components.

How it works

backend/schema.ts      your tables, beside the backend component's own
backend/*.ts           your queries, mutations and actions, each behind an access tier
  ├─ Vue pages         useQuery, useMutation, useAction: live over one WebSocket
  ├─ server render     useAsyncQuery: rendered with the data, then live in the browser
  └─ Nitro routes      fetchQuery, backendAuth(event)
backend/storage.ts     checked uploads, owner records, expiring URLs, share links
backend/crons.ts       your jobs and retention rules; the component runs its own
  1. Model. Declare your tables in backend/schema.ts, with account and workspace ids as strings. See Your data.
  2. Protect. Declare every function at its tier: signed in, a workspace member, an administrator, a role or a plan's feature. See Protect backend functions and Scope tables to a workspace.
  3. Read and write. A page subscribes to a query and re-renders whenever its result changes, in every open tab. A mutation writes in one transaction; an action calls the outside world. See Query and update data.
  4. Render on the server. useAsyncQuery fetches during the server render, as the signed-in person, and the browser goes live without a second fetch. See Render data on the server.
  5. Refuse with a reason. A refusal carries a stable code and its data, which a page reads with getBackendError. See Handle errors.
  6. Search and count. Search indexes beside your tables, and aggregates and counters that stay fast at any size. See Search your data and Keep counts and sums.
  7. Store files. Uploads checked on the server and stripped of location data, stored with their row in one mutation, shown to who may see them and shared by link. See Files.
  8. Keep it small. Delete rows once they pass an age, and run work on a clock, in steps or in bulk. See Delete old data on a schedule and Background work.

Who does what

ConvexThe packageYour app
DatabaseTables, indexes, transactions, realtime subscriptionsThe backend component's own tables, which it migrates and prunes itselfbackend/schema.ts and every table in it
FunctionsQueries, mutations, actions and HTTP routesAccess tiers (createFunctions), typed refusals (backendError), the server helpers in NitroEvery function in backend/
Search and countsSearch indexes; the aggregate and sharded counter componentsdefineSearch, useSearchThe indexes and aggregates you declare
FilesFile storage, upload URLs, ctx.storage in mutationssetupStorage: sniffed types, EXIF stripping, file and byte quotas, owner records, expiring URLs, share links, the orphan sweep; <UploadField>, over the base module's useUploadQueueWhat each file is attached to, and who may share what
RetentionThe scheduler and cronsdefineRetention, and the hourly maintenance of the component's own tablesHow long each of your tables keeps its rows
Background workThe scheduler, crons, and the workflow, workpool, action cache and migrations componentssetupWorkflows, useWorkflowStatusYour jobs

The backend component keeps accounts and sessions, workspaces and invitations, the billing cache, gifts, files and their owners, AI request records, the activity trail, flag overrides, email records and account exports. You reach them through the package's functions and composables, never through your schema, and the component deletes what it no longer needs on its own. It never reads or deletes your tables. How it works maps each capability to its component.

In development and in production

  • In development the app runs on a dev deployment that npx nuxt-backend dev creates on its first run, local or in the cloud. Both capabilities read test there: the amber light in npx nuxt-backend status. See Develop on real sandboxes.
  • In tests defineBackendTestApp from nuxt-backend/test registers the scaffold's components for convex-test, and the backend mock answers your pages' queries. See Test your app.
  • In production the deployment is a cloud or self-hosted one, and both capabilities read live, the green light. Choose its region when you create it: Convex explains the cost and the move. See Deploy.
  • Watching it. npx nuxt-backend status and the DevTools Overview tab show both capabilities' state and each maintenance pass. See Capabilities.

Which tool to use

You want toUsePage
Add a table of your own, keyed to accounts or workspacesbackend/schema.ts, and a tier from createFunctionsYour data
Keep each workspace's rows to its membersThe workspace tier and an index on workspaceIdScope tables to a workspace
Show data that updates live, and write ituseQuery, useMutation, useActionQuery and update data
Load a long list a page at a timeusePaginatedQueryQuery and update data
Render a page with its data on the first loaduseAsyncQuery, useAsyncPaginatedQueryRender data on the server
Show why a call was refused, or refuse one yourselfgetBackendError, backendErrorHandle errors
Find rows by the words in a text fielddefineSearch, useSearchSearch your data
Show a count or a sum without reading every row@convex-dev/aggregate, @convex-dev/sharded-counterKeep counts and sums
Delete rows once they pass an agedefineRetentionDelete old data on a schedule
Accept uploads under a size, type and byte limit, with location data removedsetupStorage, storage.store, useUpload, <UploadField>Accept checked uploads
Show stored images at the size a page needs<StorageImage>, <NuxtImg provider="backend">Show images
Serve a private file for a set timestorage.signedUrlShow images
Let a person share a row by linkstorage.shareable, useShareLinkShare by link
Run steps over minutes or days that survive restartssetupWorkflows, useWorkflowStatusRun a durable workflow
Run a job on a schedulecronJobs(), @convex-dev/cronsSchedule jobs
Run many jobs a few at a time, with retries@convex-dev/workpoolQueue work with a workpool
Keep an expensive action's results for a while@convex-dev/action-cacheCache expensive actions
Change existing documents in batches@convex-dev/migrationsMigrate data

What you get

What the package ships for this part of the app today, generated from the code: each name links to its reference entry.

Components
<ConnectionStatus><UploadField>
Composables
useConnectionStateuseBackendClientuseSearchuseRoomPresenceuseShareLinkuseUploadFieldpreparePhotoisPhotoFilePhotoPrepErrorgetBackendErroruseWorkflowStatus
Setup helpers
defineRetentionsetupPresencedefineSearchsetupWorkflowssetupStorage

In this section

Your data

Where your tables go, how they point at accounts and workspaces, and how they join export and erasure.

Scope tables to a workspace

Stamp, index and check the active workspace, and gate writes by the member's role.

Query and update data

Read live data with useQuery, write with useMutation, call actions, paginate, and ride out a dropped connection.

Render data on the server

Pages that arrive with their data, signed-in reads included, and go live in the browser.

Handle errors

Read a refusal's stable code on the client, and refuse from your own functions with the same codes.

Search your data

Search a table's text with a builder checked against your schema, and drive it from an input.

Keep counts and sums

Counts and sums from the aggregate component, and counters that take many writers at once.

Delete old data on a schedule

Retention rules in bounded batches, and tokens stored as hashes.

Files

Files

How uploads are checked, owned, shown, shared and swept.

Accept checked uploads

setupStorage, a photo stored with its row in one mutation, and upload URLs for large files.

Show images

<StorageImage>, <NuxtImg> sizes, and expiring private URLs.

Share by link

A link to one row, with a preview card and the sharer's referral code.

Keep storage clean

Release files, the orphan sweep, and a person's files in export and erasure.

Background work

Background work

Which tool runs work outside a request, and what the component's maintenance already runs.

Run a durable workflow

Durable multi-step functions, and a run's status live in Vue.

Schedule jobs

Fixed jobs in crons.ts, and per-person schedules with the crons component.

Queue work with a workpool

Many actions a few at a time, with retries and a callback as each ends.

Cache expensive actions

An action's results kept for a while, with expiry and invalidation.

Migrate data

Change existing documents in batches, dry-run first, and resume where a run stopped.

Not included

  • Another database. The data lives in your Convex deployment, which is what makes every query live. The package has no adapter for SQL or another store.
  • Who is online. Presence is a collaboration feature and no part of the package: the Roadmap says what to use instead.
  • Wrappers over Convex components. Counters, aggregates, cached actions, queues and migrations come straight from their components, as the recipes above show.

Next