A full-stack e-commerce application built with React and Node.js for Naksh Jewels jewelry store.
- Product listing with responsive grid layout
- Product cards with image, name, price, and Add to Cart functionality
- Shopping cart with quantity updates and item removal
- State management using React Context API
- Fully responsive design (mobile, tablet, desktop)
- Clean, custom CSS (no UI libraries)
- Local storage persistence for cart items
- RESTful API with Express.js
- Product listing endpoint (GET /api/products)
- Cart management endpoints (GET, POST, PUT, DELETE /api/cart)
- Validation middleware for request data
- Comprehensive error handling
- In-memory data storage
- Environment variable configuration
- Request logging
- Dockerized frontend and backend
- Docker Compose orchestration
- Health checks for both services
- Production-ready configurations
- Multi-stage builds for optimization
- Node.js (v18 or higher)
- Docker and Docker Compose
- Git
- Clone the repository:
git clone <repository-url>
cd ecommerce-project- Start the application:
docker-compose up --build-
Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000/api
- Health Check: http://localhost:5000/health
-
Stop the application:
docker-compose down- Navigate to backend directory:
cd backend- Install dependencies:
npm install- Create .env file (already provided):
PORT=5000
NODE_ENV=development
- Start the server:
npm startThe backend will run on http://localhost:5000
- Navigate to frontend directory:
cd frontend- Install dependencies:
npm install- Create .env file (already provided):
REACT_APP_API_URL=http://localhost:5000/api
- Start the development server:
npm startThe frontend will run on http://localhost:3000
ecommerce-project/
βββ backend/
β βββ data/
β β βββ products.js # Product data
β βββ middleware/
β β βββ errorHandler.js # Error handling middleware
β β βββ validation.js # Request validation
β βββ routes/
β β βββ cart.js # Cart API routes
β β βββ products.js # Product API routes
β βββ .dockerignore
β βββ .env
β βββ Dockerfile
β βββ package.json
β βββ server.js # Express server
β
βββ frontend/
β βββ public/
β β βββ index.html
β βββ src/
β β βββ components/
β β β βββ Header.js # Navigation header
β β β βββ Header.css
β β β βββ ProductCard.js # Product card component
β β β βββ ProductCard.css
β β βββ context/
β β β βββ CartContext.js # Global cart state
β β βββ pages/
β β β βββ Cart.js # Cart page
β β β βββ Cart.css
β β β βββ Products.js # Product listing page
β β β βββ Products.css
β β βββ services/
β β β βββ api.js # API service layer
β β βββ styles/
β β β βββ global.css # Global styles
β β βββ App.js # Main app component
β β βββ index.js # Entry point
β βββ .dockerignore
β βββ .env
β βββ Dockerfile
β βββ nginx.conf
β βββ package.json
β
βββ docker-compose.yml
Get all products
Response:
{
"success": true,
"count": 8,
"data": [
{
"id": "1",
"name": "Diamond Solitaire Ring",
"price": 45000,
"image": "...",
"description": "...",
"category": "Rings",
"inStock": true
}
]
}Get single product by ID
Get all cart items
Response:
{
"success": true,
"data": {
"items": [...],
"total": 45000,
"count": 1
}
}Add item to cart
Request Body:
{
"productId": "1",
"quantity": 1
}Update cart item quantity
Request Body:
{
"quantity": 2
}Remove item from cart
Clear entire cart
- React Context API: Chosen over Redux for simpler state management suitable for this scale
- Functional Components: All components are functional with hooks
- Custom CSS: No UI libraries to demonstrate CSS proficiency
- Responsive Design: Mobile-first approach with breakpoints at 480px, 768px, 1024px
- Local Storage: Cart persistence across page refreshes
- Express.js: Lightweight and flexible framework
- In-memory Storage: Sufficient for demo; easily replaceable with MongoDB
- Middleware Pattern: Clean separation of concerns
- RESTful API: Standard HTTP methods and status codes
- Error Handling: Centralized error handling with custom error messages
- Multi-stage Builds: Optimized frontend build with nginx
- Health Checks: Ensures services are ready before accepting traffic
- Networks: Isolated bridge network for service communication
- Volume Mounts: Prepared for MongoDB integration
- Start the application using Docker Compose
- Navigate to http://localhost:3000
- Browse products on the home page
- Click "Add to Cart" on any product
- View cart badge update in header
- Navigate to cart page
- Update quantities using +/- buttons
- Remove items using Γ button
- Clear cart using "Clear Cart" button
PORT=5000
NODE_ENV=development
REACT_APP_API_URL=http://localhost:5000/api
# Build and start services
docker-compose up --build
# Start in detached mode
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Remove volumes
docker-compose down -v
# Rebuild specific service
docker-compose build backend
docker-compose build frontend- Clean, readable code with meaningful variable names
- Consistent code formatting
- Proper error handling and edge cases
- Modular component structure
- Separation of concerns
- Comments where necessary
- No hardcoded values (using environment variables)
- Empty cart state with user-friendly message
- Product out of stock handling
- Quantity validation (minimum 1)
- Loading states during API calls
- Error states with retry options
- Responsive design for all screen sizes
- Cart persistence using localStorage
- Duplicate product addition (increases quantity)
- Input validation on backend
- Error messages don't expose sensitive info
- CORS enabled for frontend communication
- Environment variables for configuration
- User authentication
- Payment integration
- Product search and filtering
- Product categories page
- Wishlist functionality
- Order history
- Product reviews and ratings
- Admin dashboard
- Real database integration (MongoDB)
- Image optimization
- Performance monitoring
For questions or issues, please create an issue in the repository.
Built by a candidate for Naksh Jewels ReactJS & Node.js Internship
Note: This is a demonstration project showcasing full-stack development skills including React, Node.js, Express, Docker, and clean code practices.