Home management system using Node.js microservices in a single monorepo. Authentication is provided via JWT tokens and communication between services occurs via Kafka topics.
Get started by cloning the repository and starting the containers.
git clone https://github.com/dayvidwhy/quarters.git
cd quarters
docker-compose up --build
Let docker-compose bring up the containers ahead of running npm install
as this ensures it will grab linux compatible bcrypt
files.
After the containers come up, install local dependencies.
npm install
You then need to run the migrations within the container.
docker exec -it user-service bash
cd services/user
npx drizzle-kit push:pg
# Accept the prompt
You can now start making calls to the user
service and register an account.
Development is provided via containers to orchestrate the environment.
docker-compose up --build
Project leverages npm workspaces for monorepo management. Each package under ./services
is a separate Node.js application. The Dockerfile
in the root of the project is customised per service.
The monorepo is copied and installed into each running service, and then the single service corresponding to that container is started.
You can install additional packages directly into each service using the following commands from the root of the project.
Example of installing package into a service in quarters.
npm install axios -w ./services/[service-name]
# e.g
npm install axios -w ./services/user
To install a local package into another local package, simply update the relevant package.json
and add in the @quarters/[package]
line, eg;
{
...
"dependencies": {
"@quarters/auth": "^1.0.0",
}
...
}
Project is using PostgresSQL via pg
interacted with via Drizzle as the adapter.
Some useful commands:
# Generate the database
npx drizzle-kit generate:pg
# Push changes to the database
npx drizzle-kit push:pg
# Inspect the database with Drizzle kit studio
npx drizzle-kit studio
# If you're starting fresh, run generate and push to get going
npx drizzle-kit generate:pg
npx drizzle-kit push:pg
Migrations are currently kept in each services project folder. When starting up the project for the first time you'll need to run the migration.
# Execute the user migration
docker-compose up --build # ensure project is running
docker exec -it user-service bash
# Navigate to user service
cd packages/store
npm run migrate
# Accept the prompt to push the migration