Skip to content
xtandard-linksxtandard-links

Branded short links, as a library

Mount it inside your app, point it at the database you already run, and give your product (and your customers) branded short links with targeting rules, QR codes, click analytics, conversion attribution and deep links. No per-click SaaS pricing, no separate service to operate.
Terminal window
npm install @xtandard/links

A Dub / Bitly alternative you embed instead of rent. A redirect never waits on your database or your analytics: links resolve from memory, clicks are captured in the background, and your customers see their own numbers through an embeddable widget.

import { Hono } from "hono";
import { linksPanel, linksRedirect } from "@xtandard/links/hono";
import { createSqliteStorage } from "@xtandard/links/storage/sqlite";
const panel = linksPanel({
storage: createSqliteStorage({ path: "links.db" }),
basePath: "/links",
defaultDomain: "localhost",
});
const app = new Hono();
app.route("/links", panel); // admin UI + JSON API
app.use(linksRedirect({ core: panel.core })); // GET /{slug} → redirect, else next()

Adapters for Hono, Elysia (1 and 2), Express, Bun and Next.js; storage on Postgres, Redis, MongoDB, SQLite, libSQL, Drizzle, unstorage, Cloudflare KV, files or memory. Quickstart →

flowchart LR
  subgraph host["your app process"]
    direction TB
    APP["app code"] -- "createLink()" --> CORE["<b>core</b><br/>tenants · domains · links<br/>conversions · deferred handoffs"]
    PANEL["<b>panel</b><br/>admin UI + API + widget"] --> CORE
    RED["<b>redirect handler</b><br/>rules · expiry · password<br/>deep-link files"] --> RES[("memory<br/>resolver")]
    RES -. "miss / refresh" .-> CORE
    RED -- "capture()" --> ING["click ingestor<br/>batched, async"]
  end
  CORE <--> DB[("your database<br/>Postgres · Redis · Mongo<br/>SQLite · Drizzle · KV …")]
  ING --> SINK[("analytics sink<br/>KV rollups · ClickHouse<br/>Tinybird · Analytics Engine")]
  V["visitor"] -- "GET go.acme.com/x7k2" --> RED
  RED -- "302" --> V

Two planes: the control plane (core, admin API, UI, widget) is rare and human-driven; the redirect plane is hot, anonymous and full of bots. The redirect answers from an LRU with stale-while-revalidate and last-known-good, never waits on the analytics sink, and never throws into your app. Architecture →

A library, not a service

bun add and the database you already have. Every maintained permissive shortener is a standalone app; the TypeScript ones with real analytics are AGPL. This one mounts in your app.

Redirects that always answer

Memory-first resolution, a negative cache for slug scanners, last-known-good when storage hiccups, and edge waitUntil support. Runs on Workers and Vercel with zero optional deps.

Analytics you can grow into

Same-database rollups on day one. Swap the sink for ClickHouse, Tinybird or Workers Analytics Engine and keep everything else; every sink passes one conformance suite.

Multi-tenant by design

Every link belongs to a tenant, tenants own branded domains, and a scoped viewer token embeds per-customer analytics in your product.

@xtandard/links has siblings: open-source, MIT-licensed projects that share the xtandard name. Each one stands on its own.

All of them, with npm and GitHub links: the xtandard ecosystem.