31075947f9
added gitignore for testng generated test-output folder |
||
---|---|---|
.github/workflows | ||
.mvn/wrapper | ||
installers | ||
META-INF | ||
src | ||
test-output | ||
.gitignore | ||
create.sql | ||
docker-compose.yml | ||
Dockerfile | ||
image.png | ||
LICENSE | ||
mvnw | ||
mvnw.cmd | ||
pom.xml | ||
README.md | ||
server.xml | ||
shortener-deployment.yaml | ||
shortener-service.yaml | ||
testng.xml |
TUSC - The URL Shortener Company
An enterprise-grade, powerful and scalable URL shortener with integrated bio pages built using Spring Boot.
Maven Package | Github Packages - com.bitmutex.shortener |
Docker Image | DockerHub - nmpl/shortener:latest |
Table of Contents
Overview
This project is an enterprise-grade URL shortener and bio page application developed with Spring Boot. It provides a robust solution for shortening URLs and creating bio pages for users. The application is designed for scalability and includes features such as analytics, user management, and subscription plans.
Features
- Shorten URLs and create custom short URLs.
- Integrated bio pages for users.
- Analytics tracking for each shortened URL.
- User management with registration, login, and profile updates.
- Subscription plans for premium features.
- Rate limiting to prevent abuse.
- Forgot password and username recovery functionality.
- OPEN API 3.0 Complaint REST API set, with extensive docs.
Tech Stack:
- Java (JDK 21): The core programming language for the application.
- Maven 3: A build automation and project management tool. Used for managing dependencies and building the application.
- MySQL/Mariadb: Relational database management system used for data storage.
- Spring Boot: A framework that simplifies the development of Java applications, providing convention over configuration and a variety of built-in features.
- Logger (Logback): Logback is a logging framework for Java applications. It's the default logging framework in Spring Boot.
- Templating Engine (Thymeleaf): Thymeleaf is a modern server-side Java template engine for web and standalone environments. It is a well-integrated part of the Spring ecosystem.
- AJAX (Asynchronous JavaScript and XML): A technique for creating dynamic and interactive user interfaces. It allows updating parts of a web page without reloading the entire page.
- RESTful API: A standard architectural style for building web services. The application provides RESTful APIs for various functionalities.
- OpenAPI 3.0: A specification for building APIs that allows for describing, producing, consuming, and visualizing RESTful web services.
- Docker: A platform for developing, shipping, and running applications in containers. Used for containerizing the application.
- Git: A distributed version control system used for tracking changes in the source code.
- Kubernetes: A container orchestration platform used for automating the deployment, scaling, and management of containerized applications.
- Swagger UI: A tool that helps design, build, document, and consume RESTful APIs. It's often used with OpenAPI specifications.
- Tailwind CSS: A utility-first CSS framework that makes it easy to design and build modern, responsive user interfaces.
- Flowbite: A design system and UI toolkit for building responsive web applications.
Getting Started
Prerequisites
Before you begin, ensure you have the following installed:
- Java (JDK 11 or later)
- Maven
- MySQL
- Your favorite IDE (IntelliJ, Eclipse, etc.)
1-Click Local Installation Windows | Linux
Windows
- Open a Command Prompt with administrator privileges.
- Navigate to the project's
installers
folder. - Run the
install.bat
file by double-clicking on it or using the following command:install.bat
Linux
- Navigate to the project's installers folder.
- Run the
install.sh
using the following command:chmod +x install.sh ./install.sh
- Follow the on-screen instructions.
Finally, Select Application Server : Tomcat/Wildfly
Local Setup
-
Clone the repository:
git clone https://github.com/aamitn/URLShortener.git cd URLShortener
-
Apply the Database Schema:
Execute the provided db_schema.sql file to set up the necessary tables and schema for the application. This script will also create the required database.
mysql -u your_username -p{your_password} < create.sql
-
Update the application.properties file:
- Update the application.properties file in the src/main/resources directory with your application configuration.
-
Build and run the application:
mvn spring-boot:run
-
Access the application at http://localhost:8080
Deployment
-
Build a deployable WAR:
mvn clean install
-
Deploy the WAR:
-
Option 1: Manual Deployment
Deploy the generated WAR file to your Tomcat server. Copy the WAR file to the
webapps
directory of your Tomcat installation.cp target/shorten.war /path/to/tomcat/webapps/
-
Option 2: Web Interface Upload
Alternatively, if your Tomcat server provides a web interface for WAR file deployment, follow these steps:
- Access the Tomcat Manager web interface at
http://localhost:8080/manager/html
(replace with your Tomcat server address). - Log in with your Tomcat manager credentials.
- Navigate to the "WAR file to deploy" section.
- Choose the
shortener.war
file using the file upload button. - Click the "Deploy" button.
- Access the Tomcat Manager web interface at
-
-
Configure Variables on deployed war:
Set environment variables for cloud-specific settings.
-
Adjust Tomcat Configuration (Important):
To ensure proper functionality, it's important to run the application on the root of the servlet container. If you're using Tomcat, add the following line to your
server.xml
configuration file within the<Host>
section:<Context path="" docBase="shorten" reloadable="true"></Context>
This ensures that the application runs on the root context path. Adjust the
docBase
attribute according to your deployment directory. -
Start Tomcat:
Start your Tomcat server.
/path/to/tomcat/bin/startup.sh # for Linux /path/to/tomcat/bin/startup.bat # for Windows
Access the application at
http://localhost:8080/
. -
Adjust Configuration (Optional): If you need to customize the application configuration after deployment, you can find the application.properties file within the deployed WAR file. THe file can be accesses as :
vi /path/to/tomcat/webapps/shortener/WEB-INF/classes/application.properties
Cloud Native Deployment
To deploy the URL Shortener application on your cloud environment, follow the steps below:
Prerequisites
-
Clone the Repository:
git clone https://github.com/your-username/URLShortener.git cd URLShortener
-
Build and Run Your Own Image:
docker build -t shortener:latest . docker run -p 8080:8080 -p 3306:3306 shortener:latest
OR
-
Use Our Pre-built Image with Docker Compose:
docker compose build docker compose up
-
Customizing Docker Compose Configuration:
In the docker-compose.yml file, you can customize the build source for the Shortener service:
#Build from docker hub image .Comment/Uncomment Below image: nmpl/shortener:latest #Build from local Dockerfile.Comment/Uncomment Below # build: # context: . # dockerfile: Dockerfilekerfile
Comment or uncomment the relevant lines based on whether you want to use the pre-built image from Docker Hub or build from the local Dockerfile.
-
Deploy Using K8s
-
Setup Kubernetes Deployment and Service:
kubectl apply -f shortener-deployment.yaml kubectl apply -f shortener-service.yaml
-
Use the following command to monitor the deployment:
```plaintext
kubectl get pods
```
Wait until the pod is in the "Running" state.
-
Access the Application
Depending on your Kubernetes setup, you might need to get the external IP of the service:
kubectl get service shortener-service
Access your application using the provided external IP.
SMS Service Configuration
To configure the SMS service, you need to specify parameters related to the SMS provider in the application.properties
file.
-
Managed SMS Provider (Uses HttpSms API from https://httpsms.com/)
- Generate API Key : https://httpsms.com/settings/
- HttpSms API Docs : https://api.httpsms.com/
sms.provider=managed managed.sms.api.key=your_managed_sms_api_key managed.sms.phone-number=123456789
-
Self-hosted SMS Provider (Host our open source android-based SMS web gateway : https://api.httpsms.com/)
sms.provider=selfhosted selfhosted.gateway.url=https://your-smsgateway-url/index.php selfhosted.device.id=your_device_id selfhosted.hash=your_device_hash
App Health
- Check application status from the /monitoring page example http://localhost:8080/monitoring
Use Cases
- Shorten URLs by visiting the URL Shortener page.
- Access analytics for each shortened URL.
- Create and manage bio pages in the Bio section.
Contributing
Contributions are welcome! Please follow the contribution guidelines.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.