This project is a URL shortening service, akin to services like Bit.ly or TinyURL. Users input a lengthy URL, and they're presented with a condensed version which, when visited, redirects them to the initial URL.
-
Java with Spring Boot: The core of our application, processing primary tasks like generating the truncated URL and redirection.
-
H2 Database: An embedded database utilized for developmental objectives. It houses the linkage between the primary URLs and their shorter equivalents.
-
Swagger: A tool that generates API documentation and simplifies endpoint testing.
-
Docker: Guarantees consistent application performance across various environments through containerization.
-
React: A JS library for constructing user interfaces. Here, it offers a neat UI for users to interface with the URL shortening service.
-
Axios: A promise-based HTTP client. Used to make asynchronous HTTP requests to our backend.
- URL Shortening: Submit a long URL and receive its shortened version.
- URL Redirection: Use the shorter URL to redirect to the original link.
- Error Handling: Handles typical errors, such as malformed URLs or server unavailability, providing valuable feedback.
- Java (Version 11 or higher)
- Maven
- Node.js (Version 14 or higher)
- npm or yarn
- Docker (Optional if using Docker Compose)
When deploying to a production environment, consider using a persistent database rather than H2, and ensure all endpoints are secure.
- Why? Tracking the number of clicks a shortened URL receives can provide insights into its popularity and usage. This metric is essential for analytics and can help understand the effectiveness of content or campaigns.
- Why? Implementing a timeout for shortened URLs ensures they're not available indefinitely. This is particularly useful for temporary promotions or time-sensitive information.
- Why? Implementing caching mechanisms can significantly improve response times and reduce the load on the database, leading to a smoother user experience and reduced operational costs.
- Why? As the number of shortened URLs grows, there's a need to ensure that the database can handle the increased load. Scaling strategies, such as sharding or replication, can help in ensuring high availability and performance.
- Why? Comprehensive tests ensure the system's reliability and robustness. By increasing test coverage, we can catch potential issues early and ensure that new features or changes don't introduce regressions.
Each of these improvements aims to enhance the performance, reliability, and user experience of the backend service.
Interactive API documentation:
http://localhost:8080/swagger-ui/index.html
Inspect the in-memory H2 database:
http://localhost:8080/h2-console/
Make sure the JDBC URL aligns with your application settings.
The primary interface:
To spin up the entire service:
- Navigate to the project's root directory.
- Run:
$ docker-compose up --build
This command will start both the backend and frontend, providing an integrated development environment.
- Navigate to the
backend
directory. - Run:
$ mvn clean install
- After a successful build, start the application:
$ mvn spring-boot:run
The backend server will start, and it should be accessible at http://localhost:8080/
.
- Navigate to the
frontend
directory. - Install the required npm packages:
$ npm install
or
$ yarn install
- Start the React application:
$ npm start
or
$ yarn start
The React frontend will then be accessible at
http://localhost:3000/
.
- Navigate to the
backend
directory. - Run the unit tests with Maven:
$ mvn test
This will execute all unit tests in your backend service. Maven will provide a summary of the test results in the console.
- Navigate to the
frontend
directory. - Install the required npm packages (if you haven't already):
$ npm install
or
$ yarn install
- Run the React application tests:
$ npm test
or
$ yarn test