- 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
core
module 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
repositories
module that knows how to store domain entities in a relational database. - A
delivery
module that knows how to expose in the Web the functionalities. - An
app
module that contains the main, the configuration (i.e. it linkscore
,delivery
andrepositories
), 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
core
module. - If required, you will modify the persistence model in the
repositories
module. - You will implement a web-oriented solution to expose to clients in the
delivery
module.
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
gateway
responsible 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-management
On linux:
sudo apt install rabbitmq-server
sudo systemctl enable rabbitmq-server
sudo rabbitmq-plugins enable rabbitmq_management
Then 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:bootRun
The uberjar can be built and then run with:
./gradlew build
java -jar app/build/libs/app.jar
The project offers a minimum set of functionalities:
-
Create a short URL. See in
core
the use caseCreateShortUrlUseCase
and indelivery
the REST controllerUrlShortenerController
. -
Redirect to a URL. See in
core
the use caseRedirectUseCase
and indelivery
the REST controllerUrlShortenerController
. -
Log redirects. See in
core
the use caseLogClickUseCase
and indelivery
the REST controllerUrlShortenerController
. -
Check URL in black list. See in
core
the use caseBlackListUseCase
and indelivery
the REST controllerUrlShortenerController
. -
Create Short URLs from csv file. See in
core
the use caseCreateShortUrlCsvUseCase
and indelivery
the REST controllerUrlShortenerController
. -
Get info from request's header. See in
core
the use caseHeadersInfoUseCase
and indelivery
the REST controllerUrlShortenerController
. -
Show clicks summary from. See in
core
the use caseInfoSummaryUseCase
and indelivery
the REST controllerUrlShortenerController
. -
Return clicks summary from URL. See in
core
the use caseSponsorUseCase
and indelivery
the 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/link
which creates a short URL from data sent by a form.POST /api/bulk
which creates short URLs from a csv file sent by a form and downloads the resulting csv on a browser.GET /tiny-{id}
whereid
identifies 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
ShortUrl
related data, - click that represents clicks and encodes in each row
Click
related 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)