Skip to content

protickr/lyxa-assignment

Repository files navigation

Microservices Architecture — Auth & Product Service

Overview

This project demonstrates a microservices-based architecture using NestJS, RabbitMQ, and MongoDB. It consists of two independent services:

  • Auth Service → Handles authentication and user management
  • Product Service → Manages product catalog with authorization

Both services communicate asynchronously via RabbitMQ.


Architecture

Client → Product Service → RabbitMQ → Auth Service

  • No direct HTTP communication between services
  • All inter-service communication is handled via RabbitMQ

Tech Stack

  • Framework: NestJS
  • Messaging Broker: RabbitMQ
  • Database: MongoDB (Typegoose)
  • Containerization: Docker & Docker Compose
  • Authentication: JWT (Access + Refresh Tokens)

Project Structure (Monorepo)

. ├── auth-service/ │ ├── src/ │ ├── Dockerfile │ └── .env │ ├── product-service/ │ ├── src/ │ ├── Dockerfile │ └── .env │ ├── docker-compose.yml └── README.md


Auth Service Responsibilities

  • User registration & login
  • JWT generation (access + refresh tokens)
  • Token validation via RabbitMQ
  • Emits events (e.g., user.created)

Key Message Patterns

  • validate_token → Validates JWT and returns user info

Product Service Responsibilities

  • Product CRUD operations
  • Associates products with users
  • Validates JWT via Auth Service (RabbitMQ)
  • Authorization: only product owners can update/delete

Inter-Service Communication Flow

Token Validation Flow

  1. Client sends request with JWT to Product Service
  2. Product Service sends validate_token message via RabbitMQ
  3. Auth Service verifies token and responds with user data
  4. Product Service proceeds with request

Running the Project with Docker

1. Clone the repository

git clone https://github.com/protickr/lyxa-assignment.git
cd lyxa-assignment
2. Setup environment variables

Create .env files inside:

auth-service/.env
product-service/.env

(See .env.example below)

3. Run services
docker-compose up --build
4. Access Services
Service	URL
Auth Service	http://localhost:8000

Product Service	http://localhost:8001

RabbitMQ UI	http://localhost:15672

Environment Variables

auth-service/.env
PORT=3000
MONGO_URI=mongodb://mongo-auth:27017/auth-db
JWT_SECRET=supersecret
RABBITMQ_URL=amqp://rabbitmq:5672

product-service/.env
PORT=3001
MONGO_URI=mongodb://mongo-product:27017/product-db
RABBITMQ_URL=amqp://rabbitmq:5672

📬 Example API Flow
1. Register User
POST /auth/register

2. Login User
POST /auth/login

→ Returns JWT

3. Create Product
POST /products

Authorization: Bearer <token>

Features Implemented
Microservices architecture using NestJS
RabbitMQ-based communication
JWT authentication (access token)
Authorization (resource ownership)
Dockerized services
Clean modular structure

About

Design and implement a system of two independent microservices using tRPC or NestJS (your choice) with RabbitMQ for inter-service communication. Each service should be containerized and run independently, while maintaining seamless interaction.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors