ViteHub is still experimental. Expect bugs and breaking changes.

Server primitives

Build server-backed features with databases, queues, storage, and more while keeping your application portable across hosts.

Server Primitives are APIs for environment values, databases, queues, workflows, files, sandboxes, and other server features.

Application code calls the ViteHub API. The Vite integration connects that call to the implementation supported by the current development or deployment host.

Choose a primitive for the job

You needStart with
Configure the appEnv, Auth, or Rate Limit
Store data and filesDatabase, KV, Blob, Workspace, or Source
Send or receive messagesEmail or Channels
Run work laterQueue, Schedule, or Workflow
Run isolated automationBrowser, Shell, or Sandbox

How a primitive works in your app

Most ViteHub primitives follow the same pattern:

Configure ViteHub

Add ViteHub to your configuration. ViteHub uses the Vite Environment API, which requires Vite 8+, Nitro 3+, or Nuxt 5+.

vite.config.ts
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({ preset: 'node', database: true }),
  ],
})

Define the database

Create a Database Definition file that ViteHub discovers automatically. Its file name becomes the database name, and the file defines the schema and options.

src/notes.database.ts
import { defineDatabase } from 'vite-hub/database'
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'

export default defineDatabase({
  name: 'notes',
  schema: {
    notes: sqliteTable('notes', {
      id: integer('id').primaryKey(),
      title: text('title').notNull(),
    }),
  },
})

Use it from server code

Import the database API in a server route and query the named database. ViteHub connects that call to the provider configured for the current environment.

src/server.ts
import { useDatabase } from 'vite-hub/database/drizzle'

export default {
  async fetch() {
    const { db, schema } = useDatabase('notes')
    return Response.json(await db.select().from(schema.notes))
  },
}

The same path applies to other Server Primitives. Configure ViteHub, add a definition when the feature needs a name or schema, and call its server API. Check the host support matrix before choosing a deployment target.