This project consists of two microservices:
- Invoice Service: Handles invoice creation and generates daily sales reports
- Email Service: Consumes daily sales reports and sends them via email
- Node.js (v18 or later)
- Docker and Docker Compose
- MongoDB
- RabbitMQ
.
├── docker-compose.yml
├── invoice-service/
│ ├── src/
│ │ ├── invoice/
│ │ ├── report/
│ │ ├── app.module.ts
│ │ └── main.ts
│ ├── Dockerfile
│ ├── package.json
│ └── tsconfig.json
└── email-service/
├── src/
│ ├── email/
│ ├── app.module.ts
│ └── main.ts
├── Dockerfile
├── package.json
└── tsconfig.json
- Clone the repository:
git clone <repository-url>
cd invoice-service- Install dependencies for both services:
cd invoice-service && npm install
cd ../email-service && npm install- Configure environment variables:
- Create
.envfiles in both service directories with the following variables:
For invoice-service:
MONGODB_URI=mongodb://root:example@mongodb:27017/invoice?authSource=admin
RABBITMQ_URL=amqp://user:password@rabbitmq:5672For email-service:
RABBITMQ_URL=amqp://user:password@rabbitmq:5672
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=[email protected]
SMTP_PASS=password- Start the services using Docker Compose:
docker-compose up --buildInvoice Service (http://localhost:3000)
-
POST /invoices- Create a new invoice{ "customer": "John Doe", "amount": 100, "reference": "INV001", "date": "2024-01-01T00:00:00.000Z", "items": [ { "sku": "SKU001", "qt": 2 } ] } -
GET /invoices- Get all invoices -
GET /invoices/:id- Get a specific invoice -
GET /invoices/range?startDate=2024-01-01&endDate=2024-01-02- Get invoices within a date range
-
Invoice Creation:
- Create invoices with customer details, amount, and items
- Store invoices in MongoDB
- RESTful API for invoice management
-
Daily Sales Report:
- Automatically generates daily sales reports at 12:00 PM
- Calculates total sales and item-wise quantities
- Publishes reports to RabbitMQ queue
-
Email Service:
- Consumes reports from RabbitMQ queue
- Sends formatted email reports
- Configurable email settings
Run tests for each service:
# In invoice-service directory
npm test
# In email-service directory
npm testThe system uses a microservices architecture with:
- NestJS for both services
- MongoDB for invoice storage
- RabbitMQ for message queuing
- Docker for containerization
- Jest for testing
- Both services include comprehensive error handling
- Failed operations are logged
- RabbitMQ ensures message persistence
- Email sending retries on failure
- Console logging for important operations
- RabbitMQ management interface (http://localhost:15672)
- MongoDB logs
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request