Giter VIP home page Giter VIP logo

thasup / microservices-ecommerce Goto Github PK

View Code? Open in Web Editor NEW
54.0 5.0 19.0 26.59 MB

Aurapan is a beautiful women's clothes e-commerce website built with microservices architecture, perform server-side rendering by Next.js, developing on Google Cloud Platform environment, running automation test with GitHub Action workflow and deploy on DigitalOcean.

Home Page: https://www.aurapan.com

License: MIT License

Dockerfile 0.28% TypeScript 44.29% JavaScript 50.77% CSS 4.49% Shell 0.17%
typescript docker kubernetes skaffold nextjs stripe paypal mongodb digitalocean gcp

microservices-ecommerce's Introduction

Project Preview

Aurapan

deploy-client deploy-user deploy-product deploy-order deploy-payment

Aurapan is a women's clothing e-commerce website that features a fully operational microservices architecture. Built on the Next.js framework for the client-side, while the server-side is developed with TypeScript and Express framework, the website is developed on the Google Cloud Platform environment and integrated with automation testing through GitHub Action workflows. Deployed on a DigitalOcean cluster with a Let's Encrypt certificate, Aurapan delivers a secure and seamless shopping experience.

Table of contents

Demo

(Back to top)

To experience Aurapan, please visit www.aurapan.com.

Features

(Back to top)

Aurapan's features include:

  • A fully operational microservices-architecture website with user, product, order, payment, and expiration services completely separated.

  • All user, product, order, and payment data is stored in separate MongoDB collections.

  • User authentication secured by encrypting passwords using JWT and cookies.

  • A customer account settings dashboard to update profile information or see all orders.

  • An admin management dashboard with the authority to add, edit, and delete a product, user, or order.

  • Detailed product information with multiple options, such as color and size, displayed in a fashionable design with the Swiper library.

  • A full-featured shopping cart, including the ability to add, edit, and remove items.

  • A fully functional checkout process, including login, shipping address selection, and payment method selection.

  • Acceptance of both PayPal and Stripe integration payment methods.

  • Ability for an admin to mark orders as delivered.

  • The ability for customers to make product reviews and ratings with instant calculation of new ratings.

  • The ability to accept coupon promotions.

  • A cool navigation bar and breadcrumb for easy navigation.

  • Implementation of the Optimistic concurrency control concept with Mongoose to handle concurrency issues with event flow.

  • Optimization of Next.js features to maximize performance and quality in the Lighthouse report.

  • A safely secured HTTPS protocol with Let's Encrypt certificate.

  • Integration of Google Analytics 4 script to track significant events on the website.

Usage

(Back to top)

This readme file provides an overview of the usage of the Aurapan website. Here are some instructions on how to use the website's features:

Sign up for an account

  1. To create an account, visit the signup page.
  2. Enter your email, password, name, gender, and age (these can be fictional since Aurapan is a fictional store).

Purchase products

Pay with Stripe method (recommended)

  1. Use the following card number: 4242 4242 4242 4242.
  2. Use any future date for MM/YY.
  3. Use any number for CVC.

Pay with the PayPal method

  1. You will need a PayPal account.
  2. Create a PayPal developer account by visiting https://developer.paypal.com/tools/sandbox/accounts/.
  3. Choose the PayPal payment method and sign in with your sandbox account to pay for an order (with fake money).

Receive an order

  1. Only an admin can change an order status to delivered.
  2. You will never receive any real products (even if your order has been marked as delivered). ๐Ÿ˜›

Access the admin dashboard

  1. To access the admin dashboard, sign in with an admin account.
  2. Access the dashboard through the management menu in the profile dropdown menu.

Add a product to your wishlist

Unfortunately, this feature is not yet available on Aurapan. ๐Ÿ˜Ž

Perform CRUD operations on the product database (create, update, delete)

To perform CRUD operations on the product database, you need permission to access this function as an admin.

Installation

(Back to top)

Running on Google Cloud Platform

GCP Badge

Follow these steps to run the project on Google Cloud Platform:

  1. Clone the cloud branch to your local machine.

  2. Install Node.js, Skaffold, Docker, and kubectl.

  3. Sign up for a free account with $300 on GCP and create a Docker Hub account.

  4. Run the setup.sh script by executing the following command in the root directory of this project:

source setup.sh

The script will prompt you to enter your Docker registry account name and will build and push the Docker images for each folder that contains a Dockerfile.

  1. Create a new project on GCP and enable Kubernetes Engine API and Cloud Build API. After successfully enabling API services, grant permission for the Cloud Build service account permission on Cloud Build API.

  2. Create a new Kubernetes cluster with the minimum resource of 3 nodes (recommended) and select the region closest to your location.

  3. Install GCP SDK to connect our images to the GCP cluster context. (Learn how to install Google Cloud SDK on macOS here)

  4. Open the Google Cloud SDK and log in. Initiate and then choose the correct options to proceed by running the following commands:

