A modern, scalable URL shortener application built with:
- Frontend app: Next.js + TailwindCSS + Playwright
- Backend management: Express.js + Prisma(Postgres)
- Backend redirector: Fastify.js + MikroORM
Normally you will not need to have 2 different techstacks for the backend services. I did this because I want to explore different tech stack.
All services are built with Typescript. This project implements a microservices architecture with separate services for URL management, redirection, and frontend.
This is a POC for implementing URL shortener application that is designed to provide a robust and scalable solution for shortening URLs with features like password protection, custom aliases(urls), and little analytics capability. For detailed information about the project's architecture, design decisions, and technical specifications, please refer to PROJECT.md.
- 🔗 URL shortening with custom aliases
- 🔒 Password protection for URLs
- 📊 URL analytics and statistics
- 🚀 High-performance redirection with Redis caching
- 🧪 Comprehensive test coverage
- 🐳 Docker support
- 🔄 URL expiration management
The management service handles URL creation and management. It provides RESTful APIs for:
- Creating shortened URLs
View backend-management README
The redirection service handles the actual URL redirection with Redis caching for high performance. It provides:
- Fast URL redirection
- Password verification
- Redis caching
- Analytics tracking
View backend-redirector README
A modern Next.js application that provides the user interface for the URL shortener. Features include:
- Modern UI with Tailwind CSS, shadcn/ui, Lucide Icons
- Responsive design
- Password protection UI
- Playwright test framework
-
Create PostgreSQL database for backend services:
CREATE DATABASE url_shortener;
-
Create
.env
file inbackend-management
:# backend-management/.env DATABASE_URL="postgresql://user:password@localhost:5432/url_shortener
-
Run migrations:
Note: for ease of maitenance, only do migration in backend-management with Prisma. Do not run migrations with MikroORM in backend-redirector
# In backend-management directory npm run migrate:dev
-
Create a
.docker.env
file in the each project root:cp sample.env .docker.env
-
Start all services:
docker-compose up -d
-
Access the services:
- Frontend: http://localhost:3000
- Management API: http://localhost:3001
- Redirector API: http://localhost:3002
-
Stop all services:
docker-compose down
- Node.js 20.x or later
- PostgreSQL
- Redis
- Docker and Docker Compose
- npm
-
Clone the repository:
git clone https://github.com/yourusername/url-shortener.git cd url-shortener
-
Set up environment variables in
frontend
,backend-management
andbackend-redirector
:cp sample.env .env
-
Install dependencies:
# Install dependencies for all services npm install cd frontend && npm install cd ../backend-management && npm install cd ../backend-redirector && npm install
-
Start the development servers:
# Start frontend cd frontend && npm run dev # Start management service cd backend-management && npm run dev # Start redirector service cd backend-redirector && npm run dev
- setup observability stack
- setup everything in kubernetes
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.