MERN-Stack-Ecommerce-App

Fusion Electronics: A MERN-Stack E-commerce Application

Welcome to Fusion Electronics, a MERN-Stack E-commerce Application! This project is a working demo of a full-stack web application that was built using the MERN stack (MongoDB, Express.js, React.js, Node.js). It aims to provide a comprehensive example of building a modern e-commerce platform, covering frontend user interface, backend server logic, database management, and integration with third-party libraries.

Table of Contents

  1. Introduction
  2. User Interface
  3. Features
  4. Technologies Used
  5. Getting Started
  6. Project Structure
  7. Running the Application
  8. Testing the APIs
  9. Swagger API Documentation
  10. Deployment
  11. Containerization
  12. Contributing
  13. License
  14. Creator

Introduction

This project is a demonstration of building an e-commerce application using the MERN stack, which consists of MongoDB (database), Express.js (server), React.js (frontend), and Node.js (runtime environment). The application allows users to browse products, add them to a shopping cart, proceed to checkout, and simulate the order processing. It includes basic validations for user inputs and simulates the checkout process on the backend.

User Interface

Home Page

Fusion Electronics Homepage

Full Product List

Fusion Electronics Products List

Product Details Page

Fusion Electronics Product Details Page

Cart Page

Fusion Electronics Cart Page

Checkout Page

Fusion Electronics Checkout Page

Order Confirmation

Fusion Electronics Order Success Page

Features

Technologies Used

Project Structure

The project is organized into two main β€œstacks”: The backend is in the backend directory that hosts all product & order data and the frontend is in the root directory. Here is an overview of the project structure:

fullstack-ecommerce/
β”œβ”€β”€ backend/                       # Node.js server files
β”‚   β”œβ”€β”€ config/                    # Configuration files
β”‚   β”‚   └── db.js                  # Database connection
β”‚   β”œβ”€β”€ models/                    # Mongoose models
β”‚   β”‚   └── product.js             # Product schema
β”‚   β”œβ”€β”€ routes/                    # Route handlers
β”‚   β”‚   β”œβ”€β”€ products.js            # Product routes
β”‚   β”‚   β”œβ”€β”€ search.js              # Search routes
β”‚   β”‚   └── checkout.js            # Checkout routes
β”‚   β”œβ”€β”€ seed/                      # Database seed data
β”‚   β”‚   └── products.js            # Product seed data
β”‚   β”œβ”€β”€ .env                       # Environment variables
β”‚   └── index.js                   # Server entry point
β”œβ”€β”€ public/                        # Frontend public assets
β”‚   β”œβ”€β”€ index.html                 # HTML template
β”‚   β”œβ”€β”€ manifest.json              # Web app manifest
β”‚   └── favicon.ico                # Favicon
β”œβ”€β”€ src/                           # React.js frontend files
β”‚   β”œβ”€β”€ components/                # Reusable components
β”‚   β”‚   β”œβ”€β”€ CheckoutForm.jsx       # Checkout form component
β”‚   β”‚   β”œβ”€β”€ ProductCard.jsx        # Product card component
β”‚   β”‚   β”œβ”€β”€ NavigationBar.jsx      # Navigation bar component
β”‚   β”‚   β”œβ”€β”€ OrderConfirmation.jsx  # Order confirmation component
β”‚   β”‚   β”œβ”€β”€ ProductListing.jsx     # Product listing component
β”‚   β”‚   β”œβ”€β”€ SearchResults.jsx      # Search results component
β”‚   β”‚   └── ShoppingCart.jsx       # Shopping cart component
β”‚   β”œβ”€β”€ dev/                       # Development utilities
β”‚   β”‚   β”œβ”€β”€ index.js               # Development entry point
β”‚   β”‚   β”œβ”€β”€ palette.jsx            # Color palette
β”‚   β”‚   β”œβ”€β”€ preview.jsx            # Component preview
β”‚   β”‚   └── useInitials.js         # Initials hook
β”‚   β”œβ”€β”€ pages/                     # Page components
β”‚   β”‚   β”œβ”€β”€ Cart.jsx               # Cart page component
β”‚   β”‚   β”œβ”€β”€ Checkout.jsx           # Checkout page component
β”‚   β”‚   β”œβ”€β”€ Home.jsx               # Home page component
β”‚   β”‚   β”œβ”€β”€ ProductDetails.jsx     # Product details page component
β”‚   β”‚   β”œβ”€β”€ OrderSuccess.jsx       # Order success page component
β”‚   β”‚   β”œβ”€β”€ ProductDetails.jsx     # Product details page component
β”‚   β”‚   └── Shop.jsx               # Shop page component
β”‚   β”œβ”€β”€ App.jsx                    # Main application component
β”‚   β”œβ”€β”€ App.css                    # Main application styles
β”‚   └── index.js                   # React entry point
β”œβ”€β”€ build/                         # Frontend production build files
β”œβ”€β”€ tests/                         # Test files
β”œβ”€β”€ .gitignore                     # Git ignore file
β”œβ”€β”€ package.json                   # NPM package file
β”œβ”€β”€ jsconfig.json                  # JS config file
└── setupProxy.js                  # Proxy configuration

Getting Started

Prerequisites

Before running this project, ensure you have the following installed:

Installation

  1. Clone the repository:
    git clone https://github.com/hoangsonww/MERN-Stack-Ecommerce-App.git
    cd MERN-Stack-Ecommerce-App  # Fix the path if necessary
    
  2. Install project dependencies:
    # Install server (backend) dependencies
    cd backend
    npm install
    
    # Install client (frontend) dependencies
    cd ..
    npm install
    
  3. Set up the backend:

    • Create a .env file in the backend/ directory and add the following environment variable (replace the URI with your MongoDB connection string):
      MONGO_URI=mongodb://localhost:27017/Ecommerce-Products
      
    • Ensure that your MongoDB server is running. If you’re using Mac, you can start the MongoDB server with the following command:
        brew services start mongodb-community
      
    • Seed the database with sample data:
      cd backend/seed
      node productSeeds.js dev
      
    • Run the backend server: (first cd into the backend directory)
      cd ..
      npm start
      
  4. Set up the frontend:
    • First, cd into the root directory if you are not already there:
      cd ..
      

      Or

         cd fullstack-ecommerce
      
    • Start the frontend development server:
      npm start
      
    • Note: The frontend server will run on http://localhost:3000 by default. If you encounter any errors when starting related to the react-credit-cards-2 package, it is OK to just ignore them as the application will still run correctly.

Running the Application

Testing the APIs

Swagger API Documentation

The MovieVerse App Interface

Deployment

To deploy the application:

Containerization

This project can be containerized using Docker. First, ensure that Docker Desktop is running on your system. Then, to create a Docker image, run the following command:

docker compose up --build

This command will create a Docker image for the frontend and backend, and run the application in a containerized environment.

Contributing

Contributions to this project are welcome! Here are some ways you can contribute:

License

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

Creator


Thank you for exploring Fusion Electronics - a MERN Stack E-commerce Application! If you have any questions or feedback, feel free to reach out or open an issue.

Happy coding! πŸš€