This repository serves as a production-ready base template for SvelteKit projects, providing a structured starting point for building full-stack web applications with SvelteKit, PostgreSQL, and modern tooling.
Click "Use this template" on GitHub or clone this repository:
git clone <your-repo-url>
cd <your-project-name>
Before starting development, you should update the following:
mv project your-project-name
name
field in /project/package.json
:{
"name": "your-project-name"
}
docker-compose.yml: Update container names and database names:
services:
postgres:
container_name: your-project-name_postgresql
environment:
POSTGRES_DB: your-project-name
POSTGRES_USER: postgres
POSTGRES_PASSWORD: your-secure-password
pgweb:
container_name: your-project-name_pgweb
environment:
DATABASE_URL: postgres://postgres:your-secure-password@postgres:5432/your-project-name?sslmode=disable
Environment files: Copy and configure environment variables:
cd project
cp .env.example .env.development
cp .env.example .env.production # if needed
Update database URLs in your environment files:
# .env.development
DATABASE_URL=postgresql://postgres:your-secure-password@localhost:5432/your-project-name
SHADOW_DATABASE_URL=postgresql://postgres:your-secure-password@localhost:5432/your-project-name_shadow
ROOT_DATABASE_URL=postgresql://postgres:your-secure-password@localhost:5432/postgres
cd project
npm install
# This will start Docker services, watch for current migrations, and start the dev server
npm run dev
# Or start services individually:
npm run docker:up # Start PostgreSQL and pgweb
npm run dev:sveltekit # Start only the SvelteKit dev server
The template includes migration tooling. To set up your database schema:
/project/migrations/current.sql
npm run gm:dev commit
npm run kysely-codegen:db # Generate Kysely types
npm run kysely-codegen:zod # Generate Zod schemas
If running npm run dev
, the current migration will automatically be watched and applied, and the codegen tasks will run after every current migration.
From the /project
directory:
npm run dev
- Start development with Docker servicesnpm run dev:sveltekit
- Start only SvelteKit dev servernpm run build
- Build for productionnpm run preview
- Preview production buildnpm run docker:up
- Start Docker servicesnpm run docker:down
- Stop Docker servicesnpm run gm:dev
- Run Graphile Migrate commandsnpm run kysely-codegen:db
- Generate database typesnpm run kysely-codegen:zod
- Generate Zod schemasWhen running npm run dev
or npm run docker:up
:
project/
├── src/
│ ├── lib/
│ │ ├── generated/ # Auto-generated DB types and Zod schemas
│ │ └── server/ # Server-side utilities
│ └── routes/ # SvelteKit routes
├── migrations/ # Database migrations
├── static/ # Static assets
└── scripts/ # Utility scripts
.kysely-codegenrc.ts
for Kysely type generation.kysely-zod-codegenrc.ts
for Zod schema generationCreate additional environment files as needed:
.env.development
- Development settings.env.staging
- Staging settings.env.production
- Production settings