Skip to content

Kalpana0704/ecommerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Naksh Jewels - E-commerce Application

A full-stack e-commerce application built with React and Node.js for Naksh Jewels jewelry store.

πŸš€ Features

Frontend

  • 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

Backend

  • 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

DevOps

  • Dockerized frontend and backend
  • Docker Compose orchestration
  • Health checks for both services
  • Production-ready configurations
  • Multi-stage builds for optimization

πŸ“‹ Prerequisites

  • Node.js (v18 or higher)
  • Docker and Docker Compose
  • Git

πŸ› οΈ Installation & Setup

Option 1: Using Docker (Recommended)

  1. Clone the repository:
git clone <repository-url>
cd ecommerce-project
  1. Start the application:
docker-compose up --build
  1. Access the application:

  2. Stop the application:

docker-compose down

Option 2: Local Development

Backend Setup

  1. Navigate to backend directory:
cd backend
  1. Install dependencies:
npm install
  1. Create .env file (already provided):
PORT=5000
NODE_ENV=development
  1. Start the server:
npm start

The backend will run on http://localhost:5000

Frontend Setup

  1. Navigate to frontend directory:
cd frontend
  1. Install dependencies:
npm install
  1. Create .env file (already provided):
REACT_APP_API_URL=http://localhost:5000/api
  1. Start the development server:
npm start

The frontend will run on http://localhost:3000

πŸ“ Project Structure

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

πŸ”Œ API Endpoints

Products

GET /api/products

Get all products

Response:

{
  "success": true,
  "count": 8,
  "data": [
    {
      "id": "1",
      "name": "Diamond Solitaire Ring",
      "price": 45000,
      "image": "...",
      "description": "...",
      "category": "Rings",
      "inStock": true
    }
  ]
}

GET /api/products/:id

Get single product by ID

Cart

GET /api/cart

Get all cart items

Response:

{
  "success": true,
  "data": {
    "items": [...],
    "total": 45000,
    "count": 1
  }
}

POST /api/cart

Add item to cart

Request Body:

{
  "productId": "1",
  "quantity": 1
}

PUT /api/cart/:id

Update cart item quantity

Request Body:

{
  "quantity": 2
}

DELETE /api/cart/:id

Remove item from cart

DELETE /api/cart

Clear entire cart

🎨 Design Decisions

Frontend

  • 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

Backend

  • 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

Docker

  • 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

πŸ§ͺ Testing the Application

  1. Start the application using Docker Compose
  2. Navigate to http://localhost:3000
  3. Browse products on the home page
  4. Click "Add to Cart" on any product
  5. View cart badge update in header
  6. Navigate to cart page
  7. Update quantities using +/- buttons
  8. Remove items using Γ— button
  9. Clear cart using "Clear Cart" button

πŸ”§ Environment Variables

Backend (.env)

PORT=5000
NODE_ENV=development

Frontend (.env)

REACT_APP_API_URL=http://localhost:5000/api

🚒 Docker Commands

# 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

πŸ“ Code Quality

  • 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)

🎯 Edge Cases Handled

  • 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)

πŸ”’ Security Considerations

  • Input validation on backend
  • Error messages don't expose sensitive info
  • CORS enabled for frontend communication
  • Environment variables for configuration

πŸš€ Future Enhancements

  • 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

πŸ“ž Support

For questions or issues, please create an issue in the repository.

πŸ‘¨β€πŸ’» Developer

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors