1. Architecture
Social Tool Documentation
  • Tổng quan
  • Bussiness | Logic
    • Bussiness | Logic
  • Project
    • ADMIN
      • Tổng quan ADMIN
      • Architecture
        • System architecture
        • Code structure
      • Deployment
        • Local
        • Staging
        • Product
      • Hướng dẫn sử dụng
        • Đăng nhập
        • FAQ
        • Mạng xã hội
          • Tài khoản mạng xã hội
          • Nội dung bài viết & bình luận
          • Quản lý liên kết
          • Thư viện hình ảnh
          • Thu thập dữ liệu
        • Hệ thống
          • Quản lý proxy
        • Chiến dịch
          • Tạo & quản lý chiến dịch
          • Đăng nhập tài khoản
          • Check Proxy
          • Join Group
    • API
      • Tổng quan API
      • Architecture
        • System architecture
        • Database schema
        • Code structure
      • Deployment
        • Local
        • Staging
        • Product
      • API Interface
        • 🔑 Identity & Session
          • List users
          • Create user
          • Update info user
          • Update info user
          • List user departments
          • Delete user
          • List user's AI keys
          • Create AI key
          • Get user's active API key
          • Get supported services
          • Get supported AI models
          • Update AI key
          • Delete AI key
          • Get AI key by ID
          • List departments
          • Create department
          • Update department
          • Create department
          • Update department
          • Update department roles
          • Get department roles
          • Update department status
          • Delete department
          • List user sessions
          • Create user session
          • Delete user session
          • Get user sessions by user ID
          • Delete all user sessions
          • Update user session status
          • List user activity logs
          • Create user activity log
          • Get user activity logs
          • Delete user activity logs
          • User login
          • User registration
          • User logout
          • Logout from all devices
          • Refresh access token
          • Create api key
          • Reset password
          • Get current user
          • Get user roles
          • Create role
          • Update role
          • Update role
          • Update role
          • List user permission groups
          • Get user permission group by ID
          • Delete user permission group
          • Create user permission group
          • Update user permission group
          • Get all user permission groups with permissions
        • 🛰️ Proxy & Connectivity
          • List proxies
          • Create proxy
          • Create many proxies
          • Update proxy
          • Delete proxy
          • Get proxy by ID
          • Import proxies from CSV/Excel
          • Check expired proxies
          • Kiểm tra proxy (qua Campaign)
          • Xóa proxy
          • Cập nhật proxy
          • Proxy Group list
          • Create a Proxy Group
          • Get a Proxy Group by ID
          • Update a Proxy Group
          • Delete a Proxy Group
          • Delete a Proxy Group
          • List proxy providers
          • Create proxy provider
          • Update proxy provider
          • Delete proxy provider
          • Get proxy provider by ID
          • Import proxy packages from CSV
          • List proxy packages
          • Create proxy package
          • Update proxy package
          • Delete proxy package
          • Get proxy package by ID
          • Import proxy packages from CSV
        • 📱 Social Management
          • List socials
          • Create social
          • Update social
          • Delete social
          • Get social by ID
          • List social accounts
          • Create social account
          • Create social account
          • Get account tasks
          • Assign proxies to social account
          • Update social account
          • Delete social account
          • Get social account by ID
          • Join social account
          • Cancel social accounts
          • Cancel social accounts
          • Import social accounts from file
          • Get account usage statistics
          • Push cookies manually for specific accounts (via Campaign)
          • Đổi tên nhiều tài khoản (qua Campaign)
          • Đổi mật khẩu nhiều tài khoản (qua Campaign)
          • Đổi ảnh đại diện (qua Campaign)
          • Social Account Group list
          • Create a Social Account Group
          • Get a Social Account Group by ID
          • Create a Social Account Group
          • Delete a Social Account Group
          • List social pages
          • Create social page
          • Update social page
          • Delete social page
          • Get social page by ID
          • Batch update social page status
          • Batch delete social pages
          • Import social pages from file
          • Search social pages
          • Batch delete social pages
          • Social Page Group list
          • Create a Social Page Group
          • Get a Social Page Group by ID
          • Update a Social Page Group
          • Delete a Social Page Group
          • List social actions
          • Create social action
          • Update social type
          • Delete social action
          • Get social type by ID
          • List social pages
          • Create social content
          • Update social content
          • Delete social content
          • Get social content by ID
          • Batch delete social content
          • Import social accounts from file
          • Create a new social content group
          • Get paginated list of social content groups
          • Get social content group by ID
          • Update social content group
          • Soft delete social content group
          • Batch delete social content groups
          • Delete social content group
          • Get groups by social platform ID
          • Social Image list
          • Create a Social Image
          • Get a Social Image by ID
          • Update a Social Image
          • Delete a Social Image
          • Social Collect Data list
          • Create a Social Collect Data
          • Get a Social Collect Data by ID
        • 📁 Campaign Management
          • List campaigns
          • Create campaign
          • Update campaign
          • Delete campaign
          • Get campaign by ID
          • Create campaign platform
          • List campaign platforms
          • Update campaign platform
          • Delete campaign platform
          • Get campaign platform by ID
          • Create campaign platform
          • Create campaign platform
          • Clone campaign platforms
          • Cancel multiple campaign platforms
          • List campaign joins
          • Create campaign platform
          • List campaign joins
          • Update campaign platform
          • Update campaign platform
          • Update campaign platform
          • Update campaign platform
          • List jobs
          • Update job
          • Delete job
          • Get job by ID
          • List campaign platform tasks
          • Create campaign platform task
          • Update campaign platform task
          • Delete campaign platform task
          • Get campaign platform job task by ID
          • List Report Categories
          • Create Report Categories
          • Create Report Categories
          • Create Report Categories
          • List Report Details
          • Create Report Details
          • Create Report Details
          • Create Report Details
    • TOOL
      • Tổng quan TOOL
      • Architecture
        • Database schema
        • System architecture
        • Code structure
      • Deployment
        • Local
        • Staging
        • Product
      • API Interface
        • 🎯 NATS — Task
          • [NATS RPC] Tạo batch Task mới
          • [NATS RPC] Lấy danh sách tất cả Tasks
          • [NATS RPC] Đếm số Task đang chờ xử lý
          • [NATS RPC] Xóa tất cả Tasks
        • 🍪 NATS — Cookie
          • [NATS RPC] Thêm batch Cookie (Auto Login)
          • [NATS RPC] Lấy danh sách tất cả Cookies
          • [NATS RPC] Xóa tất cả Cookies
        • 🌐 NATS — Proxy
          • [NATS RPC] Gửi batch Proxy để kiểm tra
        • 🔗 NATS — TaskJoin
          • [NATS RPC] Tạo lệnh tham gia Group
          • [NATS RPC] Kiểm tra trạng thái tham gia Group
        • 📤 NATS — Callbacks
          • [NATS PUB] Kết quả thực thi Task
          • [NATS PUB] Kết quả Crawl dữ liệu
          • [NATS PUB] Kết quả Auto Login
          • [NATS PUB] Kết quả kiểm tra Proxy
          • [NATS PUB] Kết quả tham gia Group
          • [NATS PUB] Kết quả kiểm tra trạng thái tham gia
        • 📊 HTTP — Logs & Info
          • Service Root — Thông tin Worker
          • Health Check
          • Đọc file log
          • Log hôm nay
          • Log theo ngày cụ thể
          • Danh sách ngày có log
          • Test kết nối ChatGPT
        • 📋 HTTP — Data Query
          • Danh sách Tasks (phân trang + lọc)
          • Xóa tất cả Tasks
          • Danh sách tất cả Cookies
          • Xóa tất cả Cookies
          • Xóa Cookie theo _id
          • Danh sách Proxies (lọc theo task_id)
          • Xóa tất cả Proxies
          • Proxy Checks đang chờ xử lý
          • Proxy Checks đã hoàn thành
          • Xóa Proxy theo _id
          • Danh sách Task Join (phân trang + lọc)
          • Tạo Task Join (HTTP mode)
          • Xóa tất cả Task Join
  • Schemas
    • AIInfo
    • CommentInfo
    • ReplyInfo
    • ShareInfo
    • CaptchaInfo
    • PageInfo
    • SocialAccountInfo
    • ProxyInfo
    • SocialInfo
    • ActionInfo
    • CreateTaskPayload
    • CreateCookiePayload
    • CreateProxyPayload
    • CreateTaskJoinPayload
    • NatsAcceptedResponse
    • NatsRejectedResponse
    • NatsErrorResponse
    • TaskCompletedPayload
    • CookieUpdatePayload
    • ProxyCheckResultPayload
    • TaskJoinResultPayload
    • TaskJoinCheckResultPayload
    • PagingInfo
    • AppError
  1. Architecture

Database schema

Tài liệu Database Schema#

Tài liệu kỹ thuật – Phiên bản 1.0
Mô tả cấu trúc cơ sở dữ liệu của hệ thống Social Tool

1. Tổng quan Công nghệ#

Hệ thống sử dụng cơ sở dữ liệu MySQL, quản lý schema thông qua Drizzle ORM.
Thành phầnChi tiết
DatabaseMySQL
ORMDrizzle ORM
Model definitionssrc/api/models/*.model.ts
Schema entry pointsrc/api/models/schema.ts
Configdrizzle.config.ts

2. Sơ đồ quan hệ tổng thể (ERD)#


3. Luồng thực thi tác vụ#


4. Chi tiết các bảng#

4.1. Bảng users#

Quản lý thông tin đăng nhập và phân quyền cho toàn bộ nguời dùng hệ thống.
CộtKiểu dữ liệuMô tả
idintPrimary Key, tự động tăng
namevarchar(255)Tên hiển thị
emailvarchar(255)Email đăng nhập (Unique)
passwordvarchar(255)Mật khẩu đã mã hóa
phonevarchar(20)Số điện thoại liên lạc
statusbooleanTrạng thái hoạt động (true: active)
permis_idsvarcharDanh sách ID nhóm quyền, phân cách bằng dấu phẩy
secret_keyvarcharKhóa bí mật dùng cho bảo mật / API
created_attimestampThời điểm tạo
updated_attimestampThời điểm cập nhật cuối
created_byintID người tạo
updated_byintID người cập nhật cuối

4.2. Bảng social_accounts#

Lưu trữ thông tin các tài khoản mạng xã hội.
CộtKiểu dữ liệuMô tả
idintPrimary Key, tự động tăng
social_idintFK → bảng socials
group_idintFK → bảng social_account_groups
namevarcharTên gợi nhớ của tài khoản
usernamevarcharTên đăng nhập trên nền tảng
passwordvarcharMật khẩu nền tảng
old_passwordvarcharMật khẩu cũ (lưu khi có thay đổi)
secret_keytextMã 2FA hoặc khóa bảo mật bổ sung
valuetextCookie hoặc Access Token
statusvarcharTrạng thái: new, pending, active, failure...
avatarvarcharURL ảnh đại diện
emailvarcharEmail khôi phục / đăng ký tài khoản
phonevarcharSố điện thoại gắn với tài khoản
linkProfilevarcharURL profile cá nhân
genderintGiới tính (1: Nam, 2: Nữ)
user_agentvarcharUser Agent trình duyệt được giả lập
device_sizevarcharKích thước màn hình thiết bị giả lập
notetextGhi chú thêm
activebooleanTài khoản có khả dụng không
versionintPhiên bản dữ liệu (hỗ trợ migration)
created_attimestampThời điểm thêm vào hệ thống
updated_attimestampThời điểm cập nhật cuối
deleted_atdatetimeThời điểm xóa mềm (Soft Delete)

4.3. Bảng social_pages#

Quản lý các Fanpage, Group, Profile của các trang mạng xã hội.
CộtKiểu dữ liệuMô tả
idintPrimary Key
social_idintFK nền tảng
group_idintFK nhóm trang
page_urlvarcharURL đầy đủ của trang / group
titlevarcharTên hoặc tiêu đề trang
typeenumLoại trang: page, group, profile, post...
group_typeenumChế độ group: public, private
parent_idintID trang cha (nếu có cấu trúc phân cấp)
descriptiontextMô tả về mục tiêu
keywordvarcharTừ khóa phân loại
activebooleanTrạng thái hoạt động
created_atdatetimeThời gian tạo
updated_atdatetimeThời gian cập nhật
deleted_atdatetimeThời gian xóa mềm (Soft Delete)

4.4. Bảng campaigns#

Lưu thông tin cơ bản của một chiến dịch.
CộtKiểu dữ liệuMô tả
idbigintPrimary Key
social_idbigintFK nền tảng (nullable nếu là job hệ thống)
namevarcharTên chiến dịch
typevarcharLoại: join_group, login, changename...
descriptiontextMô tả mục tiêu chiến dịch
rules_jsonjsonCấu hình chung toàn chiến dịch
activebooleanChiến dịch đang hoạt động hay không
start_datetimestampNgày bắt đầu dự kiến
end_datetimestampNgày kết thúc dự kiến
created_bybigintID người tạo
updated_byintID người cập nhật cuối
created_attimestampThời gian tạo
updated_attimestampThời gian cập nhật
deleted_attimestampThời gian xóa mềm (Soft Delete)

4.5. Bảng campaign_platforms#

Quản lý chiến dịch và các cấu hình của các task sẽ thực hiện.
CộtKiểu dữ liệuMô tả
idbigintPrimary Key
action_idbigintFK hành động (Like, Comment, Share...)
campaign_idbigintFK chiến dịch gốc
parent_idbigintFK platform cha (nếu có)
namevarcharTên cấu hình platform
codevarcharMã định danh duy nhất
statusvarcharTrạng thái: pending, running, completed, cancelled...
descriptiontextMô tả chi tiết
rules_jsonjsonLogic chạy (delay, số bài mỗi tài khoản...)
metadata_jsonjsonDữ liệu thực thi (danh sách link bài, nội dung...)
activebooleanCó kích hoạt không
is_tasks_createdbooleanĐã sinh task nhỏ lẻ chưa
last_task_creation_attimestampLần cuối sinh task
start_datetimestampThời gian bắt đầu thực thi
end_datetimestampThời gian kết thúc thực thi
cancelled_attimestampThời điểm hủy (nếu có)
all_tasks_finished_attimestampThời điểm hoàn tất toàn bộ task
created_attimestampThời gian tạo
updated_attimestampThời gian cập nhật
deleted_attimestampThời gian xóa mềm (Soft Delete)

4.6. Bảng campaign_platform_tasks#

Quản lý các task cần thực hiện của chiến dịch
CộtKiểu dữ liệuMô tả
idbigintPrimary Key
campaign_platform_idbigintFK platform cấu hình
social_account_idbigintFK tài khoản thực hiện
page_idbigintFK trang mục tiêu (nếu có)
group_idvarcharNhóm các task liên quan
codevarcharMã task duy nhất
statusenumpending / running / completed / failed / cancelled
prioritybigintĐộ ưu tiên thực thi
metadatajsonDữ liệu riêng của task (link bài, nội dung comment...)
start_datetimestampThời điểm bắt đầu chạy
completed_attimestampThời điểm hoàn thành
created_attimestampThời gian tạo
updated_attimestampThời gian cập nhật
deleted_attimestampThời gian xóa mềm (Soft Delete)

4.7. Bảng proxies#

Quản lý proxy dùng để bảo vệ tài khoản khỏi checkpoint.
CộtKiểu dữ liệuMô tả
idintPrimary Key
ipvarcharĐịa chỉ IPv4 / IPv6
portintPort kết nối
usernamevarcharTên xác thực proxy
passwordvarcharMật khẩu xác thực proxy
rotate_urlvarcharURL để thực hiện rotate IP
rotate_timeintKhoảng thời gian tự động rotate (giây)
group_idintFK nhóm proxy
proxy_package_idintFK gói proxy
proxy_priceintGiá thuê proxy
notevarcharGhi chú
is_activebooleanProxy có khả dụng không
expired_attimestampNgày hết hạn
regionvarcharKhu vực địa lý của IP
disable_auto_rotatebooleanTắt tính năng tự động xoay IP
ipBlockedByFbintĐánh dấu IP bị Facebook chặn
created_attimestampThời gian thêm proxy
updated_attimestampThời gian cập nhật cuối
deleted_attimestampThời gian xóa mềm (Soft Delete)

5. Quy trình cập nhật Schema#

Các bước thực hiện:
1.
Chỉnh sửa Model — Mở file .model.ts tương ứng trong src/api/models/ và thực hiện thay đổi.
2.
Tạo Migration — Chạy lệnh để Drizzle quét code và sinh file SQL:
3.
Áp dụng Migration — Thực thi các file SQL mới vào database:

6. Nguyên tắc & Lưu ý quan trọng#

⚠️ Cần tuân thủ các quy ước dưới đây để đảm bảo tính nhất quán và an toàn dữ liệu.
Quy tắcChi tiết
🗑️ Soft DeleteLuôn dùng deleted_at thay vì xóa cứng dữ liệu quan trọng
🕐 Timestamp tự độngCác cột created_at, updated_at được Drizzle/SQL tự quản lý
📋 Đăng ký SchemaKhi thêm bảng mới, bắt buộc khai báo trong src/api/models/schema.ts để Drizzle nhận dạng quan hệ
🔗 Foreign KeyLuôn sử dụng FK để đảm bảo tính toàn vẹn dữ liệu giữa các bảng

Tài liệu được cập nhật lần cuối: 2026. Mọi thắc mắc vui lòng liên hệ đội ngũ kỹ thuật.
Modified at 2026-03-30 10:01:21
Previous
System architecture
Next
Code structure
Built with