DEV Community

胡亚洲
胡亚洲

Posted on

I built the world's shortest URL shortener — here's how

Every URL shortener claims to make links "short." But a Bitly link is 22 characters. TinyURL is 26. That's not short — that's just... shorter.

So I built y.hn. Every link is 7 characters: y.hn/abc.

Why does length matter?

  • SMS: 160 character limit. Every character counts.
  • Twitter/X: Display text matters for readability.
  • QR codes: Shorter URLs = simpler QR patterns = faster scanning.
  • Print: Shorter URLs are easier to type manually.

The tech stack

  • Framework: Next.js 16 (App Router)
  • Database: PostgreSQL 16 with pgvector
  • ORM: Drizzle ORM
  • Auth: NextAuth v5 (Google, Apple, Email)
  • Analytics: Custom-built click tracking (country, city, device, browser, UTM)

Anti-phishing at scale

URL shorteners are a prime target for phishing. We built a 7-layer detection system:

  1. Keyword blocklist matching
  2. Google Safe Browsing API
  3. PhishTank database
  4. URLhaus malware database
  5. VirusTotal (70+ security vendors)
  6. AI URL pattern analysis
  7. AI page content deep scanning

The AI content scanner uses free LLM models (DeepSeek, Groq, Cerebras, SiliconFlow). Total cost: $0.

Analytics without cookies

We track clicks using hashed IP + user agent for unique visitor counting. No cookies needed. Geographic data comes from Cloudflare headers.

Try it

y.hn — free, no account required for basic shortening. API docs for developers.

Top comments (0)