Skip to content

andriuslima/canary-services

Repository files navigation

Canary Application Services

Requirements

  • 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.

How to run

All the instructions bellow assumes you are inside the project directory (a.k.a canary-services)

1. Build Canary Api

  1. cd canary-api
  2. ./gradlew bootJar (macOS and Linux) or ./gradlew.bat bootJar (Windows)
  3. Make sure the file canary-api.jar was created inside canary-api/build/libs

2. Build Canary View Api

  1. cd canary-view-api
  2. ./gradlew bootJar (macOS and Linux) or ./gradlew.bat bootJar (Windows)
  3. Make sure the file canary-view-api.jar was created inside canary-view-api/build/libs

3. Run dependencies

Inside the docker-compose-dependencies.yml file there are all the dependencies that need to be run (PostgreSQL, MongoDB and Apache Kafka).

  1. 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.

3. Run services

Inside the docker-compose-app.yml file there are all the services that needs to be deployed.

  1. docker-compose -f docker-compose-app.yml up

Services

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.

Architecture Diagram

Canary Api

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.

Canary Event Consumer

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.

Canary View Api

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.

Users

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

Boyle

User Id = 2

JWT = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIyIn0.05H31lyoJVz6RGXXOp4l5j6DKbz18G9Uh-4YuTWSyGE

Gina

User Id = 3

JWT = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIzIn0.gpVBIeKSNK53Q_cM8Af4PT12NVOkT_5zEkLeHybqlfE

Endpoints

For each endpoint you must add a authorization header with a bearer token.

Authorization: Bearer TOKEN

Create Post

POST localhost:8081/posts
{
    "content": <string>
}

Create Repost

POST localhost:8081/posts/repost
{
    "parent": <number>
}

Create Quote Repost

POST localhost:8081/posts/quote
{
    "content": <string>,
    "parent": <number>
}

List All Posts

GET localhost:8082/posts?search=<string>

List Posts From Users I Follow

GET localhost:8082/posts/follow

List User Posts

GET localhost:8082/users/{userId}/posts

Get User Profile

GET localhost:8082/users/{userId}/profile

About

Canary Services

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published