A robust and scalable URL shortening service built with Spring Boot, featuring secure authentication and comprehensive URL management capabilities.
-
URL Management
- Create short URLs for long URLs
- Automatic URL expiration
- URL statistics tracking
- URL enable/disable functionality
- Bulk URL management
-
Security
- JWT-based authentication
- User registration and management
- CORS protection
- XSS protection
- Content Security Policy
- Rate limiting support
- Password encryption using BCrypt
-
API & Documentation
- RESTful API endpoints
- Swagger/OpenAPI documentation
- Comprehensive API versioning
- Detailed error handling
-
Monitoring & Maintenance
- Health monitoring
- Performance metrics
- Detailed logging
- Database statistics
-
Backend
- Java 17
- Spring Boot 3.x
- Spring Security
- Spring Data JPA
- PostgreSQL
- Maven
-
Tools & Libraries
- Swagger/OpenAPI 3.0
- JWT Authentication
- Lombok
- Spring Actuator
- Spring Cache
- Java 17 or higher
- Maven 3.8 or higher
- PostgreSQL 12 or higher
- Git
- Clone the repository:
git clone https://github.com/yourusername/margdarshak.git
cd margdarshak-
Configure the database:
- Create a PostgreSQL database named
margdarshak - Update the database credentials in
application.properties:spring.datasource.url=jdbc:postgresql://localhost:5432/margdarshak spring.datasource.username=your_username spring.datasource.password=your_password
- Create a PostgreSQL database named
-
Build the project:
mvn clean install- Run the application:
mvn spring-boot:runThe application will be available at http://localhost:8080
Swagger UI is available at http://localhost:8080/swagger-ui.html
- POST
/api/v1/auth/register - Request body:
{
"name": "John Doe",
"email": "[email protected]",
"password": "securepassword",
"profilePic": "https://example.com/profile.jpg"
}- POST
/api/v1/auth/login - Request body:
{
"email": "[email protected]",
"password": "securepassword"
}- POST
/api/v1/url - Headers:
Authorization: Bearer <jwt_token> - Request body:
{
"url": "https://example.com",
"expirationDays": 30
}- GET
/api/v1/url - Headers:
Authorization: Bearer <jwt_token>
- GET
/api/v1/url/detail/{code} - Headers:
Authorization: Bearer <jwt_token>
- PUT
/api/v1/url/update/{code} - Headers:
Authorization: Bearer <jwt_token> - Request body:
{
"url": "https://updated-example.com",
"expirationDays": 14
}- GET
/{code} - No authentication required
- Returns 302 redirect to original URL
- JWT-based token authentication
- Token expiration and refresh mechanism
- Secure password storage with BCrypt
- Role-based access control
- CORS configuration for specific origins
- XSS protection headers
- Content Security Policy
- Input validation and sanitization
- Rate limiting support
- Secure session management
The application includes Actuator endpoints for monitoring:
- Health:
/actuator/health - Info:
/actuator/info - Metrics:
/actuator/metrics - Environment:
/actuator/env - Mappings:
/actuator/mappings
com.ajkumarray.margdarshak.controller: REST API endpointscom.ajkumarray.margdarshak.service: Business logiccom.ajkumarray.margdarshak.repository: Data access layercom.ajkumarray.margdarshak.entity: Database entitiescom.ajkumarray.margdarshak.models.request: Request DTOscom.ajkumarray.margdarshak.models.response: Response DTOscom.ajkumarray.margdarshak.exception: Custom exceptionscom.ajkumarray.margdarshak.validator: Input validationcom.ajkumarray.margdarshak.config: Configuration classescom.ajkumarray.margdarshak.constants: Application constantscom.ajkumarray.margdarshak.util: Utility classescom.ajkumarray.margdarshak.enums: Enumeration classescom.ajkumarray.margdarshak.security: Security configuration and JWT handling
Run tests with:
mvn testBuild and run using Docker:
# Build the image
docker build -t margdarshak .
# Run the container
docker run -p 8080:8080 \
-e SPRING_DATASOURCE_URL=jdbc:postgresql://host.docker.internal:5432/margdarshak \
-e SPRING_DATASOURCE_USERNAME=your_username \
-e SPRING_DATASOURCE_PASSWORD=your_password \
margdarshak- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some 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.
For support, please open an issue in the GitHub repository or contact the maintainers.