URLShortener/README.md

355 lines
13 KiB
Markdown
Raw Permalink Normal View History

2024-02-15 17:05:28 +05:30
## <img src="https://i.ibb.co/4MFScFw/tusc-logo.png" width="20%" alt=""> **TUSC - The URL Shortener Company**
2024-02-15 20:19:55 +05:30
[![buddy pipeline](https://app.buddy.works/amitnandileo-2/urlshortener/pipelines/pipeline/483649/badge.svg?token=fb16d4ceb25aaee899aeebeb8f9d57239dd800defc2afb65a0176c36d32bd464)](https://app.buddy.works/amitnandileo-2/urlshortener/pipelines/pipeline/483649)
2024-02-15 18:54:21 +05:30
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)[![GitHub last commit](https://img.shields.io/github/last-commit/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/commits/main)[![GitHub issues](https://img.shields.io/github/issues/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/issues)[![GitHub pull requests](https://img.shields.io/github/issues-pr/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/pulls)[![GitHub contributors](https://img.shields.io/github/contributors/aamitn/URLShortener.svg)](https://github.com/aamitn/URLShortener/graphs/contributors)
2024-02-15 03:22:06 +05:30
[![Twitter](https://img.shields.io/twitter/url/https/github.com/yourusername/your-repo.svg?style=social)](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Faamitn%2FURLShortener&text=Check%20out%20this%20awesome%20URL%20Shortener%20and%20Bio%20Page%20Application&via=yourtwitterhandle)
2024-02-15 23:09:37 +05:30
[![Docker Image Size](https://badgen.net/docker/size/trueosiris/godaddypy?icon=docker&label=image%20size)](https://hub.docker.com/r/nmpl/shortener)
2024-02-01 23:50:52 +05:30
2024-02-15 16:50:39 +05:30
An enterprise-grade, powerful and scalable URL shortener with integrated bio pages built using Spring Boot.
2024-02-15 23:09:37 +05:30
<table><tbody><tr><td>Maven Package</td><td><a href="https://github.com/aamitn/URLShortener/packages/2069528">Github Packages - com.bitmutex.shortener</a></td></tr><tr><td>Docker Image</td><td><a href="https://hub.docker.com/r/nmpl/shortener">DockerHub - nmpl/shortener:latest</a></td></tr></tbody></table>
2024-02-01 23:50:52 +05:30
## Table of Contents
2024-02-14 17:40:09 +05:30
* [Overview](#overview)
* [Features](#features)
* [Getting Started](#getting-started)
* [Prerequisites](#prerequisites)
* [Local Setup](#local-setup)
* [Deployment](#deployment)
2024-02-20 17:23:30 +05:30
* [Cloud Native Deployment](#cloud-native-deployment)
* [SMS Configuration](#sms-service-configuration)
* [Use Cases](#use-cases)
2024-02-14 17:40:09 +05:30
* [Contributing](#contributing)
* [License](#license)
2024-02-22 22:40:15 +05:30
***
2024-02-01 23:50:52 +05:30
## 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
2024-02-15 16:50:39 +05:30
* 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.
2024-02-01 23:50:52 +05:30
2024-02-15 23:19:44 +05:30
## 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.
2024-02-22 22:40:15 +05:30
***
2024-02-01 23:50:52 +05:30
## Getting Started
### Prerequisites
Before you begin, ensure you have the following installed:
2024-02-14 17:40:09 +05:30
* Java (JDK 11 or later)
* Maven
* MySQL
* Your favorite IDE (IntelliJ, Eclipse, etc.)
2024-02-01 23:50:52 +05:30
2024-02-15 23:19:44 +05:30
2024-02-17 21:18:26 +05:30
### 1-Click Local Installation <a href="https://github.com/aamitn/URLShortener/releases/download/final/install.cmd">Windows</a> | <a href="https://github.com/aamitn/URLShortener/releases/download/final/install.sh">Linux</a>
2024-02-16 16:56:10 +05:30
### Windows
1. Open a Command Prompt with administrator privileges.
2. Navigate to the project's `installers` folder.
3. Run the `install.bat` file by double-clicking on it or using the following command:
```batch
install.bat
### Linux
1. Navigate to the project's installers folder.
2. Run the `install.sh` using the following command:
```bash
chmod +x install.sh
./install.sh
3. Follow the on-screen instructions.
2024-02-20 17:23:30 +05:30
##### Finally, Select Application Server : Tomcat/Wildfly
2024-02-22 22:40:15 +05:30
***
2024-02-16 16:56:10 +05:30
2024-02-01 23:50:52 +05:30
### Local Setup
2024-02-14 17:40:09 +05:30
1. Clone the repository:
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
```plaintext
2024-02-14 21:54:30 +05:30
git clone https://github.com/aamitn/URLShortener.git
2024-02-20 17:23:30 +05:30
cd URLShortener
2024-02-14 17:40:09 +05:30
```
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
2. **Apply the Database Schema:**
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
Execute the provided `create.sql` file to set up the necessary tables and schema for the application. This script will also create the required database.
2024-02-15 16:50:39 +05:30
2024-02-14 21:54:30 +05:30
```plaintext
2024-02-20 17:23:30 +05:30
mysql -u your_username -p{your_password} < create.sql
2024-02-14 17:40:09 +05:30
```
2024-02-20 17:23:30 +05:30
2024-02-14 21:54:30 +05:30
3. Update the application.properties file:
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
* Update the `application.properties` file in the src/main/resources directory with your application configuration.
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
4. Build and run the application:
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
```plaintext
2024-02-20 17:23:30 +05:30
mvn spring-boot:run
2024-02-14 17:40:09 +05:30
```
2024-02-15 16:50:39 +05:30
2024-02-14 21:54:30 +05:30
5. Access the application at http://localhost:8080
2024-02-02 00:13:15 +05:30
2024-02-22 22:40:15 +05:30
***
### Deployment Setup
2024-02-02 00:13:15 +05:30
2024-02-14 17:40:09 +05:30
1. **Build a deployable WAR:**
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
```plaintext
mvn clean install
```
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
2. **Deploy the WAR:**
* **Option 1: Manual Deployment**
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
Deploy the generated WAR file to your Tomcat server. Copy the WAR file to the `webapps` directory of your Tomcat installation.
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
```plaintext
cp target/shorten.war /path/to/tomcat/webapps/
```
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
* **Option 2: Web Interface Upload**
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
Alternatively, if your Tomcat server provides a web interface for WAR file deployment, follow these steps:
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
* 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.
2024-02-20 17:23:30 +05:30
* Choose the `shortener.war` file using the file upload button.
2024-02-14 17:40:09 +05:30
* Click the "Deploy" button.
2024-02-20 02:06:39 +05:30
3. **Configure Variables on deployed war:**
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
Set environment variables for cloud-specific settings.
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
4. **Adjust Tomcat Configuration (Important):**
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
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:
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
```xml
<Context path="" docBase="shorten" reloadable="true"></Context>
```
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
This ensures that the application runs on the root context path. Adjust the `docBase` attribute according to your deployment directory.
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
5. **Start Tomcat:**
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
Start your Tomcat server.
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
```plaintext
/path/to/tomcat/bin/startup.sh # for Linux
/path/to/tomcat/bin/startup.bat # for Windows
```
2024-02-15 16:50:39 +05:30
2024-02-14 17:40:09 +05:30
Access the application at `http://localhost:8080/`.
2024-02-15 16:50:39 +05:30
2024-02-14 21:50:00 +05:30
6. **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 :
2024-02-15 16:50:39 +05:30
2024-02-14 21:50:00 +05:30
```plaintext
2024-02-20 17:23:30 +05:30
vi /path/to/tomcat/webapps/shortener/WEB-INF/classes/application.properties
2024-02-14 21:50:00 +05:30
```
2024-02-22 22:40:15 +05:30
***
2024-02-15 16:50:39 +05:30
### Cloud Native Deployment
To deploy the URL Shortener application on your cloud environment, follow the steps below:
**Prerequisites**
* [Docker](https://www.docker.com/get-started)
* [Docker Compose](https://docs.docker.com/compose/install/)
2024-02-22 22:40:15 +05:30
* [Kubernetes/K8s](https://kubernetes.io/docs/setup/)
* [Minikube](https://minikube.sigs.k8s.io/docs/start/)
* [Helm](https://helm.sh/docs/intro/install/)
2024-02-15 16:50:39 +05:30
1. **Clone the Repository:**
```plaintext
git clone https://github.com/your-username/URLShortener.git
cd URLShortener
```
2024-02-22 22:40:15 +05:30
2. ***Deploy Using Docker***
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
* Build and Run Your Own Image:
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
```plaintext
docker build -t shortener:latest .
docker run -p 8080:8080 -p 3306:3306 shortener:latest
```
2024-02-20 17:23:30 +05:30
<p style="text-align: center;"> OR </p>
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
* Use Our Pre-built Image with Docker Compose:
2024-02-15 16:50:39 +05:30
```plaintext
docker compose build
docker compose up
```
2024-02-22 22:40:15 +05:30
* Customizing Docker Compose Configuration:
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
In the `docker-compose.yml` file, you can customize the build source for the Shortener service:
2024-02-15 20:19:55 +05:30
```plaintext
2024-02-22 22:40:15 +05:30
# Build from docker hub image .Comment/Uncomment Below
image: nmpl/shortener:latest
2024-02-15 20:19:55 +05:30
2024-02-22 22:40:15 +05:30
# Build from local Dockerfile.Comment/Uncomment Below
2024-02-15 20:19:55 +05:30
# build:
# context: .
# dockerfile: Dockerfilekerfile
```
2024-02-15 16:50:39 +05:30
2024-02-15 20:19:55 +05:30
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.
2024-02-22 22:40:15 +05:30
3. ***Deploy Using K8s***
* Setup Kubernetes Deployment and Service:
```plaintext
cd k8s
kubectl apply -f deploy.yaml,service.yaml,data.yaml
```
* Expose the K8s service:
```plaintext
kubectl port-forward service/shortener-app 8080:8080
```
Access Application at http://localhost:8080
<center>OR</center>
If you're using minikube, run the below command to run the app:
```plaintext
minikube service shortener-app
```
* Use the following command to monitor the deployment:
```plaintext
kubectl get pods
```
4. ***Deploy Using Helm Chart***
* Create Deployment from helm chart named "instance" , with a service named "instance-shortener-chart" :
```plaintext
cd k8s
helm install instance shortener-chart/ --values shortener-chart/values.yaml
```
2024-02-15 20:19:55 +05:30
2024-02-22 22:40:15 +05:30
* Expose the K8s service:
2024-02-15 20:19:55 +05:30
```plaintext
2024-02-22 22:40:15 +05:30
kubectl port-forward service/instance-shortener-chart 8080:8080
2024-02-15 20:19:55 +05:30
```
2024-02-22 22:40:15 +05:30
<center>OR</center>
If you're using minikube, run the below command to run the app:**
```plaintext
minikube service shortener-app
```
* Use the following command to monitor the deployment:
2024-02-15 20:19:55 +05:30
```plaintext
kubectl get pods
```
2024-02-22 22:40:15 +05:30
Wait until the pod is in the "Running" state.
2024-02-15 20:19:55 +05:30
2024-02-22 22:40:15 +05:30
* Access the Application
2024-02-15 20:19:55 +05:30
Depending on your Kubernetes setup, you might need to get the external IP of the service:
```plaintext
2024-02-22 22:40:15 +05:30
kubectl get service instance-shortener-chart
2024-02-15 20:19:55 +05:30
```
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
Access your application using the provided external IP(from command output) or at : http://localhost:8080.
2024-02-15 16:50:39 +05:30
2024-02-22 22:40:15 +05:30
***
2024-02-15 16:50:39 +05:30
2024-02-20 02:06:39 +05:30
### SMS Service Configuration
2024-02-15 18:26:26 +05:30
2024-02-20 02:06:39 +05:30
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/
```properties
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/)
```properties
sms.provider=selfhosted
selfhosted.gateway.url=https://your-smsgateway-url/index.php
selfhosted.device.id=your_device_id
selfhosted.hash=your_device_hash
2024-02-22 22:40:15 +05:30
***
2024-02-20 02:06:39 +05:30
2024-02-15 18:26:26 +05:30
### App Health
2024-02-22 22:40:15 +05:30
Check application status from the /monitoring page at : http://localhost:8080/monitoring
### Docs
Check application OpenAPI 3.0 compliant docs at: http://localhost:8080/docs-ui
2024-02-15 18:26:26 +05:30
2024-02-22 22:40:15 +05:30
***
2024-02-15 18:26:26 +05:30
2024-02-20 17:23:30 +05:30
### Use Cases
2024-02-14 17:40:09 +05:30
1. Shorten URLs by visiting the URL Shortener page.
2. Access analytics for each shortened URL.
3. Create and manage bio pages in the Bio section.
2024-02-02 00:13:15 +05:30
2024-02-22 22:40:15 +05:30
***
2024-02-02 00:13:15 +05:30
### Contributing
2024-02-14 17:40:09 +05:30
2024-02-02 00:13:15 +05:30
Contributions are welcome! Please follow the contribution guidelines.
### License
2024-02-14 17:40:09 +05:30
2024-02-16 16:56:10 +05:30
This project is licensed under the MIT License - see the LICENSE.md file for details.
2024-02-22 22:40:15 +05:30
***
<p style="text-align: center;">&copy; Bitmutex Technologies | 2024</p>