An AI-powered e-commerce platform with personalized product recommendations using Collaborative Filtering.
SmartShop Hub is a demonstration project showcasing modern e-commerce development with integrated artificial intelligence. The platform uses a collaborative filtering algorithm to analyze user behavior and provide personalized product recommendations based on similar users' preferences.
This project demonstrates:
- Full-stack web development (React + Node.js + MongoDB)
- AI/ML integration for real-world applications
- RESTful API design and documentation
- GDPR-compliant data handling
- Modern UI/UX with responsive design
- Automated testing and code quality
- Product Catalog: Browse 100+ electronics and gadgets
- Advanced Filtering: Filter by category, brand, price range, and search
- Active Filters Display: Visual badges showing applied filters with one-click removal
- Shopping Cart: Add, update, and remove products
- Secure Checkout: Complete order placement with shipping details
- Order History: View past orders and track status
- User Authentication: JWT-based secure login and registration
- Dynamic Breadcrumbs: Smart navigation showing category and product name
- Category Dropdown: Quick access to all product categories from navbar
- Search Functionality: Real-time product search integrated in navbar
- Mobile-Optimized: Responsive hamburger menu with full navigation
- Comprehensive Footer: Professional footer with links, contact info, and social media
- Personalized Recommendations: AI-driven product suggestions based on user behavior
- Similar Products: Find related items using collaborative filtering
- Behavioral Tracking: Track views, clicks, add-to-cart, and purchases (GDPR compliant)
- Cold Start Handling: Popular products for new users
- Real-time Learning: Recommendations improve as users interact
- GDPR Compliant: User consent for data tracking
- Data Anonymization: Automatic data expiration after 180 days
- Privacy Controls: Users can enable/disable personalized recommendations
- Node.js + Express: RESTful API server
- MongoDB: NoSQL database for flexible data storage
- JWT: Secure authentication
- Swagger: API documentation
- Jest: Unit testing
- Docker: Containerized database deployment
- React: Component-based UI framework
- React Router: Client-side routing
- Tailwind CSS: Utility-first styling
- Axios: HTTP client
- React Hot Toast: Notifications
- Collaborative Filtering: User-based recommendation algorithm
- Cosine Similarity: Calculate user similarity scores
- Caching: Performance optimization for recommendations
- Node.js (v16 or higher)
- Docker Desktop (recommended) OR MongoDB v5+ installed locally
- npm or yarn
-
Clone the repository
git clone <repository-url> cd smartshop-hub
-
Install dependencies
npm run install-all
-
Set up environment variables
Backend (.env):
cd backend cp .env.example .envEdit
backend/.env:PORT=5000 NODE_ENV=development MONGODB_URI=mongodb://localhost:27017/smartshop-hub JWT_SECRET=your-super-secret-jwt-key-change-this JWT_EXPIRE=7d FRONTEND_URL=http://localhost:3000 RECOMMENDATION_CACHE_TTL=3600 MIN_INTERACTIONS_FOR_RECOMMENDATIONS=3
Frontend (.env):
cd ../frontend cp .env.example .envEdit
frontend/.env:REACT_APP_API_URL=http://localhost:5000/api REACT_APP_NAME=SmartShop Hub
The easiest way to run MongoDB is using Docker:
# Start MongoDB with Docker Compose
docker-compose up -d
# Verify MongoDB is running
docker-compose ps
# View MongoDB logs
docker-compose logs -f mongodbMongo Express (Web UI) is included and accessible at:
- URL: http://localhost:8081
- Username:
admin - Password:
admin123
Docker Commands:
# Stop MongoDB
docker-compose down
# Stop and remove data (fresh start)
docker-compose down -v
# Restart MongoDB
docker-compose restart mongodbIf you prefer to run MongoDB locally:
# Windows
mongod
# Or as Windows service
net start MongoDB
# macOS/Linux
sudo systemctl start mongodPopulate the database with sample data:
cd backend
npm run seedThis creates:
- 120 products (electronics: laptops, smartphones, headphones, etc.)
- 60 users with diverse preferences
- 600 interactions (views, clicks, cart additions, purchases)
Expected output:
✅ Created 120 products
✅ Created 60 users
✅ Created 600 interactions
# From project root
npm run devTerminal 1 - Backend:
cd backend
npm run devExpected output:
🚀 Server running on port 5000
📚 API Documentation: http://localhost:5000/api-docs
🏥 Health Check: http://localhost:5000/health
MongoDB Connected: localhost
Terminal 2 - Frontend:
cd frontend
npm startBrowser opens automatically at http://localhost:3000
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- API Documentation: http://localhost:5000/api-docs (Swagger UI)
- MongoDB Web UI: http://localhost:8081 (if using Docker)
Main page featuring personalized product recommendations and highlighted categories
Color-coded filter badges (Search, Category, Brand, Price) with individual removal buttons
Complete product information with smart breadcrumbs: Home > Products > Category > Product Name
Contextual navigation showing current location with clickable category links
Cart management with quantity controls, item removal, and order summary
User dashboard with order history and privacy controls for AI tracking
Fully responsive layout with hamburger menu and touch-optimized interface
Interactive API documentation with all endpoints and request/response schemas
Test the application with these pre-seeded credentials:
Email: demo@example.com
Password: password123
- Enable Tracking: Log in → Profile → Settings → Enable personalized recommendations
- Browse Products: View 5-10 different products to generate interaction data
- Add to Cart: Add 2-3 products to your cart
- See Recommendations: Return to homepage to see personalized "Recommended For You" section
- Similar Products: View any product detail page to see "You May Also Like" suggestions
- Navigate to Profile → Settings
- Toggle "Enable Personalized Recommendations"
- When disabled: System shows popular products instead of personalized ones
- Users can enable/disable at any time
smartshop-hub/
├── backend/
│ ├── src/
│ │ ├── ai/ # AI recommendation engine
│ │ │ ├── recommendation-engine.js
│ │ │ └── data-tracking.js
│ │ ├── config/ # App configuration
│ │ │ ├── database.js
│ │ │ └── swagger.js
│ │ ├── controllers/ # Request handlers
│ │ ├── middleware/ # Auth, validation, errors
│ │ ├── models/ # MongoDB schemas
│ │ ├── routes/ # API endpoints
│ │ ├── scripts/ # Utility scripts
│ │ │ └── seed-database.js
│ │ ├── utils/ # Helper functions
│ │ └── server.js # Express app entry
│ ├── tests/ # Jest unit tests
│ ├── .env.example
│ ├── jest.config.js
│ └── package.json
├── frontend/
│ ├── public/
│ ├── src/
│ │ ├── components/ # Reusable components
│ │ ├── config/ # API configuration
│ │ ├── context/ # React Context (Auth, Cart)
│ │ ├── pages/ # Route pages
│ │ ├── services/ # API service layer
│ │ ├── App.js # Main app + routing
│ │ ├── index.css # Tailwind styles
│ │ └── index.js # React entry point
│ ├── .env.example
│ ├── tailwind.config.js
│ ├── postcss.config.js
│ └── package.json
├── docs/
│ └── AI_MODEL_DOCUMENTATION.md # Detailed AI explanation
├── docker-compose.yml # MongoDB + Mongo Express
├── .gitignore
├── README.md
└── package.json # Root scripts
POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/me- Get current user profilePUT /api/auth/preferences- Update user preferences
GET /api/products- Get all products (with filters)GET /api/products/:id- Get single productGET /api/products/categories/list- Get all categoriesGET /api/products/brands/list- Get all brandsGET /api/products/featured/list- Get featured products
POST /api/orders- Create new orderGET /api/orders- Get user's ordersGET /api/orders/:id- Get order by ID
GET /api/recommendations- Get personalized recommendationsGET /api/recommendations/popular- Get popular productsGET /api/recommendations/similar/:id- Get similar productsPOST /api/recommendations/track- Track user interactionGET /api/recommendations/history- Get interaction history
Full API documentation available at: http://localhost:5000/api-docs
cd backend
npm testcd backend
npm test -- --coverage- User registration and login
- Product browsing and filtering
- Shopping cart operations
- Checkout and order creation
- AI recommendations (with tracking enabled)
- Popular products (with tracking disabled)
- Profile and order history
- Privacy settings toggle
The recommendation engine uses User-Based Collaborative Filtering with cosine similarity.
- Data Collection: Tracks user interactions (views, clicks, cart, purchases)
- Similarity Calculation: Finds users with similar behavior patterns
- Recommendation Generation: Suggests products liked by similar users
- Continuous Learning: Updates recommendations as new interactions occur
- Weighted Interactions: Purchase (5) > Add to Cart (3) > Click (2) > View (1)
- Cold Start Handling: Popular products for new users
- Performance: 1-hour caching, MongoDB indexing
- Privacy: GDPR compliant, user consent required
For detailed algorithm explanation, see AI_MODEL_DOCUMENTATION.md
The project includes Docker Compose configuration for easy deployment:
# Production deployment with Docker
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -fcd backend
# Build (if using TypeScript) - not needed for this project
# npm run build
# Start production server
NODE_ENV=production npm startcd frontend
# Create production build
npm run build
# Serve with static server (e.g., nginx, serve)
npx serve -s build -l 3000Update these for production deployment:
Backend:
NODE_ENV=production
MONGODB_URI=example-mongodb-cloud-url
JWT_SECRET=generate-strong-random-secret-here
FRONTEND_URL=https://yourdomain.comFrontend:
REACT_APP_API_URL=https://api.yourdomain.com/api- Use MongoDB Atlas or managed MongoDB instance
- Generate strong JWT secret (32+ characters)
- Configure CORS for production domain
- Enable HTTPS/SSL
- Set up proper logging and monitoring
- Configure rate limiting
- Enable production error tracking
# With Docker
docker exec smartshop-mongodb mongodump --db=smartshop-hub --out=/data/backup
docker cp smartshop-mongodb:/data/backup ./backup
# Local MongoDB
mongodump --db=smartshop-hub --out=./backup# With Docker
docker cp ./backup smartshop-mongodb:/data/backup
docker exec smartshop-mongodb mongorestore --db=smartshop-hub /data/backup/smartshop-hub
# Local MongoDB
mongorestore --db=smartshop-hub ./backup/smartshop-hub# Re-run seed script
cd backend
npm run seedDocker:
# Check if container is running
docker-compose ps
# Restart MongoDB
docker-compose restart mongodb
# View logs
docker-compose logs mongodbLocal:
# Check if MongoDB is running
# Windows
tasklist | findstr mongod
# macOS/Linux
ps aux | grep mongod# Check what's using port 5000 (Windows)
netstat -ano | findstr :5000
# Kill the process (Windows)
taskkill //F //PID <PID>
# macOS/Linux
lsof -ti:5000 | xargs kill -9If breadcrumbs show "Loading..." indefinitely on product detail pages:
Symptoms:
- Breadcrumbs stuck on "Loading..."
- Product page displays correctly but navigation doesn't update
Solutions:
-
Check Backend Status: Ensure backend is running on port 5000
curl http://localhost:5000/health
-
Verify Database Connection: MongoDB should be accessible
docker-compose ps # if using Docker -
Clear Browser Cache: Hard refresh the page
- Windows/Linux:
Ctrl + Shift + R - macOS:
Cmd + Shift + R
- Windows/Linux:
-
Check Console Errors: Open browser DevTools (F12) and check for API errors
-
Test API Endpoint: Verify the product API responds correctly
curl http://localhost:5000/api/products/<product-id>
Expected API Response:
{
"success": true,
"data": {
"_id": "...",
"name": "Product Name",
"category": "category-name",
...
}
}Common Issue: If the API returns data in a different structure, breadcrumbs won't parse it correctly. The component expects response.data.data.name and response.data.data.category.
If clicking a category in the navbar dropdown doesn't update the product list when already on /products page:
Symptoms:
- Dropdown menu works on other pages
- On products page, clicking categories doesn't filter results
- URL doesn't update or filters don't apply
Solutions:
-
Hard Refresh: Clear component state with
Ctrl + Shift + R -
Check URL: After clicking, URL should update to
/products?category=<category-name> -
Verify Active Filters: Filter badges should appear above the product grid
-
Clear Local Storage: Sometimes cached state interferes
// In browser console (F12) localStorage.clear() sessionStorage.clear()
Technical Note: The Products component uses React Router's useSearchParams hook to synchronize filters with URL parameters. Changes are reflected in real-time.
If filter badges don't appear even when filters are applied:
Check:
- URL parameters are present:
/products?category=laptops - Browser console for JavaScript errors
- Filters state in React DevTools
Fix: The hasActiveFilters variable should be true when any filter is active. Check that filters are properly set in component state.
# Clear cache and reinstall
cd frontend
rm -rf node_modules package-lock.json
npm install
# If build fails
npm run build -- --verboseThis is a demonstration project showcasing full-stack development with AI integration. Feel free to:
- Report bugs or issues
- Suggest new features
- Submit pull requests
- Use as learning reference
- Fork for your own projects
MIT License - feel free to use this project for learning, portfolio, or commercial purposes.
This project demonstrates:
✅ Full-stack Development: Complete MERN stack implementation ✅ AI Integration: Real-world machine learning application ✅ API Design: RESTful architecture with Swagger documentation ✅ Modern Frontend: React with hooks, context, and responsive design ✅ Security: JWT authentication, password hashing, CORS ✅ Privacy: GDPR-compliant data tracking with user consent ✅ Testing: Unit tests with Jest ✅ DevOps: Docker containerization, environment configuration ✅ Code Quality: Clean code, comments, documentation ✅ Best Practices: Industry-standard patterns and architecture
Francesco di Biase
Full-Stack Developer specializing in AI-powered web applications.
This project is part of a portfolio demonstrating modern web development capabilities and AI integration skills.
Resources:
- 📚 Check the
/api-docsendpoint for interactive API exploration - 🤖 Review
docs/AI_MODEL_DOCUMENTATION.mdfor detailed AI implementation - 📖 See
docs/FEATURES.mdfor comprehensive feature documentation - 📝 Read
CHANGELOG.mdfor version history and updates
Built with: Node.js, React, MongoDB, Express, TailwindCSS, Docker Key Features: AI Recommendations, E-commerce, GDPR Compliance, RESTful API Purpose: Portfolio demonstration of full-stack + AI development skills Year: 2025