Skip to content

A FullStack MERN E-Commerce App. Live reviewπŸ‘‡πŸ»πŸ˜Š

License

Notifications You must be signed in to change notification settings

ghezel1995/mern-shop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

76 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸͺ MERN Shop E-Commerce App

This project is a Full-Stack E-Commerce Application built using the MERN stack (MongoDB, Express.js, React.js, Node.js). It simulates a real-world webshop with essential features like user authentication, product management, shopping cart functionality, order management, and an admin dashboard. (This project is containerized using Docker.)


Project Overview

App Preview

πŸ”— LIVE DEMO

You can check out the live version of the app here: Live Demo on Render


Table of Contents

  1. Project Overview
  2. Features
  3. Tech Stack
  4. Getting Started
  5. Installation and Setup
  6. Dockerizing the Application
  7. Running the Application
  8. Scripts
  9. File Structure
  10. Additional Notes
  11. License

Features

General Features

  • Fully functional e-commerce experience with product browsing, user authentication, and order placement.
  • Responsive user interface for seamless navigation across devices.
  • Built-in admin dashboard for managing data.

Customer Features

  • Browse products with details (image, description, price, and reviews).
  • Add products to a cart and follow a 4-step checkout process:
  1. Sign In (JWT authentication with secure token storage).
  2. Shipping: Enter shipping details.
  3. Payment: Mock payment integration (no real gateways used).
  4. Place Order: Finalize and view the order summary.
  • Review the order status (Paid, Delivered).

  • Rate and review products (each user can rate a product only once).

Admin Features

  • Access an Admin Dashboard displaying:
    • Total sales, product count, users, and orders.
  • Manage the app:
    • Products: Add, edit, or delete products (with image upload using Multer).
    • Users: View, update, or delete users accounts.
    • Orders: View orders and update statuses (Paid/Delivered).

Security

  • Password Encryption: Passwords are encrypted using bcrypt.js.
  • Token-based authentication with JWT.

Tech Stack

Frontend

  • React.js: For building the user interface.
  • React Bootstrap: For responsive styling and prebuilt UI components.
  • Redux Toolkit: For global state management.
  • React Router DOM: For routing between pages.
  • React Toastify: For user notifications.
  • SASS: For styling with extended CSS features.

Backend

  • Node.js & Express.js: For creating the RESTful API and managing server-side logic.
  • MongoDB (via Mongoose): For the database to store users, products, orders, and reviews.
  • JWT: For user authentication.
  • Multer: For handling image uploads.

Getting Started

Follow these steps to set up the project locally.

Prerequisites

Ensure you have the following installed:

  • Node.js and npm
  • A MongoDB Atlas account (free tier is sufficient).

Setting up MongoDB

  • Create a MongoDB Cluster
  1. Sign in or sign up at mongodb.com

  2. Create a new project and build a database cluster (choose free tier).

  3. Set a username and password for the database.

  4. Allow connections from your IP or enable access from anywhere.

  • Configure .env File
  • Rename example.env to .env in your project directory.
  • Add your MongoDB connection string:
NODE_ENV=development
PORT=8000
MONGO_URI=<your_mongo_uri>
JWT_SECRET=<your_jwt_secret>
  • Import Sample Data

  • Import predefined sample data:

npm run data:import
  • To clear the database:
npm run data:destroy

Installation and Setup

  • Clone the repository:
git clone <https://github.com/ghezel1995/mern-shop.git>
cd mern-shop
npm install
npm install --prefix frontend
  • Install dependencies for both backend and frontend:
npm install
npm install --prefix frontend
  • Set up your MongoDB connection:
    • Replace MONGO_URI with your MongoDB connection string.

Setting up JWT Secret

The JWT secret is simply a random string that you define in your .env file to sign and verify tokens. Just write a random string for it in the .env file for JWT_SECRET, like:

aaa111


Dockerizing the Application

The project is fully Dockerized to simplify setup and deployment. Using Docker ensures consistent environments for development and production.

Docker Prerequisites

  1. Install Docker:

  2. Verify Installation: Run the following command to ensure Docker is installed:

docker --version

Docker Commands

  1. Build the Docker Image: Navigate to the project directory and run:

    docker build -t mern-shop .

    This command:

    • Installs all dependencies for the backend and frontend.
    • Builds the production-ready React app.
    • Prepares the app for deployment.
  2. Run the Docker Container: Start a container from the built image:

    docker run -p 8000:8000 -p 3000:3000 --name mern-shop-container mern-shop
    • The backend will be available at http://localhost:8000.
    • The frontend will be available at http://localhost:3000.
  3. Stop the Docker Container: To stop the running container, use:

    docker stop mern-shop-container
  4. Remove the Docker Container: To clean up the container:

    docker rm mern-shop-container

Running the Application

Without Docker

Run the backend and frontend concurrently:

npm run dev

With Docker

Run the app using the following commands:

  1. Build the image:

    docker build -t mern-shop .
  2. Run the container:

    docker run -p 8000:8000 -p 3000:3000 mern-shop

The backend will be available at http://localhost:8000. The frontend will be available at http://localhost:3000.


Scripts

From the Root Directory

Command Description
npm start Starts the backend server.
npm run client Starts the React frontend.
npm run dev Runs both the frontend and backend concurrently.
npm run build Builds the React app for production.
npm run data:import Imports initial sample data into MongoDB.
npm run data:destroy Destroys all data in MongoDB.

File Structure

MERN-SHOP/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/               # Database connection with Mongoose
β”‚   β”œβ”€β”€ controllers/          # Controller functions for handling request logic.
β”‚   β”œβ”€β”€ data/                 # Sample data files for initial database population.
β”‚   β”œβ”€β”€ middleware/           # Custom middleware (e.g., authentication, error handling, asyncHandler).
β”‚   β”œβ”€β”€ models/               # Mongoose models(Schemas) for MongoDB collections.
β”‚   β”œβ”€β”€ routes/               # Express routes for API endpoints.
β”‚   β”œβ”€β”€ utils/                # Generating Token(JWT)
β”‚   β”œβ”€β”€ initialDataLoader.js  # Script to import and destroy sample data.
β”‚   └── server.js             # Main server file to start the backend.
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ node_modules/         # Contains frontend dependencies.
β”‚   β”œβ”€β”€ public/               # Static files and the `index.html` template.
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ assets/           # Static assets such as images and styles.
β”‚   β”‚   β”œβ”€β”€ components/       # Reusable React components (e.g., Navbar, Footer).
β”‚   β”‚   β”œβ”€β”€ screens/          # React components representing pages/screens.
β”‚   β”‚   β”œβ”€β”€ slices/           # Redux slices for global state management.
β”‚   β”‚   β”œβ”€β”€ utils/            # Utility function for cart.
β”‚   β”‚   β”œβ”€β”€ App.js            # Main app component for route management and provider setup.
β”‚   β”‚   β”œβ”€β”€ constants.js      # Application-wide constants (API URLs).
β”‚   β”‚   β”œβ”€β”€ index.js          # Entry point of the React app and Routers.
β”‚   β”‚   β”œβ”€β”€ Products.js       # Component handling product-related logic.
β”‚   β”‚   β”œβ”€β”€ setupTests.js     # Jest setup for testing.
β”‚   β”‚   └── store.js          # Redux store configuration.
β”‚
β”œβ”€β”€ uploads/                  # Directory for uploaded images (handled by Multer).
β”œβ”€β”€ .env                      # Environment variables for backend configuration.
β”œβ”€β”€ .gitignore                # Git ignore file.
β”œβ”€β”€ Dockerfile                  # Instructions for building a Docker image
β”œβ”€β”€ .dockerignore               # Specifies files and directories to ignore when building Docker images
β”œβ”€β”€ package-lock.json         # Lock file for package dependencies.
β”œβ”€β”€ package.json              # Project metadata and scripts.
└── README.md                 # Project documentation.

Additional Notes

  • Frontend Proxy: The proxy field in frontend/package.json ensures requests to /api are proxied to the backend server during development.

  • Mock Payment: The payment functionality is mocked and doesn't use real payment gateways.

License

This project is licensed under the MIT License - see the LICENSE file for details.


About

A FullStack MERN E-Commerce App. Live reviewπŸ‘‡πŸ»πŸ˜Š

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages