This E-Commerce Platform is a comprehensive online shopping solution designed for individuals and small distributors to sell their products efficiently with fully COD support. With the premise of design for small distributors, utilizing MVC architecture, the system is easy to deploy within a single application, offering cost-effective management and scalability.
- Backend: Java (Spring Boot MVC)
- Frontend: Thymeleaf, HTML, CSS, Bootstrap
- Database: MySQL (hosted on AWS RDS)
- Third-Party Integrations:
- VNPay for online payments
- GHN for shipping
- Containerization: Docker
- Hosting: AWS (EC2, S3, RDS)
- Infrastructure Provisioning: Terraform
The system comprises two separate applications: Public Site and Admin Panel.
- The Public Site allows users to browse products, place orders, and complete payments.
- The Admin Panel handles order confirmation (COD), shipment initiation, and order status management via GHN.
Both apps connect to a shared MySQL database.
The payment process in this project is integrated with VNPay, with options for COD (Cash on Delivery) or online payment. Here’s the detailed flow:
-
User Browsing Public Site:
- Users browse the site, adding products to their cart and proceeding to checkout.
-
Place Order & Save to Database:
- When the order is placed, order details are saved in the database, and an
OrderCreatedEvent
is fired.
- When the order is placed, order details are saved in the database, and an
-
Order Created Listener:
- For COD:
- The admin manually confirms the order via the admin panel.
- The order status remains pending until admin confirmation.
- For Online Payment:
- The payment service initiates the VNPay payment.
- The system sets a 15-minute expiration time for the payment.
- The user is redirected to VNPay's payment gateway to complete the payment.
- For COD:
-
VNPay Interaction:
- The user interacts with VNPay to complete the payment.
- VNPay processes the payment and returns a status (success, failure, or pending).
-
Post Payment:
- If Payment is Successful:
- The order status is updated to confirmed without admin intervention.
- Payment and order expiration schedules are canceled.
- The order moves to the shipping lifecycle.
- If Payment Fails or Expires:
- The user can retry the payment, which restarts the VNPay redirection flow.
- If Payment is Successful:
-
Shipping Lifecycle:
- For confirmed orders, shipping is delegated to the GHN API via the admin panel.
- The admin initiates the shipping process.
- The order status is updated based on GHN webhook callbacks that handle delivery updates.
- If a payment fails or expires, the user is provided with an option to retry.
- This creates a new VNPay transaction and redirects the user back to the VNPay payment gateway for another attempt.
- Refunds are initiated when a user cancels a paid order.
- A refund request is sent to VNPay through the refund API, and VNPay processes and returns a refund status that updates the order in the database.
- Checksum Validation: All requests to and from VNPay are validated using a secure checksum.
- Secure Hashing: HMAC-SHA512 is used to generate secure hash values for all VNPay communications.
- Sensitive Data Handling: Sensitive data, such as transaction details, are securely handled and stored according to best practices.
This section outlines the deployment process for the public site using Terraform for infrastructure provisioning, Docker for containerization, and AWS for hosting. This setup is designed for small distributors and individuals, providing a reliable, scalable, and cost-effective solution.
Terraform is used to define and provision the cloud infrastructure. Key components include:
- Networking: A VPC with public and private subnets is configured for the application and database.
- Compute: EC2 instances are provisioned to host the public site and admin panel.
- Database: An RDS MySQL instance is set up with a dedicated DB subnet group.
- Storage: An S3 bucket is created for storing static assets with versioning and encryption enabled.
- Security: Security groups control inbound and outbound traffic for EC2 and RDS.
The project utilizes the following AWS services:
- EC2: Hosts the public and admin sites inside Docker containers.
- RDS (MySQL): Stores order data, payments, and user information.
- S3: Handles storage for static assets such as product images.
The public and admin sites are containerized using Docker, ensuring consistency across development and production environments. Docker images include all necessary components, such as dependencies and application code.
-
Infrastructure Setup:
- Use Terraform to provision the necessary AWS resources, including VPC, subnets, EC2 instances, RDS database, and S3 bucket.
- Run
terraform init
,terraform plan
, andterraform apply
to create or update the infrastructure.
-
Application Deployment:
- Build Docker images for the public and admin sites.
- SSH into the provisioned EC2 instances and deploy the Docker containers by pulling the images from the container registry.
-
Static Asset Management:
- Upload static assets such as product images to the S3 bucket using the AWS CLI or an SDK.
-
Database Configuration:
- Configure the RDS MySQL instance with the necessary database schema and credentials.
This section provides an overview of how the application handles key business functionalities, enabling both users and admins to interact with the system seamlessly.
- Users can browse products through various categories and use search filters to find specific items.
- Each product page provides detailed information, including descriptions, pricing, discounts, and customer reviews.
- Users can add products to their cart, update quantities, and proceed to checkout.
- After placing an order, users can track their order status in real-time, whether it's in processing, shipping, or delivered stages.
- Admins have full control over managing product SKUs, including creating, updating, or disabling products.
- SKUs are linked with inventory management, ensuring that stock levels are updated as orders are processed.
- Admins can view and manage all orders, with functionality to confirm COD orders and initiate shipping.
- Admins handle shipping orders through GHN. The admin panel is integrated with GHN's API for automated shipping label generation and tracking updates.
- Shipping status updates from GHN are automatically reflected in the system via webhook callbacks.