SAH Shortener is a URL-shortening website that enables users to convert long URLs into short, manageable links. The project is built with a clean separation between the front-end and back-end for optimal performance and maintainability. It now includes Docker support for easy deployment and has been deployed on Render (back-end) and Vercel (front-end).
- HTML: Provides the structure and skeleton of the web page.
- CSS: Adds styling for an appealing user interface.
- JavaScript: Handles user interactions, sends requests to the server, and updates the UI dynamically.
- Java Spring Boot: Serves as the core framework for the back-end.
- MySQL: Used for persistent storage of URLs.
- JPA Repository: Facilitates database operations.
- Service Layer: Connects the controller with the repository for a clean architecture.
- Description: Shortens a given URL and saves it in the system.
- Request Body:
https://example.com - Response:
{ "urlKey": "abc123", "fullUrl": "https://example.com", "shortUrl": "http://localhost:8080/api/abc123" }
- Description: Redirects to the original URL using the short URL key.
- Response:
- 302 FOUND: Redirects to the full URL if the key is valid.
- 404 NOT FOUND:the page is not found .
- Description: Deletes a URL mapping from the system (admin only).
- Response:
- 200 OK: URL deleted successfully.
- 404 NOT FOUND: URL key not found.
- The system uses SHA-256 hashing to generate unique keys for URLs.
- To handle hash collisions, the key length increases dynamically.
- The back-end ensures that duplicate URLs are not stored by checking for existing entries before saving.
- Idempotency is a key feature, ensuring that the same input URL always results in the same short URL.
- Java Development Kit (JDK) 17+
- MySQL Database
- Docker (optional for containerized deployment)
- Docker comopse (optional for multi-container setup)
$ git clone https://github.com/yourusername/SAH-Shortener.git
$ cd SAH-Shortener- Build and Run with Docker compose
- Navigate to the project root directory
- Update the
docker-compose.ymlfile with your environment variables:
DATABASE_URL: MySQL database url (e.g.,jdbc:mysql://mysql-db:3306/URLs).DATABASE_USERNAME: MySQL username.DATABASE_PASSWORD: MySQL password.CURRENT_DOMAIN: Domain for the server (e.g.,http://localhost:8080/api).MYSQL_ROOT_PASSWORD: MySQL root password.MYSQL_DATABASE: MySQL database name.MYSQL_USER: MySQL user (optional)MYSQL_PASSWORD: MySQL user password (optional)
- Run Docker Compose:
$ docker-compose up --build
Back-End Setup
-
Configure MySQL:
- Create a database named
URLs. - Use the provided SQL script in the
databasefolder to set up the schema.
- Create a database named
-
Run the Spring Boot application:
$ ./mvnw spring-boot:run
Front-End Setup
- Open the
index.htmlfile in a browser. - Ensure the back-end server is running to test the full functionality.
- Use the main page to input long URLs and receive shortened URLs.
- Access the short URL to redirect to the original page.
- Admin users can delete URLs via the delete API.
This project was inspired by the Coding Challenges.
Happy shortening!