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.
npm install @xtandard/linksA 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 APIapp.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 →
const { core } = panel;
await core.createDomain({ hostname: "go.acme.com", isDefault: true });
const link = await core.createLink({ url: "https://acme.com/pricing", slug: "pricing", // omit for a generated 7-character slug tags: ["launch"], utm: { source: "newsletter", campaign: "spring" }, expiresAt: "2027-01-01T00:00:00Z",});// https://go.acme.com/pricing → 302 https://acme.com/pricing?utm_source=newsletter&utm_campaign=springTenants, branded domains per customer, expiry and click budgets, passwords, link previews, QR codes and CSV import from Bitly, Dub, Shlink and Kutt. Links & domains →
await core.createLink({ slug: "app", url: "https://acme.com/download", ios: "https://apps.apple.com/app/id123456789", android: "https://play.google.com/store/apps/details?id=com.acme", rules: [ { when: [{ field: "country", op: "in", values: ["DE", "AT", "CH"] }], url: "https://acme.de/download", }, { when: [], // everyone else: a 50/50 split, sticky per visitor variants: [ { id: "a", url: "https://acme.com/download?v=a", weight: 50 }, { id: "b", url: "https://acme.com/download?v=b", weight: 50 }, ], }, ],});Ordered rules, first match wins, deterministic A/B variants. Targeting rules →
const stats = await core.queryAnalytics({ tenant: "default", from: "2026-11-01T00:00:00Z", to: "2026-12-01T00:00:00Z", interval: "day", groupBy: "country",});// { totals: { clicks, botClicks, leads, sales, saleAmount }, timeseries: [...], breakdown: [...] }Bots and link previews flagged, device / OS / browser parsed, geo from edge headers, IPs dropped by default. Rollups in your own database on day one; ClickHouse, Tinybird or Workers Analytics Engine when you outgrow it. Click analytics →
// On your landing page (browser):import { captureClickId, getClickId } from "@xtandard/links/client";captureClickId(); // stores ?xl_id=clk_… in a first-party cookie
// On your server, when the visitor signs up and pays:await core.trackLead({ clickId, customerId: user.id, name: "Sign up" });await core.trackSale({ customerId: user.id, amount: 4900, currency: "USD", invoiceId: "inv_1" });“Which link brought this customer?” Leads and sales land next to clicks in every analytics query. Conversions →
// Your server, after your own auth:import { createViewerToken } from "@xtandard/links";const token = await createViewerToken(process.env.LINKS_VIEWER_SECRET!, { tenant: org.id });
// Your React frontend:import { LinkAnalytics } from "@xtandard/links/react";import "@xtandard/links/react/styles.css";
<LinkAnalytics apiBaseUrl="/links" token={token} />;Each of your customers sees the clicks on their links inside your product, scoped by a signed, stateless token. Analytics widget →
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.