Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ SwiftURL - High-Performance URL Shortener & Analytics System

SwiftURL is a high-throughput, collision-resistant URL Shortener service built with Node.js, Express, TypeScript, Prisma ORM, MongoDB, Redis, and BullMQ. It features a modern glassmorphic web interface, sub-millisecond cache-assisted redirects, asynchronous background analytics processing, and rate-limiting protection.


🚀 Key Features & Highlights

  • Collision-Free Base62 Code Generation: Uses an atomic sequential counter (Redis INCR backed by MongoDB durability) converted to Base62 short codes.
  • Sub-Millisecond Redis Caching: Frequently accessed short links are cached in Redis with a 24-hour TTL, bypassing database lookups.
  • Asynchronous Click Analytics (BullMQ): Non-blocking background worker process logs click events (IP address, User-Agent, Timestamp) into MongoDB without delaying HTTP 302 redirects.
  • DDoS & Rate Limiting Protection: Integrated IP rate limiting powered by express-rate-limit to prevent URL creation spam and server overload.
  • High Throughput Benchmarks: Tested at 5,000 requests/sec with k6 (76,000+ completed redirect requests in 60s).
  • Glassmorphic Web App UI: Includes a responsive web interface served at GET / with live shortening, copy-to-clipboard, history management, and QR code generation.

🛠️ Tech Stack

Layer Technology
Language TypeScript / Node.js
Framework Express.js
Database MongoDB (configured via Prisma ORM)
Caching Redis (ioredis)
Queue & Workers BullMQ
Load Testing k6
Frontend Vanilla HTML5 / CSS3 (Glassmorphism) / JS

📁 Project Architecture

├── public/                # Web Application Frontend UI
│   ├── css/styles.css     # Glassmorphic CSS Theme & Animations
│   ├── js/app.js          # Interactive Frontend Logic & QR Code
│   └── index.html         # Main Web App Markup
├── src/
│   ├── config/            # DB & Redis Configuration
│   ├── controllers/       # HTTP Route Controllers
│   ├── middleware/        # Rate Limiting & Error Handlers
│   ├── routes/            # Express Endpoint Routers
│   ├── services/          # Business Logic (UrlService, AnalyticsService)
│   ├── utils/             # Base62 Encoder & Utilities
│   ├── workers/           # BullMQ Background Worker Process
│   └── index.ts           # Server Entrypoint
├── prisma/
│   └── schema.prisma      # Prisma Data Schema (MongoDB)
├── load-test.js           # k6 Performance Stress Testing Script
└── README.md

⚡ Getting Started

Prerequisites

  • Node.js (v18+ recommended)
  • MongoDB instance (Local or MongoDB Atlas)
  • Redis instance (Local or Redis Cloud)

Installation

  1. Clone the repository:

    git clone https://github.com/hum4nBeing/SwiftURL.git
    cd SwiftURL
  2. Install dependencies:

    npm install
  3. Configure Environment Variables: Create a .env file in the root directory based on .env.example:

    PORT=3000
    DATABASE_URL="mongodb+srv://<username>:<password>@cluster.mongodb.net/url_shortener?retryWrites=true&w=majority"
    REDIS_HOST="127.0.0.1"
    REDIS_PORT=6379
    REDIS_PASSWORD=""
    BASE_URL="http://localhost:3000"
  4. Generate Prisma Client:

    npx prisma generate
  5. Start Development Server:

    npm run dev

    Access the web app at http://localhost:3000/.

  6. Build for Production:

    npm run build
    npm start

📡 API Endpoints

1. Shorten URL

  • Endpoint: POST /shorten
  • Rate Limit: 30 requests / 15 mins per IP
  • Request Body:
    {
      "url": "https://github.com/example/repo"
    }
  • Response (201 Created):
    {
      "shortCode": "q18",
      "shortUrl": "http://localhost:3000/q18",
      "originalUrl": "https://github.com/example/repo"
    }

2. Redirect Short Link

  • Endpoint: GET /:code
  • Rate Limit: 300 requests / 1 min per IP
  • Response: HTTP 302 Found with Location header pointing to original URL.

📊 Performance Benchmarks (k6)

To execute the 5,000 req/sec stress test script:

k6 run load-test.js

Benchmark Results:

  • Requests Processed: 76,806 requests in 60s
  • Peak Throughput: 5,000 req/sec
  • Cache Hit Latency: Sub-millisecond

📄 License

Distributed under the ISC License.

About

A lightning fast url shortner

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages