Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’Š PharmaEZ β€” Pharmacy & Healthcare E-Commerce Platform

A full-featured MERN Stack (MongoDB, Express.js, React.js, Node.js) e-commerce application for a pharmacy and healthcare store.


πŸ“‹ Table of Contents


βœ… Features

Customer Features

  • πŸ” User registration, login, and JWT authentication
  • πŸ›οΈ Browse products by categories and subcategories
  • πŸ” Full-text search with filters (category, price, prescription required)
  • πŸ›’ Shopping cart with quantity management
  • ❀️ Wishlist management
  • πŸ’³ Multi-step checkout with address selection
  • πŸ’Š Prescription upload and verification workflow
  • πŸ“¦ Order tracking with real-time status updates
  • ⭐ Product reviews and ratings system
  • 🎁 Loyalty points system (1 point per β‚Ή10 spent)
  • πŸ“ Multiple delivery addresses management
  • πŸ‘€ Personal profile management

Admin Features

  • πŸ“Š Analytics dashboard with revenue charts
  • πŸ“¦ Complete order management with status updates
  • πŸ’Š Product catalogue management (CRUD)
  • πŸ‘₯ User account management
  • πŸ“‹ Prescription review and approval workflow
  • 🏭 Inventory monitoring with low-stock alerts
  • πŸ“ˆ Sales and revenue reporting

Healthcare-Specific Features

  • Prescription (Rx) required flag on medicines
  • Salt/generic name tracking
  • Dosage form and strength information
  • Side effects and usage instructions
  • Batch number and expiry date management
  • Prescription upload and pharmacist review workflow
  • Medicine categories: OTC, Prescription, Vitamins, Medical Devices, Baby Care, etc.

πŸ›  Tech Stack

Layer Technology
Frontend React.js 18, React Router v6, Context API
Backend Node.js, Express.js
Database MongoDB with Mongoose ODM
Authentication JWT (JSON Web Tokens) + bcryptjs
File Upload Multer
Styling Custom CSS with CSS Variables
HTTP Client Axios
Icons React Icons (Feather Icons)
Toast Notifications React Hot Toast
Build Tool Vite

πŸ“ Project Structure

pharmaez/
β”œβ”€β”€ server/                     # Backend (Node.js + Express)
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── db.js               # MongoDB connection
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ authController.js   # Auth, profile, addresses, prescriptions
β”‚   β”‚   β”œβ”€β”€ productController.js# Products, reviews
β”‚   β”‚   β”œβ”€β”€ cartController.js   # Shopping cart
β”‚   β”‚   β”œβ”€β”€ orderController.js  # Orders, admin stats
β”‚   β”‚   └── adminController.js  # Admin: users, prescriptions, config
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ auth.js             # JWT protect + adminOnly + generateToken
β”‚   β”‚   └── errorHandler.js     # Global error handler + 404
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ User.js             # User schema (addresses, prescriptions, wishlist)
β”‚   β”‚   β”œβ”€β”€ Product.js          # Product schema (medical fields, reviews)
β”‚   β”‚   β”œβ”€β”€ Cart.js             # Cart schema
β”‚   β”‚   β”œβ”€β”€ Order.js            # Order schema (status history, prescription)
β”‚   β”‚   └── AdminConfig.js      # Banners, settings
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”‚   β”œβ”€β”€ productRoutes.js
β”‚   β”‚   β”œβ”€β”€ cartRoutes.js
β”‚   β”‚   β”œβ”€β”€ orderRoutes.js
β”‚   β”‚   └── adminRoutes.js
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   └── seeder.js           # Database seeder
β”‚   β”œβ”€β”€ uploads/                # Uploaded prescription files
β”‚   β”œβ”€β”€ .env.example
β”‚   β”œβ”€β”€ index.js                # Express server entry point
β”‚   └── package.json
β”‚
└── client/                     # Frontend (React.js + Vite)
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ assets/styles/
    β”‚   β”‚   β”œβ”€β”€ global.css      # Global styles, utilities, CSS variables
    β”‚   β”‚   └── components.css  # Shared component styles
    β”‚   β”œβ”€β”€ components/
    β”‚   β”‚   β”œβ”€β”€ admin/
    β”‚   β”‚   β”‚   β”œβ”€β”€ AdminLayout.jsx  # Admin sidebar layout
    β”‚   β”‚   β”‚   └── AdminLayout.css
    β”‚   β”‚   β”œβ”€β”€ common/
    β”‚   β”‚   β”‚   β”œβ”€β”€ ProductCard.jsx  # Reusable product card
    β”‚   β”‚   β”‚   └── ProductCard.css
    β”‚   β”‚   └── layout/
    β”‚   β”‚       β”œβ”€β”€ Navbar.jsx   # Responsive navigation + search
    β”‚   β”‚       β”œβ”€β”€ Navbar.css
    β”‚   β”‚       β”œβ”€β”€ Footer.jsx
    β”‚   β”‚       └── Footer.css
    β”‚   β”œβ”€β”€ context/
    β”‚   β”‚   β”œβ”€β”€ AuthContext.jsx  # Global auth state
    β”‚   β”‚   └── CartContext.jsx  # Global cart state
    β”‚   β”œβ”€β”€ pages/
    β”‚   β”‚   β”œβ”€β”€ admin/
    β”‚   β”‚   β”‚   β”œβ”€β”€ AdminDashboard.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ AdminProducts.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ AdminProductForm.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ AdminOrders.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ AdminUsers.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ AdminInventory.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ AdminPrescriptions.jsx
    β”‚   β”‚   β”‚   └── AdminPages.css
    β”‚   β”‚   β”œβ”€β”€ auth/
    β”‚   β”‚   β”‚   β”œβ”€β”€ AuthPages.jsx  (LoginPage + RegisterPage)
    β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ RegisterPage.jsx
    β”‚   β”‚   β”‚   └── AuthPages.css
    β”‚   β”‚   β”œβ”€β”€ user/
    β”‚   β”‚   β”‚   β”œβ”€β”€ UserDashboard.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ OrdersPage.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ OrderDetailPage.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ WishlistPage.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ PrescriptionsPage.jsx
    β”‚   β”‚   β”‚   β”œβ”€β”€ ProfilePage.jsx
    β”‚   β”‚   β”‚   └── UserPages.css
    β”‚   β”‚   β”œβ”€β”€ HomePage.jsx         # Hero, categories, featured
    β”‚   β”‚   β”œβ”€β”€ HomePage.css
    β”‚   β”‚   β”œβ”€β”€ ProductsPage.jsx     # Listing with filters/pagination
    β”‚   β”‚   β”œβ”€β”€ ProductsPage.css
    β”‚   β”‚   β”œβ”€β”€ ProductDetailPage.jsx # Detail, tabs, reviews
    β”‚   β”‚   β”œβ”€β”€ ProductDetailPage.css
    β”‚   β”‚   β”œβ”€β”€ CartPage.jsx
    β”‚   β”‚   β”œβ”€β”€ CartPage.css
    β”‚   β”‚   β”œβ”€β”€ CheckoutPage.jsx     # 3-step checkout
    β”‚   β”‚   β”œβ”€β”€ CheckoutPage.css
    β”‚   β”‚   └── OrderConfirmationPage.jsx
    β”‚   β”œβ”€β”€ utils/
    β”‚   β”‚   └── api.js          # Axios instance with interceptors
    β”‚   β”œβ”€β”€ App.jsx             # Routes + providers
    β”‚   └── main.jsx
    β”œβ”€β”€ index.html
    β”œβ”€β”€ vite.config.js
    └── package.json

βš™οΈ Prerequisites

  • Node.js v18 or higher
  • MongoDB v6 or higher (local or MongoDB Atlas)
  • npm or yarn

πŸš€ Installation & Setup

1. Clone / Download the Project

cd pharmaez

2. Backend Setup

cd server
npm install

Create your environment file:

cp .env.example .env

Edit .env with your values (see Environment Variables).

3. Frontend Setup

cd ../client
npm install

πŸ”§ Environment Variables

Create server/.env with these values:

PORT=8000
MONGO_URI=mongodb://localhost:27017/pharmaez
JWT_SECRET=pharmaez_super_secret_jwt_key_change_in_production
JWT_EXPIRES_IN=7d
NODE_ENV=development

