A full-stack MERN e-commerce application built with microservices architecture, featuring 4 separate Node.js backend services and a React frontend.
This application demonstrates modern microservices architecture with the following components:
Frontend (React) → API Gateway → Microservices
├── User Service (3001)
├── Product Service (3002)
├── Cart Service (3003)
└── Order Service (3004)
- Runtime: Node.js with Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT tokens
- Architecture: RESTful APIs with microservices
- Framework: React 18
- Routing: React Router
- State Management: React Query + Context API
- HTTP Client: Axios
- Styling: CSS3 with responsive design
- User registration and authentication
- Profile management
- JWT token generation and validation
- User data persistence
Endpoints:
POST /api/auth/register- User registrationPOST /api/auth/login- User authenticationGET /api/auth/me- Get current userGET /api/users/profile- Get user profilePUT /api/users/profile- Update user profile
- Product catalog management
- Category management
- Product search and filtering
- Inventory tracking
Endpoints:
GET /api/products- Get products with filtering/paginationGET /api/products/:id- Get single productPOST /api/products- Create product (admin)PUT /api/products/:id- Update product (admin)DELETE /api/products/:id- Soft delete product (admin)GET /api/categories- Get all categoriesPOST /api/categories- Create category (admin)
- Shopping cart management
- Add/remove/update cart items
- Cart validation
- Integration with Product Service
Endpoints:
GET /api/cart/:userId- Get user's cartPOST /api/cart/:userId/items- Add item to cartPUT /api/cart/:userId/items/:productId- Update cart itemDELETE /api/cart/:userId/items/:productId- Remove cart itemDELETE /api/cart/:userId- Clear entire cartPOST /api/cart/:userId/validate- Validate cart items
- Order creation and management
- Payment processing simulation
- Order status tracking
- Integration with Cart and Product Services
Endpoints:
GET /api/orders/user/:userId- Get user's ordersGET /api/orders/:id- Get single orderPOST /api/orders- Create new orderPUT /api/orders/:id/status- Update order statusDELETE /api/orders/:id- Cancel orderPOST /api/payments/process- Process paymentPOST /api/payments/refund- Process refund
- Node.js 16+ and npm
- MongoDB (local or cloud instance)
- Clone the repository
git clone <repository-url>
cd ecommerce-microservices- Install dependencies for each service
# Install User Service dependencies
cd backend/user-service && npm install
# Install Product Service dependencies
cd ../product-service && npm install
# Install Cart Service dependencies
cd ../cart-service && npm install
# Install Order Service dependencies
cd ../order-service && npm install
# Install Frontend dependencies
cd ../../frontend && npm install- Set up environment variables
Create .env files in each service directory:
backend/user-service/.env:
PORT=3001
MONGODB_URI=mongodb://localhost:27017/ecommerce_users
JWT_SECRET=your-jwt-secret-keybackend/product-service/.env:
PORT=3002
MONGODB_URI=mongodb://localhost:27017/ecommerce_productsbackend/cart-service/.env:
PORT=3003
MONGODB_URI=mongodb://localhost:27017/ecommerce_carts
PRODUCT_SERVICE_URL=http://localhost:3002backend/order-service/.env:
PORT=3004
MONGODB_URI=mongodb://localhost:27017/ecommerce_orders
CART_SERVICE_URL=http://localhost:3003
PRODUCT_SERVICE_URL=http://localhost:3002
USER_SERVICE_URL=http://localhost:3001frontend/.env:
REACT_APP_USER_SERVICE_URL=http://localhost:3001
REACT_APP_PRODUCT_SERVICE_URL=http://localhost:3002
REACT_APP_CART_SERVICE_URL=http://localhost:3003
REACT_APP_ORDER_SERVICE_URL=http://localhost:3004** Run services individually**
Terminal 1 - User Service:
cd backend/user-service && npm startTerminal 2 - Product Service:
cd backend/product-service && npm startTerminal 3 - Cart Service:
cd backend/cart-service && npm startTerminal 4 - Order Service:
cd backend/order-service && npm startTerminal 5 - Frontend:
cd frontend && npm startThe application will be available at:
- Frontend: http://localhost:3000
- User Service: http://localhost:3001
- Product Service: http://localhost:3002
- Cart Service: http://localhost:3003
- Order Service: http://localhost:3004
- Authentication: Register and login with JWT tokens
- Product Browsing: View products with search, filtering, and pagination
- Shopping Cart: Add, update, and remove items
- Checkout Process: Complete order placement with shipping and payment
- Order Management: View order history and track status
- Profile Management: Update personal information and addresses
- Product and category management
- Order status updates
- Inventory management
- User management
- Microservices Architecture: Loosely coupled services
- RESTful APIs: Standard HTTP methods and status codes
- Data Validation: Input validation and error handling
- Cross-Service Communication: HTTP-based service interactions
- Responsive Design: Mobile-friendly user interface
- Error Handling: Comprehensive error management
- Loading States: User-friendly loading indicators
ecommerce-microservices/
├── backend/
│ ├── user-service/
│ │ ├── models/
│ │ ├── routes/
│ │ ├── middleware/
│ │ ├── server.js
│ │ └── package.json
│ ├── product-service/
│ │ ├── models/
│ │ ├── routes/
│ │ ├── server.js
│ │ └── package.json
│ ├── cart-service/
│ │ ├── models/
│ │ ├── routes/
│ │ ├── server.js
│ │ └── package.json
│ └── order-service/
│ ├── models/
│ ├── routes/
│ ├── server.js
│ └── package.json
├── frontend/
│ ├── public/
│ ├── src/
│ │ ├── components/
│ │ ├── contexts/
│ │ ├── pages/
│ │ ├── services/
│ │ ├── App.js
│ │ └── index.js
│ └── package.json
├── package.json
└── README.md
You can test the APIs using tools like Postman or curl:
# Health check for all services
curl http://localhost:3001/health
curl http://localhost:3002/health
curl http://localhost:3003/health
curl http://localhost:3004/health
# Register a new user
curl -X POST http://localhost:3001/api/auth/register \
-H "Content-Type: application/json" \
-d '{"firstName":"John","lastName":"Doe","email":"[email protected]","password":"password123"}'
# Get products
curl http://localhost:3002/api/products
# Get categories
curl http://localhost:3002/api/categories- Environment Variables: Use proper environment variable management
- Database: Use MongoDB Atlas or other managed database services
- Process Management: Use PM2 or similar for process management
- Load Balancing: Implement load balancing for high availability
- Monitoring: Add logging and monitoring solutions
- Security: Implement rate limiting, CORS, and other security measures
Each service can be containerized with Docker:
# Example Dockerfile for a service
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 3001
CMD ["npm", "start"]- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.
For support and questions:
- Check the documentation
- Review API endpoints and expected payloads
- Ensure all services are running
- Verify database connections
- Check environment variables
- API Gateway: Centralized request routing and authentication
- Docker Containerization: Full containerization with docker-compose
- Message Queues: Async communication between services
- Caching: Redis caching for improved performance
- Search Engine: Elasticsearch for advanced product search
- File Upload: Image upload and management
- Email Service: Order confirmations and notifications
- Admin Dashboard: Administrative interface
- Analytics: Order and user analytics
- Payment Integration: Real payment gateway integration