- Docker CLI: 20.10.12
- Docker Desktop: 4.4.2
- Yarn: 1.22.17
- Java: > 11
- Gradle: > 6.8
- The applications use gradle wrapper but this is the gradle version that I use to download de wrapper.
All the instructions bellow assumes you are inside the project directory (a.k.a canary-services)
cd canary-api
./gradlew bootJar
(macOS and Linux) or./gradlew.bat bootJar
(Windows)- Make sure the file
canary-api.jar
was created insidecanary-api/build/libs
cd canary-view-api
./gradlew bootJar
(macOS and Linux) or./gradlew.bat bootJar
(Windows)- Make sure the file
canary-view-api.jar
was created insidecanary-view-api/build/libs
Inside the docker-compose-dependencies.yml
file there are all the dependencies that need to be run (PostgreSQL, MongoDB and Apache Kafka).
docker-compose -f docker-compose-dependencies.yml up
Give it a minute before going to the next steps since this dependencies may take sometime to bootstrap.
Inside the docker-compose-app.yml
file there are all the services that needs to be deployed.
docker-compose -f docker-compose-app.yml up
This is an event driven services with clean architecture principles.
The idea behind using this principles was to create a high decouple architecture keeping each codebase simple and readble. Each service has well-formed responsibilities and are not affected if another system is down or slow.
Below there is a diagram with the architecture proposed.
The Canary Api is responsible for receveing writing requests. This api will validate if a request is valid and send a event using Kafka.
This Api will apply businesses rules to check if the request format is valid - like content length. It will not validate if the user is allowed to create a post because it is not responsible of actually creating a post.
The Canary Event Consumer will consume those events above-mentioned. It has handlers to handle each type of events supported. For each event it will apply the applicable businesses rules - like checking if the user already created 5 posts in a day. It will also persist all the necessary entities to a PostgreSQL database.
Afterwards it will send a event using kafka.
The Canary View Api is responsible for receveing reading requests.
This Api will also consume the event generated by Posterr Event Consumer.
It will receive those events and it will save entities in a optimazed way to build a view at runtime. Each view is a data visualization requirement. If there is a screen that needs the user basic information, post, follows and following count there must be a view with that information.
A list of users with their respective id and JWT. You can use this information to send HTTP requests. ### Jake
User Id = 1
JWT = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxIn0.7hmuwze5HBr3hNtSAQyHE2Baqp4b9TgdNMOREOTBNW0
User Id = 2
JWT = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIyIn0.05H31lyoJVz6RGXXOp4l5j6DKbz18G9Uh-4YuTWSyGE
User Id = 3
JWT = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIzIn0.gpVBIeKSNK53Q_cM8Af4PT12NVOkT_5zEkLeHybqlfE
For each endpoint you must add a authorization header with a bearer token.
Authorization: Bearer TOKEN
POST localhost:8081/posts
{
"content": <string>
}
POST localhost:8081/posts/repost
{
"parent": <number>
}
POST localhost:8081/posts/quote
{
"content": <string>,
"parent": <number>
}
GET localhost:8082/posts?search=<string>
GET localhost:8082/posts/follow
GET localhost:8082/users/{userId}/posts
GET localhost:8082/users/{userId}/profile