Vibekit

Database & ORM

Manage your data schema, models, and type-safe queries with Prisma.

VibeKit uses Prisma ORM with PostgreSQL as the primary relational database. The schema is defined in packages/database/prisma/schema.prisma.

Schema definition

The Prisma schema defines your data models, relations, and generators:

datasource db {
  provider = "postgresql"
}

generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
}

generator zod {
  provider = "prisma-zod-generator"
  output   = "../src/zod"
  config   = "./zod-generator.config.json"
}

Core models

  • User: Account details, email verification status, roles (user, admin), and relations to sessions, teams, and purchases.
  • UserSession: Active login sessions managed by Better Auth.
  • Team & TeamMembership: Multi-tenant organizations and membership roles (OWNER, MEMBER).
  • Subscription: Current team entitlement for purchases or subscriptions.
  • PaymentRecord: Provider events, purchases and refunds with a unique provider ID.
  • SystemSetting: Persisted module, template and integration configuration.

Database commands

CommandAction
bun run db:generateGenerates the Prisma client and Zod validation schemas.
bun run db:pushPushes schema changes directly to the local database without migration files.
bun run db:studioOpens Prisma Studio in your browser to view and edit database rows.

Development vs Production workflow

Use bun run db:push during early development when experimenting with schema fields. In production, always use reviewed Prisma migration files (prisma migrate deploy). Never hand-edit files in packages/database/src/zod.

Querying the database

Import the singleton db client from the database workspace package:

import { db } from "database";

// Fetch user by email with active sessions
const user = await db.user.findUnique({
  where: { email: "[email protected]" },
  include: { sessions: true },
});

Learn how queries connect to the frontend in tRPC API Layer.

On this page