Skip to content

nirvagold/svelteship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

67 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Svelteship

License: MIT SvelteKit TypeScript Tailwind CSS PostgreSQL

Production-ready SvelteKit boilerplate with authentication, database, UI components, and advanced features. Ship modern web applications quickly and securely.

Preview Β· Documentation Β· Report Bug Β· Request Feature


πŸ“‹ Table of Contents


✨ Features

Authentication & Security

  • πŸ” Complete Auth System - Register, login, logout with session management
  • οΏ½ OAuth Integration - Google and GitHub social login
  • �️ PSecure Sessions** - HTTP-only cookies with secure flags
  • πŸ”’ Password Hashing - Argon2 algorithm for maximum security
  • πŸšͺ Protected Routes - Automatic redirect for unauthenticated users
  • οΏ½ Email rVerification - Verify user emails with tokens
  • οΏ½ Passwlord Reset - Secure password recovery flow

Database & ORM

  • πŸ—„οΈ PostgreSQL - Robust relational database
  • πŸ“Š Drizzle ORM - Type-safe SQL query builder
  • πŸ”„ Migrations - Version-controlled database schema
  • 🐳 Docker Setup - One-command local database

UI & Styling

  • 🎨 Tailwind CSS 4 - Utility-first CSS framework
  • 🌸 DaisyUI - Beautiful component library (32+ themes)
  • πŸŒ“ Theme Selector - Full theme support with persistence
  • οΏ½ Responsive - Mobile-first design
  • 🧩 Layout Components - Sidebar, Topbar, Centered, Split layouts
  • πŸ“ Form Components - Input, Select, Checkbox, Radio, Textarea, DatePicker, FileInput

Advanced Features (v0.5.0)

  • 🌐 Internationalization (i18n) - Multi-language support (EN, ID)
  • πŸ“§ Email Service - Resend integration with HTML templates
  • πŸ“ File Storage - Local, S3, and Cloudflare R2 support
  • πŸ“‘ Real-time SSE - Server-Sent Events for notifications
  • πŸ“Š Analytics - Plausible, Umami, Google Analytics support
  • πŸ“ Structured Logging - JSON logging with Sentry integration
  • πŸ“š API Documentation - Interactive API docs page
  • πŸ› οΈ CLI Generator - Generate components, routes, and APIs

Developer Experience

  • πŸ“ TypeScript - Full type safety
  • ⚑ Vite - Lightning-fast HMR
  • πŸ§ͺ Testing - Unit, property-based, and E2E tests (476+ tests)
  • πŸ“¦ Pre-built Components - 16+ UI components ready to use

�️ Tecch Stack

Category Technology
Framework SvelteKit 2 with Svelte 5
Language TypeScript 5
Styling Tailwind CSS 4 + DaisyUI 5
Database PostgreSQL 16
ORM Drizzle ORM
Authentication Lucia Auth 3
Email Resend
Storage Local / AWS S3 / Cloudflare R2
Testing Vitest + Playwright + fast-check
Container Docker

πŸš€ Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/nirvagold/svelteship.git
cd svelteship

# Install dependencies
npm install

# Copy environment variables
cp .env.example .env

# Start PostgreSQL with Docker
docker-compose up -d

# Run database migrations
npm run db:migrate

# Start development server
npm run dev

Open http://localhost:5173 in your browser.


πŸ“ Project Structure

