https://github.com/spences10/sveltekit-short-urls
Short URLs with SvelteKit
https://github.com/spences10/sveltekit-short-urls
short-url short-urls svelte sveltekit vercel
Last synced: 3 months ago
JSON representation
Short URLs with SvelteKit
- Host: GitHub
- URL: https://github.com/spences10/sveltekit-short-urls
- Owner: spences10
- Created: 2022-01-29T18:58:36.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-08-23T21:40:32.000Z (3 months ago)
- Last Synced: 2025-08-24T09:13:04.077Z (3 months ago)
- Topics: short-url, short-urls, svelte, sveltekit, vercel
- Language: TypeScript
- Homepage: https://sveltekit-short-urls.vercel.app/links
- Size: 1.69 MB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SvelteKit Short URLs
A modern URL shortener built with SvelteKit and Turso (libSQL).
Features link management, click tracking, and referrer analytics.
## Features
- Short URL creation and redirection
- Click tracking and analytics
- Referrer tracking
- Web interface for viewing active links
- Position-based link ordering
- Visibility controls for links
## Database Schema
The application uses Turso (libSQL) with two main tables:
### Links Table
- `id`: Unique identifier
- `source`: Short URL path
- `destination`: Target URL
- `position`: Order position
- `description`: Link description
- `clicks`: Click counter
- `visible`: Visibility flag
### Referrers Table
- Tracks traffic sources for each link
- Maintains count of visits per referrer
## Setup
1. Create a Turso database and obtain credentials
2. Set environment variables:
```bash
TURSO_DB_URL=your_database_url
TURSO_DB_AUTH_TOKEN=your_auth_token
TURSO_SYNC_URL=your_sync_url # Optional
```
## Database Operations
### Adding a Link
```sql
INSERT INTO links (source, destination, description, visible, position)
VALUES ('key', 'https://destination.com', 'Description', true, 1);
```
### Updating a Link
```sql
UPDATE links
SET destination = 'new-url', description = 'new description'
WHERE source = 'key';
```
### Deleting a Link
```sql
DELETE FROM links WHERE source = 'key';
```
### Viewing Links
```sql
-- All visible links
SELECT * FROM links WHERE visible = true;
-- Most clicked links
SELECT source, destination, clicks
FROM links
ORDER BY clicks DESC
LIMIT 10;
-- Top referrers
SELECT r.referrer, SUM(r.count) as total_referrals
FROM referrers r
GROUP BY r.referrer
ORDER BY total_referrals DESC
LIMIT 10;
```
## Development
```bash
# Install dependencies
pnpm install
# Run development server
pnpm dev
# Run tests
pnpm test
```
## Security Features
- Server-side database operations only
- No client-side fetch operations
- Secure redirect handling
- Environment variable protection