Mô hình dữ liệu¶
Cập nhật gần nhất: 17/03/2026
Thực thể cốt lõi¶
Các collection Firestore chính:
clansbranchesmembersrelationshipseventsfundstransactionsscholarshipProgramsawardLevelsachievementSubmissionsnotificationsinvitesauditLogsusersvà collection conusers/{uid}/deviceTokens
Các collection cho billing:
subscriptionssubscriptionInvoicespaymentTransactionspaymentWebhookEventsbillingSettingsbillingAuditLogs
Các trường quan trọng của thuê bao gồm:
planCode (FREE, BASE, PLUS, PRO), memberCount, amountVndYear,
expiresAt, paymentMode, autoRenew, nextPaymentDueAt và cờ quyền lợi
quảng cáo (showAds, adFree).
Mô hình quan hệ¶
- cạnh quan hệ chuẩn được lưu trong
relationships - các mảng phi chuẩn hóa trên
members(parentIds,childrenIds,spouseIds) giúp đọc nhanh khi render cây và hồ sơ - khi tạo quan hệ, phía server kiểm tra trùng quan hệ vợ/chồng và chặn vòng lặp cha mẹ - con cái
Mô hình định danh và phiên¶
members.authUidliên kết tài khoản Firebase Auth với hồ sơ thành viênusers/{uid}lưu ngữ cảnh truy cập để fallback cho rules:memberIdclanIdvàclanIdsbranchIdprimaryRoleaccessModelinkedAuthUid- token FCM được lưu ở
users/{uid}/deviceTokens/{token}
Chiến lược truy vấn và index¶
Các index ưu tiên truy vấn theo phạm vi clan, tìm kiếm thành viên và dữ liệu theo thời gian:
- members theo
clanId + normalizedFullName - relationships theo
clanId + personA/personB + type - events theo
clanId/branchId + startsAt - notifications theo
memberId + createdAt
Bộ index cho billing:
- subscriptions theo
clanId + status + expiresAt - payment transactions theo
clanId + createdAt - invoices theo
clanId + periodStart/periodEnd