gcloud auth login
gcloud init
  1. Create a Kubernetes context on your desktop by running this command (replace <YOUR_CLUSTER_NAME> with the name of the cluster you created on GCP):
gcloud container clusters get-credentials <YOUR_CLUSTER_NAME>
  1. See the list of contexts and then select a new context by running these commands:
kubectl config get-contexts
kubectl config use-context <CONTEXT_NAME>
  1. Install ingress-nginx and ingress-nginx for GCP.

  2. Find your load balancing port, which GCP automatically generated, in the Network Services tab in GCP.

  3. For Windows users, open the host file at C:\Windows\System32\drivers\etc\hosts. For Mac users, open the host file at \etc\hosts. Then, edit the file by adding YOUR_LOAD_BALANCING_PORT YOUR_CUSTOM_URL and save as an administrator (e.g., 56.125.456.45 custom.com).

  4. Configure all the YAML files to match your GCP project ID.

  5. Create all Kubernetes secrets.

  6. Run the following command and authenticate the GCP account via a web browser:

gcloud auth application-default login
  1. Ensure that you are using the correct context before running this command at the root directory:
skaffold dev
  1. Open a web browser and enter your custom URL with https:// to see the project come to life

Please note that the setup.sh script is designed to streamline the installation process by automatically building and pushing Docker images for each folder that contains a Dockerfile. This helps simplify the steps required to set up the project on GCP.

Running on Docker Desktop

Docker Badge

Follow the below steps to run this project on Docker Desktop:

  1. Clone the dev branch on your computer.

  2. Install the following software:

  3. Enable Kubernetes in Docker Desktop preferences.

  4. Run the setup.sh script by executing the following command in the root directory of this project:

source setup.sh

The script will prompt you to enter your Docker registry account name and will build and push the Docker images for each folder that contains a Dockerfile.

  1. View the list of Kubernetes contexts and select a new context by running these commands:
