This repository contains the backend code for the Mebius eCommerce project. It is built with Node.js, Express, and MongoDB to provide a scalable, secure, and efficient e-commerce backend with integrated payment processing.
- Product Management: Complete CRUD operations for products and categories
- Shopping Cart: Persistent cart management with user authentication
- Order Processing: Comprehensive order lifecycle management
- User Management: Authentication and authorization with Clerk integration
- Wishlist System: User wishlist management and persistence
- Stripe Integration: Secure payment processing with PaymentIntents
- Multiple Payment Methods: Support for credit/debit cards and COD
- Webhook Handling: Real-time payment status updates
- Payment Security: PCI-compliant payment processing
- Order Payment Tracking: Complete payment status management
- Clerk Integration: Modern authentication and user management
- JWT Token Validation: Secure API endpoint protection
- CORS Configuration: Cross-origin resource sharing setup
- Input Validation: Comprehensive request validation and sanitization
- Error Handling: Global error handling with proper HTTP status codes
- MongoDB Integration: Scalable NoSQL database with Mongoose ODM
- Data Models: Structured schemas for products, orders, users, and reviews
- Review System: User-generated product reviews and ratings
- Search & Filtering: Advanced product discovery capabilities
- Node.js for the backend runtime environment
- Express.js for the web application framework
- MongoDB & Mongoose for database management and ODM
- Stripe for payment processing and webhooks
- Clerk for authentication and user management
- Dotenv for environment variable management
- CORS for cross-origin resource sharing
- Helmet for security headers
- Node.js (v16 or higher)
- npm or yarn package manager
- MongoDB database (local or cloud)
- Stripe account for payment processing
- Clerk account for authentication
-
Clone the repository:
git clone https://github.com/DLSNemsara/mebius-backend.git
-
Navigate to the project directory:
cd mebius-backend
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory:PORT=8000 MONGO_URI=your_mongodb_connection_string STRIPE_SECRET_KEY=your_stripe_secret_key CLERK_SECRET_KEY=your_clerk_secret_key CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
-
Start the development server:
npm run dev
-
Verify the server is running: Navigate to
http://localhost:8000/api/health
npm run dev
- Start development server with nodemonnpm start
- Start production servernpm run build
- Build TypeScript to JavaScriptnpm run lint
- Run ESLintnpm run lint:fix
- Fix ESLint issues
- Local MongoDB instance
- Development Stripe keys
- Local Clerk configuration
- CORS enabled for localhost frontend
- Cloud MongoDB (MongoDB Atlas)
- Production Stripe keys
- Production Clerk configuration
- CORS configured for deployed frontend
src/
├── api/ # API routes and middleware
│ ├── middleware/ # Custom middleware functions
│ └── routes/ # Route definitions
├── application/ # Business logic layer
├── domain/ # Data models and interfaces
├── infrastructure/ # External services and database
└── index.ts # Application entry point
POST /api/auth/verify
- Verify Clerk JWT tokens
GET /api/products
- Get all products with filteringGET /api/products/:id
- Get product by IDGET /api/categories
- Get all categories
POST /api/orders
- Create new orderGET /api/orders
- Get user ordersGET /api/orders/:id
- Get order by IDPATCH /api/orders/:id
- Update order status
GET /api/wishlist
- Get user wishlistPOST /api/wishlist
- Add product to wishlistDELETE /api/wishlist/:productId
- Remove product from wishlist
POST /api/reviews
- Create product reviewGET /api/reviews/:productId
- Get product reviews
POST /api/payment/webhook
- Stripe webhook endpoint
The backend integrates with Stripe for secure payment processing:
- Payment Intent Creation: Creates PaymentIntents for card payments
- Webhook Handling: Processes Stripe webhooks for payment updates
- Order Status Updates: Automatically updates order status based on payment events
- Metadata Management: Links Stripe payments to internal orders
- Configure webhook endpoint:
https://your-domain.com/api/payment/webhook
- Select events:
checkout.session.completed
,payment_intent.succeeded
,payment_intent.payment_failed
- Copy webhook signing secret to environment variables
- Frontend Authentication: Clerk handles user sign-up/sign-in
- JWT Token: Clerk provides JWT tokens for authenticated requests
- Backend Verification: Backend verifies tokens using Clerk's public key
- Protected Routes: API endpoints check authentication before processing
The backend is deployed on Render:
- Automatic deployments from main branch
- Environment variable configuration
- MongoDB Atlas integration
- SSL certificate management
- Use Postman or similar tools for endpoint testing
- Test authentication flows
- Verify payment webhook handling
- Check error handling scenarios
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
For any inquiries or feedback, please contact us at sinelnemsara19@gmail.com.
Mebius Backend - Secure E-commerce API