New
Apps 6,419Makers 6,403This week 7
Promote your app−30%
4views in
the last 30 days

TinyLink

A blazing-fast, production-grade URL shortener built with TypeScript, Fastify, and PostgreSQL. πŸš€

Built with Claude Code

by thanhnam2811 Β· Unclaimed Β· from VNVietnam Β· added Oct 29, 2026
no ratings0 comments

TinyLink

A production-grade URL shortener built as a full-stack monorepo β€” fast, trackable, and deployable on free-tier infrastructure.

Live: link.namtt.dev


πŸ“Έ Demo

TinyLink landing page


✨ Features

  • Blazing-fast redirects β€” 302/307 redirects served via Redis cache, near-zero latency
  • Click analytics β€” IP, User-Agent, referrer, geo-location (country/city), time series
  • Password-protected links β€” optional password lock on both redirect and analytics
  • Link expiration β€” set TTL per link
  • QR code generation β€” built-in QR for every short link
  • Guest β†’ user link claiming β€” create links as a guest, claim them on sign-in
  • OAuth authentication β€” Google & GitHub via Auth0
  • User dashboard β€” manage, search, and delete your links
  • Admin dashboard β€” full system analytics, link management, geo distribution charts
  • Bot detection & edge middleware β€” filter bots at the edge, inject OpenGraph metadata
  • Rate limiting β€” Redis-backed, prevents spam and brute-force
  • Memory queue + batch insert β€” click events buffered in-memory, flushed to DB in batches
  • Glassmorphism + Minimalist UI β€” Framer Motion animations, Lenis smooth scroll, dark/light/system theme
  • Resilience pages β€” custom 404, error boundary, skeleton loading screens

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Client (Next.js)           β”‚
β”‚  Landing β”‚ Dashboard β”‚ Stats β”‚ Admin        β”‚
β”‚  BFF Proxy ──────────────────────────────►  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚ HTTP (Internal API Key)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Server (Fastify)               β”‚
β”‚  /api/links  β”‚  /api/analytics  β”‚  /api/authβ”‚
β”‚              β”‚                  β”‚           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Memory Queue β†’ Batch DB Insert     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚              β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
     β”‚  PostgreSQL  β”‚  β”‚   Redis  β”‚
     β”‚  (Prisma)    β”‚  β”‚  Cache   β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Click flow:

  1. User hits /:code β†’ Edge Middleware checks for bots
  2. Fastify checks Redis cache β†’ DB fallback
  3. 302 redirect sent immediately
  4. Click event pushed to in-memory queue
  5. Background worker batch-inserts to PostgreSQL every few seconds

πŸ“¦ Monorepo Structure

tiny-link/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ server/     # Fastify API β€” core shortening, analytics, auth
β”‚   β”œβ”€β”€ client/     # Next.js β€” public app, user dashboard, stats
β”‚   β”œβ”€β”€ admin/      # Next.js β€” admin dashboard, system analytics
β”‚   β”œβ”€β”€ db/         # Prisma schema + generated client (shared)
β”‚   └── shared/     # TypeScript types, Zod/TypeBox schemas
β”œβ”€β”€ docs/           # ROADMAP, release templates, agent workflows
β”œβ”€β”€ scripts/        # Version bumping, utilities
β”œβ”€β”€ docker-compose.yml
└── .github/workflows/pipeline.yml

πŸ›  Tech Stack

Layer Technology
Frontend Next.js 16, React 19, Tailwind CSS v4, Framer Motion, Lenis
Backend Fastify 5, Node.js 24, Pino logging
Database PostgreSQL 17 + Prisma 7 ORM
Cache / Rate Limit Redis 7 + ioredis
Auth Auth0 β€” Google & GitHub OAuth
Charts Recharts
UI Components shadcn/ui, Base UI
Validation Zod (client), TypeBox (server)
Testing Vitest + React Testing Library
DevOps Docker, GitHub Actions, Self-hosted VPS (Cloudflare Tunnel)
Package Manager pnpm 10 workspaces

πŸš€ Quick Start

Prerequisites

  • Node.js β‰₯ 24 (matches CI and production; see .node-version β€” fnm use / nvm use picks it up automatically)
  • pnpm β‰₯ 10
  • Docker & Docker Compose

1. Clone & install

git clone https://github.com/thanhnam2811/tiny-link.git
cd tiny-link
pnpm install

2. Configure environment

# Server
cp packages/server/.env.example packages/server/.env

# Client
cp packages/client/.env.example packages/client/.env

