Skip to content

A microservices-based application using NestJS that demonstrates user management with event-driven notifications.

License

Notifications You must be signed in to change notification settings

kennysghub/ms-nestjs

Repository files navigation

NestJS Microservices Application

A microservices-based application using NestJS that demonstrates user management with event-driven notifications. The application consists of two services: a User Service for managing user data and a Notification Service for handling user-related notifications.

Architecture

  • User Service: RESTful API handling CRUD operations for users
  • Notification Service: Event-driven service for sending notifications
  • Message Broker: Redis for inter-service communication
  • Error Handling: Comprehensive error handling with custom exceptions
  • Testing: Unit tests for critical components

Prerequisites

  • Node.js (v16 or later)
  • npm (v8 or later)
  • Docker and Docker Compose (for Redis)

Installation

  1. Install dependencies for both services:
# Install User Service dependencies
cd user-service
npm install

# Install Notification Service dependencies
cd ../notification-service
npm install
  1. Install global dependencies:
npm install -g @nestjs/cli

Configuration

The application uses Redis as a message broker. The default configuration assumes Redis is running on localhost:6379. You can modify the connection settings in:

  • user-service/src/users/users.module.ts
  • notification-service/src/main.ts

Running the Application

  1. Start Redis using Docker:
docker-compose up -d
  1. Start the User Service (in a new terminal):
cd user-service
npm run start:dev
  1. Start the Notification Service (in a new terminal):
cd notification-service
npm run start:dev

The services will be available at:

API Endpoints

User Service

  • POST /users - Create a new user

    curl -X POST http://localhost:3000/users \
      -H "Content-Type: application/json" \
      -d '{"email": "test@example.com", "name": "Test User"}'
  • GET /users - Get all users

    curl http://localhost:3000/users
  • GET /users/:id - Get a specific user

    curl http://localhost:3000/users/:id
  • PUT /users/:id - Update a user

    curl -X PUT http://localhost:3000/users/:id \
      -H "Content-Type: application/json" \
      -d '{"name": "Updated Name"}'
  • DELETE /users/:id - Delete a user

    curl -X DELETE http://localhost:3000/users/:id

Running Tests

Both services include unit tests for critical components.

# Run User Service tests
cd user-service
npm run test

# Run Notification Service tests
cd notification-service
npm run test

About

A microservices-based application using NestJS that demonstrates user management with event-driven notifications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published