For MongoDB Atlas (Cloud):

MONGO_URI=mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/pharmaez?retryWrites=true&w=majority

🌱 Seeding Sample Data

After setting up your .env, run the seeder to populate the database with:

  • 1 Admin user
  • 1 Sample customer
  • 12 Healthcare products across all categories
cd server
npm run seed

Default login credentials after seeding:

Role Email Password
Admin admin@pharmaez.com admin123
User raj@example.com user123

▢️ Running the Application

Development Mode (recommended β€” runs both frontend and backend)

Terminal 1 β€” Backend:

cd server
npm run dev       # Uses nodemon for hot-reload
# Server starts at http://localhost:8000

Terminal 2 β€” Frontend:

cd client
npm run dev       # Vite dev server with HMR
# App starts at http://localhost:5173

Open your browser at http://localhost:5173

Production Build

# Build frontend
cd client
npm run build
# dist/ folder is created

# Start backend in production
cd ../server
NODE_ENV=production npm start

πŸ“‘ API Documentation

Base URL: http://localhost:8000/api

Authentication Endpoints

Method Endpoint Access Description
POST /auth/register Public Register new user
POST /auth/login Public Login and get JWT token
GET /auth/profile Private Get user profile + wishlist
PUT /auth/profile Private Update profile
PUT /auth/change-password Private Change password
POST /auth/address Private Add delivery address
DELETE /auth/address/:id Private Delete delivery address
POST /auth/wishlist/:productId Private Toggle product in wishlist
POST /auth/prescription Private Upload prescription (multipart)

Product Endpoints

Method Endpoint Access Description
GET /products Public List with filters: keyword, category, subcategory, minPrice, maxPrice, prescriptionRequired, sort, page, limit
GET /products/featured Public Featured products
GET /products/category/:category Public Products by category
GET /products/:id Public Single product
POST /products/:id/reviews Private Add review
POST /products Admin Create product
PUT /products/:id Admin Update product
DELETE /products/:id Admin Delete product

Cart Endpoints

Method Endpoint Access Description
GET /cart Private Get user's cart
POST /cart Private Add item { productId, quantity }
PUT /cart/:itemId Private Update item quantity
DELETE /cart/:itemId Private Remove item
DELETE /cart Private Clear entire cart

Order Endpoints

Method Endpoint Access Description
POST /orders Private Place order
GET /orders/my Private Get user's orders
GET /orders/:id Private Get order by ID
PUT /orders/:id/cancel Private Cancel order
GET /orders/admin/stats Admin Dashboard statistics
GET /orders/admin/all Admin All orders with filters
PUT /orders/admin/:id/status Admin Update order status

Admin Endpoints

Method Endpoint Access Description
GET /admin/users Admin All users with pagination
PUT /admin/users/:id/toggle Admin Toggle user active status
GET /admin/prescriptions Admin All uploaded prescriptions
PUT /admin/prescriptions/:userId/:prescriptionId Admin Approve/reject prescription
GET /admin/config Public Get store configuration
PUT /admin/config Admin Update store configuration
GET /admin/inventory Admin Inventory report

Health Check

GET /api/health

πŸ—„οΈ Database Schema

User

name, email (unique), password (hashed), phone, dateOfBirth, gender
addresses: [{ fullName, phone, street, city, state, pincode, isDefault }]
prescriptions: [{ fileName, fileUrl, uploadedAt, status, doctorName, notes }]
wishlist: [ObjectId β†’ Product]
isActive, role (user|admin), loyaltyPoints

Product

name, genericName, description, manufacturer
category (enum: 10 categories), subcategory
images: [String], price, discountPrice, discountPercent
stock, unit, packSize, prescriptionRequired
saltComposition, dosageForm, strength
sideEffects: [String], usageInstructions, storageInstructions
expiryDate, batchNumber, isAvailable, isFeatured
reviews: [{ user, name, rating, comment }]
rating, numReviews, tags: [String]

Cart

user: ObjectId β†’ User
items: [{ product, name, image, price, discountPrice, quantity, prescriptionRequired, packSize }]
couponCode, discount
virtuals: totalItems, subtotal

Order

