- Overall structure
- Run
- Build and Run
- Functionalities
- Delivery
- Repositories
- Reference Documentation
- Guides
The structure of this project is heavily influenced by the clean architecture:
- A
coremodule where we define the domain entities and the functionalities (also known as uses cases, business rules, etc.). They do not know that this application. has a web interface or that data is stored in relational databases. - A
repositoriesmodule that knows how to store domain entities in a relational database. - A
deliverymodule that knows how to expose in the Web the functionalities. - An
appmodule that contains the main, the configuration (i.e. it linkscore,deliveryandrepositories), and the static assets (i.e. html files, JavaScript files, etc. )
Usually, if you plan to add a new feature, usually:
- You will add a new use case to the
coremodule. - If required, you will modify the persistence model in the
repositoriesmodule. - You will implement a web-oriented solution to expose to clients in the
deliverymodule.
Sometimes, your feature will not be as simple, and it would require:
- To connect a third party (e.g. an external server).
In this case you will add a new module named
gatewayresponsible for such task. - An additional application.
In this case you can create a new application module (e.g.app2) with the appropriate configuration to run this second server.
Features that require the connection to a third party or having more than a single app will be rewarded.
First you need to install and start the RabbitMQ service:
On windows:
docker pull rabbitmq:3-management
docker run -d -p 15672:15672 -p 5672:5672 --name rabbit-urlshortener rabbitmq:3-managementOn linux:
sudo apt install rabbitmq-server
sudo systemctl enable rabbitmq-server
sudo rabbitmq-plugins enable rabbitmq_managementThen access to the RabbitMQ dashboard (http://localhost:15672) and login with "guest" as user and password
The application can be run as follows:
./gradlew :app:bootRunThe uberjar can be built and then run with:
./gradlew build
java -jar app/build/libs/app.jarThe project offers a minimum set of functionalities:
-
Create a short URL. See in
corethe use caseCreateShortUrlUseCaseand indeliverythe REST controllerUrlShortenerController. -
Redirect to a URL. See in
corethe use caseRedirectUseCaseand indeliverythe REST controllerUrlShortenerController. -
Log redirects. See in
corethe use caseLogClickUseCaseand indeliverythe REST controllerUrlShortenerController. -
Check URL in black list. See in
corethe use caseBlackListUseCaseand indeliverythe REST controllerUrlShortenerController. -
Create Short URLs from csv file. See in
corethe use caseCreateShortUrlCsvUseCaseand indeliverythe REST controllerUrlShortenerController. -
Get info from request's header. See in
corethe use caseHeadersInfoUseCaseand indeliverythe REST controllerUrlShortenerController. -
Show clicks summary from. See in
corethe use caseInfoSummaryUseCaseand indeliverythe REST controllerUrlShortenerController. -
Return clicks summary from URL. See in
corethe use caseSponsorUseCaseand indeliverythe REST controllerUrlShortenerController.
The objects in the domain are:
ShortUrl: the minimum information about a short urlRedirection: the remote URI and the redirection modeShortUrlProperties: a handy way to extend data about a short urlClick: the minimum data captured when a redirection is loggedClickProperties: a handy way to extend data about a clickCsvResponse: a handy way to extend data about the processed urls from a csv
The above functionality is available through a simple API:
POST /api/linkwhich creates a short URL from data sent by a form.POST /api/bulkwhich creates short URLs from a csv file sent by a form and downloads the resulting csv on a browser.GET /tiny-{id}whereididentifies the short url, deals with redirects, and logs use (i.e. clicks).GET /api/link/{id}which shows the clicks summary of an URL.
In addition, GET / returns the landing page of the system.
All the data is stored in a relational database. There are only two tables.
- shorturl that represents short url and encodes in each row
ShortUrlrelated data, - click that represents clicks and encodes in each row
Clickrelated data.
For further reference, please consider the following sections:
The following guides illustrate how to use some features concretely:
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
- Accessing Data with JPA
- Messaging with RabbitMQ with Spring
- Setup SonarCloud for Gradle (Solo en parte, pues al vincular SonarCloud con tu cuenta de github y el proyecto, el propio SonarCloud tiene una guia de un par de pasos sobre como añadirlo a gradle y al CI)