Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/amanvarshney01/create-better-t-stack/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Better-T-Stack supports automated setup for popular database providers. Choose a managed provider for production or Docker for local development.

Setup options by database type

SQLite

Turso - SQLite for Production, powered by libSQLFeatures:
  • Edge-replicated SQLite
  • HTTP API
  • Branching support
  • Generous free tier
Setup:
npm create better-t-stack@latest my-app \
  --database sqlite \
  --orm drizzle \
  --db-setup turso
What you get:
  • Turso CLI installation helper
  • Connection string template
  • Environment variable configuration
Next steps:
  1. Sign up at turso.tech
  2. Create a database: turso db create my-app
  3. Get connection URL: turso db show my-app --url
  4. Get auth token: turso db tokens create my-app
  5. Add to .env:
    DATABASE_URL=libsql://your-db.turso.io
    DATABASE_AUTH_TOKEN=your-token
    

PostgreSQL

Neon Postgres - Serverless Postgres with branchingFeatures:
  • Serverless, scale-to-zero
  • Database branching (like Git)
  • Instant read replicas
  • Generous free tier
Setup:
npm create better-t-stack@latest my-app \
  --database postgres \
  --orm drizzle \
  --db-setup neon
Next steps:
  1. Sign up at neon.tech
  2. Create a project
  3. Copy connection string from dashboard
  4. Add to .env:
    DATABASE_URL=postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/neondb?sslmode=require
    

MySQL

PlanetScale - MySQL on Vitess with NVMe storageSetup:
npm create better-t-stack@latest my-app \
  --database mysql \
  --orm drizzle \
  --db-setup planetscale
See PostgreSQL > PlanetScale tab for details.

MongoDB

MongoDB Atlas - Fully managed cloud MongoDBFeatures:
  • Global clusters
  • Automated backups
  • Monitoring and alerts
  • Free tier (512MB)
Setup:
npm create better-t-stack@latest my-app \
  --database mongodb \
  --orm mongoose \
  --db-setup mongodb-atlas
Next steps:
  1. Sign up at mongodb.com/cloud/atlas
  2. Create a cluster
  3. Create a database user
  4. Whitelist your IP address
  5. Get connection string
  6. Add to .env:
    DATABASE_URL=mongodb+srv://user:pass@cluster.mongodb.net/myapp?retryWrites=true&w=majority
    

Connection strings

Each database type uses a specific connection string format:

SQLite

# Local file
DATABASE_URL=file:./dev.db

# Turso (libSQL)
DATABASE_URL=libsql://your-db.turso.io
DATABASE_AUTH_TOKEN=your-token

PostgreSQL

# Standard Postgres
DATABASE_URL=postgresql://user:pass@host:5432/dbname

# With SSL
DATABASE_URL=postgresql://user:pass@host:5432/dbname?sslmode=require

# Prisma Postgres
DATABASE_URL=prisma+postgres://accelerate.prisma-data.net/?api_key=xxx

MySQL

# Standard MySQL
DATABASE_URL=mysql://user:pass@host:3306/dbname

# PlanetScale
DATABASE_URL=mysql://user@host.psdb.cloud/dbname?sslaccept=strict

MongoDB

# Local MongoDB
DATABASE_URL=mongodb://localhost:27017/dbname

# MongoDB Atlas
DATABASE_URL=mongodb+srv://user:pass@cluster.mongodb.net/dbname?retryWrites=true&w=majority

Environment variables

Location

Database URLs are typically stored in:
apps/server/.env          (for server-side code)
packages/db/.env          (for database packages)
packages/infra/.env       (for Alchemy deployments)

Required variables

Standard setup:
DATABASE_URL=your-connection-string
Turso (requires auth token):
DATABASE_URL=libsql://your-db.turso.io
DATABASE_AUTH_TOKEN=your-token
Cloudflare D1 (no env vars needed): D1 uses bindings configured in alchemy.run.ts. No connection string needed.

For Alchemy deployments

If using Cloudflare deployment with Alchemy:
// packages/infra/alchemy.run.ts
import { config } from "dotenv";

config({ path: "../../apps/server/.env" });

export const server = await Worker("server", {
  bindings: {
    DATABASE_URL: alchemy.secret.env.DATABASE_URL!,
  },
});

Applying schema

After setting up your database:

With Drizzle

Push schema (development):
bun run db:push
Generate migration:
bun run db:generate
Apply migration (production):
bun run db:migrate

With Prisma

Push schema (development):
bun run db:push
Generate migration:
cd packages/db && npx prisma migrate dev --name init
Apply migration (production):
cd packages/db && npx prisma migrate deploy

With Mongoose

Mongoose doesn’t require migrations - schemas are applied automatically on first connection.

Switching providers

To switch database providers after creation:
1

Update connection string

Replace DATABASE_URL in your .env files with the new provider’s connection string.
2

Update ORM configuration (if needed)

Some ORMs require provider-specific configuration:Drizzle:
// packages/db/src/index.ts
import { drizzle } from "drizzle-orm/postgres-js"; // or /mysql2, /better-sqlite3
Prisma:
// packages/db/prisma/schema.prisma
datasource db {
  provider = "postgresql" // or "mysql", "sqlite"
  url      = env("DATABASE_URL")
}
3

Regenerate migrations

bun run db:generate
bun run db:push
4

Update deployment config (if using Alchemy)

If switching to/from Cloudflare D1, update your alchemy.run.ts.

Troubleshooting

Issue: Cannot connect to databaseSolutions:
  • Verify connection string format
  • Check database is running (docker ps for Docker)
  • Confirm firewall/network access
  • For cloud providers, whitelist your IP address
Issue: SSL certificate validation failsSolutions:
  • Add ?sslmode=require to PostgreSQL URLs
  • Add ?sslaccept=strict to MySQL URLs
  • For self-signed certificates, use ?sslmode=disable (dev only)
Issue: Username/password rejectedSolutions:
  • Verify credentials are correct
  • Check database user has proper permissions
  • For cloud providers, ensure database user is created
  • URL-encode special characters in passwords
Issue: Schema migrations don’t applySolutions:
  • Check connection string is valid
  • Ensure database exists
  • Verify migration files are in correct location
  • For Drizzle, run bun run db:generate first

Next steps

Project structure

Learn where database code lives

Examples

See database usage in Todo example

Deployment

Deploy with database providers

Compatibility

Database and ORM compatibility

Build docs developers (and LLMs) love