Data, files and jobs
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
- Model. Declare your tables in
backend/schema.ts, with account and workspace ids as strings. See Your data. - 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.
- 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.
- Render on the server.
useAsyncQueryfetches during the server render, as the signed-in person, and the browser goes live without a second fetch. See Render data on the server. - Refuse with a reason. A refusal carries a stable code and its data, which a page reads with
getBackendError. See Handle errors. - 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.
- 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.
- 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
| Convex | The package | Your app | |
|---|---|---|---|
| Database | Tables, indexes, transactions, realtime subscriptions | The backend component's own tables, which it migrates and prunes itself | backend/schema.ts and every table in it |
| Functions | Queries, mutations, actions and HTTP routes | Access tiers (createFunctions), typed refusals (backendError), the server helpers in Nitro | Every function in backend/ |
| Search and counts | Search indexes; the aggregate and sharded counter components | defineSearch, useSearch | The indexes and aggregates you declare |
| Files | File storage, upload URLs, ctx.storage in mutations | setupStorage: sniffed types, EXIF stripping, file and byte quotas, owner records, expiring URLs, share links, the orphan sweep; <UploadField>, over the base module's useUploadQueue | What each file is attached to, and who may share what |
| Retention | The scheduler and crons | defineRetention, and the hourly maintenance of the component's own tables | How long each of your tables keeps its rows |
| Background work | The scheduler, crons, and the workflow, workpool, action cache and migrations components | setupWorkflows, useWorkflowStatus | Your 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 devcreates on its first run, local or in the cloud. Both capabilities readtestthere: the amber light innpx nuxt-backend status. See Develop on real sandboxes. - In tests
defineBackendTestAppfromnuxt-backend/testregisters the scaffold's components forconvex-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 statusand the DevTools Overview tab show both capabilities' state and each maintenance pass. See Capabilities.
Which tool to use
| You want to | Use | Page |
|---|---|---|
| Add a table of your own, keyed to accounts or workspaces | backend/schema.ts, and a tier from createFunctions | Your data |
| Keep each workspace's rows to its members | The workspace tier and an index on workspaceId | Scope tables to a workspace |
| Show data that updates live, and write it | useQuery, useMutation, useAction | Query and update data |
| Load a long list a page at a time | usePaginatedQuery | Query and update data |
| Render a page with its data on the first load | useAsyncQuery, useAsyncPaginatedQuery | Render data on the server |
| Show why a call was refused, or refuse one yourself | getBackendError, backendError | Handle errors |
| Find rows by the words in a text field | defineSearch, useSearch | Search your data |
| Show a count or a sum without reading every row | @convex-dev/aggregate, @convex-dev/sharded-counter | Keep counts and sums |
| Delete rows once they pass an age | defineRetention | Delete old data on a schedule |
| Accept uploads under a size, type and byte limit, with location data removed | setupStorage, 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 time | storage.signedUrl | Show images |
| Let a person share a row by link | storage.shareable, useShareLink | Share by link |
| Run steps over minutes or days that survive restarts | setupWorkflows, useWorkflowStatus | Run a durable workflow |
| Run a job on a schedule | cronJobs(), @convex-dev/crons | Schedule jobs |
| Run many jobs a few at a time, with retries | @convex-dev/workpool | Queue work with a workpool |
| Keep an expensive action's results for a while | @convex-dev/action-cache | Cache expensive actions |
| Change existing documents in batches | @convex-dev/migrations | Migrate 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
Scope tables to a workspace
Query and update data
useQuery, write with useMutation, call actions, paginate, and ride out a dropped connection.Render data on the server
Handle errors
Search your data
Files
Background work
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
- New here? Read Your data, then Query and update data.
- Charging for what you built: Billing. Putting it online: Ship.
Provenance
Mark what a model made, in the file and in the page: the IPTC digital source type, and C2PA content credentials signed with the deployment's key, in each JPEG, PNG or WebP stored through `ctx.storeImage` once `setupAi({ provenance })` is on, a provenance record of which model made what from which inputs, and the visible AI-generated label the EU AI Act asks for.
Your data
Where your own tables go beside the backend component, how they point at accounts and workspaces, which tier guards them, and how they join export, erasure and the activity trail.