Short.ly is a powerful and user-friendly URL shortening service designed for individuals and businesses. It transforms lengthy URLs into concise, shareable links, offering robust features like custom aliases, detailed analytics, and secure user authentication with subscription plans.
This project is built using Spring Boot for the backend and a modern HTML, CSS, and JavaScript frontend, ensuring a seamless and responsive user experience.
- URL Shortening: Convert long, unwieldy URLs into compact, easy-to-share short links.
- Custom Aliases: Create personalized and memorable short URLs (e.g., short.ly/MyProject).
- User Authentication: Secure user registration and login system to manage personal links.
- Subscription Plans:
- Free: Basic link shortening with limited features.
- Pro: Advanced features like increased link limits, custom domains, API access, and priority support.
- Business: High-volume link management, multiple custom domains, premium analytics, and 24/7 support.
- Real-time History: View a list of your recently shortened URLs directly on the dashboard.
- Theming: Toggle between light and dark modes for a personalized browsing experience.
- Responsive Design: Optimized for seamless usage across all devices (desktop, tablet, mobile).
- Stripe Integration: Secure payment processing for subscription plans via Stripe Checkout.
- Backend Webhooks: Handles Stripe webhook events for automated subscription and payment management.
- Database Persistence: Stores all URL mappings, user data, subscriptions, and payments in a MySQL database.
- Java 17+
- Spring Boot 3.x: Application framework.
- Spring Data JPA: For robust database interaction and ORM.
- MySQL: Relational database for data storage.
- Stripe Java SDK: For payment processing and webhook handling.
- HikariCP: High-performance JDBC connection pool.
- Apache Commons Lang: Utility functions for string manipulation.
- Maven: Build automation and dependency management.
- Lombok: Reduces boilerplate code.
- Flyway: Database migration tool for schema version control.
- HTML5: Semantic structure for all web pages.
- CSS3: Modern styling with custom properties (CSS variables) for easy theming (Light/Dark Mode).
- JavaScript (Vanilla JS): Interactive elements, API calls, and client-side logic.
- Font Awesome: For scalable vector icons.
- Google Fonts (Inter, Merriweather): Typography for a clean and professional look
.
βββ src/
β βββ main/
β β βββ java/com/example/url_shortener/
β β β βββ config/ # Spring configurations (e.g., PricingPlanConfig)
β β β βββ controller/ # REST API endpoints (Payment, Pricing, URL, Auth)
β β β βββ dto/ # Data Transfer Objects (e.g., UrlDto)
β β β βββ model/ # JPA Entities (User, Subscription, Payment, PricingPlan, Url)
β β β β βββ enums/ # Enums for statuses (PaymentStatus, SubscriptionStatus)
β β β βββ repository/ # Spring Data JPA repositories and PasswordEncoder
β β β βββ service/ # Business logic (Payment, Pricing, URL, User, Auth)
β β β βββ UrlShortenerApplication.java # Main Spring Boot application
β β βββ resources/
β β βββ resources/db/migration/ # Flyway SQL migration scripts
β β βββ static/ # Frontend static assets
β β β βββ css/
β β β β βββ style.css # Unified global styles
β β β βββ js/
β β β β βββ main.js # Consolidated JavaScript logic for all pages
β β β βββ about.html # About page
β β β βββ index.html # Main URL shortening page
β β β βββ login.html # User login page
β β β βββ price.html # Pricing plans page
β β β βββ signup.html # User registration page
β β βββ application.properties # Spring Boot configuration (database, Stripe keys)
βββ .gitignore # Specifies intentionally untracked files to ignore
βββ pom.xml # Maven project object model
βββ README.md # Project README file
- Java Development Kit (JDK) 17 or later
- Apache Maven
- MySQL Server (running locally or via Docker)
- Git
- An IDE (e.g., IntelliJ IDEA, VS Code) is recommended.
git clone https://github.com/AzharuddinMalik/URLShort.git
cd URLShort
- Ensure your MySQL server is running.
- Update src/main/resources/application.properties with your MySQL database credentials.
spring.datasource.url=jdbc:mysql://localhost:3306/url_shortener_db?createDatabaseIfNotExist=true&useSSL=false&serverTimezone=UTC
spring.datasource.username=your_mysql_username
spring.datasource.password=your_mysql_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Hibernate Configuration
spring.jpa.hibernate.ddl-auto=update # Use 'update' for development, 'validate' or 'none' for production
spring.jpa.show-sql=true
spring.jpa.open-in-view=false
- Flyway will automatically run the migration script V1__Create_pricing_plan_table.sql to create necessary tables.
-
Obtain your Stripe Secret Key (sk_test_...) and Webhook Secret (whsec_...) from your Stripe Dashboard (Developers -> API keys and Webhooks).
-
IMPORTANT: DO NOT commit your actual keys to GitHub. For local development, you can add them to application.properties. For production, use environment variables.
-
In src/main/resources/application.properties:
stripe.api.key=sk_test_YOUR_ACTUAL_STRIPE_SECRET_KEY
stripe.webhook.secret=whsec_YOUR_ACTUAL_STRIPE_WEBHOOK_SECRET
mvn clean install
The frontend files are located in src/main/resources/static/. They are served directly by the Spring Boot application. No separate build step is required for the frontend.
mvn spring-boot:run
The application will start on http://localhost:8080/.
Open your web browser and navigate to:
http://localhost:8080/
- Navigate to /signup.html to create a new user account.
- Navigate to /login.html to log in with your credentials.
- On the homepage (index.html), enter a long URL and optionally a custom alias.
- Click "Shorten URL" to generate your short link.
- Visit /price.html to view different subscription plans.
- Enter your email and click "Get Started" or "Start Free Trial" to be redirected to Stripe Checkout for secure payment.
- For local development, use a tool like ngrok to expose your local webhook endpoint to the internet.
ngrok http 8080
- Copy the https forwarding URL provided by ngrok.
- Go to your Stripe Dashboard -> Developers -> Webhooks.
- Add a new endpoint: Paste your ngrok URL followed by
/api/payment/webhook(e.g.,https://your-ngrok-url.ngrok-free.app/api/payment/webhook). - Select the events you want to listen to:
checkout.session.completed,invoice.paid,customer.subscription.deleted. - Save the endpoint. This allows Stripe to notify your application of payment and subscription events.
Contributions are welcome! If you'd like to contribute, please follow these steps:
-
Fork the repository.
-
Create a new branch (
git checkout -b feature/your-feature-name). -
Make your changes.
-
Commit your changes (
git commit -m 'feat: Add new feature'). -
Push to the branch (
git push origin feature/your-feature-name). -
Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.

