A modern, full-stack e-commerce platform built with React, Node.js, Express, and MongoDB. Features M-Pesa payment integration, responsive design, and admin dashboard.
- π¨ Modern, responsive UI with Tailwind CSS & custom brand colors
- β‘ Fast performance with React 18 and Vite
- π Smooth animations with Framer Motion
- π± Mobile-first design
- π Full light/dark mode support
- π Shopping cart with persistent storage
- π³ M-Pesa payment integration
- π Product search and filtering
- π Admin dashboard with real-time analytics
- π¬ Real-time chat system
- π₯ CSV import/export for products & orders
- π Express.js REST API
- ποΈ MongoDB with Mongoose ODM (100% MongoDB)
- π Clerk authentication (JWT-free)
- π° M-Pesa STK Push integration
- π Cloudinary image upload
- π‘οΈ Security middleware (Helmet, CORS, Rate Limiting)
- π Request logging with Morgan & Winston
- π§ͺ Comprehensive error handling
- π Real-time analytics endpoints
- π₯ CSV import/export APIs
- Node.js (v16 or higher)
- MongoDB (local or cloud)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd BEN-MARKET
-
Install dependencies
# Backend cd backend npm install # Frontend cd ../frontend npm install
-
Environment Setup
Create
.envfiles in bothbackend/andfrontend/directories:Backend
.env:# Server PORT=5000 NODE_ENV=development # Database MONGO_URI=mongodb://localhost:27017/benmarket # Clerk Authentication (REQUIRED) CLERK_SECRET_KEY=sk_test_xxxxx CLERK_PUBLISHABLE_KEY=pk_test_xxxxx # Required for @clerk/express middleware CLERK_WEBHOOK_SECRET=whsec_xxxxx # Frontend URL FRONTEND_URL=http://localhost:5173 # Cloudinary (for image uploads) CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name CLOUDINARY_API_KEY=your_cloudinary_api_key CLOUDINARY_API_SECRET=your_cloudinary_api_secret # M-Pesa Configuration (optional) MPESA_CONSUMER_KEY=your_mpesa_consumer_key MPESA_CONSUMER_SECRET=your_mpesa_consumer_secret MPESA_SHORTCODE=174379 MPESA_PASSKEY=your_mpesa_passkey MPESA_CALLBACK_URL=https://your-domain.com/api/mpesa/callback MPESA_ENVIRONMENT=sandbox
Frontend
.env:VITE_API_URL=http://localhost:5000 VITE_CLERK_PUBLISHABLE_KEY=pk_test_xxxxx
-
Seed the database
Basic seed (minimal data):
cd backend npm run seedEnhanced seed (comprehensive test data - recommended for testing):
cd backend npm run seed:enhancedThis will create:
- 100+ products across 12 categories
- 50-100 sample orders (if users exist)
- Loyalty program setup
- Award loyalty points for existing orders
-
Start the development servers
# Terminal 1 - Backend cd backend npm run dev # Terminal 2 - Frontend cd frontend npm run dev
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- Health Check: http://localhost:5000/health
- Browse Products: Visit the homepage to see all available products
- Search & Filter: Use the search bar and category filters to find specific items
- View Details: Click on any product to see detailed information
- Add to Cart: Add items to your cart and adjust quantities
- Checkout: Proceed to checkout and enter your delivery information
- Pay with M-Pesa: Complete payment using M-Pesa STK Push
- Login: Use admin credentials ([email protected] / AdminPass123!)
- Manage Products: Add, edit, or delete products
- View Orders: Monitor customer orders and payment status
- Analytics: View sales data and insights
POST /api/auth/register- User registrationPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutPOST /api/auth/refresh/refresh- Refresh access token
GET /api/products- Get all productsGET /api/products/:id- Get single productPOST /api/products- Create product (admin)PUT /api/products/:id- Update product (admin)DELETE /api/products/:id- Delete product (admin)
POST /api/orders- Create orderGET /api/orders/:id- Get order details
POST /api/mpesa/stkpush- Initiate STK pushPOST /api/mpesa/callback- Handle payment callback
POST /api/upload/image- Upload image to CloudinaryGET /api/upload/signed- Get signed upload URL
BEN-MARKET/
βββ backend/
β βββ Controllers/ # Route controllers
β βββ Models/ # Database models
β βββ Routes/ # API routes
β βββ middleware/ # Custom middleware
β βββ config/ # Configuration files
β βββ seed/ # Database seeders
β βββ tests/ # Test files
βββ frontend/
β βββ src/
β β βββ components/ # React components
β β βββ pages/ # Page components
β β βββ context/ # React context
β β βββ api/ # API services
β β βββ assets/ # Static assets
β βββ public/ # Public assets
βββ docs/ # Documentation
Backend:
npm run dev- Start development server with nodemonnpm start- Start production servernpm run seed- Seed database with basic sample datanpm run seed:enhanced- Seed database with comprehensive test data (100+ products, orders, loyalty points)
Frontend:
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production build
- Sandbox Testing: Use the provided sandbox credentials
- Test Phone Numbers: Use
254708374149for testing - Callback URL: Use ngrok to expose your local server:
Update
ngrok http 5000
MPESA_CALLBACK_URLin your.envfile
- Connect your repository
- Set environment variables
- Deploy
- Connect your repository
- Set build command:
npm run build - Set output directory:
dist - Deploy
Make sure to set all required environment variables in your production environment, especially:
MONGO_URI- Production MongoDB connection stringMPESA_*- Production M-Pesa credentialsCLOUDINARY_*- Production Cloudinary credentials
- CORS protection
- Rate limiting
- Helmet.js security headers
- Input validation and sanitization
- Environment variable protection
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For support, email [email protected] or create an issue in the repository.
- Admin dashboard with real-time analytics
- CSV import/export for products & orders
- Real-time chat system
- Order tracking
- Product reviews and ratings
- Wishlist functionality
- Clerk authentication (JWT-free)
- Full light/dark mode support
- Professional brand color palette
- Production-ready security
- Email notifications
- Multi-language support
- Mobile app (React Native)
- Advanced analytics & reporting
Built with β€οΈ by the BenMarket Team