A powerful and modular URL shortening service built with NestJS and Prisma, featuring click analytics, custom aliases, and JWT-based user authentication.
- 🔗 Shorten Long URLs into compact, shareable links
- ✍️ Custom Aliases for personalized and memorable short URLs
- 📈 Click Analytics with visitor tracking (IP, user agent, referrer)
- 🔐 JWT Authentication for secure access and management
- 📘 Swagger API Docs for easy integration and testing
| Layer | Tool/Service |
|---|---|
| Backend | NestJS |
| ORM | Prisma + Accelerate |
| Database | SQLite (Development) |
| Auth | JWT (Bearer Tokens) |
| Docs | Swagger |
| DNS Resolver | Cloudflare DNS over HTTPS |
- Node.js
v14+ - npm or yarn
- Clone the repository
git clone https://github.com/YashPatrot/Url-Shortener.git
cd Url-Shortener- Install dependencies
npm install- Set up environment variables
Create a .env file in the root directory using the template below:
# Base URL for all short links
URL_PREFIX=http://localhost:3000/
# Cloudflare DNS API for IP resolution
CLOUDFLARE_URL=https://cloudflare-dns.com/dns-query
# Application port (optional, defaults to 3000)
PORT=3000- Initialize database
npx prisma migrate dev- Start the application
npm run start:devSwagger UI is available at:
👉 http://localhost:3000/api
| Method | Endpoint | Description |
|---|---|---|
| POST | /web-url |
Create a shortened URL |
| GET | /web-url |
List all URLs for the user |
| GET | /web-url/:id |
Get details of a specific URL |
| DELETE | /web-url/:id |
Delete a specific URL |
| GET | /:url |
Public redirect to the original URL |
- Users submit a long URL and optionally a custom alias.
- The backend:
- Saves the original URL.
- Generates a random 10-character slug if no alias is provided.
- Resolves IP address via Cloudflare DNS over HTTPS.
- Logs metadata on each redirect.
- Shortened URLs redirect via a public endpoint:
/:slug.
# Unit tests
npm run test
# End-to-end tests
npm run test:e2eWe welcome contributions! Follow these steps:
1. Fork the repo
2. Create your feature branch: git checkout -b feature/amazing-feature
3. Commit your changes: git commit -m "Add amazing feature"
4. Push to the branch: git push origin feature/amazing-feature
5. Open a pull requestThis project is licensed under the MIT License. See the LICENSE file for details.
Built with ❤️ by YashPatrot