user: ObjectId β†’ User
orderNumber (auto-generated, e.g. PEZ7829430001)
items: [{ product, name, image, price, quantity, packSize, prescriptionRequired }]
shippingAddress: { fullName, phone, street, city, state, pincode }
paymentMethod (cod|upi|card|netbanking|wallet)
paymentStatus (pending|paid|failed|refunded)
itemsPrice, shippingPrice, taxPrice, discountAmount, totalPrice
orderStatus (placed|confirmed|processing|shipped|delivered|cancelled|returned)
prescriptionStatus (not_required|pending|approved|rejected)
statusHistory: [{ status, timestamp, note }]
estimatedDelivery, deliveredAt, notes, couponCode

πŸ₯ Application Modules

1. Authentication & Authorization

  • JWT-based stateless authentication
  • Role-based access control (user / admin)
  • Protected and admin-only routes
  • Password hashing with bcryptjs (salt rounds: 10)

2. Product Management

  • 10 healthcare categories
  • Full-text search across name, genericName, and tags
  • Advanced filtering (price range, category, prescription required)
  • Sort by price, rating, newest, relevance
  • Pagination (12 per page by default)
  • Product reviews with rating aggregation

3. Prescription Workflow

  1. Customer uploads prescription (image/PDF)
  2. System flags order as "prescription pending"
  3. Admin reviews prescription in dashboard
  4. Admin approves or rejects with notes
  5. Order proceeds or is cancelled

4. Cart & Checkout

  • Real-time stock validation
  • Prevents overselling
  • Free shipping threshold (β‚Ή499)
  • GST calculation (5%)
  • 3-step checkout: Address β†’ Payment β†’ Review
  • Multiple saved addresses

5. Order Management

  • Auto-generated order numbers (PEZ + timestamp + sequence)
  • Status progression: placed β†’ confirmed β†’ processing β†’ shipped β†’ delivered
  • Status history audit trail
  • Stock auto-deduction on order placement
  • Stock restoration on cancellation
  • Loyalty points awarded automatically (1 point per β‚Ή10)

πŸŽ›οΈ Admin Dashboard

Access at /admin after logging in with admin credentials.

Page URL Description
Dashboard /admin KPIs, revenue chart, recent orders, low stock
Products /admin/products List, search, edit, delete products
Add/Edit Product /admin/products/new Full product creation form
Orders /admin/orders All orders, status updates, detail panel
Users /admin/users User list, activate/deactivate
Inventory /admin/inventory Stock overview, low-stock alerts
Prescriptions /admin/prescriptions Review, approve, reject prescriptions

🚒 Deployment

Backend (e.g., Railway, Render, Heroku)

  1. Set environment variables on your platform
  2. Set MONGO_URI to your MongoDB Atlas connection string
  3. Set NODE_ENV=production
  4. Start command: node index.js

Frontend (e.g., Vercel, Netlify)

  1. Build: npm run build
  2. Publish directory: dist
  3. Set the VITE_API_URL if you move away from the proxy approach

Full Stack on Single Server

Build the React app and serve it from Express:

// Add to server/index.js for production
if (process.env.NODE_ENV === 'production') {
  const path = require('path');
  app.use(express.static(path.join(__dirname, '../client/dist')));
  app.get('*', (req, res) => {
    res.sendFile(path.resolve(__dirname, '../client/dist/index.html'));
  });
}

πŸ”’ Security Notes

  • Change JWT_SECRET to a strong random string in production
  • Enable HTTPS in production
  • Configure CORS to only allow your frontend domain
  • Add rate limiting (express-rate-limit) for production
  • Validate and sanitize all inputs
  • Never commit .env to version control

πŸ“ License

This project is for educational purposes. Built with the MERN stack.


πŸ‘¨β€πŸ’» Tech Credits

  • React.js, Node.js, Express.js, MongoDB, Mongoose
  • React Router v6, React Hot Toast, React Icons
  • Axios, Multer, bcryptjs, jsonwebtoken
  • Vite (build tool)

About

PharmaEZ is a full-featured MERN Stack pharmacy and healthcare e-commerce platform featuring prescription management, inventory tracking, order processing, JWT authentication, admin dashboard, and healthcare-specific workflows.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages