SvelteKit Short URLs is a self-hosted URL shortener template built with SvelteKit and Turso (libSQL) that creates short links and tracks clicks and referrer traffic.
What is SvelteKit Short URLs?
SvelteKit Short URLs is a web application for running your own link-shortening service. It stores a source path (the short key) and a destination URL in a Turso database, then redirects visitors from the short link to the target while recording each click. The template runs on SvelteKit, a full-stack framework for Svelte, and is configured for deployment to Vercel. Its GitHub repository includes the source code, SQL schema, and development tooling.
Key Features
- Short URL creation and redirection — The
linkstable holdssourceanddestinationcolumns; a request to a short path triggers a redirect to the stored destination. - Click tracking — A
clickscounter on each link increments with every redirect, and the sample SQL queries can return the most-clicked links. - Referrer analytics — The
referrerstable records each traffic source per link and maintains a visit count per referrer, with an aggregation query for top referrers. - Web interface — The app includes a web interface for viewing active links, with a
visibleflag to control which links appear. - Position-based ordering — Links have a
positioncolumn used for ordering in the interface. - Server-side database operations — All database access is done server-side; there are no client-side fetch operations, and redirect handling is secured against open-redirect issues.
- Environment-variable configuration — The app connects to Turso using
TURSO_DB_URLandTURSO_DB_AUTH_TOKEN, with an optionalTURSO_SYNC_URL.
Who should use SvelteKit Short URLs?
- Developers who want a fully controlled, self-hosted URL shortener with a codebase they can modify.
- Product teams that need click and referrer data on internal links without relying on third-party analytics.
- SvelteKit learners looking for a small, practical example of server-side data handling and redirects.
What can you do with SvelteKit Short URLs?
- Create branded short links: Insert a row into
linkswith asourcekey anddestinationURL, then share the short path. - Find top content: Run
SELECT source, destination, clicks FROM links ORDER BY clicks DESC LIMIT 10;to see your most-clicked links. - Identify traffic sources: Use the referrer aggregation query to see which sites send the most visitors.
- Control link visibility: Toggle the
visibleboolean to show or hide links in the web interface.
How does SvelteKit Short URLs work?
Setup requires a Turso database. After creating one, you set the environment variables, install dependencies with pnpm install, and start development with pnpm dev. The project also includes tests run with pnpm test. Links are managed through SQL operations; the README documents exact INSERT, UPDATE, DELETE, and SELECT statements.
FAQ
What database does SvelteKit Short URLs use?
The template uses Turso, which is a libSQL database. You must provide TURSO_DB_URL and TURSO_DB_AUTH_TOKEN to connect.
Does SvelteKit Short URLs track referrers?
Yes. The referrers table stores the referrer URL and a count of visits per link. A provided SQL query sums these counts to return the top referrers.
How do I add a new short link?
You insert a record into the links table with a source path, destination URL, description, visibility flag, and position. The repository includes the exact SQL statement for this.
What are the required environment variables?
TURSO_DB_URL (the database URL) and TURSO_DB_AUTH_TOKEN (the auth token) are required. TURSO_SYNC_URL is optional.
How do I run the development server?
Install dependencies with pnpm install, then run pnpm dev. The project also has tests invoked with pnpm test.








