A modular marketplace backend built as a set of Node.js microservices. The architecture uses separate services for authentication, products, cart, orders, payments, notifications, seller operations, and an AI shopping assistant.
- Backend stack: Node.js, Express, MongoDB, RabbitMQ, Redis, JWT, Razorpay.
- Frontend: React + Vite + Redux Toolkit Query (external client assumed).
- Deployment target: Docker / AWS ECR → ECS Fargate behind an ALB with path-based routing.
- Observability: request logging, request correlation IDs, structured logs.
- Security: JWT auth, refresh tokens, CORS, CSRF protections, input validation, RBAC.
This repo is organized as one folder per microservice:
auth/— authentication, user management, token issuance.product/— catalog CRUD, seller product management.cart/— shopping cart operations.order/— order creation, status changes, order history.payment/— Razorpay payment orchestration and verification.notification/— email notifications and event listeners.ai-buddy/— AI shopping assistant and natural language query support.seller-dashboard/— seller analytics, order view, inventory management.
Each service is implemented as a standalone Express application and can be run independently.
| Service | Folder | Default Port |
|---|---|---|
| Auth | auth/ |
3000 |
| Product | product/ |
3001 |
| Cart | cart/ |
3002 |
| Order | order/ |
3003 |
| Payment | payment/ |
3004 |
| AI Buddy | ai-buddy/ |
3005 |
| Notification | notification/ |
3006 |
| Seller Dashboard | seller-dashboard/ |
3007 |
Handles:
- user registration and login
- JWT access / refresh token management
- user profile and address management
- secure session handling
Handles:
- product listing, search, filtering, pagination
- product detail retrieval and image handling
- seller product creation, updates, deletion
- event publishing for product lifecycle changes
Handles:
- add / update / remove cart items
- cart retrieval and total calculation
- price revalidation to prevent client-side tampering
Handles:
- converting cart contents into orders
- order lifecycle state management
- shipping address updates before payment
- order cancellation flow
Handles:
- Razorpay order creation and verification
- payment record storage
- secure gateway integration
Handles:
- email notification delivery
- asynchronous event consumption from RabbitMQ
- decoupled notification workflow
Handles:
- natural language product search
- conversational shopping assistance
- cart creation and intent-driven actions
Handles:
- seller analytics and revenue metrics
- order list for sellers
- inventory management and product status
- Services communicate using REST APIs and event-driven messaging.
- RabbitMQ is used for asynchronous events such as user creation, product updates, order creation, and notifications.
- MongoDB stores domain data for each service.
- Redis is available for caching, rate limiting, and session protection when configured.
- Install Node.js 18+.
- Install dependencies in each service folder:
cd auth && npm install cd ../product && npm install cd ../cart && npm install cd ../order && npm install cd ../payment && npm install cd ../notification && npm install cd ../ai-buddy && npm install cd ../seller-dashboard && npm install
- Provision infrastructure:
- MongoDB or MongoDB Atlas
- RabbitMQ
- Redis (optional)
- Configure environment variables for each service. Common values include:
MONGO_URIJWT_SECRETJWT_REFRESH_SECRETRABBITMQ_URLPORTRAZORPAY_KEY_IDRAZORPAY_KEY_SECRETEMAIL_HOST,EMAIL_PORT,EMAIL_USER,EMAIL_PASS
- Start services:
cd auth && node server.js cd ../product && node server.js cd ../cart && node server.js cd ../order && node server.js cd ../payment && node server.js cd ../notification && node server.js cd ../seller-dashboard && node server.js cd ../ai-buddy && node server.js
Use multiple terminals or a process manager like
pm2to run services in parallel.
Each service supports tests from its own folder.
cd auth && npm testRepeat for product, cart, order, payment, and other services with tests.
- Services are designed for separate containers.
- AWS ECS Fargate is a good deployment target.
- Use an ALB with path-based routing to forward traffic to each service.
- Store secrets securely and avoid hardcoding API credentials.
- Request logging is enabled in the services.
- Correlation IDs can trace requests across services.
- Logs can be forwarded to CloudWatch or another centralized log service.
- JWT access and refresh tokens for authentication.
- HttpOnly refresh cookies.
- Input validation with
express-validatorandzod. - Role-based access control for protected endpoints.
- Rate limiting and CORS protections where configured.
- add
.env.examplefiles for every service - add Dockerfiles and a root
docker-compose.yml - document endpoint contracts for frontend integration
- add API versioning and health checks
auth/— authentication and user managementproduct/— product catalog and seller operationscart/— cart lifecycle managementorder/— order creation and order historypayment/— Razorpay payment flownotification/— email notifications and event listenersai-buddy/— conversational shopping assistantseller-dashboard/— seller analytics and operations
Stores user notifications (email, SMS, in-app).
{
"notificationId": "string (UUID)",
"userId": "string (FK → User.userId)",
"type": "enum: ['email', 'sms', 'push']",
"message": "string",
"status": "enum: ['pending', 'sent', 'failed']",
"createdAt": "date"
}(Optional but common in e-commerce).
{
"reviewId": "string (UUID)",
"productId": "string (FK → Product.productId)",
"userId": "string (FK → User.userId)",
"rating": "number (1-5)",
"comment": "string",
"createdAt": "date"
}- User
- Product
- Cart
- Order
- Payment
- Notification
| Service | Entities Owned | Responsibilities | Dependencies | RabbitMQ Events |
|---|---|---|---|---|
| Auth/User Service | User | Register/login, issue tokens, manage profiles & addresses, emit USER_CREATED/UPDATED | Needed by all services (for auth) | Emits user.created, user.updated |
| Product Service | Product (and optional Review) | CRUD products, manage stock, serve product data to Cart/Order, emit PRODUCT_CREATED/UPDATED/DELETED | Cart, Order, Review Service | Emits product.created, product.updated |
| Cart Service | Cart | Add/remove items, validate stock/price, compute totals, maintain one cart per user | Product Service (for price/stock) | Subscribes to product.updated (optional) |
| | Order Service | Order | Create/manage orders, track lifecycle, reserve inventory, emit ORDER_CREATED/UPDATED | Cart, Payment, Notification | Emits order.created, order.cancelled | | Payment Service | Payment | Handle Razorpay/Stripe integration, verify payments, emit PAYMENT_SUCCESS/FAILED | Order, Notification | Emits payment.success, payment.failed | | Notification Service | Notification | Listen to events, send emails/SMS/push, track delivery status | User, Order, Payment | Subscribes to all major events (order.created, payment.success, etc.) | | Seller Dashboard Service | Aggregated seller metrics & insights | /seller/dashboard/metrics, /seller/dashboard/orders, /seller/dashboard/products | | Subscribes to order.created, payment.success, product.updated |
Displaying Cohort online market place .md.