https://github.com/treeofmapple/url-shortener
Service built with Spring Boot that allows users to convert long URLs easy-to-share links.
https://github.com/treeofmapple/url-shortener
java jjwt jpa jwt-tokens mapstruct redirect-urls redis security spring-boot springboot swagger web
Last synced: 10 months ago
JSON representation
Service built with Spring Boot that allows users to convert long URLs easy-to-share links.
- Host: GitHub
- URL: https://github.com/treeofmapple/url-shortener
- Owner: treeofmapple
- License: bsd-2-clause
- Created: 2025-01-26T04:55:10.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-02-13T19:23:46.000Z (11 months ago)
- Last Synced: 2025-02-13T20:28:18.084Z (11 months ago)
- Topics: java, jjwt, jpa, jwt-tokens, mapstruct, redirect-urls, redis, security, spring-boot, springboot, swagger, web
- Language: Java
- Homepage:
- Size: 57.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README-EN.md
- License: LICENSE
Awesome Lists containing this project
README
ShortURL is an efficient and secure URL shortener built on Spring Boot that allows you to convert long links into short, easy-to-share URLs. The system supports JWT authentication, caching with Redis, persistence in PostgreSQL, and documentation via Swagger or Postman.
> **[Leia esta documentaรงรฃo em portuguรชs](README-PT.md)**
## ๐ **Index**
- [Overview](#-overview)
- [Prerequisites](#-prerequisites)
- [Technologies](#-technologies)
- [Swagger](#-swagger)
- [Postman](#-postman)
- [Environment Variables](#%EF%B8%8F-environment-variables)
- [Testing](#-testing)
- [License](#-license)
- [References](#references)
## ๐ญ **Overview**
ShortURL allows users to shorten URLs and track access statistics. With support for JWT authentication, Redis caching, and PostgreSQL as the database, it is scalable and secure. The system also includes **Swagger** for API exploration and **Flyway** for database migration control.
**Main Features:**
- URL shortening.
- Authentication and authorization of `/actuator` via JWT.
- Redis support for performance improvement.
- Integration with PostgreSQL for persistence.
- API documentation via **Swagger** or **Postman**.
- Flexible configurations via **environment variables**.
---
##
**Prerequisites**
- **JDK** (version **21** or later)
- **Maven** (version **3.8** or later)
- **Spring Boot** (version **3.4.2** or later)
- **PostgreSQL** (version **16** or later)
- **Redis** (Optional, for caching)
---
## ๐ป **Technologies**
- **Spring Boot** (Main framework)
- **Spring Security** (Authentication and authorization via JWT)
- **Spring Data JPA** (Relational database persistence)
- **Spring Data Redis** (Cache for URL shortening)
- **MapStruct** (DTO and entity conversion)
- **JWT (JJWT)** (Authentication and security)
- **Flyway** (Database migration)
- **Swagger (SpringDoc OpenAPI)** (API documentation)
- **PostgreSQL** (Primary database)
- **H2 Database** (In-memory database for testing)
- **Redis** (Optional, used for cache and performance)
- **Prometheus** (Optional used for monitoring)
---
## ๐**Swagger**
The project provides API documentation via Swagger. To access it, re-enable Swagger in `application.yml` and in `SecurityConfig`, then start the system and go to:
๐ **`http://localhost:8000/swagger-ui.html`**
---
## ๐**Postman**
Test collection for **Postman** available:
[Postman Collection](https://www.postman.com/sam-goldman11/programs-of-mapple/collection/r2yhoqi/url-shortener)
---
##
**Program Installation**
Configure the available files with environment variables detailed in `config.args` for deployment. If performing tests, use `testes.args` to set the appropriate parameters for a test environment or define attributes directly in the IDE with the latest version.
To start the program automatically with configured environment variables, use one of the available scripts:
- **`run.bat`** (For Windows)
- **`run.ps1`** (For Windows PowerShell)
These scripts ensure that all environment variables are correctly loaded before running the Java program.
---
##
**Eclipse IDE**
The project includes configuration files for **Eclipse IDE**, which can be imported directly into **Run Configuration**. This facilitates automatic loading of environment variables and switching between different implementation types, such as:
- **Development Environment**
- **Testing Environment**
- **Production Deployment**
---
## โ๏ธ **Environment Variables**
|**Description**|**Parameter**|**Default values**|
|---|---|---|
|`Server port`|`SERVER_PORT`|`8000`|
|`JWT Secret Key for /actuator authentication`|`SECRET-KEY`|`NONE`|
|`Password to access /actuator`|`SECURITY_PASSWORD`|`NONE`|
|`Database URL`|`DB_HOST`|`LOCALHOST`|
|`Database port`|`DB_PORT`|`5432`|
|`Database name`|`DB_DATABASE`|`example`|
|`Database user`|`DB_USER`|`NONE`|
|`Database password`|`DB_PASSWORD`|`NONE`|
|`Max connection lifetime`|`DB_MAXLIFETIME`|`300000`|
|`Idle timeout`|`DB_IDLE-TIMEOUT`|`180000`|
|`Clean expired URLs`|`EXPIRED_DATA`|`1200000`|
|`Redis user`|`REDIS_USERNAME`|`NONE`|
|`Redis host`|`REDIS_HOST`|`NONE`|
|`Redis password`|`REDIS_PASSWORD`|`NONE`|
|`Redis port`|`REDIS_PORT`|`NONE`|
|`Redis SSL`|`REDIS_SSL`|`NONE`|
|`Redis connection check interval`|`REDIS_CONNECTION`|`300000`|
|`Redis-to-Database sync interval`|`REDIS_SYNC`|`300000`|
|`Prometheus logging with Docker or AWS` (Experimental)|`PROMETHEUS_REGION`|`NONE`|
|`Prometheus remote write URL` (Experimental)|`REMOTE_WRITE_URL`|`NONE`|
|`Enable or disable Swagger`|`SWAGGER_ENABLE`|`false`|
|`Swagger URL`|`SWAGGER_URL`|`/docs`|
---
## **Testing**
To run tests, execute with specific parameters for the test environment using the following command:
> ๐จ Check the [prerequisites](#-prerequisites)
bash
CopyEdit
`mvn test`
---
## **Environment Variables for Testing**
|**Description**|**Parameter**|**Default values**|
|---|---|---|
|`Server port`|`SERVER_PORT`|`8000`|
|`JWT Secret Key for /actuator authentication`|`SECRET-KEY`|`NONE`|
|`Password to access /actuator`|`SECURITY_PASSWORD`|`NONE`|
|`Redis user`|`REDIS_USERNAME_TEST`|`NONE`|
|`Redis host`|`REDIS_HOST_TEST`|`NONE`|
|`Redis password`|`REDIS_PASSWORD_TEST`|`NONE`|
|`Redis port`|`REDIS_PORT_TEST`|`NONE`|
|`Redis SSL`|`REDIS_SSL_TEST`|`NONE`|
---
## ๐ **License**
This project is licensed under the **BSD 2-Clause License**. For more details, see the [LICENSE](LICENSE) file.
> ๐ **[BSD 2-Clause License](https://opensource.org/license/bsd-2-clause)**
---
## ๐**References**
> Based on the original project by **[Zeeshaan Ahmad](https://github.com/zeeshaanahmad/url-shortener)**.