kubectl config get-contexts
kubectl config use-context docker-desktop
  1. Install ingress-nginx and enable Kubernetes in Docker Desktop software. (choose don't have Helm version)

  2. For Windows users, open the host file at C:\Windows\System32\drivers\etc\hosts. For Mac users, open the host file at /etc/hosts. Then, add 127.0.0.1 YOUR_CUSTOM_URL and save the file as an admin. For example, 127.0.0.1 custom.com.

  3. Configure the infra/k8s-dev/ingress-srv.yaml file at line 10 to be your custom URL. (ex. mywebsite.com)

  4. Create all Kubernetes secrets.

  5. Run skaffold dev in the root directory of this project, and make sure to use the correct context before running the command.

  6. Open a web browser and enter your custom URL with https:// to see this project come to life!

Please note that the setup.sh script is designed to streamline the installation process by automatically building and pushing Docker images for each folder that contains a Dockerfile. This helps simplify the steps required to set up the project on Docker Desktop.

Setup Kubernetes Secret

(Back to top)

Create all these Kubernetes secrets in the Kubernetes context:

MONGO_URI_USER, MONGO_URI_PRODUCT, MONGO_URI_ORDER, MONGO_URI_PAYMENT : MongoDB

kubectl create secret generic mongo-secret \
"--from-literal=MONGO_URI_PRODUCT=<YOUR_MONGO_DB_URI>" \
"--from-literal=MONGO_URI_USER=<YOUR_MONGO_DB_URI>" \
"--from-literal=MONGO_URI_ORDER=<YOUR_MONGO_DB_URI>" \
"--from-literal=MONGO_URI_PAYMENT=<YOUR_MONGO_DB_URI>"

Example for YOUR_MONGO_DB_URI: mongodb+srv://admin:<password>@aurapan.ygmpl.mongodb.net/<your_database_name>?retryWrites=true&w=majority

JWT_KEY : --whatever you want--

kubectl create secret generic jwt-secret --from-literal=JWT_KEY=<YOUR SECRET>

STRIPE_KEY : Stripe

kubectl create secret generic stripe-secret --from-literal=STRIPE_KEY=<YOUR_STRIPE_KEY>

PAYPAL_CLIENT_ID : Paypal

kubectl create secret generic paypal-secret --from-literal=PAYPAL_CLIENT_ID=<YOUR_PAYPAL_CLIENT_ID>

Deployment

(Back to top)

Deploy on DigitalOcean

DigitalOcean

  1. sign up a free account with a $200 for 60 days trial and create a Kubernetes cluster in a new project on Digital Ocean

  2. generate a new access token on Digital Ocean to connect with Digital Ocean via doctl, go to the API menu then click generate a new token, set expiration date and enable both read and write scopes, copy the token code for use in the next step

  3. install doctl and kubectl, then run

doctl auth init --access-token <API_TOKEN_CODE>
  1. connect with Digital Ocean k8s cluster context by running this command and authorize with your credentials
doctl kubernetes cluster kubeconfig save <YOUR_CLUSTER_NAME>
  1. switch Kubernetes context to the new context by running
kubectl config use-context <CONTEXT_NAME>
  1. setup all Kubernetes secrets following this step

  2. create _GitHub workflow for building an initial docker image on push event at the main branch and perform automated testing in every service on pull request event trigger with trying to merge with the main branch

name: deploy-client

on:
  push:
    # watch for pull request into main branch
    branches:
      - main

    # watch for changes in client folder
    paths:
      - "client/**"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      # build an image
      - run: cd client && docker build -t <YOUR_ACCOUNT_NAME>/<YOUR_IMAGE_NAME> .

      # login on docker hub
      - run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
        env:
          DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

      # push an image to docker hub
      - run: docker push <YOUR_ACCOUNT_NAME>/<YOUR_IMAGE_NAME>
  1. generate another new access token on Digital Ocean for authentication via GitHub Action, go to the API menu then click generate a new token, set expiration date and enable both read and write scopes, copy the token code for use in the next step as a DIGITALOCEAN_ACCESS_TOKEN

  2. add GitHub action secrets for docker credentials and digitalocean access token key at the security setting in the repository

DIGITALOCEAN_ACCESS_TOKEN = 
DOCKER_USERNAME = 
DOCKER_PASSWORD = 
  1. edit files in every service then commit code to the main branch for triggering Github Action workflows to build and push all images to your Docker Hub

  2. install ingress-nginx to automatically create DigitalOcean Load Balancer

  3. separate k8s folder to k8s-dev and k8s-prod then copy ingress-srv.yaml file to both folders and edit the host URL to a new domain name

  4. create a GitHub workflow for telling the Kubernetes cluster to use images we built by adding these lines

- uses: digitalocean/action-doctl@v2
  with:
    token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- run: doctl kubernetes cluster kubeconfig save <YOUR_CLUSTER_NAME>
- run: kubectl rollout restart deployment <YOUR_DEPLOYMENT_NAME>
  1. purchase a domain name with a promotion that can be very cheap as $1 for the 1st year such as Namecheap, Porkbun, or Dynadot

  2. config custom domain name nameserver with your domain name registration website by custom adding these lines

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com
  1. add a domain name in the Digital Ocean at networking tab then create a new record
// A record
HOSTNAME: @
WILL DIRECT TO: <YOUR_LOAD_BALANCER>
TTL: 30

// CNAME record
HOSTNAME: www
IN AN ALIAS OF: @
TTL: 30
  1. add your cluster name at deploy-manifests.yaml file then redo step 7. again
name: deploy-manifests

on:
  push:
    # watch for pull request into main branch
    branches:
      - main

    # watch for changes in infra folder
    paths:
      - "infra/**"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      # use and cliententicate doctl
      - uses: digitalocean/action-doctl@v2
        with:
          token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

      # use and cliententicate doctl
      - run: doctl kubernetes cluster kubeconfig save <YOUR_CLUSTER_NAME>

      # apply deployment yaml files (k8s-prod is for production!)
      - run: kubectl apply -f infra/k8s && kubectl apply -f infra/k8s-prod
  1. change do-loadbalancer-hostname and host at file infra/k8s-prod/ingress-srv.yaml to your domain name

  2. change the URL in client/api/build-client.js to your domain name

  3. after that, we will follow step 4 of this guide How to Set Up an Nginx Ingress with Cert-Manager on DigitalOcean Kubernetes to make our website ready for HTTPS requests with the certificate issued by Let's encrypt

  4. begin with installing the cert-manager namespace by running the command

kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.7.1/cert-manager.yaml
  1. change your directory to infra/issuer/ there will be 2 files that you need to change the email and name of a secret key as you wish then run the command
kubectl create -f staging_issuer.yaml
kubectl create -f production_issuer.yaml
  1. at file infra/k8s-prod/ingress-srv.yaml change cert-manager.io/cluster-issuer to "letsencrypt-staging" then run this command at infra/k8s-prod/ directory
kubectl apply -f ingress-srv.yaml
  1. then change cert-manager.io/cluster-issuer back to "letsencrypt-prod" and run this command at infra/k8s-prod/ directory
kubectl apply -f ingress-srv.yaml
  1. waiting around 2-15 minutes for setting up then browse your website with HTTPS protocol

Technology

(Back to top)

This project is built using the following technologies:

Disclaimer

(Back to top)

All images used in this project are for educational purposes only. ๐Ÿ˜˜

microservices-ecommerce's People

Contributors

thasup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

microservices-ecommerce's Issues

Unable to run the application with docker desktop.

Hi just found your repo and very and I'm very impressed with your work,
So I realy want to run your application to see and learn the technologies you use in this project.

But I'm facing a huge problem I can't open the application even though I followed your instructions.
When I run the command "skaffold dev" everything look like works perfectly but when I access http://localhost:3000
it doesn't work.

I don't know what I did wrong and I hope you can help.
Thank you.

Screenshot 2023-12-11 175801

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.