clc03 Hmtoan Ass4
clc03 Hmtoan Ass4
THÔNG
KHOA CÔNG NGHỆ THÔNG TIN
1
Chapter 1 : Requirements Of Commerce
I. Determine requirement
1.Actors
Actor Description
Actor Description
2
Add/Edit Books, Manage Inventory,
Add/Edit Electronic Devices
3
II. Analyze Requirements
Class Attribute
4
Cart Customer, Item, Quantity
Customer
ID: Integer (AutoField)
Name: Name (Object)
Email: Email (String)
Password: String
Phone: String
Address: Address (Object)
5
Item
ID: Integer (AutoField)
Name: String
Category: String
Price: Decimal
Stock: Integer
Provider: Provider (Reference)
Cart
Customer: Customer (Reference)
Item: Item (Reference)
Quantity: Integer
Order
Customer: Customer (Reference)
Order Date: DateTime
Status: String
Total Amount: Decimal
Payment
Order: Order (Reference)
Payment Method: String
Transaction ID: String
Payment Status: String
BankTransaction
ID: Integer (AutoField)
Order: Order (Reference)
Transaction ID: String
Status: String
Timestamp: DateTime
Shipping
Order: Order (Reference)
Delivery Address: Address (Object)
Status: String
Tracking Number: String
Staff
ID: Integer (AutoField)
6
Name: Name (Object)
Role: String ("order", "delivery", etc.)
Contact Info: String
Book
Linked Item: Item (OneToOne)
Title: String
Author: String
Publisher: Publisher (Reference)
ISBN: String
Electronic Device
Linked Item: Item (OneToOne)
Specifications: Text
Warranty Period: String
Producer: Producer (Reference)
Provider: Provider (Reference)
Name
Family Name: String
Last Name: String
Name: String
Address
Nation: String
City: String
Province: String
Street: String
House Number: String
Office Code: String
Admin
ID: Integer (AutoField)
Name: Name (Object)
Email: Email
Password: String
Phone: String
7
Address: Address (Object)
Phone: String
Class Function
Customer register_customer(),
login_customer(), view_profile(),
edit_profile()
Payment initiate_payment(),
confirm_payment(),
view_payment_status()
Bank validate_payment(),
process_refund()
Shipping assign_delivery(),
update_shipping_status(),
track_order()
8
Admin Panel add_publisher(), edit_provider(),
delete_producer(),
list_all_metadata()
Provider get()
4.Determine templates
Customer-facing template
9
edit_item.html Form to update general product
information
Admin Templates
10
add_publisher.html Add a new publisher
Shared templates
Component Responsiblity
11
links to both Producer and Provider
12
Order Service Order: place_order(), view_order(),
update_order_status(),
cancel_order()
3.Design API
13
/api/cart/ GET/POST/DELETE Cart operations
4.Conclusion
The design phase of this e-commerce system has demonstrated a clear and
effective application of microservices architecture using Django. Each service
has been independently modeled, structured, and connected to promote high
cohesion, low coupling, and domain-driven design, which are fundamental
principles of modern software engineering.
Microservices-Centric Architecture
The system has been decomposed into six core microservices: Customer,
Item,
Cart, Order, Payment, and Shipping. Each microservice is independently
responsible for a specific set of business capabilities and maintains its own
models, database schema, and logic. This separation allows for:
• Independent development and deployment of services.
• Improved scalability, as each service can be scaled horizontally based on
its specific demand.
• Fault isolation, meaning failure in one service (e.g., Shipping) does not
directly crash the others.
• Database autonomy, enabling optimized data storage technologies (e.g.,
14
using MongoDB for flexible item catalog and PostgreSQL for transaction
heavy modules).
15
16
17
18
19
20
21
22
23
24
Chapter 3 : AI In E-Commerce
1.Application of Deep Learning in E-commerce
Deep learning is transforming e-commerce by automating personalization,
improving search, optimizing logistics, and enhancing user experience. Key
applications include:
🔹 Product Recommendation
Using customer behavior history, embedding-based models (e.g., Word2Vec
for product sequences) can recommend relevant items.
Deep neural networks such as DeepFM or Wide & Deep models can capture
high-order feature interactions.
25
Convolutional Neural Networks (CNNs) can be used to analyze product
images and group similar-looking items.
🔹 Dynamic Pricing
Recurrent Neural Networks (RNNs) or Transformer-based models forecast
demand, allowing for optimized dynamic pricing based on trends and
competitor activity.
2.Sentiment Analysis
Sentiment analysis extracts user opinions from product reviews or customer
support interactions.
🔹 Goal:
Classify a review or comment as positive, neutral, or negative.
🔹 Approaches:
Traditional ML:
Logistic Regression, Naive Bayes with Bag-of-Words or TF-IDF
Deep Learning:
LSTM, GRU with word embeddings (Word2Vec, GloVe)
Transformer Models (Recommended):
BERT, RoBERTa, DistilBERT — high accuracy, context-aware
🔹 Pipeline:
Data Preprocessing:
Remove stopwords, lowercase, punctuation, emojis
Tokenization:
Using HuggingFace Tokenizer
Model Input Formatting:
Add [CLS] token for BERT
26
Fine-tuning:
Use pretrained BERT → Fine-tune on labeled e-commerce reviews
Output:
Use Cases:
- Review-aware Recommendation: Models like DeepCoNN and NARRE
combine user-item interaction with review embeddings.
- Sentiment Filtering: Boost or reduce visibility of products based on
recent sentiment trends.
- Cold Start Enhancement: Use textual sentiment to compensate for
🔹
limited purchase data.
Workflow:
- Collect and clean review text
- Use a fine-tuned BERT model for sentiment classification
- Generate a sentiment score for each product-user pair
- Combine with purchase history in hybrid recommendation engines
4.Deployment
To bring these AI features into production, several deployment strategies can
be used:
27
Message Queues: RabbitMQ or Kafka for real-time sentiment analysis on
reviews
Monitoring: Prometheus + Grafana for model inference performance and
uptime
Architecture Integration:
AI services can be treated as microservices, callable from Django apps
REST API endpoints like /api/reviews/sentiment/ can classify incoming text
Recommendation services can run periodically or respond to user sessions
dynamically
Step 1: Model Development and Training
Before deployment, train your sentiment classification model (e.g., fine-tune
BERT) using labeled customer review data.
Example Workflow:
Data Preparation: Clean and label your customer review dataset.
Model Selection: Choose a model like DistilBERT (lightweight but powerful).
Fine-tuning: Train on sentiment labels (positive, negative, neutral).
Save the model using transformers and torch.save() or
model.save_pretrained().
28
Request throughput
Latency (API response time)
Error rates
GPU/CPU usage
Add Prometheus client to your FastAPI:
bash
5.Conclusion
The integration of AI and deep learning into e-commerce systems brings a
new level of intelligence, automation, and personalization. From
understanding customer emotions through sentiment analysis to delivering
smarter product recommendations, AI enables a scalable, adaptive, and
customer-centric shopping experience.
29
Chapter 4 Implementation and deployment
30
Models.py
31
32
33
34
35
36
Serializers.py
37
38
views.py
39
40
41
42
Urls.py
43
44
Templates
45
46
47
48
49
50
Running
51
52
53
54
55