- Node.js (v20 or higher)
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/your-repo/monorepo-microservices.git cd monorepo-microservices
-
Install dependencies for both microservices:
cd apps/customers yarn install cd ../orders yarn install
-
Start Kafka and Zookeeper using Docker Compose:
cd infra/kafka docker-compose up -d
-
Start Kong and Konga (API Gateway and Admin Interface):
cd ../kong docker-compose up -d
-
Start the
customers
microservice:cd ../../apps/customers yarn run start:dev
-
Start the
orders
microservice:cd ../orders yarn run start:dev
To run tests for each microservice, use the following commands:
-
For
customers
microservice:cd apps/customers yarn run test
-
For
orders
microservice:cd apps/orders yarn run test
The customers
and orders
microservices communicate with each other using Kafka messaging. When a new customer is created in the customers
microservice, a Kafka message is sent to the orders
microservice to create a reference to this customer.
To run Kafka locally, you can use the docker-compose.yml
file located in kafka.
-
Start Kafka and Zookeeper:
cd infra/kafka docker-compose up -d
-
Verify the connection:
nc -zv localhost 22181 # Zookeeper nc -zv localhost 29092 # Kafka
-
Create a new Kafka topic:
docker exec -it kafka /usr/bin/kafka-topics --create --topic new_topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
-
List Kafka topics:
docker exec -it kafka /usr/bin/kafka-topics --list --bootstrap-server localhost:9092
To configure Kong and the services and routes within Konga, follow the instructions below:
- Access the Konga interface at
http://localhost:1337
. - Add a new service in Konga:
- Name: customers-service
- URL: http://customers:3000
- Add a route for the
customers-service
:- Paths: /customers
- Repeat the process for the
orders-service
:- Name: orders-service
- URL: http://orders:3000
- Paths: /orders
- Customer
id
: String (Primary Key)email
: String (Unique)password
: Stringname
: Stringphone
: StringcreatedAt
: DateTime (Default: now)updatedAt
: DateTime (Updated automatically)
-
Order
id
: String (Primary Key)createdAt
: DateTime (Default: now)updatedAt
: DateTime (Updated automatically)total
: FloatcustomerId
: String (Foreign Key referencingCustomer
incustomers
microservice)customer
: Customer (Relation toCustomer
entity incustomers
microservice)
-
Customer
id
: String (Primary Key)createdAt
: DateTime (Default: now)updatedAt
: DateTime (Updated automatically)externalId
: String (Reference toCustomer
entity incustomers
microservice)
- Environment Variables: Ensure to set the necessary environment variables in a
.env
file for both microservices. - Code Quality: The project uses ESLint and Prettier for code quality and formatting. Run
yarn lint
andyarn format
to check and format the code. - Database: Both microservices use SQLite as the database. Prisma is used as the ORM.
This project is licensed under the MIT License.