Stuff Delivery is a simple study of a microservice architecture using the most famous (and some new ones as well) technologies.
- Kafka
- Node.js
- Kubernetes
- Docker
- React.js
- gRPC
- Kibana
- ElasticSearch
- Fluentd
- Grafana
- Redis
- Postgres
- Nginx
- AWS S3
- LocalStack
We have currently 3 main microservices:
Responsible for making all related User business rules, per example: User Authentication, Profile Update, Authentication Token Verification and so on.
Owns the responsability of Tracking Packages and Delivery Mans.
Controls all notification that needs to be sent, per example: Emails and Push Notifications.
We have currently 2 main clients:
Client used by users in order to track the deliveries they want to. It is built focused on the offline first approach (with a great help of RxDB)
Client used by the people responsible for managing all the delivery system, such as error reports and track updates.
We have three basic ways to make communication with/between the microservices:
- REST: In case someone outside needs to use a resource from some microservice. Ex: Someone tries to log in.
- RPC: In case a microservice needs to use a resource from another that does not need to be processed in background. Ex: The microservice(1) needs to know if a user is authenticated, but this method is owned by microservice(2).
- Pub/Sub: In case a microservice requests a resource from another that needs to be processed in background. Ex: An action ocurred and an email needs to be sent.
The REST Requests relies on Nginx since we use it as a Ingress Controller and Load Balancer. Below you can see an example:
A user attempts to log in
> POST /asgardian/login
The request goes first to Nginx, the path is verified and forwarded to the needed microservice
> PROXY_PASS asgardian:3040
The RPC System relies on gRPC in order to make fast communication between microservices. Below you can see an example:
A user tries to get his current list of packages being tracked
> GET /hermes/deliveries { token }
The Hermes Microservice uses Asgardian Microservice to verify if user is authenticated
> RPC Asgardian.isAuthenticated { token }
The Pub/Sub System relies on Kafka and every message send there comes in the format of an event. Below you can see an example:
A user signs up
> POST /asgardian/signup { email, password }
The Asgardian Microservice publishes a message to Kafka
> PUBLISH CustomerSignedUp { email, password }
The Iris Microservice is subscribed to CustomerSignedUp event and makes the action of sending a email to new user
> SERVICE Iris.sendWelcomeMail { email, password }
All the services inside each microservice follow the TDD principles.
That's a monorepo managed by Lerna, the microservices can be found on /apps
folder. The modules shared between all of them can be found on /apps/shared
.
The API Documentation is powered by ApiDoc.
All the the app design was made with help of Figma and Dribbble. Besides, the stylesheet can be found here.
- Clone this repository
- Open the root directory and run the following command:
docker-compose up # Inits all needed resources
- Install all dependencies:
npm run bootstrap # Will use lerna to install every repo dependency
- Goes inside every repo inside apps folder and do the following:
- Duplicate .env.example
- Change .env.example name to .env
- Add the needed environmental variables
- Execute the command:
npm run dev
Now the resources will be available at:
- http://127.0.0.1/asgardian (Asgardian Microservice)
- http://127.0.0.1/hermes (Hermes Microservice)
- http://127.0.0.1/api-docs (REST API Documentation)
- http://127.0.0.1/delivy (User Client)
If you have Insomnia installed on your computer, you can download the API routes by clicking in the button below: