Skip to content

How Shortener works

Shortener turns long URLs into short /s/ links and counts the clicks. It is a small Next.js app, a FastAPI service and a PostgreSQL database, packaged with Docker so it runs entirely on infrastructure you control.

The journey of a click

What happens between someone tapping a short link and arriving at the destination.

your-host/s/launchexample.com/a/very/long/path
  1. Someone opens the short link

    GET /s/launch

    From a post, a chat message, a QR code or a typed address.

  2. The web app hands it to the API

    Next.js rewrites /s/* → FastAPI

    The browser never talks to the database directly; one service owns every rule.

  3. The API looks it up and records the click

    INSERT INTO click_events (time, referrer, user_agent)

    The slug is matched against custom aliases and random keys, and the expiry is checked before anything is written.

    • 404Unknown slug: a “link not found” page
    • 410Past its expiry: a “link expired” page, no click counted
  4. The visitor lands on the destination

    307 Temporary Redirect → https://example.com/…

    A temporary redirect, so browsers keep asking this server and every visit is counted.

What you can do

Shorten
Paste any http or https URL. Pick a custom alias (3–32 letters, digits or hyphens) or let the server generate a random key, and optionally make the link expire after 7, 30 or 90 days. Shortening the same URL twice returns the existing link instead of creating a duplicate.
Track
Every visit to a short link is recorded before the redirect: clicks per day, the referring site and the browser’s user agent. The stats page shows totals, a daily chart, top links and top referrers for the last 7, 30 or 90 days or any custom range.
Manage
Search, sort and filter every link by status. Open a link to see its own chart and referrers, change or remove its expiry, expire it immediately, or delete it with its click history. Export the full list as CSV and download QR codes as PNG or SVG.

Your data

Links and clicks are stored in the PostgreSQL volume of this deployment and nowhere else. A click record holds the time, the referrer and the user agent; IP addresses are used in memory for rate limiting and are not saved. Fonts are served from this server and the coloured domain marks are drawn locally, so pages make no third-party requests.

The Your links list on the home page lives in your browser’s local storage. Clearing it only hides links from that list; the links keep working.

Upgrades rebuild the containers without touching the database volume, and the repository ships backup and restore scripts in scripts/.

Use the API

Everything the interface does goes through a JSON API you can script against. If the server sets ADMIN_API_KEY, creating, editing and deleting links require it in the X-API-Key header. The full reference is at /docs.

Create a link
curl -X POST https://your-host/api/url \
  -H 'Content-Type: application/json' \
  -d '{"url": "https://example.com/a/very/long/path", "alias": "launch", "expires_in_days": 30}'

# → {"public_slug": "launch"}
Read one link’s clicks
curl 'https://your-host/api/urls/launch/stats?days=30'
Remove the expiry, or delete
curl -X PATCH https://your-host/api/urls/launch \
  -H 'Content-Type: application/json' -d '{"expires_in_days": null}'

curl -X DELETE https://your-host/api/urls/launch -H 'X-API-Key: <key>'

Keyboard shortcuts

/Focus the URL field (home) or search (stats)
CtrlVPaste a URL anywhere on the home page
cCopy the link you just created, or the selected one
jkMove through the links table
EnterOpen the selected link’s details
?Show all shortcuts