svelteship/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/           # UI primitives (Button, Modal, Toast, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ forms/        # Form components (Input, Select, etc.)
β”‚   β”‚   β”‚   └── layouts/      # Layout components (Sidebar, Topbar, etc.)
β”‚   β”‚   β”œβ”€β”€ hooks/            # Svelte hooks (useDebounce, useForm, useSSE, etc.)
β”‚   β”‚   β”œβ”€β”€ utils/            # Shared utilities (date, currency, etc.)
β”‚   β”‚   β”œβ”€β”€ i18n/             # Internationalization (locales, translations)
β”‚   β”‚   β”œβ”€β”€ analytics/        # Analytics integration
β”‚   β”‚   └── server/           # Server-only code
β”‚   β”‚       β”œβ”€β”€ db/           # Database client & schema
β”‚   β”‚       β”œβ”€β”€ email/        # Email service & templates
β”‚   β”‚       β”œβ”€β”€ storage/      # File storage (local, S3, R2)
β”‚   β”‚       β”œβ”€β”€ oauth/        # OAuth providers (Google, GitHub)
β”‚   β”‚       β”œβ”€β”€ logger.ts     # Structured logging
β”‚   β”‚       β”œβ”€β”€ sse.ts        # Server-Sent Events
β”‚   β”‚       └── auth.ts       # Lucia configuration
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ (auth)/           # Auth pages (login, register, logout, oauth)
β”‚   β”‚   β”œβ”€β”€ (app)/            # Protected pages (dashboard, profile, settings)
β”‚   β”‚   β”œβ”€β”€ api/              # API endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ docs/         # Interactive API documentation
β”‚   β”‚   β”‚   └── notifications/# SSE notification stream
β”‚   β”‚   β”œβ”€β”€ docs/             # Component documentation
β”‚   β”‚   └── +page.svelte      # Landing page
β”‚   β”œβ”€β”€ examples/             # Optional features (copy if needed)
β”‚   β”‚   β”œβ”€β”€ notifications/    # Notification system
β”‚   β”‚   β”œβ”€β”€ onboarding/       # Onboarding wizard
β”‚   β”‚   β”œβ”€β”€ admin/            # Admin dashboard
β”‚   β”‚   β”œβ”€β”€ sessions/         # Session management
β”‚   β”‚   └── security/         # Password change, 2FA
β”‚   └── hooks.server.ts       # Session validation middleware
β”œβ”€β”€ scripts/
β”‚   └── generate.ts           # CLI generator for components/routes/APIs
β”œβ”€β”€ drizzle/                  # Database migrations
β”œβ”€β”€ e2e/                      # Playwright E2E tests
β”œβ”€β”€ static/                   # Static assets
└── docker-compose.yml        # PostgreSQL container

πŸ“– Documentation

Available Scripts

Command Description
npm run dev Start development server
npm run build Build for production
npm run preview Preview production build
npm run check Run svelte-check
npm run test Run unit tests
npm run test:e2e Run E2E tests
npm run lint Run ESLint
npm run db:generate Generate migrations
npm run db:migrate Run migrations
npm run db:studio Open Drizzle Studio
npm run generate CLI generator for components/routes/APIs

πŸ”§ Environment Variables

Create a .env file in the root directory. See .env.example for all available options:

# Database
DATABASE_URL=postgres://svelteship:svelteship@localhost:5432/svelteship

# OAuth (optional)
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

# Email (optional)
EMAIL_PROVIDER=console  # or "resend"
RESEND_API_KEY=

# Storage (optional)
STORAGE_PROVIDER=local  # or "s3", "r2"

# Analytics (optional)
ANALYTICS_PROVIDER=     # "plausible", "umami", "google", "custom"

�️ Database

Schema

The database includes these main tables:

Table Description
users User accounts with email, password, preferences
sessions Active user sessions
oauth_accounts Linked OAuth providers (Google, GitHub)
email_verification_tokens Email verification tokens
password_reset_tokens Password reset tokens

Commands

# Start PostgreSQL
docker-compose up -d

# Stop PostgreSQL
docker-compose down

# Generate new migration
npm run db:generate

# Apply migrations
npm run db:migrate

# Open database GUI
npm run db:studio

πŸ” Authentication

Svelteship uses Lucia Auth for authentication.

Features

  • Registration - Email/password with validation
  • Login - Secure session creation
  • Logout - Session invalidation
  • OAuth - Google and GitHub social login
  • Email Verification - Verify user emails
  • Password Reset - Secure recovery flow
  • Protected Routes - Automatic auth guards
  • Session Refresh - Automatic token renewal

OAuth Setup

  1. Create OAuth app on Google Cloud Console or GitHub Developer Settings
  2. Add credentials to .env:
    GOOGLE_CLIENT_ID=your-client-id
    GOOGLE_CLIENT_SECRET=your-client-secret
    GITHUB_CLIENT_ID=your-client-id
    GITHUB_CLIENT_SECRET=your-client-secret
  3. OAuth buttons will appear on login page automatically

🎨 UI Components

UI Primitives (src/lib/components/ui/)

Component Description
Button Buttons with variants, sizes, loading state
Modal Dialog with backdrop, sizes, close button
Toast Notification toasts with auto-dismiss
ConfirmDialog Confirmation dialogs with callbacks
Dropdown Dropdown menus with keyboard navigation
Tabs Tab navigation with panels
Accordion Collapsible content sections
Table Data tables with sorting
Pagination Page navigation with ellipsis
Tooltip Hover tooltips with positions
Badge Status badges with variants
Avatar User avatars with fallback
Progress Progress bars with animation
Spinner Loading spinners
Skeleton Loading placeholders
Breadcrumb Navigation breadcrumbs

