Skip to content

Managed monorepo, that implements event driven flow using tRPC and Kafka.

Notifications You must be signed in to change notification settings

imbenrabi/Event-Driven-Architecture

Repository files navigation

Event-Driven Architecture with Fastify, tRPC, and Kafka

This project implements an event-driven architecture where events/messages are sent from a client to a Kafka queue via a tRPC server, and subsequently to an end provider/service. The project is organized in a monorepo and includes repository management tools such as lint, Husky, and Commitlint.

Notable Technologies

Setting Up Kafka Using Docker

We'll use Docker to simplify the installation process.

Prerequisites

  1. Docker: Ensure Docker is installed on your machine. You can download it from here.

Steps to Set Up Kafka locally

1. Run Zookeper and Kafka with Docker

In root, run:

docker-compose up -d

Running the project

1. Install Deps

Install project deps. Go to root and run:

npm install

2. Run Kafka

Make sure Docker image is running succesfully. Go to root and run:

npm run dev:kafka

The script will start a Kafka consumer that is using batching. you can disable batching by setting KAFKA_MESSAGE_BATCHING env variable to false.

3. Run Server

Go to root and run:

npm run dev:server

4. Run client

Make sure server is running succesfully. Go to root and run:

npm run dev:client

Go to localhost.

Checking results

Go to Kafdrop - a Kafka UI Client

The Docker compose command installed and ran Kafdrop image as well. Go to localhost:19000 to review results.

Tests

We are using Mocha and Chai for testing, alongside nyc for HTML report.

Running tests

From a specific package root, run:

npm run test

OR From root, run:

npm run test:all
  • You can also run per package - see package.json scripts.

Running tests with coverage and opening the HTML report

From a specific package root, run:

npm run test:coverage:open

OR from root, run:

npm run test:coverage:open:<packageName>

For specific package.

OR

npm run test:coverage:open:all

For all packages.