Skip to content

Kiến trúc Storage và File Service của MINAP ​

Version: 2.2
Date: 2026-11-26
Status: Working baseline (hub slim — SoT chi tiết = docs-file lab)

Canonical SoT File Service: https://docs-file.minap.fxmonit.com/
Catalog sites: /docs-sites. Hub trang này chỉ giữ overview nền tảng, ranh giới platform, quota OPEN, và pointer.

1. Quyết định (platform) ​

Applications tích hợp MINAP File Service — không gắn trực tiếp AWS S3, Cloudflare R2 hay object store self-host. Bytes qua adapter S3-compatible; đích cloud đăng ký trong storage_connections.

  • D-005 — hướng tích hợp FS + variant on-demand + multi-connection + Infisical
  • Schema metadata: PostgreSQL minap_file (D-022)
  • Secrets/ENV disk roots: Infisical (D-016)
  • MinIO Community không dùng cho triển khai mới — /architecture/database/92-object-storage-after-minio

Hub DB pointer (không còn column-level): /architecture/database/02-file-service.

2. Trách nhiệm (tóm tắt) ​

BênSở hữu
File ServiceMetadata + file_id / tmp_id; authz upload/download/lifecycle/variant; adapter S3; jobs temp GC / migrate / purge / variant GC; size_bytes; workspace_id nullable (foresight quota)
Applications / Platform CoreÝ nghĩa nghiệp vụ; soft-ref …_file_id + display projection …_file_meta (DECIDED D-005, Owner 2026-11-26) — §2.1; không credentials / path vendor
Quota / billing (tương lai)Pool / allowance / phí — không bảng trong FS DB (§4)

Chi tiết actors/rules/flows/schema: docs-file.

2.1 Display projection (DECIDED — D-005) ​

Domain file refs bắt buộc soft-ref + projection (Owner 2026-11-26). Ngoại lệ chỉ qua change control.

LớpLưu gìVai trò
File ServiceMetadata đầy đủ + bytesSoT
Domain (Core / App / Chat / …)Soft-ref …_file_id (hoặc cột file_id)Canonical pointer
DomainJSON …_file_meta (hoặc tương đương)Projection — tối thiểu display_name, content_type, size_bytes, source_updated_at (không lặp file_id nếu đã có cột soft-ref)
  • Sync projection khi gắn / đổi / clear ref (snapshot từ promote hoặc GET /v1/files/{file_id}/meta — copy FS updated_at → source_updated_at).
  • Stale detect: FS updated_at ≠ projection source_updated_at → refresh meta (Owner 2026-11-26). Có thể false-positive nếu FS bump updated_at vì migrate/lifecycle — refresh vẫn an toàn.
  • Không lưu storage key / URL dài hạn / credentials.
  • Canonical id = cột soft-ref; meta chỉ field hiển thị. Snapshot nhúng (mảng không có cột id 1:1) có thể gồm file_id trong từng object.
  • Avatar Account (avatar_file_id + avatar_file_meta) là ví dụ; cùng pattern cho logo Workspace, attachment Chat, và mọi file ref domain.
  • Bytes / variant / original vẫn qua FS + authz.

3. Metadata vs bytes ​

Quan tâmSoT
Bytes gốcDisk local (FS_LOCAL_ROOT) hoặc object store S3-compatible
MetadataPostgres schema minap_file
Variant WebPFS_VARIANT_ROOT + variant_cache
Nghiệp vụ domainSoft-ref …_file_id + …_file_meta (DECIDED D-005)

Luồng logic (temp → promote local → migrate cloud → variant): xem docs-file lifecycle và sequence dưới (minh họa).

4. Isolation (platform) ​

  • L1 (MVP): cụm/provider chung; authz luôn qua FS; workspace_id không thay authz; basename object = UUIDv7 — không dựa tên bucket làm biên bảo mật.
  • L2: bucket/credentials riêng; secret qua Infisical (D-016).
  • L3: account/cụm store riêng khi hợp đồng yêu cầu.

Wire Chat membership ↔ FS: /architecture/06-minap-chat-architecture §4 (OPEN).

5. Nhà cung cấp storage ​

FS là lớp duy nhất App gọi. Chọn self-host OSS / S3 / R2 = OPEN O3/O4 trên 92. Ops FS: https://docs-file.minap.fxmonit.com/ops/.

6. Quota và Cloud Storage (hub giữ OPEN) ​

Không bảng quota/usage trong File Service DB. Service billing riêng (tương lai) đọc size_bytes (+ uploader_account_id, workspace_id).

Foresight: workspace_id nullable trên temp_uploads / files — không denorm organization_id.

6.1 Rủi ro bypass (bắt buộc) ​

Nếu cộng usage theo từng workspace_id độc lập, user có thể tạo thêm Personal Workspace để bypass. Ứng viên pool Q-A / Q-B / Q-C: /architecture/11-decisions-and-open-questions § File Service — Quota aggregation.

7. Bảo mật (baseline platform) ​

TLS; signed URL / delivery mode OPEN; authz server-side mọi đọc (kể variant); không public bucket mặc định; malware scan + FS audit_events = DEFERRED.

8. Variant / video cover — pointer ​

Chi tiết không nhân bản trên hub. SoT:

Tóm tắt hướng: variant WebP on-demand; video tạo cover lúc promote; gen size từ cover (không tải lại video từ object store chỉ để lấy frame).

9. Tài liệu SoT ​

Chủ đềNơi đọc
Overview / ranh giới FShttps://docs-file.minap.fxmonit.com/overview/
Business + OPENhttps://docs-file.minap.fxmonit.com/business/
Schema cộtdocs-file database
Lifecycledocs-file lifecycle
API surfacesdocs-file api
Ops / object store FShttps://docs-file.minap.fxmonit.com/ops/
Object-store vendor (platform)92
Hub DB stub02-file-service

Hub SoT · chi tiết theo repo: /docs-sites · văn xuôi tiếng Việt + thuật ngữ chuyên ngành English