Node.js, Express, MongoDB, and RabbitMQ implementation of the Ecommerce Microservices.
| Service | Port | Responsibility |
|---|---|---|
| Customer Service | 3001 | Stores and exposes seeded customers |
| Product Service | 3002 | Stores and exposes seeded products |
| Order Service | 3003 | Validates checkout data, creates pending orders, calls payment |
| Payment Service | 3004 | Simulates payment and publishes transaction events |
| Transaction Worker | n/a | Consumes transaction events and stores transaction history |
npm install
npm run build
docker compose -f docker.compose.yml up --buildSeed customer and product data:
npm run seedRun tests:
npm test- Customer submits an order request to
POST /orders. - Order Service validates the customer through Customer Service.
- Order Service validates product availability through Product Service.
- Order Service stores a pending order in MongoDB.
- Order Service calls Payment Service.
- Payment Service publishes transaction details to RabbitMQ.
- Transaction Worker consumes the event and persists transaction history.
Place a checkout order by sending a POST to the Order Service. Use IDs from the seeded customer and product data.
POST http://localhost:3003/orders
Content-Type: application/json
{
"customerId": "684a1f3e2c8b4d001f6e3a12",
"productId": "684a1f3e2c8b4d001f6e3b45",
"quantity": 2
}Response 201 Created
{
"success": true,
"message": "Order created and payment initiated",
"data": {
"order": {
"id": "684a2c1e9f0b3d001a7c5e88",
"orderId": "a3f7b2d1-4c8e-4a2f-b6d9-1e3c7f5a9b20",
"customerId": "684a1f3e2c8b4d001f6e3a12",
"productId": "684a1f3e2c8b4d001f6e3b45",
"quantity": 2,
"amount": 24000,
"orderStatus": "pending",
"paymentStatus": "successful",
"transactionId": "txn_9b3f1d72e4a85c60"
},
"paymentStatus": "successful",
"transactionId": "txn_9b3f1d72e4a85c60"
}
}Note: Payment is simulated and always returns
successful. The transaction is persisted asynchronously by the Transaction Worker via RabbitMQ.