A lightweight, efficient URL shortening service built with Java and Spring Boot. Transform long URLs into short, manageable links with comprehensive analytics and management features.
- URL Shortening: Convert long URLs into short, memorable links
- Custom Aliases: Create personalized short URLs with custom keywords
- Analytics Dashboard: Track clicks, referrers, and usage statistics
- API Access: RESTful API for programmatic URL shortening
- Bulk Operations: Shorten multiple URLs simultaneously
- Expiration Control: Set expiration dates for temporary links
- QR Code Generation: Automatic QR code creation for each shortened URL
- Backend: Java 17, Spring Boot 3.x
- Database: H2 (development), PostgreSQL (production)
- Caching: Redis for high-performance link resolution
- Frontend: Thymeleaf templates with Bootstrap
- Build Tool: Maven
- Testing: JUnit 5, Mockito
- Java 17 or higher
- Maven 3.6+
- Redis server (optional, for caching)
- PostgreSQL (for production deployment)
- Clone the repository:
git clone https://github.com/voloshynm/UrlShortener.git
cd UrlShortener
- Configure application properties:
# Edit src/main/resources/application.properties
server.port=8080
spring.datasource.url=jdbc:h2:mem:testdb
app.base-url=http://localhost:8080
- Build and run:
mvn clean install
mvn spring-boot:run
- Access the application:
- Web Interface:
http://localhost:8080 - API Documentation:
http://localhost:8080/swagger-ui.html
- Web Interface:
POST /api/shorten
Content-Type: application/json
{
"originalUrl": "https://example.com/very/long/url",
"customAlias": "mylink",
"expirationDate": "2025-12-31T23:59:59"
}
GET /{shortCode}
# Redirects to original URL
GET /api/stats/{shortCode}
# Returns click count, creation date, etc.
UrlShortener/
├── src/main/java/
│ ├── controller/ # REST controllers
│ ├── service/ # Business logic
│ ├── repository/ # Data access layer
│ ├── model/ # Entity classes
│ └── config/ # Configuration classes
├── src/main/resources/
│ ├── templates/ # Thymeleaf templates
│ ├── static/ # CSS, JS, images
│ └── application.properties
└── src/test/ # Unit and integration tests
# H2 (Development)
spring.datasource.url=jdbc:h2:mem:testdb
spring.h2.console.enabled=true
# PostgreSQL (Production)
spring.datasource.url=jdbc:postgresql://localhost:5432/urlshortener
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.password=your_redis_password
Run the test suite:
mvn test
Run integration tests:
mvn verify
| Feature | Description | Status |
|---|---|---|
| URL Shortening | Basic URL shortening functionality | ✅ |
| Custom Aliases | User-defined short codes | ✅ |
| Click Analytics | Track and display usage statistics | ✅ |
| QR Codes | Generate QR codes for URLs | ✅ |
| Bulk Operations | Process multiple URLs at once | ✅ |
| API Access | RESTful API endpoints | ✅ |
| Link Expiration | Time-based URL expiration | ✅ |
| Admin Dashboard | Management interface | 🚧 |
# Build Docker image
docker build -t urlshortener .
# Run container
docker run -p 8080:8080 urlshortener
- Configure production database
- Set environment variables
- Build production JAR:
mvn clean package -Pprod - Deploy to your preferred platform
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Maksym Voloshyn
- GitHub: @voloshynm
- LinkedIn: Maksym Voloshyn
- Spring Boot team for the excellent framework
- Bootstrap for responsive UI components
- H2 Database for easy development setup
Built with ❤️ for efficient link management
Keywords: java spring-boot url-shortener rest-api maven h2-database redis analytics