Tài liệu Kiến trúc Giải pháp (SA) Solution Architecture Document — Website TMĐT TechVN Thông tin tài liệu Mã tài liệu SA-TECHVN-2026-001 Phiên bản 1.0 Ngày tạo 20/04/2026 Ngày cập nhật 09/05/2026 Tác giả Lê Văn Cường — CTO / Solution Architect Đồng tác giả Đặng Hoàng Nam — Senior Backend Engineer Người phê duyệt Trần Quốc Hùng — CEO Trạng thái Đã phê duyệt (Approved) Mức độ bảo mật Nội bộ — Hạn chế (Internal — Restricted) BRD tham chiếu BRD-TECHVN-2026-001 v1.0 PRD tham chiếu PRD-TECHVN-2026-001 v1.0 SRS tham chiếu SRS-TECHVN-ECOM-2026-001 v1.0
Lịch sử thay đổi Phiên bản Ngày Người thay đổi Mô tả 0.1 20/04/2026 Lê Văn Cường Khởi tạo, kiến trúc tổng quan 0.4 28/04/2026 Đặng Hoàng Nam Bổ sung chi tiết backend, database schema 0.7 03/05/2026 Lê Văn Cường Bổ sung tích hợp, bảo mật, vận hành 0.9 07/05/2026 Security Team Review bảo mật, bổ sung threat model 1.0 09/05/2026 Lê Văn Cường Hoàn thiện sau phê duyệt
Mục lục Tổng quan kiến trúc Quyết định kiến trúc (ADR) Kiến trúc ứng dụng Thiết kế cơ sở dữ liệu Thiết kế API Tích hợp hệ thống bên ngoài Kiến trúc hạ tầng Bảo mật Hiệu năng và Khả năng mở rộng Giám sát và Vận hành Disaster Recovery CI/CD Pipeline Phụ lục 1. Tổng quan kiến trúc 1.1 Nguyên tắc kiến trúc # Nguyên tắc Mô tả Áp dụng AP-01 Đơn giản trước, phức tạp khi cần Bắt đầu với monolith modular, tách microservice khi có bottleneck rõ ràng Không over-engineer từ đầu AP-02 Cloud-native nhưng không lock-in Sử dụng managed services nhưng abstract qua interface Có thể chuyển cloud provider AP-03 API-first Mọi tính năng đều expose qua REST API trước, UI consume API Frontend/Backend phát triển song song AP-04 Security by design Bảo mật là yêu cầu chức năng, không phải afterthought OWASP top 10, mã hóa, audit log AP-05 Observable Mọi thành phần phải có logging, metrics, tracing Debug production issues nhanh AP-06 Infrastructure as Code Hạ tầng quản lý bằng code, reproducible Terraform, Docker, K8s manifests
1.2 Sơ đồ kiến trúc tổng quan (C4 Level 1 — System Context) ┌─────────────┐
│ Khách hàng │
│ (Browser / │
│ Mobile) │
└──────┬───────┘
│ HTTPS
▼
┌───────────────────────┐
│ │
│ WEBSITE TECHVN │
│ (techvn.vn) │
│ │
│ ┌─────────────────┐ │
│ │ Frontend │ │
│ │ (Next.js) │ │
│ └────────┬────────┘ │
│ │ API │
│ ┌────────▼────────┐ │
│ │ Backend │ │
│ │ (NestJS) │ │
│ └────────┬────────┘ │
│ │ │
└───────────┼───────────┘
│
┌────────────────┼────────────────┐
│ │ │
┌─────▼─────┐ ┌──────▼──────┐ ┌─────▼──────┐
│ Thanh │ │ Vận │ │ ERP │
│ toán │ │ chuyển │ │ (SAP B1) │
│ │ │ │ │ │
│ VNPAY │ │ GHTK │ │ Tồn kho │
│ MoMo │ │ GHN │ │ Giá │
│ Bank │ │ Viettel │ │ Sản phẩm │
└────────────┘ └─────────────┘ └────────────┘
│ │ │
┌─────▼─────┐ ┌──────▼──────┐ ┌─────▼──────┐
│ Trả góp │ │ SMS │ │ Analytics │
│ │ │ Gateway │ │ │
│ HD Saison │ │ SpeedSMS │ │ GA4 │
│ FE Credit │ │ Twilio │ │ FB Pixel │
└────────────┘ └─────────────┘ └────────────┘ 1.3 Sơ đồ kiến trúc chi tiết (C4 Level 2 — Container) ┌─────────────────────────────────────────────────────────────────────┐
│ AWS ap-southeast-1 │
│ │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ CloudFront CDN │ │
│ │ ├── Static assets (JS, CSS, Images, Fonts) │ │
│ │ └── Edge caching, Gzip/Brotli compression │ │
│ └──────────────────────────┬───────────────────────────────────┘ │
│ │ │
│ ┌──────────────────────────▼───────────────────────────────────┐ │
│ │ Application Load Balancer (ALB) │ │
│ │ ├── SSL Termination (TLS 1.3) │ │
│ │ ├── Health check │ │
│ │ └── Path-based routing: │ │
│ │ /api/* → Backend Service │ │
│ │ /* → Frontend Service │ │
│ └────────┬─────────────────────────────┬───────────────────────┘ │
│ │ │ │
│ ┌────────▼──────────┐ ┌──────────▼──────────┐ │
│ │ ECS Fargate │ │ ECS Fargate │ │
│ │ Frontend │ │ Backend │ │
│ │ │ │ │ │
│ │ Next.js 15 │ │ NestJS │ │
│ │ TypeScript │ │ TypeScript │ │
│ │ Tailwind CSS │ │ Node.js 20 LTS │ │
│ │ React 19 │ │ │ │
│ │ │ │ Modules: │ │
│ │ Features: │ │ ├── Auth │ │
│ │ ├── SSR/SSG │ │ ├── Product │ │
│ │ ├── ISR (15min) │ │ ├── Order │ │
│ │ ├── Image Opt │ │ ├── Payment │ │
│ │ └── API Routes │ │ ├── Shipping │ │
│ │ │ │ ├── Promotion │ │
│ │ Instances: 2-6 │ │ ├── User │ │
│ │ (auto-scale) │ │ ├── Notification │ │
│ │ │ │ ├── Review │ │
│ └───────────────────┘ │ ├── Search │ │
│ │ ├── Analytics │ │
│ │ └── Admin │ │
│ │ │ │
│ │ Instances: 2-8 │ │
│ │ (auto-scale) │ │
│ └──────────┬───────────┘ │
│ │ │
│ ┌───────────────────────────────┼──────────────────┐ │
│ │ │ │ │
│ ┌──────▼───────┐ ┌───────────────┐ ┌▼──────────────┐ │ │
│ │ PostgreSQL │ │ Redis │ │ Elasticsearch │ │ │
│ │ 16 │ │ 7 │ │ 8 │ │ │
│ │ │ │ │ │ │ │ │
│ │ RDS Multi-AZ │ │ ElastiCache │ │ OpenSearch │ │ │
│ │ │ │ Cluster │ │ Service │ │ │
│ │ Primary + │ │ │ │ │ │ │
│ │ Read Replica │ │ Uses: │ │ Uses: │ │ │
│ │ │ │ ├── Session │ │ ├── Product │ │ │
│ │ Storage: │ │ ├── Cache │ │ │ full-text │ │ │
│ │ ├── Users │ │ ├── Cart │ │ ├── Auto- │ │ │
│ │ ├── Products │ │ ├── OTP │ │ │ complete │ │ │
│ │ ├── Orders │ │ ├── Rate │ │ └── Faceted │ │ │
│ │ ├── Payments │ │ │ Limit │ │ search │ │ │
│ │ └── Reviews │ │ └── Queue │ │ │ │ │
│ │ │ │ │ │ │ │ │
│ └──────────────┘ └───────────────┘ └───────────────┘ │ │
│ │ │
│ ┌──────────────┐ ┌───────────────┐ ┌───────────────┐ │ │
│ │ S3 │ │ SQS │ │ SES │ │ │
│ │ │ │ │ │ │ │ │
│ │ Product │ │ Message Queue │ │ Email │ │ │
│ │ Images │ │ │ │ Service │ │ │
│ │ Documents │ │ Queues: │ │ │ │ │
│ │ Backups │ │ ├── order- │ │ Transactional │ │ │
│ │ │ │ │ events │ │ + Marketing │ │ │
│ │ │ │ ├── notif- │ │ │ │ │
│ │ │ │ │ ications │ │ │ │ │
│ │ │ │ ├── inventory │ │ │ │ │
│ │ │ │ │ sync │ │ │ │ │
│ │ │ │ └── payment- │ │ │ │ │
│ │ │ │ webhooks │ │ │ │ │
│ └──────────────┘ └───────────────┘ └───────────────┘ │ │
│ │ │
└────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘ 2. Quyết định kiến trúc (ADR) ADR-001: Monolith modular thay vì Microservices Trạng thái Đã chấp nhận Ngày 20/04/2026 Người quyết định CTO — Lê Văn Cường
Bối cảnh: Đội phát triển 5-7 người. Sản phẩm mới, yêu cầu có thể thay đổi. Budget hạn chế.
Quyết định: Sử dụng kiến trúc monolith modular (NestJS modules) thay vì microservices.
Lý do:
Tiêu chí Monolith Modular Microservices Độ phức tạp vận hành Thấp ✅ Cao ❌ Phù hợp đội nhỏ (5-7 người) Cao ✅ Thấp ❌ Tốc độ phát triển ban đầu Nhanh ✅ Chậm ❌ Chi phí hạ tầng Thấp ✅ Cao ❌ Khả năng tách service sau này Có (nhờ module boundary) ✅ N/A Scale độc lập từng service Không ❌ Có ✅
Hệ quả:
Các NestJS modules phải có boundary rõ ràng, communicate qua interface — không import trực tiếp internal class. Khi traffic vượt 10.000 CCU, đánh giá lại việc tách Search và Order thành service riêng. ADR-002: Next.js cho Frontend Trạng thái Đã chấp nhận Ngày 22/04/2026
Quyết định: Next.js 15 với App Router.
Lý do:
SSR/SSG/ISR cho SEO: Trang sản phẩm, danh mục cần Google index tốt.React ecosystem : Thư viện phong phú, dễ tuyển dụng tại VN.Image Optimization : Built-in, giảm bandwidth 30-50%.Edge Runtime : Middleware tại edge cho geo-routing, A/B testing.Phương án đã loại:
Framework Lý do loại Nuxt.js (Vue) Ecosystem nhỏ hơn React tại VN, khó tuyển dụng Remix Community nhỏ, ít production case study tại VN SPA thuần (Vite + React) Không có SSR built-in → SEO yếu cho ecommerce
ADR-003: PostgreSQL cho Database chính Trạng thái Đã chấp nhận Ngày 22/04/2026
Quyết định: PostgreSQL 16 trên AWS RDS Multi-AZ.
Lý do:
JSONB support : Lưu thông số kỹ thuật sản phẩm linh hoạt (mỗi danh mục có spec khác nhau).Full-text search (bổ trợ): Tìm kiếm cơ bản trước khi Elasticsearch sẵn sàng.Mature, reliable : Proven cho ecommerce workload.AWS RDS : Managed, Multi-AZ failover, automated backup.Phương án đã loại:
Database Lý do loại MySQL JSONB support yếu hơn, Full-text search tiếng Việt hạn chế MongoDB Không cần schemaless toàn bộ, SQL tốt hơn cho reporting
ADR-004: Elasticsearch cho Search Trạng thái Đã chấp nhận Ngày 25/04/2026
Quyết định: AWS OpenSearch Service (Elasticsearch 8 compatible).
Lý do:
Full-text search tiếng Việt : Plugin ICU + Vietnamese analyzer.Faceted search : Bộ lọc đa chiều (giá, brand, specs) với aggregation.Autocomplete : Completion suggester cho gợi ý realtime.Performance : Search < 100ms cho 5.000 SKU.Thay thế xem xét: Meilisearch (đơn giản hơn nhưng ít mature cho production, thiếu Vietnamese analyzer tốt).
ADR-005: SQS cho Message Queue Trạng thái Đã chấp nhận Ngày 28/04/2026
Quyết định: AWS SQS thay vì RabbitMQ self-hosted.
Lý do:
Managed : Không cần quản lý cluster, auto-scale.Reliability : 99.999999999% durability.Chi phí thấp cho workload ecommerce (vài nghìn messages/ngày).Dead Letter Queue : Built-in retry + DLQ cho failed messages.Use cases:
Queue Producer Consumer Mục đích order-eventsOrder Module Notification, Inventory, Analytics Xử lý async sau đặt hàng notificationsOrder, Promotion, System Notification Module Gửi email, SMS, push inventory-syncERP Connector Product Module Đồng bộ tồn kho từ SAP payment-webhooksAPI Gateway Payment Module Xử lý callback thanh toán
3. Kiến trúc ứng dụng 3.1 Backend — NestJS Module Structure src/
├── main.ts
├── app.module.ts
│
├── common/ # Shared utilities
│ ├── decorators/
│ ├── filters/ # Exception filters
│ ├── guards/ # Auth, Role guards
│ ├── interceptors/ # Logging, Transform
│ ├── pipes/ # Validation pipes
│ ├── interfaces/
│ └── utils/
│
├── config/ # Configuration module
│ ├── database.config.ts
│ ├── redis.config.ts
│ ├── aws.config.ts
│ └── app.config.ts
│
├── modules/
│ ├── auth/ # Authentication & Authorization
│ │ ├── auth.module.ts
│ │ ├── auth.controller.ts
│ │ ├── auth.service.ts
│ │ ├── strategies/ # JWT, Google, Facebook
│ │ ├── guards/
│ │ └── dto/
│ │
│ ├── user/ # User management
│ │ ├── user.module.ts
│ │ ├── user.controller.ts
│ │ ├── user.service.ts
│ │ ├── entities/
│ │ │ ├── user.entity.ts
│ │ │ └── address.entity.ts
│ │ └── dto/
│ │
│ ├── product/ # Product catalog
│ │ ├── product.module.ts
│ │ ├── controllers/
│ │ │ ├── product.controller.ts
│ │ │ ├── category.controller.ts
│ │ │ └── brand.controller.ts
│ │ ├── services/
│ │ │ ├── product.service.ts
│ │ │ ├── category.service.ts
│ │ │ ├── variant.service.ts
│ │ │ └── product-search.service.ts
│ │ ├── entities/
│ │ │ ├── product.entity.ts
│ │ │ ├── product-variant.entity.ts
│ │ │ ├── product-spec.entity.ts
│ │ │ ├── category.entity.ts
│ │ │ └── brand.entity.ts
│ │ └── dto/
│ │
│ ├── order/ # Order management
│ │ ├── order.module.ts
│ │ ├── controllers/
│ │ ├── services/
│ │ │ ├── order.service.ts
│ │ │ ├── cart.service.ts
│ │ │ └── checkout.service.ts
│ │ ├── entities/
│ │ │ ├── order.entity.ts
│ │ │ ├── order-item.entity.ts
│ │ │ └── cart.entity.ts
│ │ └── events/ # Order domain events
│ │
│ ├── payment/ # Payment processing
│ │ ├── payment.module.ts
│ │ ├── payment.controller.ts
│ │ ├── services/
│ │ │ ├── payment.service.ts
│ │ │ ├── vnpay.service.ts
│ │ │ ├── momo.service.ts
│ │ │ └── installment.service.ts
│ │ ├── entities/
│ │ └── webhooks/ # Payment callbacks
│ │
│ ├── shipping/ # Shipping integration
│ │ ├── shipping.module.ts
│ │ ├── services/
│ │ │ ├── shipping.service.ts
│ │ │ ├── ghtk.service.ts
│ │ │ └── ghn.service.ts
│ │ └── dto/
│ │
│ ├── promotion/ # Coupon & Promotion
│ │ ├── promotion.module.ts
│ │ ├── services/
│ │ │ ├── coupon.service.ts
│ │ │ └── flash-sale.service.ts
│ │ └── entities/
│ │
│ ├── review/ # Product reviews
│ │ ├── review.module.ts
│ │ ├── review.controller.ts
│ │ ├── review.service.ts
│ │ └── entities/
│ │
│ ├── notification/ # Multi-channel notification
│ │ ├── notification.module.ts
│ │ ├── services/
│ │ │ ├── notification.service.ts
│ │ │ ├── email.service.ts
│ │ │ ├── sms.service.ts
│ │ │ └── push.service.ts
│ │ └── templates/
│ │
│ ├── search/ # Search & Indexing
│ │ ├── search.module.ts
│ │ ├── search.controller.ts
│ │ ├── search.service.ts
│ │ └── indexer.service.ts
│ │
│ ├── admin/ # Admin back-office
│ │ ├── admin.module.ts
│ │ ├── controllers/
│ │ │ ├── admin-product.controller.ts
│ │ │ ├── admin-order.controller.ts
│ │ │ ├── admin-user.controller.ts
│ │ │ └── dashboard.controller.ts
│ │ └── services/
│ │ ├── dashboard.service.ts
│ │ └── report.service.ts
│ │
│ └── integration/ # External system integration
│ ├── integration.module.ts
│ └── services/
│ └── erp-sync.service.ts
│
├── database/
│ ├── migrations/
│ └── seeds/
│
└── workers/ # Background jobs
├── inventory-sync.worker.ts
├── notification.worker.ts
├── cart-cleanup.worker.ts
└── report-generator.worker.ts 3.2 Frontend — Next.js App Structure src/
├── app/ # App Router (Next.js 15)
│ ├── layout.tsx # Root layout (header, footer)
│ ├── page.tsx # Homepage (SSG + ISR 15min)
│ ├── loading.tsx # Global loading skeleton
│ ├── error.tsx # Error boundary
│ ├── not-found.tsx
│ │
│ ├── (auth)/ # Auth group (no header)
│ │ ├── dang-nhap/page.tsx
│ │ ├── dang-ky/page.tsx
│ │ └── quen-mat-khau/page.tsx
│ │
│ ├── (shop)/ # Shop group (with header)
│ │ ├── [category]/ # Dynamic category pages (SSG)
│ │ │ └── page.tsx
│ │ ├── [category]/[product]/ # Product detail (SSG + ISR)
│ │ │ └── page.tsx
│ │ ├── tim-kiem/page.tsx # Search results (SSR)
│ │ ├── so-sanh/page.tsx # Compare (CSR)
│ │ └── khuyen-mai/page.tsx # Promotions (SSR)
│ │
│ ├── gio-hang/page.tsx # Cart (CSR)
│ ├── thanh-toan/ # Checkout (CSR, protected)
│ │ └── page.tsx
│ │
│ ├── tai-khoan/ # Account (CSR, protected)
│ │ ├── layout.tsx
│ │ ├── thong-tin/page.tsx
│ │ ├── don-hang/page.tsx
│ │ ├── don-hang/[id]/page.tsx
│ │ ├── dia-chi/page.tsx
│ │ └── yeu-thich/page.tsx
│ │
│ ├── admin/ # Admin (CSR, role-protected)
│ │ ├── layout.tsx
│ │ ├── page.tsx # Dashboard
│ │ ├── san-pham/
│ │ ├── don-hang/
│ │ ├── khach-hang/
│ │ ├── khuyen-mai/
│ │ └── bao-cao/
│ │
│ └── api/ # API routes (BFF pattern)
│ ├── auth/[...nextauth]/
│ └── revalidate/
│
├── components/
│ ├── ui/ # Design system atoms
│ │ ├── Button/
│ │ ├── Input/
│ │ ├── Modal/
│ │ ├── Skeleton/
│ │ ├── Badge/
│ │ └── Toast/
│ ├── layout/ # Layout components
│ │ ├── Header/
│ │ ├── Footer/
│ │ ├── MegaMenu/
│ │ └── Sidebar/
│ ├── product/ # Product domain
│ │ ├── ProductCard/
│ │ ├── ProductGallery/
│ │ ├── ProductSpecs/
│ │ ├── ProductFilter/
│ │ ├── CompareTable/
│ │ └── QuickView/
│ ├── cart/
│ ├── checkout/
│ └── account/
│
├── hooks/ # Custom React hooks
│ ├── useCart.ts
│ ├── useAuth.ts
│ ├── useSearch.ts
│ └── useDebounce.ts
│
├── lib/ # Utilities
│ ├── api-client.ts # Axios/Fetch wrapper
│ ├── format.ts # Price, date formatting
│ └── validators.ts
│
├── stores/ # State management (Zustand)
│ ├── cart.store.ts
│ ├── compare.store.ts
│ └── auth.store.ts
│
└── styles/
└── globals.css # Tailwind + custom tokens 3.3 Rendering Strategy Trang Phương pháp Revalidation Lý do Trang chủ SSG + ISR 15 phút Nội dung ít thay đổi, SEO quan trọng Trang danh mục SSG + ISR 15 phút SEO, danh sách SP ít thay đổi theo phút Trang chi tiết SP SSG + ISR 60 phút SEO, thông tin SP ổn định, giá update qua ISR Tìm kiếm SSR Mỗi request Kết quả dynamic theo từ khóa Giỏ hàng CSR N/A Dữ liệu cá nhân, không cần SEO Checkout CSR N/A Dữ liệu cá nhân, bảo mật Tài khoản CSR N/A Dữ liệu cá nhân Admin CSR N/A Internal tool, không cần SEO
4. Thiết kế cơ sở dữ liệu 4.1 Sơ đồ ERD ┌──────────────────┐ ┌──────────────────────┐
│ users │ │ addresses │
├──────────────────┤ ├──────────────────────┤
│ id PK │───┐ │ id PK │
│ email UQ │ │ │ user_id FK │
│ phone UQ │ └──>│ recipient_name │
│ password_hash │ │ phone │
│ full_name │ │ province_code │
│ avatar_url │ │ district_code │
│ status │ │ ward_code │
│ role │ │ address_detail │
│ loyalty_points │ │ is_default │
│ created_at │ │ created_at │
│ updated_at │ └──────────────────────┘
└──────────────────┘
│
│ 1:N
▼
┌──────────────────┐ ┌──────────────────────┐
│ orders │ │ order_items │
├──────────────────┤ ├──────────────────────┤
│ id PK │───┐ │ id PK │
│ order_code UQ │ │ │ order_id FK │
│ user_id FK │ └──>│ product_id FK │
│ address_id FK │ │ variant_id FK │
│ subtotal │ │ product_name │
│ discount_amount │ │ sku │
│ shipping_fee │ │ unit_price │
│ total │ │ quantity │
│ status │ │ total │
│ payment_method │ └──────────────────────┘
│ payment_status │
│ shipping_provider│ ┌──────────────────────┐
│ tracking_code │ │ payments │
│ note │ ├──────────────────────┤
│ internal_note │ │ id PK │
│ coupon_code │ ┌──>│ order_id FK │
│ created_at │───┘ │ method │
│ confirmed_at │ │ provider │
│ shipped_at │ │ transaction_id │
│ delivered_at │ │ amount │
│ cancelled_at │ │ status │
└──────────────────┘ │ provider_response │
│ created_at │
└──────────────────────┘
┌──────────────────┐ ┌──────────────────────┐
│ categories │ │ brands │
├──────────────────┤ ├──────────────────────┤
│ id PK │ │ id PK │
│ parent_id FK │──┐ │ name │
│ name │ │ │ slug UQ │
│ slug UQ │ │ │ logo_url │
│ image_url │<─┘ │ description │
│ description │ │ sort_order │
│ sort_order │ └──────────────────────┘
│ is_active │
│ level │
└──────────────────┘
│
│ 1:N
▼
┌──────────────────┐ ┌──────────────────────┐
│ products │ │ product_variants │
├──────────────────┤ ├──────────────────────┤
│ id PK │───┐ │ id PK │
│ category_id FK │ │ │ product_id FK │
│ brand_id FK │ └──>│ name │
│ name │ │ sku UQ │
│ slug UQ │ │ price │
│ sku UQ │ │ sale_price │
│ price │ │ stock_quantity │
│ sale_price │ │ attributes JSONB │
│ stock_quantity │ │ is_active │
│ short_desc │ └──────────────────────┘
│ description │
│ status │ ┌──────────────────────┐
│ is_featured │ │ product_specs │
│ avg_rating │ ├──────────────────────┤
│ review_count │ │ id PK │
│ sold_count │ ┌──>│ product_id FK │
│ specs JSONB │───┘ │ spec_group │
│ seo_title │ │ spec_name │
│ seo_description │ │ spec_value │
│ created_at │ │ sort_order │
│ updated_at │ └──────────────────────┘
│ published_at │
└──────────────────┘ ┌──────────────────────┐
│ │ product_images │
│ 1:N ├──────────────────────┤
└────────────────>│ id PK │
│ product_id FK │
│ url │
│ alt_text │
│ sort_order │
│ is_primary │
└──────────────────────┘
┌──────────────────┐ ┌──────────────────────┐
│ reviews │ │ coupons │
├──────────────────┤ ├──────────────────────┤
│ id PK │ │ id PK │
│ product_id FK │ │ code UQ │
│ user_id FK │ │ type │
│ order_id FK │ │ value │
│ rating │ │ max_discount │
│ title │ │ min_order_value │
│ content │ │ usage_limit │
│ images JSONB │ │ used_count │
│ status │ │ per_user_limit │
│ admin_reply │ │ applicable_categories│
│ created_at │ │ start_date │
│ approved_at │ │ end_date │
└──────────────────┘ │ is_active │
│ created_at │
└──────────────────────┘
┌──────────────────┐
│ audit_logs │
├──────────────────┤
│ id PK │
│ admin_id FK │
│ action │
│ entity_type │
│ entity_id │
│ old_values JSONB │
│ new_values JSONB │
│ ip_address │
│ user_agent │
│ created_at │
└──────────────────┘ 4.2 Indexing Strategy Bảng Index Loại Lý do products(category_id, status, sort_order)B-tree Danh sách SP theo danh mục products(brand_id, status)B-tree Lọc theo thương hiệu products(status, is_featured, created_at DESC)B-tree Trang chủ, SP nổi bật products(slug)Unique URL lookup products(specs)GIN JSONB query thông số kỹ thuật orders(user_id, created_at DESC)B-tree Lịch sử đơn hàng orders(status, created_at DESC)B-tree Admin danh sách đơn hàng orders(order_code)Unique Tra cứu theo mã đơn order_items(order_id)B-tree Join chi tiết đơn reviews(product_id, status, created_at DESC)B-tree Hiển thị đánh giá users(email)Unique Đăng nhập users(phone)Unique Đăng nhập SĐT
4.3 Data Partitioning (kế hoạch tương lai) Bảng Chiến lược Trigger ordersRange partition theo created_at (monthly) > 1 triệu đơn audit_logsRange partition theo created_at (monthly) > 10 triệu records product_views (analytics)Range partition theo ngày Từ khi tạo
5. Thiết kế API 5.1 Quy ước API Quy ước Chi tiết Base URL https://api.techvn.vn/v1Format JSON (application/json) Authentication Bearer JWT token trong header Authorization Versioning URL path (/v1/, /v2/) Naming Lowercase, kebab-case cho URL, camelCase cho JSON fields Pagination Cursor-based (default) hoặc Offset-based (admin) Error Format { "statusCode": 400, "message": "...", "error": "Bad Request" }Rate Limiting 100 req/phút/IP (public), 300 req/phút/user (authenticated) Compression Gzip / Brotli
5.2 API Endpoints chính Authentication Method Endpoint Mô tả Auth POST /v1/auth/registerĐăng ký tài khoản Public POST /v1/auth/verify-otpXác thực OTP Public POST /v1/auth/loginĐăng nhập email/SĐT Public POST /v1/auth/login/googleĐăng nhập Google OAuth Public POST /v1/auth/login/facebookĐăng nhập Facebook OAuth Public POST /v1/auth/forgot-passwordYêu cầu đặt lại mật khẩu Public POST /v1/auth/reset-passwordĐặt lại mật khẩu Public POST /v1/auth/refresh-tokenLàm mới access token Refresh Token POST /v1/auth/logoutĐăng xuất (invalidate token) User
Products Method Endpoint Mô tả Auth GET /v1/productsDanh sách SP (filter, sort, paginate) Public GET /v1/products/:slugChi tiết sản phẩm Public GET /v1/products/:id/reviewsĐánh giá của sản phẩm Public GET /v1/products/compare?ids=1,2,3So sánh sản phẩm Public GET /v1/categoriesCây danh mục Public GET /v1/categories/:slug/productsSP theo danh mục Public GET /v1/brandsDanh sách thương hiệu Public GET /v1/search?q=...Tìm kiếm sản phẩm Public GET /v1/search/suggest?q=...Gợi ý tìm kiếm (autocomplete) Public
Cart & Orders Method Endpoint Mô tả Auth GET /v1/cartXem giỏ hàng User POST /v1/cart/itemsThêm SP vào giỏ User PATCH /v1/cart/items/:idCập nhật số lượng User DELETE /v1/cart/items/:idXóa SP khỏi giỏ User POST /v1/cart/couponÁp dụng mã giảm giá User DELETE /v1/cart/couponXóa mã giảm giá User POST /v1/ordersTạo đơn hàng (checkout) User GET /v1/ordersLịch sử đơn hàng User GET /v1/orders/:idChi tiết đơn hàng User POST /v1/orders/:id/cancelHủy đơn hàng User POST /v1/orders/:id/reviewsĐánh giá sản phẩm trong đơn User
Payment (Webhooks) Method Endpoint Mô tả Auth POST /v1/payments/vnpay/callbackVNPAY IPN callback VNPAY signature POST /v1/payments/momo/callbackMoMo IPN callback MoMo signature GET /v1/payments/vnpay/returnVNPAY return URL Public
Shipping Method Endpoint Mô tả Auth POST /v1/shipping/calculateTính phí vận chuyển User GET /v1/shipping/provincesDanh sách Tỉnh/Thành Public GET /v1/shipping/districts?province=...Quận/Huyện Public GET /v1/shipping/wards?district=...Phường/Xã Public
Admin (prefix /v1/admin/) Method Endpoint Mô tả Auth GET /v1/admin/dashboardDữ liệu dashboard Admin CRUD /v1/admin/productsQuản lý sản phẩm Admin POST /v1/admin/products/importImport Excel Admin CRUD /v1/admin/ordersQuản lý đơn hàng Admin POST /v1/admin/orders/:id/confirmXác nhận đơn Admin POST /v1/admin/orders/:id/shipTạo đơn vận chuyển Admin POST /v1/admin/orders/:id/refundHoàn tiền Admin CRUD /v1/admin/couponsQuản lý mã giảm giá Admin CRUD /v1/admin/usersQuản lý khách hàng Admin GET /v1/admin/reports/revenueBáo cáo doanh thu Admin GET /v1/admin/audit-logsNhật ký thao tác SuperAdmin
5.3 Authentication Flow ┌────────┐ ┌──────────┐ ┌──────────┐
│ Client │ │ Backend │ │ Redis │
└───┬────┘ └────┬─────┘ └────┬─────┘
│ │ │
│ POST /auth/login │ │
│ {email, password} │ │
├─────────────────────────>│ │
│ │ Verify credentials │
│ │ Generate tokens │
│ │ │
│ │ Store refresh token │
│ ├─────────────────────────>│
│ │ │
│ {accessToken (15min), │ │
│ refreshToken (30d)} │ │
│<─────────────────────────┤ │
│ │ │
│ GET /products │ │
│ Authorization: Bearer │ │
│ <accessToken> │ │
├─────────────────────────>│ │
│ │ Verify JWT │
│ 200 OK │ (no DB call needed) │
│<─────────────────────────┤ │
│ │ │
│ --- Access token expired --- │
│ │ │
│ POST /auth/refresh │ │
│ {refreshToken} │ │
├─────────────────────────>│ │
│ │ Verify refresh token │
│ ├─────────────────────────>│
│ │ Valid? Rotate token │
│ │<─────────────────────────┤
│ {new accessToken, │ │
│ new refreshToken} │ │
│<─────────────────────────┤ │ JWT Payload:
json {
"sub" : "user-uuid" ,
"email" : "[email protected] " ,
"role" : "customer" ,
"iat" : 1715230000 ,
"exp" : 1715230900
} 6. Tích hợp hệ thống bên ngoài 6.1 Ma trận tích hợp Hệ thống Giao thức Hướng Tần suất Retry Policy VNPAY REST HTTPS Bidirectional Per transaction 3 retries, exponential backoff MoMo REST HTTPS Bidirectional Per transaction 3 retries, exponential backoff GHTK REST HTTPS Outbound + Webhook Per order 3 retries, 30s interval GHN REST HTTPS Outbound + Webhook Per order 3 retries, 30s interval SAP Business One REST HTTPS (DI API) Bidirectional Poll every 5 min Queue + retry SpeedSMS REST HTTPS Outbound Per event 2 retries AWS SES AWS SDK Outbound Per event SQS + retry Google OAuth OAuth 2.0 Inbound Per login N/A Facebook OAuth OAuth 2.0 Inbound Per login N/A Google Analytics 4 JavaScript SDK Outbound Per event Client-side Facebook Pixel JavaScript SDK Outbound Per event Client-side
6.2 Luồng thanh toán VNPAY ┌────────┐ ┌──────────┐ ┌──────────┐ ┌────────┐
│ Client │ │ Backend │ │ VNPAY │ │ SQS │
└───┬────┘ └────┬─────┘ └────┬─────┘ └───┬────┘
│ │ │ │
│ Place order │ │ │
├─────────────>│ │ │
│ │ Create order │ │
│ │ status= │ │
│ │ PENDING_PAY │ │
│ │ │ │
│ │ Create VNPAY │ │
│ │ payment URL │ │
│ ├──────────────>│ │
│ │ Payment URL │ │
│ │<──────────────┤ │
│ │ │ │
│ Redirect to │ │ │
│ VNPAY │ │ │
│<─────────────┤ │ │
│ │ │ │
├──────────────────────────────>│ │
│ Customer completes │ │
│ payment on VNPAY │ │
│<─────────────────────────────┤ │
│ │ │ │
│ Return URL │ IPN Callback │ │
├─────────────>│<──────────────┤ │
│ │ │ │
│ │ Verify VNPAY │ │
│ │ checksum │ │
│ │ │ │
│ │ Update order │ │
│ │ status=PAID │ │
│ │ │ │
│ │ Emit event ──────────────────>│
│ │ "order.paid" │ │
│ │ │ │
│ Order │ │ Workers: │
│ success page │ │ - Email │
│<─────────────┤ │ - SMS │
│ │ │ - Stock │ 6.3 Đồng bộ tồn kho với ERP (SAP Business One) Chiến lược: Polling + Event-driven hybrid
┌──────────────────────────────────────────────┐
│ INVENTORY SYNC FLOW │
│ │
│ ┌─────────┐ Poll every 5 min ┌────────┐ │
│ │ SAP B1 │ ──────────────────> │ Sync │ │
│ │ DI API │ │ Worker │ │
│ └─────────┘ └───┬────┘ │
│ │ │
│ ┌───────▼────┐ │
│ │ Compare & │ │
│ │ Diff │ │
│ └───────┬────┘ │
│ │ │
│ ┌────────────┼────┐ │
│ │ │ │ │
│ No change Has changes │ │
│ (skip) │ │ │
│ ┌───▼───────┐ │
│ │ Update │ │
│ │ PostgreSQL│ │
│ └───┬───────┘ │
│ │ │
│ ┌───▼───────┐ │
│ │ Invalidate│ │
│ │ Redis │ │
│ │ Cache │ │
│ └───┬───────┘ │
│ │ │
│ ┌───▼───────┐ │
│ │ Re-index │ │
│ │ Elastic- │ │
│ │ search │ │
│ └───────────┘ │
│ │
│ Website purchase ──> Deduct stock in DB │
│ ──> Sync back to SAP │
│ (via SQS queue) │
└──────────────────────────────────────────────┘ Xử lý xung đột:
Kịch bản Xử lý SAP stock = 0, Web stock > 0 Cập nhật Web = 0, đánh dấu "Hết hàng" Khách đặt hàng trong lúc sync Kiểm tra stock tại thời điểm checkout (DB lock), nếu hết → thông báo SAP giá thay đổi Cập nhật giá trên Web, thông báo khách có SP trong giỏ SAP không phản hồi (timeout) Retry 3 lần, sau đó alert ops team, giữ nguyên dữ liệu hiện tại
7. Kiến trúc hạ tầng 7.1 AWS Infrastructure Service Mục đích Cấu hình Ước tính chi phí/tháng ECS Fargate App containers (Frontend + Backend) Frontend: 2-6 tasks (0.5 vCPU, 1GB), Backend: 2-8 tasks (1 vCPU, 2GB) ~$350 RDS PostgreSQL Database chính db.r6g.large, Multi-AZ, 100GB gp3, 1 Read Replica ~$450 ElastiCache Redis Cache, Session, Queue cache.r6g.large, 2 nodes (cluster mode) ~$300 OpenSearch Full-text search t3.medium.search, 2 nodes, 50GB ~$180 S3 Object storage (images, backups) Standard, ~500GB (estimate) ~$15 CloudFront CDN ~2TB transfer/tháng ~$120 ALB Load Balancer 1 ALB, path-based routing ~$30 SQS Message Queue ~100K messages/tháng ~$5 SES Email Service ~50K emails/tháng ~$5 Route 53 DNS techvn.vn ~$1 ACM SSL Certificate Wildcard *.techvn.vn Free CloudWatch Logging, Monitoring Logs + Metrics + Alarms ~$50 WAF Web Application Firewall Core rule set + rate limiting ~$30 ECR Container Registry Docker images ~$5 Secrets Manager Secrets management API keys, DB credentials ~$5 Tổng ước tính ~$1.546 (~15 triệu VNĐ/tháng)
7.2 Network Architecture ┌─────────────────────────────────────────────────────────────────┐
│ VPC: 10.0.0.0/16 │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Public Subnet (10.0.1.0/24, 10.0.2.0/24) │ │
│ │ ├── ALB │ │
│ │ ├── NAT Gateway │ │
│ │ └── Bastion Host (optional, for emergency access) │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Private Subnet — App (10.0.10.0/24, 10.0.11.0/24) │ │
│ │ ├── ECS Fargate Tasks (Frontend) │ │
│ │ ├── ECS Fargate Tasks (Backend) │ │
│ │ └── ECS Fargate Tasks (Workers) │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Private Subnet — Data (10.0.20.0/24, 10.0.21.0/24) │ │
│ │ ├── RDS PostgreSQL (Primary + Read Replica) │ │
│ │ ├── ElastiCache Redis Cluster │ │
│ │ └── OpenSearch Domain │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ Security Groups: │
│ ├── sg-alb: Inbound 80, 443 from 0.0.0.0/0 │
│ ├── sg-app: Inbound from sg-alb only │
│ ├── sg-db: Inbound 5432 from sg-app only │
│ ├── sg-redis: Inbound 6379 from sg-app only │
│ └── sg-es: Inbound 9200 from sg-app only │
└─────────────────────────────────────────────────────────────────┘ 7.3 Multi-AZ Deployment Component AZ-a AZ-b Failover ALB ✅ ✅ Automatic ECS Tasks ✅ (min 1) ✅ (min 1) Automatic (ECS scheduler) RDS Primary ✅ Automatic failover to standby RDS Standby ✅ Promoted automatically RDS Read Replica ✅ Manual promotion if needed Redis Node 1 ✅ Automatic failover Redis Node 2 ✅ Promoted automatically NAT Gateway ✅ ✅ Redundant
8. Bảo mật 8.1 Security Architecture Layers ┌──────────────────────────────────────────────┐
│ Layer 1: Edge Security │
│ ├── CloudFront (DDoS L3/L4) │
│ ├── AWS WAF (OWASP rules, rate limiting) │
│ └── AWS Shield Standard │
├──────────────────────────────────────────────┤
│ Layer 2: Network Security │
│ ├── VPC with private subnets │
│ ├── Security Groups (least privilege) │
│ ├── NACLs │
│ └── No public IP on app/data instances │
├──────────────────────────────────────────────┤
│ Layer 3: Application Security │
│ ├── JWT authentication │
│ ├── RBAC authorization │
│ ├── Input validation (class-validator) │
│ ├── SQL injection prevention (TypeORM) │
│ ├── XSS prevention (React auto-escape) │
│ ├── CSRF protection (SameSite cookies) │
│ ├── Rate limiting (per IP, per user) │
│ └── Helmet.js (security headers) │
├──────────────────────────────────────────────┤
│ Layer 4: Data Security │
│ ├── Encryption at rest (AES-256, RDS) │
│ ├── Encryption in transit (TLS 1.3) │
│ ├── Password hashing (bcrypt, cost=12) │
│ ├── PII masking in logs │
│ ├── Secrets Manager (no hardcoded secrets) │
│ └── Database audit logging │
├──────────────────────────────────────────────┤
│ Layer 5: Operational Security │
│ ├── IAM roles (least privilege) │
│ ├── MFA for AWS console │
│ ├── Container image scanning (ECR) │
│ ├── Dependency vulnerability scanning │
│ └── Security monitoring (CloudTrail) │
└──────────────────────────────────────────────┘ 8.2 OWASP Top 10 Mitigation # Lỗ hổng Biện pháp A01 Broken Access Control RBAC, resource-level authorization checks, JWT validation A02 Cryptographic Failures TLS 1.3, AES-256 at-rest, bcrypt passwords, no sensitive data in URL A03 Injection TypeORM parameterized queries, class-validator input validation A04 Insecure Design Threat modeling, security review in PR process A05 Security Misconfiguration Infrastructure as Code, security headers (Helmet), disable debug in production A06 Vulnerable Components Dependabot, npm audit in CI, container scanning A07 Auth Failures Rate limiting login, account lockout, secure password policy, OTP A08 Data Integrity Failures HMAC verification for payment callbacks, signed URLs for S3 A09 Logging Failures Structured logging, PII masking, audit trail for admin actions A10 SSRF Allowlist for outbound requests, no user-controlled URLs in server requests
8.3 Tuân thủ pháp lý Quy định Yêu cầu Implementation Nghị định 13/2023/NĐ-CP (Bảo vệ DLCN) Xin đồng ý trước khi thu thập PII, quyền xóa dữ liệu, thông báo khi rò rỉ Consent popup, API xóa tài khoản, Incident response plan Nghị định 52/2013/NĐ-CP (TMĐT) Đăng ký website TMĐT, hiển thị thông tin DN, chính sách rõ ràng Đăng ký online.gov.vn, trang "Giới thiệu", các trang chính sách PCI-DSS Không lưu thông tin thẻ, sử dụng cổng thanh toán certified Redirect to VNPAY/MoMo, no card data touches our server
9. Hiệu năng và Khả năng mở rộng 9.1 Caching Strategy Layer Công nghệ Cache Target TTL Invalidation CDN CloudFront Static assets (JS, CSS, images, fonts) 30 ngày Deploy invalidation CDN CloudFront SSG/ISR pages 15-60 phút ISR revalidation Application Redis Product catalog (list, detail) 15 phút On product update Application Redis Category tree 1 giờ On category update Application Redis Search results (top queries) 10 phút On product index Application Redis User session 30 phút (idle) On logout Application Redis Shopping cart 30 ngày On cart update Application Redis OTP codes 5 phút One-time use Application Redis Rate limit counters 1 phút Auto-expire Database PostgreSQL Query plan cache Auto Auto Browser Service Worker Shell + critical assets Until update SW update
Metric Target Đo bằng FCP (First Contentful Paint) ≤ 1.5s Lighthouse, Web Vitals LCP (Largest Contentful Paint) ≤ 2.5s Lighthouse, Web Vitals CLS (Cumulative Layout Shift) ≤ 0.1 Lighthouse, Web Vitals INP (Interaction to Next Paint) ≤ 200ms Web Vitals TTFB (Time to First Byte) ≤ 500ms Lighthouse JS Bundle (initial) ≤ 150KB gzipped Webpack Analyzer Total page weight (homepage) ≤ 1.5MB Network tab API response (P95) ≤ 500ms Application monitoring Search response (P95) ≤ 300ms Application monitoring Image load (above fold) ≤ 1s Web Vitals
9.3 Auto-scaling Configuration Component Metric Scale Out Scale In Min Max Frontend ECS CPU > 70% (3 min) +2 tasks CPU < 30% (10 min), -1 task 2 6 Backend ECS CPU > 60% (3 min) +2 tasks CPU < 25% (10 min), -1 task 2 8 Worker ECS SQS queue depth > 100 +1 task Queue depth = 0 (5 min), -1 task 1 4 RDS Read Replica Thêm replica khi cần Manual Manual 1 3
Flash Sale scaling plan:
T-24h: Scale Backend lên 6 tasks, Redis lên r6g.xlarge. T-1h: Scale Backend lên 8 tasks, pre-warm cache cho SP flash sale. T+0: Monitor realtime, sẵn sàng manual scale nếu cần. T+2h: Bắt đầu scale down nếu traffic giảm. 10. Giám sát và Vận hành 10.1 Monitoring Stack ┌──────────────────────────────────────────────┐
│ OBSERVABILITY STACK │
│ │
│ ┌────────────────┐ ┌────────────────────┐ │
│ │ Metrics │ │ Logs │ │
│ │ │ │ │ │
│ │ CloudWatch │ │ CloudWatch Logs │ │
│ │ Metrics │ │ + Log Insights │ │
│ │ │ │ │ │
│ │ Custom: │ │ Structured JSON: │ │
│ │ - Order count │ │ - Request logs │ │
│ │ - Revenue │ │ - Error logs │ │
│ │ - Cart abandon │ │ - Audit logs │ │
│ │ - API latency │ │ - Business events │ │
│ └───────┬────────┘ └────────┬───────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────────────────────────────────┐│
│ │ CloudWatch Dashboards ││
│ │ + Alarms + SNS Notifications ││
│ └──────────────────────────────────────────┘│
│ │
│ ┌────────────────┐ ┌────────────────────┐ │
│ │ Errors │ │ Uptime │ │
│ │ │ │ │ │
│ │ Sentry │ │ AWS Synthetics │ │
│ │ (Error track) │ │ (Canary checks) │ │
│ └────────────────┘ └────────────────────┘ │
└──────────────────────────────────────────────┘ 10.2 Alerting Rules Alert Điều kiện Severity Thông báo Hành động API Error Rate High 5xx > 5% trong 5 phút 🔴 Critical Slack + SMS oncall Investigate immediately API Latency High P95 > 2s trong 5 phút 🟡 Warning Slack Check slow queries, cache CPU High > 85% trong 10 phút 🟡 Warning Slack Auto-scale should handle Memory High > 90% trong 5 phút 🔴 Critical Slack + SMS Check memory leak, restart DB Connection Pool > 80% used 🟡 Warning Slack Check connection leaks DB Replication Lag > 10s 🟡 Warning Slack Check replica health Disk Usage > 80% 🟡 Warning Slack Extend volume / cleanup Payment Failure Rate > 10% trong 15 phút 🔴 Critical Slack + SMS + Email PO Check payment gateway Order Volume Drop < 50% so với cùng giờ hôm qua 🟡 Warning Slack Check if site is accessible SSL Certificate Expiry < 30 ngày 🟡 Warning Email Renew (ACM auto-renew) Health Check Failed 3 consecutive failures 🔴 Critical Slack + SMS Check service, ALB routing
10.3 On-call Rotation Tuần Primary Secondary Escalation Chẵn Backend Engineer 1 DevOps Engineer CTO Lẻ Backend Engineer 2 DevOps Engineer CTO
SLA phản hồi:
Severity Thời gian phản hồi Thời gian xử lý 🔴 Critical (site down, payment broken) 15 phút 1 giờ 🟡 Warning (degraded performance) 30 phút 4 giờ 🟢 Info (non-urgent) Next business day 1 tuần
11. Disaster Recovery 11.1 Backup Strategy Component Phương thức Tần suất Retention Vị trí RDS PostgreSQL Automated snapshot Hàng ngày (02:00 UTC+7) 30 ngày Same region (ap-southeast-1) RDS PostgreSQL Manual snapshot Trước mỗi deployment 90 ngày Cross-region (ap-northeast-1) Redis RDB snapshot Mỗi 6 giờ 7 ngày S3 S3 (Product images) Cross-region replication Realtime Indefinite ap-northeast-1 Elasticsearch Index snapshot Hàng ngày 14 ngày S3 Application code Git repository Every commit Indefinite GitHub Infrastructure Terraform state Every apply Versioned S3 + DynamoDB lock
11.2 Recovery Procedures Kịch bản RPO RTO Quy trình Single AZ failure 0 (Multi-AZ) < 5 phút Automatic failover (RDS, Redis, ECS) Database corruption ≤ 24 giờ ≤ 2 giờ Restore từ RDS snapshot gần nhất Application bug (bad deploy) 0 ≤ 15 phút Rollback ECS task definition to previous version Region failure ≤ 1 giờ ≤ 4 giờ Deploy to backup region (ap-northeast-1) từ Terraform + DB snapshot Data breach N/A ≤ 1 giờ Kích hoạt Incident Response Plan, revoke tokens, notify users
11.3 Disaster Recovery Test Test Tần suất Scope Backup restore test Hàng tháng Restore RDS snapshot to test instance, verify data Failover drill Hàng quý Force RDS failover, verify app reconnection Full DR drill 6 tháng/lần Simulate region failure, deploy to backup region
12. CI/CD Pipeline 12.1 Pipeline Architecture ┌─────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Code │───>│ Build │───>│ Test │───>│ Deploy │───>│ Verify │
│ Push │ │ & Lint │ │ & Scan │ │ Stage │ │ & Ship │
└─────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘
│ │ │ │ │
│ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐
│ │TypeScript│ │Unit Test│ │ Deploy │ │ Smoke │
│ │ compile │ │ (Jest) │ │ Staging │ │ Tests │
│ │ │ │ │ │ │ │ │
│ │ESLint │ │Int Test │ │ Manual │ │ Health │
│ │Prettier │ │(Supertest│ │ QA │ │ Check │
│ │ │ │ │ │ Sign-off│ │ │
│ │Docker │ │Security │ │ │ │ Deploy │
│ │ Build │ │ Scan │ │ Deploy │ │ Prod │
│ │ │ │(Trivy, │ │ Prod │ │ │
│ │Push ECR │ │ npm │ │ (Blue/ │ │ Monitor │
│ │ │ │ audit) │ │ Green) │ │ 30 min │
│ └─────────┘ └─────────┘ └─────────┘ └─────────┘
│
│ Triggers:
├── Push to main → Build + Test + Deploy Staging (auto)
├── PR to main → Build + Test (auto), no deploy
├── Tag v* → Build + Test + Deploy Staging + Deploy Prod (manual approval)
└── Hotfix branch → Build + Test + Deploy Prod (manual approval) 12.2 Environment Strategy Environment Branch URL Mục đích Auto Deploy Development developdev.techvn.vn Development testing Có Staging mainstaging.techvn.vn QA, UAT, demo Có Production Tag v* techvn.vn Live Manual approval
12.3 Deployment Strategy — Blue/Green ALB
│
┌──────┴──────┐
│ │
┌────▼────┐ ┌────▼────┐
│ BLUE │ │ GREEN │
│ (live) │ │ (new) │
│ │ │ │
│ v1.2.0 │ │ v1.3.0 │
└─────────┘ └─────────┘
Step 1: Deploy new version to GREEN
Step 2: Run smoke tests against GREEN
Step 3: Switch ALB traffic to GREEN
Step 4: Monitor 30 minutes
Step 5: If OK → decommission BLUE
If NOT OK → switch back to BLUE (rollback < 1 min) 13. Phụ lục 13.1 Technology Stack Summary Layer Công nghệ Phiên bản License Frontend Next.js 15.x MIT React 19.x MIT TypeScript 5.x Apache 2.0 Tailwind CSS 4.x MIT Zustand 5.x MIT React Query 5.x MIT Backend NestJS 11.x MIT Node.js 20 LTS MIT TypeORM 0.3.x MIT class-validator 0.14.x MIT Passport.js 0.7.x MIT Bull (job queue) 5.x MIT Database PostgreSQL 16.x PostgreSQL License Cache Redis 7.x BSD Search OpenSearch (ES-compatible) 2.x Apache 2.0 Infrastructure Docker 25.x Apache 2.0 Terraform 1.7.x MPL 2.0 GitHub Actions N/A GitHub Monitoring Sentry SaaS Paid CloudWatch AWS AWS pricing
13.2 Ước lượng tài nguyên theo giai đoạn Giai đoạn Traffic (CCU) Backend Instances DB Instance Redis Chi phí/tháng Launch (T1-3) 500 2 × 1vCPU/2GB db.r6g.large cache.r6g.large ~$1.500 Growth (T4-12) 2.000 4 × 1vCPU/2GB db.r6g.xlarge cache.r6g.xlarge ~$2.500 Scale (T13-24) 5.000 6 × 2vCPU/4GB db.r6g.2xlarge + replica cache.r6g.xlarge cluster ~$4.500 Flash Sale (peak) 20.000 8 × 2vCPU/4GB + 2 read replicas + Redis replica ~$7.000 (temporary)
13.3 Tài liệu liên quan Mã Tên Quan hệ BRD-TECHVN-2026-001 Business Requirements Document Yêu cầu kinh doanh PRD-TECHVN-2026-001 Product Requirements Document Yêu cầu sản phẩm SRS-TECHVN-ECOM-2026-001 Software Requirements Specification Yêu cầu phần mềm chi tiết IEEE 42010:2011 Systems and Software Engineering — Architecture Description Tiêu chuẩn tham chiếu
13.4 Glossary kỹ thuật Thuật ngữ Định nghĩa SSR Server-Side Rendering — render HTML trên server mỗi request SSG Static Site Generation — pre-render HTML tại build time ISR Incremental Static Regeneration — SSG + revalidation theo thời gian CSR Client-Side Rendering — render trên browser bằng JavaScript ALB Application Load Balancer — phân phối traffic đến app instances ECS Fargate AWS Elastic Container Service (serverless) — chạy container không cần quản lý server Multi-AZ Multi-Availability Zone — triển khai trên nhiều data center cùng region Blue/Green Chiến lược deploy với 2 môi trường song song, chuyển traffic zero-downtime RBAC Role-Based Access Control — phân quyền dựa trên vai trò DLQ Dead Letter Queue — hàng đợi lưu message xử lý thất bại
Ghi chú: Tài liệu kiến trúc này là cơ sở cho quá trình phát triển và vận hành hệ thống. Mọi thay đổi kiến trúc đáng kể cần được ghi nhận dưới dạng ADR (Architecture Decision Record) và được CTO phê duyệt trước khi triển khai. Các thông số cấu hình cụ thể (instance size, threshold...) sẽ được fine-tune dựa trên dữ liệu thực tế sau go-live.