1. Architecture
Traffic Tool
  • Traffic Tool Docs
    • Tổng quan
      • Tổng Quan
      • Setup Guide
      • System Architecture
      • Code Structure
      • Logs and Monitoring
      • Environment & Configuration
      • Deployment
        • Local
        • Staging
        • Product
    • Bussiness | Logic
      • 1. Thống kê hàng ngày (Daily Statistics)
      • 2. Thống kê hệ thống (System Statistics)
      • 3. Tìm kiếm tự động (Automated Discovery)
      • 4. Trung tâm Báo cáo (Report Center)
      • 5. Quản lý tài khoản (Account Management)
      • 6. Quản lý Hệ thống (System Management)
      • 7. Quản lý tài khoản Google (Google Account Management)
    • Project
      • ADMIN
        • Tổng quan
        • Hướng dẫn sử dung
          • Đăng Nhập & Xác Thực Hai Bước
          • Thống Kê Hệ Thống
          • Thống Kê Hàng Ngày
          • Tìm Kiếm Tự Động
          • Trung Tâm Báo Cáo
          • Quản Lý Tài Khoản
          • Quản Lý Server
          • Quản Lý Proxy
          • Quản Lý Gói Proxy
          • Quản Lý Nhà Cung Cấp Proxy
          • Quản Lý Backup Proxy
          • Quản Lý Tài Khoản Google
          • User Guide
        • Architecture
          • System Architecture
          • Code Structure
          • Environment & Configuration
          • Logs and Monitoring
        • Deployment
          • Local
          • Staging
          • Production
      • API
        • Tổng quan
        • Architecture
          • Database Schema
          • System Architecture
          • Code Structure
          • Environment & Configuration
          • Logs and Monitoring
        • Deployment
          • Local
          • Staging
          • Production
        • API Interface
          • 🔑 Identity & Session
            • Đăng nhập hệ thống (Login)
            • Đăng ký tài khoản mới (Public)
            • Lấy danh sách người dùng (Phân trang)
            • Admin tạo người dùng mới
            • Lấy thông tin cá nhân hiện tại
            • Khởi tạo bảo mật 2FA
            • Xác thực mã OTP
            • Chi tiết người dùng theo ID
            • Cập nhật thông tin người dùng
            • Xóa tài khoản người dùng
            • Đổi mật khẩu
            • Kiểm tra Cấu hình Thông báo Telegram Toàn hệ thống
            • Bật/Tắt Thông báo Telegram Toàn cục
          • 📁 Campaign Management
            • Danh sách Chiến dịch Toàn cầu
            • Khởi tạo Chiến dịch Mới
            • Chi tiết Chiến dịch
            • Cập nhật Chiến dịch
            • Xóa Chiến dịch
            • Tắt/Mở Chiến dịch (Hàng loạt)
            • Dữ liệu Hình mẫu SEO (Negative SEO)
          • ⚙️ Project Mechanics
            • Danh sách Dự án (Projects List)
            • Khởi tạo Kịch bản Mô phỏng
            • Lấy chi tiết cấu hình Dự án
            • Cập nhật Kịch bản chạy
            • Xóa Dự án
            • Chỉnh sửa Hàng loạt (Bulk)
            • Bật/Tắt Dự án
          • 👤 Profile Management
            • Danh sách Vân tay số (Profiles Data)
            • Tạo Hồ sơ Đơn lẻ (Tạo Vân tay mới)
            • Nhập kho Tài khoản Email (Bulk Import)
            • Chi tiết Session/Cookies
            • Chỉnh sửa Hồ sơ/Ghi chú
            • Xóa Vân tay số và Dữ liệu Local
            • Mở khóa Captcha/Trạng thái Blocked
            • Tra cứu Kho Profile Khả dụng
            • Báo cáo Sức khỏe Kho Tài Khoản
          • 🦾 Worker Interface
            • Đăng ký Khởi tạo Node (Handshake)
            • Nhịp Tim Khảo Sát Tình Trạng (Heartbeat)
            • Nhận Cấu hình Bypass & Hệ thống
            • Kéo (PULL) Nhiệm vụ Traffic SEO
            • Báo cáo Sự cố Node (Crash Report)
          • 📊 Report: Execution
            • Kéo Công việc Báo cáo (Worker Pull)
            • Quản lý Giám sát Nhiệm vụ (Task Dashboard)
            • Bắn Lại Báo Cáo Thất Bại (Manual Retry)
          • 📊 Report: Discovery
            • Danh sách Tên miền Chờ Xử Lý (Discovery Pool)
            • Nhập Mục Tiêu Thủ Công (Manual Insert)
            • Kích hoạt Heuristic Scanner (Cào tự động)
            • Chi tiết Bằng Chứng (Evidence Data)
            • Dán nhãn Vi Phạm / Cập nhật Screenshot
            • Loại Bỏ Mục Tiêu
            • Duyệt Yêu Cầu (Approve to Execution)
          • 📊 Report: Platforms Configuration
            • Truy vấn Danh sách Nền tảng Đối tác (Vendor)
            • Tạo Nền tảng Vendor Báo cáo Mới
            • Bật/Tắt Trang báo cáo theo Loại
            • Cập nhật Metadata Trang
            • Xóa Trang Báo Cáo
            • Lấy Cài đặt LLM cho Vendor cụ thể
            • Cập nhật Cài đặt Tạo mẫu LLM
            • Lấy Cấu hình Schema Biểu mẫu cho Vendor
            • Cập nhật Yêu cầu Trường Biểu mẫu
          • 📊 Report: Email Automation
            • Danh sách SMTP/Mailer Server
            • Thêm kết nối SMTP Mới
            • Nhật ký Nhiệm vụ Gửi Mail (Email Log)
            • Phân tích Tỉ lệ Chuyển đổi (Email Delivery Analytics)
          • 🌐 Global Proxies
            • Danh sách Kho Proxy Phân trang (Proxy Pool)
            • Thêm mới Tuyến IP (Bulk Import)
            • Cập nhật Thông tin máy chủ Proxy
            • Xóa Proxy (Thu hồi tài nguyên)
            • Kích hoạt Xoay vòng (Rotate IP) Cưỡng bức
          • 📈 System Intelligence
            • Báo cáo Luồng Bảo mật Hợp nhất (Colossal Report)
            • Bản Đồ Lưu Lượng GeoIP (Heatmap)
          • 🪝 Webhook Integrations
            • Callback Hoàn tất Gói Lưu lượng SEO (Traffic Node)
            • Callback Thông báo Hoàn tất Bắn Report AI
      • Tool
        • Tổng quan
        • Architecture
          • System Architecture
          • Code Structure
          • Environment & Configuration
          • Logs And Monitoring
          • Database Schema
        • Deployment
          • Local
          • Staging
          • Production
        • API interface
          • Tasks
            • Lấy tasks có phân trang và lọc
            • Xóa tất cả tasks
            • Get all tasks
            • Cập nhật một task
            • Xóa một task theo ID
            • Get all tasks
          • Group task
            • Tạo nhiều task groups
            • Lấy tất cả task groups
            • Xóa tất cả task groups
            • Xóa một task group theo ID
            • Endpoint /api/task-traffics/
            • Test parse proxy string
            • Endpoint /api/task-traffics/
          • Test
            • Mock proxy endpoint cho development
            • Mock profile endpoint cho development
            • Endpoint /api/test
            • Endpoint /api/test/account-stats
            • Endpoint /api/test/session-recommendation
            • Endpoint /api/test/check-browser
            • Endpoint /api/test/clear-browser-sessions
          • Proxies
            • Lấy tất cả proxy records
            • Tạo proxy record mới
            • Xóa tất cả proxies
            • Get all proxies
            • Xóa một proxy theo ID
            • Reset proxy process counter
            • Get all proxies
            • Get all proxies
          • Report Platforms
            • Submit report to multiple platforms
            • Submit report to specific platform
            • Get available platforms
            • Get platform statistics
            • Health check
          • Reports
            • Create a new report
            • Create a new report
            • Get report by ID
            • Get report by ID
            • Get report statistics
            • Get report groups
            • Get report groups
            • Get report group
            • Add report to group
            • Bulk add reports to group
            • Get report group statistics
            • Get analytics data
            • Get platform success rates
            • Get reports by platform
            • Get reports by group
            • Create test reports in bulk
            • Tạo PC report CSV
            • Lấy PC report JSON
            • Lấy report tasks
            • Giám sát report tasks
            • Report tasks đang hoạt động
            • Chi tiết report task
            • Thống kê reports
            • Dữ liệu biểu đồ reports
            • Lấy danh sách report sites
            • Tạo report site
            • Thống kê sites
            • Toggle site enabled/disabled
            • Toggle tất cả sites
            • Toggle sites theo type
            • Cập nhật hàng loạt AI prompts
            • Cập nhật site
            • Xóa site
            • Lấy cấu hình đầy đủ của site
            • Lấy AI prompt của site
            • Cập nhật AI prompt của site
            • Lấy GPT config của site
            • Cập nhật GPT config
            • Lấy response config của site
            • Cập nhật response config
            • Lấy security vendors đang bật
            • Phân tích keywords
            • Top keywords
            • Thống kê analytics
            • PC report dashboard
            • Lấy report domains
            • Thêm report domain
            • Chi tiết report domain
            • Thống kê hàng ngày
            • Cập nhật hàng loạt reports
          • Test Report
            • Test Microsoft report submission
            • Test AdGuard report submission
            • Test Google Ads report submission
            • Test Spamhaus report submission
            • Test ESET report submission
            • Test multi-platform report submission
            • Get available platforms
          • ESET Test
            • Simple test
            • Minimal POST test
            • Generate ESET report content
            • Get sample test data
            • Test form filling
            • Test full form submission
          • Spamhaus Test
            • Simple test
            • Minimal POST test
            • Generate Spamhaus report content
            • Get sample test data
            • Test Spamhaus form filling
            • Test full Spamhaus form submission
          • Report Scheduler
            • Get report scheduler statistics
            • Process ad detection result
            • Submit a scheduled report
            • Start report scheduler
            • Stop report scheduler
            • Get scheduler status
            • Process scheduled reports
            • Test browser session (non-headless)
            • Test report submission (non-headless)
          • Comprehensive Analytics
            • Get comprehensive dashboard analytics
            • Get overview statistics
            • Get brand-wise statistics
            • Get daily statistics
            • Get platform success rates
            • Get account performance
            • Get summary report
          • Search
            • Tạo nhiều search tasks
            • Lấy tổng số search tasks
          • Report Tasks
            • Tạo report tasks cho một domain
            • Tạo report tasks trực tiếp (hỗ trợ profileCountry và domainType rõ ràng)
            • Tạo report tasks cho nhiều domains cùng lúc
            • Tạo email-based report tasks
            • Lấy report task PENDING tiếp theo
            • Cập nhật status của report task
            • Lấy danh sách platforms có sẵn
            • Thống kê report tasks
            • Kích hoạt thực thi thủ công
          • Monitor
            • Thông tin tài nguyên hệ thống
          • System
            • Hello World
            • Health check
            • Đọc file log từ xa
            • Monitor worker status
          • Auth
            • Đăng nhập
            • Đăng ký tài khoản
          • User Management
            • Danh sách users có phân trang
            • Tạo user mới (Admin only)
            • Lấy tất cả users (không phân trang)
            • Lấy thông tin profile của user hiện tại
            • Tạo QR code TOTP cho 2FA
            • Xác thực TOTP để bật 2FA
            • Lấy user theo ID
            • Cập nhật thông tin user
            • Xóa user
            • Đổi mật khẩu user
          • Campaign Management
            • Danh sách campaigns có phân trang
            • Tạo campaign mới
            • Lấy tất cả campaigns
            • Thống kê tổng hợp campaigns
            • Xuất campaigns ra Excel
            • Lấy dữ liệu Negative SEO
            • Xuất dữ liệu Negative SEO ra Excel
            • Xuất Negative SEO theo IDs
            • Lấy dữ liệu Home Traffic
            • Xuất Home Traffic ra Excel
            • Xuất Home Traffic theo IDs
            • Lấy báo cáo campaigns (Public)
            • Lấy tất cả báo cáo campaigns (Public)
            • Lấy chi tiết campaign
            • Cập nhật campaign
            • Xóa campaign
            • Lấy campaigns đã fired theo type
          • Server Management
            • Danh sách servers có phân trang
            • Tạo server mới
            • Lấy tất cả servers
            • Lấy servers từ MongoDB
            • Báo cáo hiệu suất server
            • Thống kê health check
            • Thống kê task monitor
            • Lịch sử lỗi server
            • Thống kê lỗi server
            • Thay đổi trạng thái server
            • Xóa nhiều servers
            • Lấy server theo ID
            • Cập nhật server
            • Xóa server
            • Báo cáo servers (Public)
          • Project Management
            • Lấy tất cả projects
            • Tạo project mới
            • Lấy projects theo campaign
            • Cập nhật dữ liệu traffic
            • Cập nhật nhiều projects
            • Xóa nhiều projects
            • Lấy project theo ID
            • Cập nhật project
            • Cập nhật state của project
            • Cập nhật status của project
            • Tính lại chi tiết project
          • Task Management
            • Worker yêu cầu tasks
            • Reset task creation
          • Proxy Management
            • Danh sách proxies
            • Tạo proxy mới
            • Xóa tất cả proxies
            • Xuất proxies ra Excel
            • Tải template Excel mẫu
            • Tạo nhiều proxies
            • Import proxies từ Excel
            • Import từ tất cả providers
            • Xóa nhiều proxies
            • Lấy proxy theo ID
            • Cập nhật proxy
            • Xóa proxy
            • Toggle trạng thái proxy
          • Backup Proxy
            • Lấy danh sách backup proxies
            • Tạo backup proxy
            • Xóa nhiều backup proxies
            • Import từ Proxifly
            • Chạy health check
            • Lấy backup proxy theo ID
            • Cập nhật backup proxy
            • Xóa backup proxy
            • Test backup proxy
          • Proxy Providers
            • Lấy danh sách proxy providers
            • Tạo proxy provider
            • Xóa nhiều providers
            • Lấy provider theo ID
            • Cập nhật provider
            • Xóa provider
          • Proxy Packages
            • Lấy danh sách proxy packages
            • Tạo proxy package
            • Xóa nhiều packages
            • Lấy package theo ID
            • Cập nhật package
            • Xóa package
          • Profiles
            • Lấy profiles khả dụng (Public)
            • Lấy profile ngẫu nhiên (Public)
            • Danh sách profiles có phân trang
            • Phân tích profiles
            • Health check profiles
            • Tạo profile session
            • Lấy profile session
            • Cập nhật profile session
            • Xóa profile session
            • Đánh dấu profile đã dùng
            • Cập nhật nhiều profiles
            • Tạo nhiều profiles
            • Dọn dẹp sessions hết hạn
            • Dọn dẹp toàn diện
            • Tạo profile mới
            • Lấy profile theo ID
            • Cập nhật profile
            • Xóa profile
            • Thống kê profile
            • Sessions của profile (phân trang)
            • Report tasks của profile
            • Domains đã report bởi profile
            • Tasks theo domain của profile
            • Reset cooldown của profile
            • Test kết nối profile
            • Reset số lần đăng nhập thất bại
            • Ghi nhận đăng nhập thất bại
          • Keywords
            • Danh sách keywords
            • Tạo keyword mới
            • Xuất keywords ra Excel
            • Xác nhận fire keyword
            • Reset tất cả keywords
            • Lấy keyword theo ID
            • Cập nhật keyword
            • Xóa keyword
            • Reset keyword
            • Cập nhật status keyword
            • Kết quả SERP của keyword
          • Dashboard
            • Dữ liệu tổng hợp dashboard
            • Thống kê hệ thống
            • Thống kê traffic theo ID
            • Dữ liệu bảng biểu đồ traffic
            • Xuất báo cáo ra Excel
            • Lấy dữ liệu báo cáo
            • Cập nhật hàng loạt dashboard
            • Tính lại chi tiết projects (Admin only)
          • System Settings
            • Toggle Telegram notifications
            • Trạng thái Telegram notification
          • Activity Logs
            • Lấy activity logs
          • Locations
            • Lấy tất cả locations
            • Tạo location mới
            • Lấy location theo ID
            • Cập nhật location
            • Xóa location
          • Evidence
            • Kiểm tra evidence tồn tại
            • Kiểm tra evidence hàng loạt
            • Lấy evidence mới nhất
          • Files
            • Upload file
            • Download file
          • Server Hourly Reports
            • Lấy server hourly reports
          • Task Logs
            • Lấy task logs
          • Webhooks - Proxy
            • Lấy proxy cho task (Worker webhook)
            • Lấy proxies có thể rotate (Worker webhook)
            • Báo cáo kết quả proxy rotation (Worker webhook)
            • Lấy backup proxy (Worker webhook)
          • Webhooks - Profile
            • Lấy profiles (admin view, webhook)
            • Lấy profile ngẫu nhiên (Worker webhook)
            • Profiles khả dụng (webhook)
            • Lấy profile session (webhook)
            • Tạo profile session (webhook)
            • Đánh dấu profile đã dùng (webhook)
            • Lấy profile tags (webhook)
            • Lấy tất cả profile sessions (webhook)
          • Webhooks - Task
            • Cập nhật kết quả thực thi task (Worker webhook)
          • Webhooks - Search
            • Báo cáo domains đã click (webhook)
            • Lấy clicked domains (webhook)
            • Báo cáo domains (webhook)
            • Third party callback (webhook)
          • Webhooks - Logs
            • Lấy file logs (webhook)
            • Xóa nội dung log (webhook)
            • Kiểm tra IP address (webhook)
          • Webhooks - Keyword
            • Gửi kết quả SERP keyword (webhook)
          • Webhooks - Report
            • Cập nhật trạng thái report task (webhook)
          • Webhooks - CocCoc Token
            • Lấy CocCoc tokens (webhook)
            • Lock CocCoc token (webhook)
            • Unlock CocCoc token (webhook)
    • Schemas
      • LoginRequest
      • UpdateTask
      • WorkerStatus
      • StandardResponse
      • UserResponseDto
      • CreateTaskGroupRequest
      • HealthResponse
      • UserModel
      • CreateProxy
      • ErrorResponse
      • Pagination
      • CreateUserRequest
      • ReportTaskCreation
      • ErrorResponseFull
      • BulkDeleteRequest
      • UpdateUserRequest
      • CreateEmail
      • MessageResponse
      • UserResponse
      • PagingInfo
      • CreateMultipleSearchRequest
      • TrafficType
      • CampaignResponse
      • ProfileModel
      • CreateMultipleReportRequest
      • ServerResponse
      • CreateProfileRequest
      • UpdateReportStatusRequest
      • Task
      • BulkImportProfileReq
      • TestProxyRequest
      • TaskGroup
      • ProxyResponse
      • UpdateProfileRequest
      • CreateTask
      • UpdateTaskBody
      • KeywordResponse
      • CampaignModel
      • CreateSearch
      • TaskPaginatedResponse
      • LocationResponse
      • CreateCampaignRequest
      • ProxyTestResult
      • UpdateCampaignRequest
      • CreateReportTaskBody
      • BulkUpdateCampaignStatusReq
      • CreateEmailReportTaskBody
      • NegativeSeoData
      • BatchReportTaskItem
      • CreateProjectRequest
      • CreateReportTaskResponse
      • UpdateProjectRequest
      • BatchReportTaskResponse
      • ProjectModel
      • BulkUpdateProjectRequest
      • ReportTask
      • WorkerHandshakeRequest
      • UpdateReportTaskStatusBody
      • WorkerHandshakeResponse
      • UpdateReportTaskStatusResponse
      • WorkerHeartbeatPayload
      • PlatformsListResponse
      • WorkerGlobalSettings
      • ReportTaskStatsResponse
      • TaskPullRequest
      • ExecuteReportTaskResponse
      • WorkerFatalLog
      • CreateSearchTask
      • TaskModel
      • Proxy
      • TaskUpdateDto
      • CreateProxyBody
      • ReportTaskModel
      • CreateProxyResponse
      • ReportTaskResult
      • ResetProcessResponse
      • PCReportResponse
      • MonitorResponse
      • ReportSiteItem
      • CreateReportSiteRequest
      • TestProxyResponse
      • GPTConfig
      • TestProfileResponse
      • ResponseConfig
      • ReportDomainsResponse
      • ReportDomainItem
      • AddReportDomainRequest
      • UpdateReportDomainRequest
      • BulkUpdateDashboardRequest
      • ProxyModel
      • CreateProxyRequest
      • UpdateProxyRequest
      • SMTPServerConfig
      • EmailTaskLog
      • GeoLocation
      • CampaignConfigs
      • ProjectAttribute
      • TaskTrafficType
      • ReportTaskItem
      • SummaryStats
      • DailyStats
      • BrandStats
      • ProfileStats
      • FieldConfig
  1. Architecture

System Architecture

Kiến Trúc Hệ Thống — Admin Dashboard Traffic Tools V2#


1. Tổng quan#

Admin Dashboard là SPA thuần túy, render hoàn toàn phía client. Không có SSR, không có middleware nào giữa trình duyệt và Backend API Engine.
Sau khi build, ứng dụng tạo ra tập hợp file tĩnh (HTML, CSS, JS) được phục vụ bởi Nginx. Mọi logic điều hướng, xác thực và hiển thị dữ liệu đều chạy trong trình duyệt.

1.1. Công nghệ sử dụng#

TầngCông nghệPhiên bảnVai trò
Framework UIVue 3^3.4.31Core framework, Composition API với <script setup>
BundlerVite^5.3.3Build tool và dev server, dùng ESBuild
Ngôn ngữTypeScript~5.5.2Kiểu dữ liệu tĩnh toàn bộ mã nguồn
State managementPinia^2.1.7Thay thế Vuex, hỗ trợ Composition API
Persist storepinia-plugin-persistedstate^3.2.1Đồng bộ store với localStorage
UI libraryNaive UI^2.38.2Bộ component UI cho Vue 3
Biểu đồ chínhApache ECharts + vue-echarts^5.5.1 / ^7.0.3Biểu đồ thống kê và phân tích hiệu suất
Biểu đồ phụChart.js^4.5.1Biểu đồ bổ sung cho một số màn hình
Trực quan hóaD3.js^7.9.0Trực quan hóa dữ liệu phức tạp
HTTP clientAxios^1.7.2Giao tiếp với Backend API Engine
CSS utilitiesTailwind CSS^3.4.4Utility-first CSS
CSS preprocessorSASS^1.77.8SCSS cho các style phức tạp
Xuất Excelxlsx + xlsx-js-style^0.18.5 / ^1.2.0Xuất báo cáo .xlsx có định dạng màu sắc
Vue utilities@vueuse/core^10.11.0Composables: clipboard, event bus, URL params
Đa ngôn ngữvue-i18n^9.13.1Tiếng Việt và Tiếng Anh
Routervue-router^4.4.0Điều hướng SPA với History Mode
Icon@iconify/vue^4.1.2Thư viện icon đa dạng
Validationzod^3.23.8Schema validation cho form data
Utilitieslodash^4.17.21Xử lý mảng, object, chuỗi

