This project is a backend API for a URL shortener service with advanced features including:
- URL Shortening with custom short codes
- Analytics for tracking visits
- Caching for optimizing performance
- API Rate Limiting to prevent abuse
- Background Jobs for updating and maintaing Analytics
The API is designed to be robust, scalable, and easy to integrate with other services.
- Node.js and npm
- MongoDB
- Redis (for caching and queue)
- bullmq (for queues and background workers)
- Clone the repository:
git clone https://github.com/hritik-hk/shrinkly.git cd shrinkly
- Install dependencies:
npm install
- Set up environment variables in a .env file:
DB_URL=<your-mongodb-uri>
REDIS_URL=<your-redis-url>
PORT=8080
Request body:
{
"originalUrl": "https://example.com",
}
Request body:
{
"originalUrl": "https://example.com",
"customCode": "mycodex",
}
Redirect to the original URL and track analytics. Response: -302 Redirect to the original URL -404 if the URL does not exist
Response:
{
"deviceTypes": {
"desktop": number,
"mobile": number
},
shortCode": string,
"originalUrl": string,
"totalVisits": number,
"uniqueVisits": number,
"visitHistory": {"clientIp":string, "timeStamp":datetime, "userAgent":string}[]
}
- caches frequency used results in memory redis database/store
- API rate limiting on basis of requested URL and IP address
- used redis to maintain request count and TTL
- processes jobs/updates from queue and updates database asynchronously
- implemented using bullmq