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.
Client → Product Service → RabbitMQ → Auth Service
- No direct HTTP communication between services
- All inter-service communication is handled via RabbitMQ
- Framework: NestJS
- Messaging Broker: RabbitMQ
- Database: MongoDB (Typegoose)
- Containerization: Docker & Docker Compose
- Authentication: JWT (Access + Refresh Tokens)
. ├── auth-service/ │ ├── src/ │ ├── Dockerfile │ └── .env │ ├── product-service/ │ ├── src/ │ ├── Dockerfile │ └── .env │ ├── docker-compose.yml └── README.md
- User registration & login
- JWT generation (access + refresh tokens)
- Token validation via RabbitMQ
- Emits events (e.g.,
user.created)
validate_token→ Validates JWT and returns user info
- Product CRUD operations
- Associates products with users
- Validates JWT via Auth Service (RabbitMQ)
- Authorization: only product owners can update/delete
- Client sends request with JWT to Product Service
- Product Service sends
validate_tokenmessage via RabbitMQ - Auth Service verifies token and responds with user data
- Product Service proceeds with request
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