A SvelteKit + PostgreSQL deployment sample. This modern guestbook application demonstrates how to build and deploy full-stack web applications with a PostgreSQL database.
This repository serves as a deployment sample, showcasing:
Clone and install dependencies:
git clone <your-repo>
cd sveltekit-sample
bun install
Set up PostgreSQL:
.env.example
to .env
and fill in your database URLpsql -d your_database_name -f schema.sql
Run the development server:
bun run dev
src/
āāā lib/
ā āāā components/ # Reusable UI components
ā ā āāā Header.svelte # Page header component
ā ā āāā Navigation.svelte # Site navigation
ā ā āāā MessageCard.svelte # Individual message display
ā ā āāā MessageForm.svelte # Guestbook entry form
ā ā āāā FeatureCard.svelte # Feature showcase card
ā āāā database.ts # PostgreSQL client setup
ā āāā index.ts # Component exports
āāā routes/
ā āāā +layout.svelte # Root layout with navigation
ā āāā +page.svelte # Guestbook home page
ā āāā +page.server.ts # Server-side data loading & form actions
ā āāā about/
ā ā āāā +page.svelte # About page
ā āāā api/
ā āāā messages/
ā āāā +server.ts # REST API endpoints for messages
āāā app.html # HTML template
Create a .env
file with the following required variables:
# PostgreSQL Configuration (Required)
DATABASE_URL=postgresql://username:password@localhost:5432/database_name
# Optional Environment Variables
NODE_ENV=development
PORT=3000
Required Variables:
DATABASE_URL
- Your PostgreSQL connection stringOptional Variables:
NODE_ENV
- Environment mode (development, production)PORT
- Port number for the application (defaults to 3000)The guestbook uses a messages table with optional fields for rich entries:
CREATE TABLE guestbook_messages (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT,
message TEXT NOT NULL,
location TEXT,
website TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
This app is configured for deployment with the Node.js adapter. For other platforms:
svelte.config.js
@sveltejs/adapter-static
for static sitesbun run dev
- Start development serverbun run build
- Build for productionbun run preview
- Preview production buildbun run check
- Run TypeScript checksbun run lint
- Lint codebun run format
- Format code