Skip to content

Why @xtandard/links

Every permissive, maintained shortener is a standalone app — Shlink (PHP), Kutt (Express), YOURLS (PHP), chhoto-url (Rust). The TypeScript ones with real analytics (Dub, Sink) are AGPL, and Dub’s open core depends on hosted Tinybird, Upstash and PlanetScale. Nothing lets a TypeScript SaaS add branded short links and click analytics inside its own app and database — the email tool that tracks links in newsletters, the CRM that shortens links per contact, the social scheduler that needs QR codes and per-customer analytics.

@xtandard/links is that library:

  • Embeddable: createLinksCore({ storage }) + one mount line per framework (Elysia, Hono, Express, Bun, Next.js). Your process, your database.
  • Fast and resilient redirects: a memory-first resolver (LRU + TTL + stale-while-revalidate + negative cache + last-known-good); the redirect handler never throws into your app and never waits on analytics.
  • Real analytics: async batched click capture with bot and link-preview filtering, user-agent parsing, geo from edge headers, privacy modes (IPs dropped by default). Rollups in the same database on day one; ClickHouse, Tinybird or Workers Analytics Engine when you outgrow it.
  • Beyond redirects: targeting rules and A/B splits, expiry and click budgets, passwords, link previews (Open Graph), UTM templates, QR codes, bulk CSV import from Bitly/Dub/Shlink/Kutt, conversion attribution (trackLead / trackSale), and deep links with apple-app-site-association / assetlinks.json, store fallback and deferred deep linking — the Firebase Dynamic Links gap.
  • Multi-tenant by design: every link belongs to a tenant; tenants can own branded domains; a per-tenant analytics widget with scoped, stateless viewer tokens embeds in your product.
  • Same shape as its siblings @xtandard/flags and @xtandard/webhooks: ten storage drivers, auth/authorization providers, hooks, a bundled admin UI, React embeds, CLI and Docker image.

If you only need a shortener for yourself and are happy running a separate service, use Shlink — it is excellent. See the landscape.

flowchart LR
  subgraph host["Your app process"]
    A[app code] -- "createLink()" --> C[core]
    P[admin UI / analytics widget] --> C
    R[redirect handler] --> M[(memory resolver)]
    M -. miss / refresh .-> C
    R -- "capture()" --> I[click ingestor]
  end
  C --> S[(storage: links, domains, attribution)]
  I -- "batched" --> K[(analytics sink)]
  V[visitor] -- "GET go.acme.com/x7k2" --> R
  R -- "302" --> V
Control plane Redirect plane
Surface createLinksCore + admin API + UI + widget createRedirectHandler on your short domain
Traffic rare, human-driven hot, anonymous, bursty, full of bots
Guards auth, authorization, before hooks, audit log rules, expiry, password; never 500s
Failure stance fail loudly to the operator always answer: redirect, 404 page, or fall through

See Architecture and ADRs 0002 and 0004.