Hệ thống quản lý thư viện/cửa hàng sách - Ứng dụng full-stack được thiết kế cho khách hàng, nhân viên và quản trị viên nhằm tối ưu hóa hoạt động mua bán và quản lý sách.
Dự án Quản Lý Thư Viện/Cửa Hàng Sách là một giải pháp phần mềm full-stack hiện đại, được phát triển để nâng cao và đơn giản hóa quy trình quản lý cửa hàng sách. Xây dựng bằng NestJS (Backend) và Next.js (Frontend), tích hợp MySQL/PostgreSQL qua TypeORM, ứng dụng này mang đến giao diện thân thiện và API mạnh mẽ (GraphQL + REST) cho việc quản lý các khía cạnh khác nhau của doanh nghiệp sách.
- Chức năng đăng nhập/đăng ký an toàn với JWT Authentication.
- Hỗ trợ Google OAuth 2.0 để đăng nhập nhanh.
- Phân quyền truy cập theo vai trò (USER/ADMIN) để đảm bảo mức độ ủy quyền phù hợp.
- Quản lý Refresh Token và Blacklist Token để bảo mật cao.
- Thêm, sửa hoặc xóa các sản phẩm sách khỏi kho (Admin).
- Tìm kiếm, lọc và phân loại sách theo thể loại, tác giả, giá.
- Theo dõi mức tồn kho thông qua module Inventory.
- Hỗ trợ import dữ liệu sách từ file CSV.
- Hiển thị thông tin chi tiết sách với hình ảnh, mô tả, đánh giá.
- Quản lý giỏ hàng của khách hàng (thêm, xóa, cập nhật số lượng).
- Xử lý đơn hàng hiệu quả với tích hợp thanh toán Stripe.
- Lưu trữ lịch sử giao dịch và đơn hàng của khách hàng.
- Thêm, cập nhật và quản lý hồ sơ người dùng.
- Quản lý trạng thái tài khoản (Active/Inactive).
- Xem lịch sử mua hàng và hoạt động của người dùng.
- Khách hàng có thể để lại bình luận và đánh giá cho sách.
- Hệ thống bình luận có cấu trúc reply (trả lời bình luận).
- Quản lý và kiểm duyệt bình luận (Admin).
- Hệ thống thông báo tự động cho người dùng.
- WebSocket/Socket.IO để cập nhật thông báo theo thời gian thực.
- Quản lý và đánh dấu thông báo đã đọc/chưa đọc.
- Tích hợp Stripe để xử lý thanh toán trực tuyến an toàn.
- Hỗ trợ webhook để xác nhận thanh toán.
- Tạo và lưu trữ lịch sử thanh toán.
- Tìm kiếm sách thông minh với autocomplete.
- Lưu lịch sử tìm kiếm của người dùng.
- Cache kết quả tìm kiếm để tăng hiệu suất.
- Gửi email xác nhận đăng ký, reset password.
- Template email với Handlebars.
- Tích hợp Nodemailer để gửi email.
KTPM-Final-Project/
├── backend/ # NestJS Backend
│ ├── src/
│ │ ├── main.ts # Entry point
│ │ ├── app.module.ts # Root module
│ │ ├── schema.gql # GraphQL schema
│ │ ├── config/
│ │ │ └── db.config.ts # Database configuration
│ │ ├── modules/
│ │ │ ├── auth/ # Authentication module
│ │ │ │ ├── guards/ # JWT & Role guards
│ │ │ │ ├── strategies/ # Passport strategies
│ │ │ │ └── entities/ # RefreshToken, Blacklist
│ │ │ ├── users/ # User management
│ │ │ ├── books/ # Book management
│ │ │ │ └── mockData/ # CSV import data
│ │ │ ├── cart/ # Shopping cart
│ │ │ ├── Payment/ # Stripe integration
│ │ │ ├── comment/ # Comments & reviews
│ │ │ ├── notification/ # Notifications
│ │ │ ├── inventory/ # Stock management
│ │ │ └── Blacklist/ # Token blacklist
│ │ ├── mails/ # Email templates
│ │ ├── decorator/ # Custom decorators
│ │ ├── enum/ # Enums (Roles, etc.)
│ │ ├── entities/ # Shared entities
│ │ ├── helpers/ # Utility functions
│ │ ├── interceptors/ # Cache interceptor
│ │ └── middleware/ # Logging middleware
│ ├── package.json
│ ├── tsconfig.json
│ └── dockerfile
│
├── Frontend/ # Next.js Frontend
│ ├── src/
│ │ ├── app/ # App router pages
│ │ ├── components/ # React components
│ │ ├── lib/ # API clients, utilities
│ │ ├── context/ # React Context
│ │ ├── hooks/ # Custom hooks
│ │ └── Shared/ # Shared constants
│ ├── public/ # Static assets
│ ├── package.json
│ ├── next.config.ts
│ ├── tailwind.config.ts
│ └── dockerfile
│
├── Machine-Learning-Sentimental-Classfication/ # ML model
│ └── analyze-sentimental-review.ipynb
│
├── docker-compose.yml # Docker orchestration
└── README.md
-
Authentication
POST /auth/register- Đăng ký tài khoảnPOST /auth/login- Đăng nhậpPOST /auth/refresh- Refresh tokenPOST /auth/logout- Đăng xuấtGET /auth/google- Google OAuth login
-
Payment
POST /payment/create-checkout-session- Tạo phiên thanh toánPOST /payment/webhook- Stripe webhook
Truy cập GraphQL Playground tại http://localhost:3000/graphql
Queries:
# Lấy danh sách sách
query {
books {
id
title
author
price
stock
}
}
# Lấy giỏ hàng
query {
cart {
id
totalPrice
items {
book {
title
price
}
quantity
}
}
}
# Lấy thông báo
query {
notifications {
id
title
message
read
createdAt
}
}Mutations:
# Thêm sách vào giỏ
mutation {
addToCart(bookId: "uuid", quantity: 1) {
id
totalPrice
}
}
# Tạo bình luận
mutation {
createComment(input: {
bookId: "uuid"
content: "Great book!"
rating: 5
}) {
id
content
createdAt
}
}- Framework: NestJS (Node.js)
- Ngôn Ngữ: TypeScript
- API: GraphQL (Apollo Server) + REST API
- ORM: TypeORM
- Cơ Sở Dữ Liệu: MySQL
- Authentication: JWT, Passport.js, Google OAuth 2.0
- Thanh Toán: Stripe
- Email: Nodemailer + Handlebars
- Real-time: Socket.IO
- Cache: Cache Manager
- Security: Throttler (Rate Limiting), Helmet
- Framework: Next.js 14+ (React)
- Ngôn Ngữ: TypeScript
- Styling: Tailwind CSS
- State Management: React Context API
- UI Components: Radix UI, Shadcn/ui
- HTTP Client: Axios, Apollo Client (GraphQL)
- Forms: React Hook Form
- Containerization: Docker Compose
- Quản Lý Phiên Bản: Git, GitHub, Github Action
- IDE: Visual Studio Code
Trước khi bắt đầu, hãy đảm bảo rằng các yêu cầu sau đã được cài đặt:
- Node.js (LTS version, >=16.x)
- Docker Desktop - Môi trường ảo
- Git
Option 1: MySQL
-
Tải image MySQL:
docker pull mysql:8.0
-
Tạo container MySQL:
docker run --name mysql-db -e MYSQL_ROOT_PASSWORD=Thanhtuan@123 -e MYSQL_DATABASE=bookstore -p 3306:3306 -d mysql:8.0
-
Kiểm tra container đang chạy:
docker ps
-
Kết nối MySQL:
- Host:
localhost - Port:
3306 - Username:
root - Password:
Thanhtuan@123 - Database:
bookstore
- Host:
-
Clone repository:
# Sử dụng HTTPS git clone https://github.com/CallmeSen/KTPM-Final-Project.git # Sử dụng SSH git clone git@github.com:CallmeSen/KTPM-Final-Project.git
-
Cài đặt dependencies cho Backend:
cd KTPM-Final-Project/backend npm install -
Cấu hình file
.envcho Backend:Tạo file
.envtrong thư mụcbackend/với nội dung:# Database Configuration DB_HOST=localhost DB_PORT=3306 DB_USERNAME=root DB_PASSWORD=Thanhtuan@123 DB_NAME=bookstore # JWT Configuration JWT_SECRET=your-super-secret-jwt-key-here JWT_REFRESH_SECRET=your-refresh-secret-key-here JWT_EXPIRES_IN=1h JWT_REFRESH_EXPIRES_IN=7d # Google OAuth GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/callback # Stripe Configuration STRIPE_SECRET_KEY=your-stripe-secret-key STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret # Email Configuration MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USER=your-email@gmail.com MAIL_PASSWORD=your-app-password MAIL_FROM=noreply@bookstore.com # Application PORT=3000 NODE_ENV=development
-
Chạy Backend:
# Development mode npm run start:dev # Production mode npm run build npm run start:prod
Backend sẽ chạy tại
http://localhost:3000 -
Cài đặt dependencies cho Frontend:
cd ../Frontend npm install -
Cấu hình file
.env.localcho Frontend:Tạo file
.env.localtrong thư mụcFrontend/với nội dung:NEXT_PUBLIC_API_URL=http://localhost:3000 NEXT_PUBLIC_GRAPHQL_URL=http://localhost:3000/graphql NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=your-stripe-publishable-key
-
Chạy Frontend:
# Development mode npm run dev # Production mode npm run build npm start
Frontend sẽ chạy tại
http://localhost:3001
-
Từ thư mục root của project:
docker-compose up --build
-
Dừng containers:
docker-compose down
cd backend
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:covcd Frontend
# Run tests
npm run test
# Test with coverage
npm run test:coverage-
Build production:
npm run build
-
Start production server:
npm run start:prod
-
Build production:
npm run build
-
Start production server:
npm start
docker-compose -f docker-compose.prod.yml up -dSau khi chạy seeder hoặc import dữ liệu mẫu:
-
Admin:
- Email:
admin@bookstore.com - Password:
Admin@123
- Email:
-
User:
- Email:
user@bookstore.com - Password:
User@123
- Email:
- Kiểm tra Docker container có đang chạy không:
docker ps - Kiểm tra thông tin kết nối trong file
.env - Restart container:
docker restart mysql-dbhoặcdocker restart postgres-db
- Xóa folder
distvànode_modules/.cache - Chạy lại
npm install - Restart TypeScript server trong VS Code
- Thay đổi port trong file
.envvàmain.ts - Hoặc kill process đang sử dụng port:
# Windows netstat -ano | findstr :3000 taskkill /PID <PID> /F
This project is licensed under the GPL-3.0 License.
- Project Leader: Lâm Quang Khôi
- Team Member: Huỳnh Thanh Tuấn
- Team Member: Nguyễn Trọng Nghĩa
- Team Member: Nguyễn Huỳnh Phương Lộc
Note: Đây là project học tập.