1.2. Công cụ chất lượng mã#

Công cụFile cấu hìnhChức năng
ESLint.eslintrc.cjsPhân tích tĩnh, phát hiện lỗi cú pháp và anti-pattern.
Prettier.prettierrc.jsonTự động định dạng code theo chuẩn nhất quán.
Husky.husky/Git hooks — chặn commit nếu code không qua lint.
lint-staged.husky/lintstagedrc.jsChỉ lint các file đã thay đổi, tối ưu thời gian commit.
Commitizen + cz-gitcz.config.jsEnforce chuẩn Conventional Commits.
commitlintcommitlint.config.tsKiểm tra format commit message theo Angular convention.
vue-tsc—Kiểm tra kiểu TypeScript cho file .vue với <script setup>.

2. Kiến trúc module#

2.1. Sơ đồ phụ thuộc giữa các lớp#

src/views/          ← Màn hình nghiệp vụ
      |
      | sử dụng
      v
src/composables/    ← Logic tái sử dụng
      |
      +---------------------------+
      |                           |
      v                           v
src/stores/         ← Pinia state     src/services/api/  ← Axios API calls
      |                           |
      +---------------------------+
                    |
                    v
            src/configs/axios.ts  ← HTTP layer (interceptors, auth headers)
                    |
                    v
            Backend API Engine

2.2. Kiến trúc router#

Tầng 1 — Route ngoài layout:
/login, /signup và các trang lỗi (404, 403). Không dùng LayoutDefault, không yêu cầu xác thực. Định nghĩa trong src/router/modules/remaining.ts.
Tầng 2 — Route trong layout (protected):
Tất cả trang nghiệp vụ đều bọc trong LayoutDefault.vue và chịu sự kiểm soát của router.beforeEach. Các route module được tự động nạp:
Tầng 3 — Child routes (nested routing):
Các màn hình phức tạp dùng nested routing để quản lý tab nội bộ:
/auto-search → google-search, coccoc-search, server-performance, location
/system-management → server-management, proxy-management, backup-proxy-management, proxy-package-management, proxy-provider-management
/dashboard1 → click-ads, negative-seo, search-ads, traffic-natural
/user-management → users, activities

2.3. Service layer#

Mỗi module có một file service riêng trong src/services/api/, tất cả dùng Axios instance từ src/configs/axios.ts:
File serviceAPI prefixCác phương thức chính
auth.ts/userlogin, getMe, refreshToken, signup, generateGoogleAuthenticator, verifyGoogleAuthenticator
autoSearch.ts/keywordsgetList, getDetail, create, update, updateStatus, autoFire, reset, delete, exportExcel, historyKeyword
servers.ts/servergetList, getDetail, create, update, changeStatus, delete, bulkDelete
serverPerformance.ts/server/reportgetList, getDetail
proxies.ts/proxygetList, getDetail, create, update, delete, updateActive, uploadProxy, bulkDelete
backup-proxies.ts/backup-proxygetList, create, update, delete, testProxy, importFromProxifly, healthCheck, bulkDelete
package.ts/proxy-packagesgetList, getDetail, create, update, delete, bulkDelete
provider.ts/proxy-providersgetList, getDetail, create, update, delete, updateSort, getDataUsage, bulkDelete
campain.ts/campaigngetList, getDetail, create, update, delete, getStatistics, exportData
users.ts/usergetList, getDetail, create, update, delete, updateActive, changePassword
activities.ts/activitygetList
location.ts/locationgetList, getDetail, create, update, delete
profiles.ts/profilegetList, getDetail, create, update, delete
task.ts/projectgetList, getDetail, create, update, delete, updateStatus, updateDomainStatus
reports.tsNhiều endpointClass ReportApiService với các phương thức static

3. Quản lý trạng thái#

3.1. Cấu trúc Pinia stores#

src/stores/
├── authStore.ts       ← Token, Profile, 2FA logic, logout
├── appStore.ts        ← UI settings (locale, sidebar, breadcrumbs)
└── reportStore.ts     ← Dữ liệu tạm cho màn hình báo cáo
    report/
    └── (các store con cho module báo cáo)

3.2. authStore#

State:
TrườngKiểuPersistMô tả
authTokenAuth.AuthToken | nullCó (localStorage)JWT token, refresh token và device token.
profileAuth.UserProfile | nullKhôngThông tin người dùng đang đăng nhập.
is_2fabooleanKhôngTrạng thái 2FA từ server.
messagestringKhôngThông điệp phản hồi từ API.
Actions:
ActionAPI endpointMô tả
login(data)POST /api/user/loginĐăng nhập, nhận AuthToken, cập nhật is_2fa.
getMe()GET /api/user/profileLấy thông tin profile. Tự kiểm tra localStorage nếu store trống.
signUp(data)POST /api/user/registerĐăng ký tài khoản mới (chỉ dùng ở môi trường dev).
logout()—Xóa token, profile, sessionStorage và redirect về login.
refreshToken()POST /api/user/refreshLàm mới token, cập nhật store và localStorage.
Kiểu dữ liệu AuthToken:
Kiểu dữ liệu UserProfile:

3.3. appStore#

State persist vào localStorage:
sideBarCollapsed: boolean — Trạng thái thu gọn sidebar. Mặc định false.
i18nLocale: I18nLocalesKey — Ngôn ngữ hiện tại. Mặc định 'vi-VN'.
State không persist:
isLoadingWebsite: boolean — Cờ loading toàn trang.
breadcrumbs: Breadcrumb[] — Cập nhật sau mỗi lần chuyển route.
Actions:
setLocale(locale) — Cập nhật i18nLocale và đồng bộ i18n.global.locale.value.

3.4. reportStore#

Lưu dữ liệu tạm cho module báo cáo: thống kê tổng quan từ API, trạng thái filter và phân trang, cache dữ liệu biểu đồ để tránh gọi API lại khi chuyển tab.

4. Lớp HTTP#

4.1. Cấu hình Axios instance#

Hàm init() phải được gọi trong src/main.ts sau khi Pinia khởi tạo để interceptor có thể truy cập useAuthStore().

4.2. Timeout đặc biệt#

URL chứa /import-all: 300,000ms (5 phút) — import proxy hàng loạt từ Excel.
URL chứa /get-data-report: 60,000ms (1 phút) — tổng hợp báo cáo lớn.
Mọi request khác: 10,000ms.

4.3. Hàng đợi request khi refresh token#

Khi token hết hạn và đang refresh, các request mới không bị hủy mà được đưa vào hàng đợi this.requests. Sau khi có token mới, tất cả request trong hàng đợi được thực thi lại. Cờ this.isRefreshing ngăn gọi refresh token nhiều lần đồng thời.

4.4. Phân loại lỗi HTTP#

Mã HTTPXử lý trong Admin
400Reject Promise, component gọi showMessageError() để hiển thị lỗi validation.
401Interceptor tự động gọi authStore.logout() và redirect về login.
403Reject Promise, component hiển thị thông báo không có quyền.
404Reject Promise, component hiển thị thông báo không tìm thấy.
408 / TimeoutAxios tự reject sau khi vượt quá timeout.
500Reject Promise, component hiển thị lỗi server.
Network ErrorAxios reject với error.message = 'Network Error'.

5. Component và Composable#

5.1. Composables cốt lõi#

src/composables/utils.ts:
HàmMô tả
useHelper()Trả về getCatchMsg() và showMessageError() để xử lý lỗi API.
useEnv(key)Đọc biến môi trường từ window.configs trước, fallback về import.meta.env.
useDownload(blob, fileName)Tạo link tải file từ Blob response và kích hoạt download.
useDownloadUrl(url, fileName)Tải file từ URL bên ngoài bằng Axios rồi kích hoạt download.
useCopyToClipboard()Copy text vào clipboard với fallback cho trình duyệt cũ.
useEnsureHttp()Đảm bảo URL luôn có tiền tố http:// hoặc https://.
src/composables/useBulkSelection.ts:
Composable generic useBulkSelection<T> quản lý chọn nhiều bản ghi trong bảng:
getRowKey(row) — Bắt buộc. Lấy key định danh duy nhất của mỗi dòng.
onBulkDelete(selectedRows) — Callback xử lý xóa hàng loạt.
onBulkExport(selectedRows) — Callback xử lý xuất dữ liệu hàng loạt.
onBulkUpdate(selectedRows, updates) — Callback xử lý cập nhật hàng loạt.
State: selectedRowKeys, isProcessing, hasSelection, selectionCount.
Các composable khác:
format.ts — Định dạng số, ngày tháng, trạng thái cho bảng và biểu đồ.
render.ts — Tạo cột bảng Naive UI Data Table dạng động (button, tag màu, tooltip).
toggle.ts — Quản lý isOpen, isLoading, isEditing trong modal và form.
router.ts — replaceParamsInPath() để thay thế tham số động trong đường dẫn route.