Fill in the required values (see Environment Variables).

3. Start infrastructure

pnpm docker:up        # starts PostgreSQL + Redis

4. Migrate database

cd packages/db
npx prisma migrate deploy
# or for development:
npx prisma db push

5. Run in development

pnpm dev              # starts all packages in parallel

🐳 Docker (Production)

# Build & run everything
pnpm docker:build
docker compose up

# Or just start DB + Redis, run app locally
pnpm docker:up
pnpm dev

The docker-compose.yml includes:

  • PostgreSQL 17 (port 5432, persistent volume)
  • Redis 7 (port 6379, 50MB LRU eviction)
  • App (Fastify server, port 3001, multi-stage build)

πŸ” Environment Variables

Server (packages/server/.env)

Variable Description Required
DATABASE_URL PostgreSQL connection string βœ…
REDIS_URL Redis connection string βœ…
CLIENT_URL Frontend URL for CORS βœ…
INTERNAL_API_KEY Shared secret for clientβ†’server calls βœ…
JWT_SECRET JWT signing secret βœ…
ADMIN_PASSWORD Admin dashboard password βœ…

Client (packages/client/.env)

Variable Description Required
AUTH0_SECRET 32-byte hex secret for encrypting session cookies βœ…
AUTH0_DOMAIN Auth0 tenant domain βœ…
AUTH0_CLIENT_ID Auth0 application client ID βœ…
AUTH0_CLIENT_SECRET Auth0 application client secret βœ…
APP_BASE_URL Public URL of the client app βœ…
DATABASE_URL PostgreSQL URL (local User table synced from Auth0) βœ…
INTERNAL_API_URL Fastify server base URL βœ…
INTERNAL_API_KEY Shared secret matching server βœ…

πŸ”§ Scripts

pnpm dev          # Start all packages in parallel (development)
pnpm build        # Clean + build shared β†’ db β†’ all packages
pnpm lint         # ESLint across all packages
pnpm test         # Vitest across all packages
pnpm format       # Prettier format

pnpm docker:up    # Start PostgreSQL + Redis
pnpm docker:down  # Stop all Docker services
pnpm docker:build # Build Docker image

🚒 CI/CD Pipeline

GitHub Actions pipeline (.github/workflows/pipeline.yml) β€” 4 stages:

PR to main ──────────── Lint & Test only (gate)
Push to main (merge) ──┐
    β”‚                   β”‚
    β–Ό                   β”‚
1. Lint & Test ──────── ESLint + Vitest (Node 24)
    β”‚
    β–Ό
2. Docker Build ──────── Multi-stage image β†’ GHCR
    β”‚                    tags: latest | sha
    β–Ό
3. DB Migration ──────── prisma migrate deploy (production)
    β”‚
    β–Ό
4. Deploy ────────────── SSH (via Cloudflare Tunnel) β†’ VPS pulls & restarts

πŸ“Š Analytics

Each short link tracks:

  • Total clicks with time-series (last 7 days)
  • Geographic distribution β€” country-level via geoip-lite
  • Referrer breakdown
  • User-Agent parsing (browser/device/OS)

Analytics are accessible via:

  • /stats/:code β€” public stats page (password-protected if set)
  • Admin dashboard β€” aggregate system-wide stats

πŸ”’ Security

  • Rate limiting on all API endpoints (Redis-backed, per-IP)
  • Argon2 password hashing for link passwords
  • JWT authentication between services
  • INTERNAL_API_KEY header for clientβ†’server requests
  • Bot detection at Next.js edge middleware
  • Non-root Docker user (nodeuser)

πŸ“ Development Guide

Branch strategy

Branch Purpose Environment
feature/* or fix/* Feature development Local
main Production Production (auto-deploy)

Workflow: branch off main β†’ PR into main β†’ merge β†’ CI builds, migrates, and deploys automatically.

Database changes

# Create a new migration
cd packages/db
npx prisma migrate dev --name your_migration_name

# Apply migrations (CI/production)
npx prisma migrate deploy

# Quick schema sync (dev only)
npx prisma db push

Build order

Workspace packages must be built in order:

pnpm --filter @tiny-link/shared run build
pnpm --filter @tiny-link/db run build
# then client/server/admin

πŸ“„ License

MIT

Description taken from the repository README.

Ratings

–
0 ratings
5 0
4 0
3 0
2 0
1 0

Rate this app

Sign in to rate

Comments 0

Sign in to comment

No comments yet.

Related apps

#url-shortener Β· #typescript