Form Components (src/lib/components/forms/)

Component Description
Input Text input with label, error, helper text
Select Dropdown select with options
Checkbox Checkbox with label
Radio Radio group with options
Textarea Multi-line input with character count
DatePicker Date selection with min/max
FileInput File upload with drag-drop and preview

Layout Components (src/lib/components/layouts/)

<script>
  import { SidebarLayout, TopbarLayout, CenteredLayout, SplitLayout } from '$lib/components/layouts';
</script>

<!-- Sidebar navigation -->
<SidebarLayout navItems={items} collapsible>
  <main>Content</main>
</SidebarLayout>

<!-- Top navigation bar -->
<TopbarLayout navItems={items} sticky>
  <main>Content</main>
</TopbarLayout>

<!-- Centered content (auth pages) -->
<CenteredLayout size="md" background="gradient">
  <div class="card">Login form</div>
</CenteredLayout>

<!-- Two-column layout -->
<SplitLayout ratio="1/2">
  {#snippet left()}<aside>Sidebar</aside>{/snippet}
  {#snippet right()}<main>Content</main>{/snippet}
</SplitLayout>

πŸš€ Advanced Features

Internationalization (i18n)

import { t, locale, setLocale } from '$lib/i18n';

// Get translation
const greeting = t('common.welcome'); // "Welcome" or "Selamat Datang"

// Change language
setLocale('id'); // Switch to Indonesian

// Format date/number by locale
import { formatDate, formatNumber } from '$lib/i18n';
formatDate(new Date()); // "December 30, 2024" or "30 Desember 2024"
formatNumber(1234.56);  // "1,234.56" or "1.234,56"

Email Service

import { sendEmail } from '$lib/server/email';

// Send verification email
await sendEmail({
  to: 'user@example.com',
  subject: 'Verify your email',
  template: 'verification',
  variables: { name: 'John', link: 'https://...' }
});

File Storage

import { storage } from '$lib/server/storage';

// Upload file
const url = await storage.upload(file, 'uploads/avatar.png');

// Delete file
await storage.delete('uploads/avatar.png');

// List files
const files = await storage.list('uploads/');

Real-time SSE

// Client-side
import { useSSE } from '$lib/hooks/useSSE';

const { data, error, connected } = useSSE('/api/notifications/stream');

$effect(() => {
  if (data) {
    console.log('New notification:', data);
  }
});

CLI Generator

# Generate a new component
npm run generate
# Select: component
# Name: MyComponent
# Creates: src/lib/components/ui/MyComponent.svelte

# Generate a new route
npm run generate
# Select: route
# Path: /dashboard/analytics
# Creates: src/routes/dashboard/analytics/+page.svelte

# Generate a new API endpoint
npm run generate
# Select: api
# Path: /api/users
# Creates: src/routes/api/users/+server.ts

πŸ“¦ Examples

Optional features in src/examples/ that you can copy into your project:

Example Description
notifications/ Full notification system with database
onboarding/ Multi-step onboarding wizard
admin/ Admin dashboard with role-based access
sessions/ Session management UI
security/ Password change, 2FA settings

Using Examples

# Example: Add notifications
cp -r src/examples/notifications src/routes/(app)/notifications

Each example includes README with setup instructions.


πŸ§ͺ Testing

Svelteship includes comprehensive testing with 476+ tests:

Unit Tests (Vitest)

# Run unit tests
npm run test

# Run with coverage
npm run test -- --coverage

E2E Tests (Playwright)

# Run E2E tests
npm run test:e2e

# Run with UI
npm run test:e2e:ui

Test Coverage

  • βœ… Input validation (email, password)
  • βœ… Authentication flows (register, login, logout, OAuth)
  • βœ… Protected route guards
  • βœ… Profile management
  • βœ… Theme persistence
  • βœ… Form components
  • βœ… i18n translations
  • βœ… Email service
  • βœ… File storage
  • βœ… SSE hooks
  • βœ… Analytics

🚒 Deployment

Vercel (Recommended)

npm install -g vercel
vercel

Docker

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["node", "build"]

Environment Setup

Set these environment variables in your deployment platform:

  • DATABASE_URL - PostgreSQL connection string
  • NODE_ENV - Set to production
  • OAuth, Email, Storage credentials as needed

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide first.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments


Made with ❀️ by the Svelteship Team

Back to top ↑

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •