LiteSaaS Starter Kit

Open-source Next.js 15 + SQLite SaaS starter kit featuring WAL mode concurrency, Drizzle ORM, self-hosted session authentication, and automated Litestream S3 replication.

#nextjs#sqlite#drizzle#tailwindcss#typescript#saas

The Database Trap for Lean SaaS

Modern web frameworks typically guide developers toward managed cloud database vendors (Supabase, Neon, PlanetScale, AWS RDS) from day one.

For solo founders and early-stage products, this architecture introduces two severe penalties:

  1. Unnecessary Fixed Overhead: Monthly minimum tier pricing (25–100+/month) and compute idling costs accumulate before achieving product-market fit.
  2. Network Round-Trip Penalty: Querying a remote database over TCP adds 20–50 ms latency to every server-side page render, requiring complex connection pooling (PgBouncer) and caching layers (Redis).

LiteSaaS proves that an embedded database architecture using SQLite in Write-Ahead Logging (WAL) mode paired with Litestream S3 replication can comfortably handle hundreds of concurrent requests with sub-millisecond query latencies on a $4/month VPS.

LiteSaaS Production Architecture & Single-Box Deployment


High-Concurrency SQLite Architecture

The pervasive myth that "SQLite cannot handle web applications" stems from default configurations that operate in rollback journal mode. In rollback mode, write operations acquire an exclusive lock on the entire database file, blocking all concurrent read queries.

LiteSaaS reconfigures the SQLite engine into high-throughput WAL mode with tuned PRAGMAs:

sql
-- High-Concurrency Production PRAGMA Configuration
PRAGMA journal_mode = WAL;        -- Readers do not block writers; writers do not block readers
PRAGMA busy_timeout = 5000;       -- Wait up to 5000ms on write locks instead of throwing instant errors
PRAGMA synchronous = NORMAL;      -- Safe with WAL mode while dramatically reducing fsync disk writes
PRAGMA cache_size = 10000;        -- Allocate 40MB in-memory page cache for lightning reads
PRAGMA foreign_keys = ON;         -- Enforce strict relational integrity
┌────────────────────────────────────────────────────────────────────────┐
│                     LiteSaaS Data Flow & Replication                   │
├────────────────────────────────────────────────────────────────────────┤
│ Client Request ───> Next.js 15 Server Action (App Router)              │
│                           │                                            │
│                           ▼                                            │
│                    Drizzle ORM (Type-Safe Query Layer)                 │
│                           │                                            │
│                           ▼                                            │
│                SQLite Engine (WAL Mode)                                │
│                ├── Memory Page Cache (< 0.2ms Read)                    │
│                └── wal.db Frame Log                                    │
│                           │                                            │
│                           ▼ (Continuous Streaming Sync)                │
│                 Litestream Background Daemon                           │
│                           │                                            │
│                           ▼                                            │
│             Cloudflare R2 / AWS S3 Bucket (Zero-RPO Backup)            │
└────────────────────────────────────────────────────────────────────────┘

Disaster Recovery & Zero-RPO Replication via Litestream

Running SQLite on a local VPS filesystem raises an obvious question: What happens if the VPS crashes or the disk fails?

LiteSaaS integrates Litestream, an open-source continuous streaming replication tool written in Go:

  • Continuous WAL Streaming: Litestream runs as a lightweight sidecar process, intercepting every WAL frame committed to disk and streaming compressed snapshots to S3-compatible object storage (Cloudflare R2 or AWS S3).
  • Near-Zero Recovery Point Objective (RPO): Data loss in a catastrophic failure is bounded to sub-second transactions.
  • Instant Cold Restoration: Restoring a complete database onto a brand-new VPS or Docker container takes under 2 seconds:
    bash
    litestream restore -v -config /etc/litestream.yml /data/production.db
    

Self-Hosted Session Auth (Zero Vendor Lock-In)

LiteSaaS Dashboard and Production Architecture Overview

Third-party authentication vendors (Clerk, Auth0, Stytch) charge aggressive per-monthly-active-user (MAU) rates once applications scale.

LiteSaaS implements an independent, self-hosted session authentication architecture:

  • Cookie-Based Sessions: Secure, HTTP-only, SameSite=Strict, encrypted session identifiers stored in SQLite with automatic TTL expiration.
  • Password Hashing: Implemented with argon2id and bcrypt with automatic salt generation.
  • CSRF Protection: Native Next.js Server Action token validation.

Tech Stack & Production Tooling

  • Framework: Next.js 15 (App Router, React 19, Server Actions)
  • Database Engine: Embedded SQLite (better-sqlite3)
  • ORM: Drizzle ORM (100% TypeScript type inference)
  • Replication & Backups: Litestream streaming to Cloudflare R2 / AWS S3
  • Containerization: Multi-stage Dockerfile (~95MB Alpine image)
  • Deployment Cost: $4/mo on Hetzner / DigitalOcean, or 1-click Railway deployment