Skip to content

E-Store is a Serverless Ecommerce Platform implementation of a serverless shopping cart for an e-commerce website.

Notifications You must be signed in to change notification settings

evanigwilo/e-store

Repository files navigation

E-Store Backend Implementation Using Event-driven Serverless Microservice Architecture

Test TypeScript

The Serverless E-Store Backend is an implementation of a serverless backend for an e-commerce website. Functionalities are split across multiple micro-services that communicate through APIs.

This project is as an inspiration on how to build event-driven serverless microservice on AWS. This makes lots of assumptions on the order flow suitable for most e-commerce platform.

Please note that you may incure AWS charges for deploying the ecommerce platform into your AWS account as not all services used are part of the free tier and you might exceed the free tier usage limit. To track costs in your AWS account, consider using AWS Cost Explorer and AWS Billing and Cost Management. You can also set up a billing alarm to get notified of unexpected charges.

You can explore the Live REST API

Design Notes

  • There are two users with usernames admin and user with same password 123456
    • admin has full privileges which includes managing products and users
    • user has privileges of managing only products
  • REST API and CRUD endpoints using AWS Lambda, API Gateway
  • User authentication/authorization and verification using AWS Cognito and Amazon Simple Email Service (SES)
  • Data persistence with AWS DynamoDB and AWS S3
  • Cloud stack development with Infrastructure as code (IaC) using AWS CloudFormation and AWS Cloud Development Kit (AWS CDK)
  • Payment processing using Stripe APIs and Webhooks
  • Test Driven Development (TDD)

Architecture

High-level architecture

This is a high-level view of how the different microservice interact with each other.

High-level Architecture


AWS Technologies used

Communication/Messaging:

Authentication/Authorization:

  • Amazon Cognito for managing and authenticating users, and providing JSON web tokens used by services.
  • AWS Identity and Access Management for service-to-service authorization, either between microservices (e.g. authorize to call an Amazon API Gateway REST endpoint), or within a microservice (e.g. granting a Lambda function the permission to read from a DynamoDB table).

Compute:

  • AWS Lambda as serverless compute either behind APIs or to react to asynchronous events.

Storage:

  • Amazon DynamoDB as a scalable NoSQL database for persisting informations.
  • Amazon S3 store data as objects within resources called “buckets” with features that include capabilities to append metadata tags to objects, move and store data.

CI/CD:

Networking/Routing:

  • AWS Route 53 scalable DNS and Domain Name Registration. It resolves domain names to it's equivalent IP address.
  • AWS Certificate Manager (ACM) makes it easy to provision, manage, deploy, and renew SSL/TLS certificates

Management:

  • AWS Systems Manager with Parameter Store provides a centralized store to manage your configuration data, whether plain-text data such as database strings or secrets such as passwords.

Monitoring:

Lambda services

Services Description
auth Gets user attributes for the current authenticated user.
register Registers and authenticates users.
login Logs in and authenticates users.
logout Logs out the current authenticated user.
verify Sends or verifies user using code sent via email.
refresh Refreshes tokens using refresh token from cookie.
category Gets supported product categories.
country Gets supported countries for delivery.
products Query/Search for products.
product/{id} Manages a product such creating, updating and deleting.
order Query/Search for orders.
order/create Manages an order such creating, updating and deleting.
order/{intent} Gets an order by intent such as cart or payment intent.
payment/checkout Checkouts an order.
payment/hook Webhook for updating payment processing.
users Gets users.
user-group/{groupname} Manages user groups such as adding and removing.

Other Technologies Used

Payment:

  • Stripe | Payment Processing Platform with Webhooks notifies application using HTTPS when an event happens; used for asynchronous events such as when a customer’s bank confirms a payment, a customer disputes a charge, a recurring payment succeeds, or when collecting subscription payments.

Requirements

Before getting started, make sure you have the following requirements:

Note: Make sure that your AWS Profile has been configured properly, run the below command to view profiles:

aws configure list-profiles

Run The Project

Follow these steps to get your development environment set up:

  1. Clone this repository locally;
# Change to the desired directory
$ cd <desired-directory>

# Clone the repo
$ git clone https://github.com/evanigwilo/e-store.git

# Change to the project directory
$ cd e-store

# Checkout to the server branch
$ git checkout server

# Install dependencies
npm install
  1. Change AWS profile name in package.json file at "cdk": "cdk --profile aws-cli-v2" from aws-cli-v2 to your configured profile name

  2. At the root directory, run below command:

npm run cdk -- deploy
  1. Wait for provision of all microservices into aws cloud. That’s it!

  2. At the root directory, in cdk-outputs.json file, the API url can be found with the key apiUrl

Note: Make sure your Stripe API secret key and Webhook secret are stored in Parameter Store with the parameter name stripe-secret and keys stripe_api_secret_key and webhook_signing_secret for webhooks to function properly.

I've hidden the values of my keys below, but this is the JSON we use to store our data for Stripe:

{
  "stripe_api_secret_key":"sk_test_51JU2XXXXXXXXXXXX", // stripe API secret key
  "webhook_signing_secret":"whsec_TqW4TXXXXXXXXXXXX", // stripe webhook signing secret
}

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • npm run cdk -- deploy deploy this stack to your default AWS account/region
  • npm run cdk -- diff compare deployed stack with current state
  • npm run cdk -- synth emits the synthesized CloudFormation template
  • npm run cdk -- destroy deletes the CloudFormation stacks created by this project

References

Amazon Web Services | Cloud Computing Services

Stripe | Payment Processing Platform

Swagger: API Documentation & Design Tools for Teams