Welcome to the E-commerce Serverless Backend project! This is a fully serverless, microservices-based backend for an e-commerce platform, built using AWS services and the Serverless Framework. It provides functionality for user authentication, banner and category image management, product uploads with approval, and order processing. This repository is designed to be a scalable, cost-efficient solution leveraging AWS's serverless ecosystem.
This project implements a backend for an e-commerce application using a microservices architecture. Each service is independent, deployable, and communicates via HTTP APIs or event-driven mechanisms. Here's a brief overview of the services:
- authService: Manages user registration, authentication, and session management using AWS Cognito and DynamoDB.
- bannerService: Handles uploading and retrieving banner images, stored in S3 and tracked in DynamoDB.
- categoryService: Manages category images with a cleanup mechanism for outdated entries, using S3, DynamoDB, and SNS.
- productService: Allows authenticated users to upload products with images, includes an approval process, and cleans up outdated products, using S3, DynamoDB, and SNS.
- orderService: Processes customer orders with SQS for queueing, Step Functions for workflow management, and SES for email notifications, storing data in DynamoDB.
The application follows a microservices architecture, with each service handling a specific domain:
- authService: Uses AWS Cognito for user management and DynamoDB for storing user data.
- bannerService: Uploads images to S3 via pre-signed URLs, with S3 events triggering Lambda functions to update DynamoDB.
- categoryService: Similar to bannerService, with additional scheduled cleanup of outdated categories and SNS notifications.
- productService: Requires JWT authentication, stores product data in DynamoDB, and triggers image updates via S3 events, with scheduled cleanup.
- orderService: Queues orders in SQS, processes them with Step Functions, updates DynamoDB, and sends SES email notifications.
Services communicate via HTTP APIs (API Gateway) or event-driven triggers (S3 events, SQS messages, scheduled tasks).
Purpose: Handles user authentication and management.
Endpoints:
-
Sign Up
- Endpoint:
POST /sign-up - Input:
{ "email": "jayspprajapati24@gmail.com", "fullName": "Jay S Prajapati", "password": "passwrod123" } - Output:
{ "msg": "Account created. Please varify your email." }
- Endpoint:
-
Confirm Sign Up
- Endpoint:
POST /confirm-sign-up - Input:
{ "fullName": "Jay S Prajapati", "confirmationCode": "274023" } - Output:
{ "msg": "User successfully confirmed!" }
- Endpoint:
-
Sign In
- Endpoint:
POST /sign-in - Input:
{ "fullName": "Jay S Prajapati", "password": "passwrod123" } - Output:
{ "msg": "User successfully signed in!", "tokens": { "AccessToken": "...", "ExpiresIn": 3600, "IdToken": "...", "RefreshToken": "...", "TokenType": "Bearer" } }
- Endpoint:
-
Sign Out
- Endpoint:
POST /sign-out - Input:
{ "accessToken": "..." } - Output:
{ "msg": "User succesfully signed out!" }
- Endpoint:
Notes:
- Uses AWS Cognito for user pools.
- Stores user data in DynamoDB with a
userIdas the partition key. - Usernames are derived from full names by replacing spaces with underscores.
Purpose: Manages banner images for the e-commerce platform.
Endpoints:
-
Get Upload URL
- Endpoint:
POST /upload-url - Input:
{ "fileName": "baner1.png", "fileType": "image/png" } - Output:
{ "uploadURL": "https://banner-images-jaysp-jy952466-new.s3.amazonaws.com/baner1.png?..." }
- Endpoint:
-
Get All Banners
- Endpoint:
GET /banners - Output:
{ "banners": [ { "imageUrl": "https://banner-images-jaysp-jy952466-new.s3.amazonaws.com/baner1.png" } ] }
- Endpoint:
Notes:
- Images are uploaded to S3 using pre-signed URLs.
- S3 events trigger a Lambda function to store metadata in DynamoDB.
- S3 bucket is publicly readable for banner retrieval.
Purpose: Manages category images with cleanup functionality.
Endpoints:
-
Get Upload URL
- Endpoint:
POST /upload-url - Input:
{ "fileName": "fashion1.png", "fileType": "image/png", "categoryName": "fashion1" } - Output:
{ "uploadUrl": "https://category-images-jaysp-jy952466-new.s3.amazonaws.com/fashion1.png?..." }
- Endpoint:
-
Get All Categories
- Endpoint:
GET /categories - Output:
[ { "categoryName": "fashion1", "imageUrl": "https://category-images-jaysp-jy952466-new.s3.amazonaws.com/fashion1.png" } ]
- Endpoint:
Notes:
- Similar to bannerService, with added category metadata.
- A scheduled Lambda function (every 2 minutes) cleans up categories older than 1 hour without an image URL, notifying via SNS.
- S3 bucket is publicly readable.
Purpose: Manages product uploads and approvals.
Endpoints:
-
Get Upload URL
- Endpoint:
POST /get-upload-url - Headers:
Authorization: Bearer <JWT_TOKEN> - Input:
{ "fileName": "shoes.png", "fileType": "image/png", "productName": "gucci", "productPrice": 100, "description": "I love it.", "quantity": 40, "category": "Clothes" } - Output:
{ "uploadUrl": "https://product-images-jaysp-jy952466-new.s3.amazonaws.com/shoes.png?..." }
- Endpoint:
-
Get Approved Products
- Endpoint:
GET /approve-products - Output:
{ "products": [ { "id": { "S": "df38e02c-2adf-4e3a-948f-c6d7bc02d767" }, "fileName": { "S": "shoes.png" }, "productName": { "S": "gucci" }, "productPrice": { "N": "100" }, "description": { "S": "I love it." }, "quantity": { "N": "40" }, "category": { "S": "Clothes" }, "imageUrl": { "S": "https://product-images-jaysp-jy952466-new.s3.amazonaws.com/shoes.png" }, "isApproved": { "BOOL": true }, "email": { "S": "jayspprajapati24@gmail.com" }, "createdAt": { "S": "2025-04-19T03:05:28.210Z" } } ] }
- Endpoint:
Notes:
- Requires JWT authentication from Cognito.
- Products are stored in DynamoDB with an
isApprovedflag (initially false). - S3 events update the
imageUrlafter upload. - A scheduled Lambda function (every 2 minutes) cleans up unapproved products older than 1 hour without an image URL, notifying via SNS.
Purpose: Handles order placement and processing.
Endpoints:
- Place Order
- Endpoint:
POST /create-order - Headers:
Authorization: Bearer <JWT_TOKEN> - Input:
{ "id": "df38e02c-2adf-4e3a-948f-c6d7bc02d767", "quantity": 30 } - Output:
{ "message": "order placed successfully", "orderId": "ac518658-bdf7-4b25-9df0-b21d59b3d59d" }
- Endpoint:
Notes:
- Requires JWT authentication.
- Orders are queued in SQS, processed by Step Functions (updates status to "shipping"), and stored in DynamoDB.
- SES sends email notifications to the user (e.g., "gucci now shipping").
- Checks stock availability against approved products.
Before deploying or using this project, ensure you have:
- An AWS account with credentials configured.
- Node.js (v22.x) and npm installed.
- Serverless Framework installed globally (
npm install -g serverless). - An AWS Cognito User Pool and App Client set up (Client ID stored in SSM as
/CLIENT_ID). - An SES-verified email address (
jayspprajapati24@gmail.com) for notifications.
To deploy the project:
-
Clone the Repository:
git clone https://github.com/<your-username>/ecommerce-serverless-backend.git cd ecommerce-serverless-backend
-
Install Dependencies:
- For each service directory (
authService,bannerService, etc.):cd <service-directory> npm install cd ..
- For each service directory (
-
Configure AWS Resources:
- Store the Cognito App Client ID in AWS SSM:
aws ssm put-parameter --name "/CLIENT_ID" --value "<your-client-id>" --type "SecureString" --region us-east-1
- Verify your SES email identity:
aws ses verify-email-identity --email-address jayspprajapati24@gmail.com --region us-east-1
- Store the Cognito App Client ID in AWS SSM:
-
Deploy Each Service:
- From each service directory:
cd <service-directory> serverless deploy cd ..
- This creates API Gateway endpoints, Lambda functions, S3 buckets, DynamoDB tables, SQS queues, SNS topics, and Step Functions as defined in
serverless.yml.
- From each service directory:
Explore each service's section for all endpoint details.
We welcome contributions! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -m "Add your feature"). - Push to your branch (
git push origin feature/your-feature). - Open a pull request.
