coolify-bun-svelte Svelte Themes

Coolify Bun Svelte

bun-coolify-template

A minimal SvelteKit + Bun template with raw Bun SQL, optimized for deployment on Coolify.

Features

  • SvelteKit with Svelte 5
  • Bun runtime with native SQL interface
  • SQLite database (file-based)
  • Tailwind CSS v4
  • Remote functions enabled
  • Docker-ready with persistent volume support

Development

# Install dependencies
bun install

# Start development server
bun run dev

# Type check
bun run check

# Build for production
bun run build

Database

This template uses Bun's native SQL interface with SQLite:

import { sql } from '$lib/server/db';

// Query (await returns array of objects)
const users = await sql`SELECT * FROM users` as User[];

// Insert/Update
await sql`INSERT INTO users (name) VALUES (${name})`;

Database file location is configured via DATABASE_PATH environment variable (required).

Migrations

Migrations are embedded in src/lib/server/db/migrate.ts:

const migrations: { name: string; sql: string }[] = [
    {
        name: '001_create_users',
        sql: `CREATE TABLE IF NOT EXISTS users (...)`
    }
];

Run migrations programmatically:

import { migrate } from '$lib/server/db/migrate';
await migrate(); // Idempotent - tracks applied migrations in _migrations table

Visit /test to verify the database and migrations are working.

Coolify Deployment

1. Create New Project

In Coolify dashboard:

  • Click + Add New ResourceApplication
  • Select Public Repository (or Private if using GitHub App)

2. Add GitHub Origin

Enter your repository URL:

https://github.com/your-username/your-repo.git

Set branch to main.

3. Configure Build

Under Build Pack, select Dockerfile. The included Dockerfile handles:

  • Multi-stage build for minimal image size
  • Production dependencies only
  • SQLite data directory creation

4. Configure Storage

Add a persistent volume for SQLite under Storages:

  • Source Path: Choose a path on your server (e.g., /data/myapp)
  • Destination Path: /usr/src/app/data

This preserves your database across deployments.

5. Deploy

Click Deploy. The app runs on port 3002 by default.

Environment Variables

Copy .env.example to .env:

DATABASE_PATH=./data/app.sqlite

Project Structure

src/
  lib/
    server/
      db/
        index.ts       # Bun SQL connection
        migrate.ts     # Migration runner (embedded SQL)
    index.ts           # Shared lib exports
  routes/
    +layout.svelte     # Root layout
    +page.svelte       # Home page
    layout.css         # Tailwind imports
    test/              # Database test route
  app.html             # HTML template
  app.d.ts             # App types
static/                # Static assets
data/                  # SQLite volume mount point

Top categories

Loading Svelte Themes