Architecture
sptfy.in uses a modern JAMstack architecture with a serverless frontend and a self-hosted backend:Frontend Stack
SvelteKit
SvelteKit is the full-stack framework built on Svelte, providing:- File-based routing with
+page.sveltefiles - Server-side rendering (SSR) and static site generation (SSG)
- API routes via
+server.jsfiles - Built-in form handling with progressive enhancement
@sveltejs/adapter-cloudflare for Cloudflare Pages deployment
Svelte 5 (Runes)
Svelte 5 introduced runes, a new way to declare reactive state:example.svelte
UI Components
Shadcn-Svelte
shadcn-svelte provides beautifully designed, accessible components built on:- bits-ui - Headless UI primitives
- Tailwind CSS - Utility-first CSS framework
- tailwind-variants - Component variants with type safety
$lib/components/ui/:
Additional UI Libraries
- lucide-svelte - Icon library (e.g.,
<iconify-icon icon="lucide:icon-name">) - svelte-sonner - Toast notifications
- vaul-svelte - Drawer/bottom sheet component
- mode-watcher - Dark mode support
Styling
Tailwind CSS
Tailwind CSS v3.4+ with:- @tailwindcss/typography - Beautiful typographic defaults
- tailwind-merge - Intelligent class merging
- clsx - Conditional class names
Fonts
Plus Jakarta Sans - Clean, modern sans-serif font familyForms & Validation
- sveltekit-superforms - Type-safe form handling with SvelteKit
- formsnap - Form state management
- zod - Schema validation
form-example.svelte
Security
- svelte-turnstile - Cloudflare Turnstile CAPTCHA integration
Backend Stack
PocketBase
PocketBase v0.23.12 - An open-source backend in a single binary:- Database: Embedded SQLite with automatic migrations
- Authentication: OAuth2 (Spotify), email/password
- API: Auto-generated REST API with real-time subscriptions
- Admin UI: Web-based dashboard at
/_/ - File Storage: Built-in file uploads
- Hooks: Server-side JavaScript hooks for custom logic
PocketBase Client
The frontend connects to PocketBase using the official JavaScript SDK:src/lib/pocketbase.js
Collections
- users - User accounts (Spotify OAuth)
- random_short - Short link records
- analytics - Click tracking and geolocation
Hooks
Server-side hooks inpocketbase/pb_hooks/:
random.pb.js:
- Turnstile verification before creating links
- Field protection on updates
- Spotify user ID extraction on OAuth
main.pb.js:
- Custom API routes
Database
SQLite - Lightweight, serverless database:- Single-file database (
pb_data/data.db) - ACID-compliant transactions
- Automated backups to Cloudflare R2
Development Tools
Package Manager
pnpm - Fast, disk-space efficient package managerThe project enforces pnpm usage via the
preinstall script. npm and yarn will be rejected.Build Tools
- Vite v6.3+ - Next-generation frontend build tool
- vite-plugin-mkcert - HTTPS for local development
Code Quality
Linting
ESLint v9+ with:eslint-plugin-svelte- Svelte-specific ruleseslint-config-prettier- Disable conflicting rules
Formatting
Prettier v3.6+ with:prettier-plugin-svelte- Format.sveltefilesprettier-plugin-tailwindcss- Sort Tailwind classes
.prettierrc):
Testing
Vitest v3.1+ - Blazing fast unit testing frameworksrc/lib/**tests**.
Version Control
- Git - Source control
- GitHub - Code hosting and CI/CD
- beads - Git-native issue tracking for AI agents
Deployment
Frontend Deployment
Cloudflare Pages:- Automatic builds on push to
main - Global CDN with edge caching
- Instant rollbacks via dashboard
- Custom domain:
sptfy.in
pnpm buildOutput directory:
build/
Backend Deployment
VPS (Virtual Private Server):- Docker container with PocketBase
- Nginx reverse proxy (
127.0.0.1:8091) - GitHub Actions for automated deployment
- Location:
~/pb-docker/
- Push to
mainbranch - Changes to
pocketbase/pb_hooks/**,pocketbase/pb_migrations/**, ordocker-compose.yml
Monitoring
- BetterStack - Status page and uptime monitoring
- Public status page: status.sptfy.in
Backups
- Automated: PocketBase built-in backup feature
- Destination: Cloudflare R2 (S3-compatible storage)
- Frequency: Configurable in PocketBase settings
Key Dependencies
Runtime Dependencies
Development Dependencies
Scripts
Common npm scripts defined inpackage.json:
Environment Variables
Development (.env.development)
Production
Configured in Cloudflare Pages dashboard:VITE_POCKETBASE_URL- Production PocketBase URLVITE_CF_SECRET- Real Cloudflare Turnstile secretVITE_CF_SITE_KEY- Real Cloudflare Turnstile site keyVITE_APP_URL- Production app URL
File Naming Conventions
- Components:
kebab-case.svelte(e.g.,user-profile.svelte) - Routes:
+page.svelte,+server.js,+layout.svelte - Utilities:
camelCase.js(e.g.,formatDate.js) - Types:
PascalCase.ts(e.g.,UserProfile.ts)
Code Style Guidelines
From.prettierrc and AGENTS.md:
- Indentation: Tabs (not spaces)
- Quotes: Single quotes (
') - Trailing commas: None
- Line width: 100 characters
- Svelte 5 patterns: Always use runes (
$state,$derived,$props) - Import order: Framework imports first, then libraries, then local
Next Steps
- Set up your Local Development Environment
- Read the Contributing Guidelines
- Explore the API Documentation