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.
- Collision-Free Base62 Code Generation: Uses an atomic sequential counter (Redis
INCRbacked 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-limitto 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.
| 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 |
├── 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
- Node.js (v18+ recommended)
- MongoDB instance (Local or MongoDB Atlas)
- Redis instance (Local or Redis Cloud)
-
Clone the repository:
git clone https://github.com/hum4nBeing/SwiftURL.git cd SwiftURL -
Install dependencies:
npm install
-
Configure Environment Variables: Create a
.envfile 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"
-
Generate Prisma Client:
npx prisma generate
-
Start Development Server:
npm run dev
Access the web app at
http://localhost:3000/. -
Build for Production:
npm run build npm start
- 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" }
- Endpoint:
GET /:code - Rate Limit: 300 requests / 1 min per IP
- Response:
HTTP 302 FoundwithLocationheader pointing to original URL.
To execute the 5,000 req/sec stress test script:
k6 run load-test.jsBenchmark Results:
- Requests Processed: 76,806 requests in 60s
- Peak Throughput: 5,000 req/sec
- Cache Hit Latency: Sub-millisecond
Distributed under the ISC License.