Repository files navigation
How to Run the Project Locally
Make sure you have Java 21, Maven, Docker, and MySQL installed.
Start MySQL and create the database:
mysql -u root -p
CREATE DATABASE shortener_db;
Update src/main/resources/application.properties with your MySQL credentials if needed.
Build and run the app:
mvn clean package
java -jar target/* .jar
Or run with Docker:
docker build -t shortener-backend .
docker run -p 8080:8080 --env SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/shortener_db --env SPRING_DATASOURCE_USERNAME=root --env SPRING_DATASOURCE_PASSWORD=YOUR_PASSWORD shortener-backend
Shorten a URL:
curl -X POST http://localhost:8080/api/shorten -H " Content-Type: application/json" -d ' {"url":"https://example.com"}'
# Response: { "shortCode": "abc123" }
Redirect:
curl -v http://localhost:8080/abc123
# 302 redirect to https://example.com
Analytics:
curl http://localhost:8080/api/analytics/abc123
# Response: { "originalUrl": ..., "shortCode": ..., "redirectCount": ..., "createdAt": ... }
GitHub Actions workflow runs on every push/PR to main.
Steps: linter (Checkstyle), unit tests, build JAR, build & push Docker image to Docker Hub.
Uses MySQL service for integration tests in CI.
Docker image is deployed to Google Cloud Run.
Cloud Run connects to Cloud SQL (MySQL) using the Cloud SQL Proxy.
Environment variables for DB connection are set in Cloud Run.
Service listens on the port provided by the PORT environment variable.
Core API & DB logic: ~4 hours
Dockerization: ~30 minutes
CI/CD setup: ~4 hour
Cloud Run deployment: ~2 hour
Debugging & edge cases: ~3 hour
Used reflection for unit tests to avoid Spring context loading in CI.
Did not implement full integration tests (could be added for end-to-end validation).
Used basic URL validation (Java URL class) instead of a more robust validator.
Secrets for DB and Docker Hub are managed via GitHub Actions and Cloud Run env vars.
Some test cases and debugging steps were generated or assisted by OpenAI's ChatGPT.
You can’t perform that action at this time.