Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MERN Marketplace Microservices

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.

Overview

  • 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.

Architecture

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 Ports

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

Core Service Responsibilities

Auth Service (auth/)

Handles:

  • user registration and login
  • JWT access / refresh token management
  • user profile and address management
  • secure session handling

Product Service (product/)

Handles:

  • product listing, search, filtering, pagination
  • product detail retrieval and image handling
  • seller product creation, updates, deletion
  • event publishing for product lifecycle changes

Cart Service (cart/)

Handles:

  • add / update / remove cart items
  • cart retrieval and total calculation
  • price revalidation to prevent client-side tampering

Order Service (order/)

Handles:

  • converting cart contents into orders
  • order lifecycle state management
  • shipping address updates before payment
  • order cancellation flow

Payment Service (payment/)

Handles:

  • Razorpay order creation and verification
  • payment record storage
  • secure gateway integration

Notification Service (notification/)

Handles:

  • email notification delivery
  • asynchronous event consumption from RabbitMQ
  • decoupled notification workflow

AI Buddy Service (ai-buddy/)

Handles:

  • natural language product search
  • conversational shopping assistance
  • cart creation and intent-driven actions

Seller Dashboard (seller-dashboard/)

Handles:

  • seller analytics and revenue metrics
  • order list for sellers
  • inventory management and product status

Data Flow

  • 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.

Local Setup

  1. Install Node.js 18+.
  2. 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
  3. Provision infrastructure:
    • MongoDB or MongoDB Atlas
    • RabbitMQ
    • Redis (optional)
  4. Configure environment variables for each service. Common values include:
    • MONGO_URI
    • JWT_SECRET
    • JWT_REFRESH_SECRET
    • RABBITMQ_URL
    • PORT
    • RAZORPAY_KEY_ID
    • RAZORPAY_KEY_SECRET
    • EMAIL_HOST, EMAIL_PORT, EMAIL_USER, EMAIL_PASS
  5. 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 pm2 to run services in parallel.

Testing

Each service supports tests from its own folder.

cd auth && npm test

Repeat for product, cart, order, payment, and other services with tests.

Deployment Notes

  • 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.

Observability

  • 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.

Security Highlights

  • JWT access and refresh tokens for authentication.
  • HttpOnly refresh cookies.
  • Input validation with express-validator and zod.
  • Role-based access control for protected endpoints.
  • Rate limiting and CORS protections where configured.

Recommended Improvements

  • add .env.example files for every service
  • add Dockerfiles and a root docker-compose.yml
  • document endpoint contracts for frontend integration
  • add API versioning and health checks

Folder Summary

  • auth/ — authentication and user management
  • product/ — product catalog and seller operations
  • cart/ — cart lifecycle management
  • order/ — order creation and order history
  • payment/ — Razorpay payment flow
  • notification/ — email notifications and event listeners
  • ai-buddy/ — conversational shopping assistant
  • seller-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"
}

7. Review Entity

(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"
}

Final Entity Count

  • User
  • Product
  • Cart
  • Order
  • Payment
  • Notification

Service–Entity Mapping Table

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages