F
PlatformCập nhật 2026-06-30 · platform/DATA-ARCHITECTURE.md

Data Architecture — Kiến trúc dữ liệu

Một database multi-tenant, shared schema, tenant_id + RLS. Spine giữ entity dùng chung; vertical extend, không nhân bản.

Nguyên tắc

  • Single DB, shared schema + tenant_id trên mọi bảng tenant-scoped + Postgres RLS (lớp phòng thủ #2). Không schema-per-tenant / db-per-tenant (over-engineering).
  • Spine entity dùng chung (User, Tenant, Payment, Notification...) — vertical tham chiếu, không copy.
  • Vertical extend entity lõi (Reservable, Reservation, Place...) bằng bảng mở rộng/discriminator, không tạo "Hotel/Room" riêng lẻ.
  • Trust/eval dataset (Travel Intelligence) tách store riêng (provenance + temporal), feedback-corrected.

Tầng dữ liệu

┌ SHARED (spine) ────────────────────────────────────────────────┐
│ Tenant, User, Role, Membership, Payment, PayoutRequest,         │
│ Notification, MediaAsset, AuditLog, CmsPage, Coupon             │
└────────────────────────────────────────────────────────────────┘
┌ CORE DOMAIN (Booking module #1) ───────────────────────────────┐
│ Listing, RoomType/Unit, RatePlan, Availability, PriceCalendar,  │
│ Reservation, Guest, Review                                      │
└────────────────────────────────────────────────────────────────┘
┌ VERTICAL EXTENSIONS ───────────────────────────────────────────┐
│ Affiliate, ReferralCode, Commission                             │
│ Restaurant, Table, MenuItem, FnbOrder, Bill                     │
│ Tour, Experience  (extend Reservable + Reservation)            │
│ HealthProvider, TreatmentPackage, PatientProfile, CarePlan      │
│   (extend Place/Reservable/Customer/Reservation)               │
└────────────────────────────────────────────────────────────────┘
┌ INTELLIGENCE (Travel Intelligence store, tách) ────────────────┐
│ Place, Review, ReviewAspect, KnowledgeFact, Feature, Score,     │
│ EvaluationReport (provenance + temporal + feedback)            │
└────────────────────────────────────────────────────────────────┘

Multi-tenant

  • Mọi bảng tenant-scoped: cột tenant_id (FK Tenant) + RLS policy tenant_id = current_setting('app.tenant').
  • Spine entity toàn cục (vd Payment provider config) tách rõ scope.
  • Brand/theme/domain ở TenantSettings.

Quy tắc tránh ngay từ đầu

  1. Không db-per-tenant / schema-per-tenant.
  2. Không khoá tên "Hotel/Room" — dùng Listing/Inventory/Reservation.
  3. Không gắn role vào User trực tiếp — gắn vào Membership (user × tenant).
  4. Payment polymorphic (target type) ngay — Booking/F&B/Medical dùng chung.
  5. PHI (PatientProfile/CarePlan) mã hoá + audit chặt.

Hiện trạng

Frontend hiện dùng mock + domain models (lib/domain/models) đã phản ánh các entity lõi. Schema DB thật = Phase 2 (Prisma theo models này). Travel Intelligence đã có Prisma schema riêng (Phase 4 nối).