5.2. Components dùng chung#

BulkActions.vue — Thanh công cụ hiển thị khi có bản ghi được chọn (xóa, xuất, cập nhật hàng loạt).
pagination/ — Component phân trang tùy chỉnh tích hợp với Naive UI Pagination.
common/ — DateRangePicker, SearchInput, StatusTag dùng trên nhiều màn hình.

6. Build và phân phối#

6.1. Các lệnh build#

LệnhMôi trườngMô tả
npm run devDevelopmentKhởi động Vite Dev Server với HMR.
npm run build:devDevelopmentBuild tĩnh cho môi trường Development.
npm run build:stgStagingBuild tĩnh cho môi trường Staging.
npm run build:releaseReleaseBuild tĩnh cho môi trường Release.
npm run build:prodProductionBuild tĩnh cho Production, chạy typecheck sau khi build.
npm run build:prod:dockerProductionBuild cho Production trong Docker, không chạy typecheck riêng.
npm run typecheck—Chạy vue-tsc --build --force kiểm tra kiểu dữ liệu.
npm run lint—Chạy ESLint và tự sửa lỗi trên toàn bộ file .vue, .ts.

6.2. Output build#

Vite tạo ra thư mục dist/ với:
index.html — Entry point HTML.
assets/ — Các file .js, .css, hình ảnh đã được hash tên file để cache-busting tự động.
Tên file theo pattern: assets/[name].[hash].js. Hash thay đổi mỗi khi nội dung thay đổi.

6.3. Phân tách bundle#

Vite tách bundle thành các chunk riêng để tối ưu cache:
naiveUI — Toàn bộ Naive UI (~1MB, ít thay đổi).
lodash — Lodash và lodash-es.
vue — Vue core (ổn định nhất).
Ba thư viện này chiếm phần lớn kích thước bundle nhưng hiếm khi thay đổi. Tách riêng giúp browser cache lại và không cần tải lại khi code nghiệp vụ thay đổi.

6.4. Yêu cầu môi trường phát triển#

Node.js >= 18.3.0.
Backend API Engine phải đang chạy và cho phép CORS từ http://localhost:5173.

7. Module báo cáo#

7.1. Cấu trúc service#

Module báo cáo có kiến trúc service phức tạp nhất, tách thành nhiều file trong src/services/api/reports/:
src/services/api/reports/
├── useReportRequest.ts      ← Hàm request() wrapper với base URL riêng
├── useReportEndpoints.ts    ← Các endpoint đặc thù của module báo cáo
├── useReportCrud.ts         ← CRUD cơ bản: getReports, createReport, deleteReport
└── useReportStats.ts        ← Thống kê: getDashboardStats, getPlatformPerformance
ReportApiService trong reports.ts là class static tổng hợp tất cả phương thức, cung cấp interface thống nhất cho các component.

7.2. Kiểu dữ liệu báo cáo#

PCReportData — Dữ liệu báo cáo tổng hợp:
ReportDomainItem — Một domain đang được theo dõi:

8. Đa ngôn ngữ#

locales/
├── vi-VN.json    ← Chuỗi Tiếng Việt (mặc định)
├── en-US.json    ← Chuỗi Tiếng Anh
└── _schema.json  ← Schema kiểm tra cấu trúc file ngôn ngữ
Cấu hình plugin:

9. Webhook#

File src/configs/webhook-axios.ts cung cấp một Axios instance riêng cho các request đến webhook endpoint, tách biệt với instance chính để tránh ảnh hưởng về cấu hình timeout và header. Dùng để gửi thông báo đến các hệ thống bên ngoài (Slack, Telegram) khi có sự kiện quan trọng.

10. Tổng kết kiến trúc#

Điểm mạnh:
Tách biệt rõ ràng giữa các lớp: View, Composable, Store, Service, Config.
Auto-import giảm boilerplate và đảm bảo nhất quán.
TypeScript namespace tổ chức theo module nghiệp vụ, dễ tìm kiếm và bảo trì.
Axios interceptor tập trung xử lý xác thực và lỗi.
Pinia store tối giản, chỉ lưu dữ liệu thực sự cần chia sẻ toàn cục.
Các quyết định kỹ thuật quan trọng:
Dùng <script setup lang="ts"> thay vì Options API để có type inference tốt hơn.
Dùng import.meta.glob để tự động nạp route modules.
Dùng window.configs injection để override biến môi trường mà không cần build lại.
Dùng multi-stage Docker build để giảm kích thước image production.
Dùng pinia-plugin-persistedstate để đồng bộ store với localStorage theo cách khai báo.
Modified at 2026-03-27 04:31:57
Previous
User Guide
Next
Code Structure
Built with