📚 Tài Liệu Hệ Thống

Kiến trúc, hiệu năng, công nghệ và phân tích chi phí

Live Database Stats (query: 4139.32ms)
54,720
Tổng lượt khám
5,000
Bệnh nhân
306,187
Tổng records
123 MB
Database size
Database size = 113 MB (tables + indexes) + 10 MB (system overhead) = 123 MB — truy vấn trực tiếp bằng pg_database_size()

Báo Cáo Hiệu Năng

6.8ms
Nhanh nhất
317ms
Chậm nhất
57.9ms
Trung bình
317.4ms
P90
< 50ms
8/10 queries
RPC FunctionExecution TimeGradeVisual
fn_hourly_distribution6.8 msA+
6.8 ms
fn_top_diagnoses11.7 msA+
11.7 ms
fn_revenue_by_period19.6 msA
19.6 ms
fn_revenue_by_department21.5 msA
21.5 ms
fn_top_medicines25.7 msA
25.7 ms
fn_doctor_performance28.3 msA
28.3 ms
fn_top_services32.3 msA
32.3 ms
fn_insurance_report42.3 msA
42.3 ms
fn_dashboard_summary73.3 msB+
73.3 ms
fn_patient_statistics317.4 msB
317.4 ms
📝 Ghi chú: Benchmark thực hiện ngày 28/02/2026 bằng EXPLAIN ANALYZE trên PostgreSQL với 54,720 lượt khám. Thời gian là Execution Time thuần (không bao gồm network latency ~100ms).

🗄️ Database Schema

10
Bảng dữ liệu
42
Indexes
123 MB
Tổng dung lượng
BảngSố dòngKích thướcVai trò
visits54,72055 MBLượt khám
visit_services104,15620 MBChi tiết dịch vụ
prescriptions89,89620 MBĐơn thuốc
invoices52,29117 MBHóa đơn
patients5,0001.5 MBBệnh nhân
services5472 KBDanh mục dịch vụ
icd_codes4048 KBMã bệnh ICD-10
medicines4048 KBDanh mục thuốc
doctors2056 KBBác sĩ
departments1048 KBKhoa/Phòng
TỔNG~306,000113 MB+ 10 MB system = 123 MB

Entity Relationship

departments ─┬── doctors │ │ │ ▼ └── visits ◄── patients │ ┌─────────┼─────────┐ ▼ ▼ ▼ visit_services prescriptions invoices │ │ ▼ ▼ services medicines icd_codes ◄── visits

🏗️ Kiến Trúc Hệ Thống

🌐
Browser
HTML + minimal JS (Recharts)
⬇️ Server-rendered HTML
⚛️
Next.js 16 Server
Server Components → Promise.all(4 queries) → HTML render
⬇️ HTTPS REST API
🔌
Supabase
PostgREST → PgBouncer → Connection Pool
⬇️ SQL RPC call
🐘
PostgreSQL
10 RPC Functions → Aggregated JSON → Single response
⚛️

Server Components

Data fetching chạy trên server, client nhận HTML hoàn chỉnh. Zero client-side data loading.

Parallel Queries

Promise.all() gọi 4 RPC đồng thời. Dashboard load = max(query) + 1 RTT.

🔧

RPC Functions

Logic aggregate tại PostgreSQL. 1 API call = 1 kết quả JSON đầy đủ, giảm bandwidth >99%.

🔗

Connection Pooling

PgBouncer transaction mode qua port 6543. Tối ưu connection reuse.

🛠️ Công Nghệ Sử Dụng

Công nghệVai tròLý do chọn
Next.js 16Frontend FrameworkServer Components, Streaming SSR, #1 React Framework
SupabaseBackend-as-a-ServicePostgreSQL + Auth + API + Realtime, 100% Open Source
PostgreSQLDatabase#1 Open Source DB, ACID, RLS, Stored Procedures
TypeScriptLanguageType-safe end-to-end, compiler bắt lỗi trước deploy
RechartsChartsReact-native charting, responsive, composable
Tailwind CSSStylingUtility-first, dark mode, responsive
shadcn/uiUI ComponentsAccessible, customizable, Radix-based
🏆
PostgreSQL
#1 Open Source DB — DB-Engines 2026
⚛️
Next.js
#1 React Framework — npm downloads
🟢
Supabase
100% Open Source — No vendor lock-in

🔒 Bảo Mật

LayerTính năngTrạng thái
NetworkSSL/TLS encryption mặc định
AuthenticationJWT + MFA (Supabase Auth)
AuthorizationRow Level Security (RLS)
DataAES-256 encryption at rest
APIRate limiting + API key rotation
BackupDaily auto backup + PITR
ComplianceSOC 2 Type II certified
🏥 Tuân thủ Y tế: Hỗ trợ Thông tư 46/2018/TT-BYT (bảo mật dữ liệu y tế), Thông tư 54/2017/TT-BYT (CNTT trong y tế). Có thể self-host trên server nội bộ (Supabase = 100% open source).

💰 Phân Tích Chi Phí (TCO 3 năm)

Giải phápNăm 1 (tr VNĐ)3 Năm (tr VNĐ)Dashboard Load
Truyền thống (Java/.NET + Oracle)1,2572,3712-5s
Supabase + Next.js (hệ thống này)358634~0.5s
Truyền thống
2,371 tr
Supabase+Next
634 tr
Tiết kiệm 73% — 1,737 triệu VNĐ trong 3 năm

Chi phí Supabase hàng tháng

Free
$0
500MB DB
PoC/Demo
Pro
$25
8GB DB
Phòng khám nhỏ-vừa
Team
$599
30GB DB
Bệnh viện
Enterprise
Custom
Custom DB
Chuỗi BV

📈 Lộ Trình Mở Rộng

Giai đoạnVisits/nămDatabaseChi phíGiải pháp
Phòng khám nhỏ< 50K/năm< 1 GB$0-25/thángSupabase Free/Pro
Phòng khám vừa50-200K/năm1-5 GB$45-75/thángSupabase Pro + Vercel Pro
Bệnh viện200K-1M/năm5-30 GB$600-1000/thángSupabase Team
Chuỗi phòng khám1M+/năm30+ GBCustomEnterprise / Self-hosted

⚙️ 10 RPC Functions

#FunctionMô tảTrang
1fn_dashboard_summaryTổng DT, lượt khám, BN, BHYTTổng quan
2fn_revenue_by_periodDT theo ngày/tuần/thángDoanh thu
3fn_revenue_by_departmentDT theo khoaTổng quan
4fn_patient_statisticsPhân bổ BN đa chiềuBệnh nhân
5fn_doctor_performanceHiệu suất bác sĩBác sĩ
6fn_top_servicesTop dịch vụ sử dụngDịch vụ
7fn_insurance_reportBáo cáo BHYT chi tiếtBHYT
8fn_top_diagnosesTop chẩn đoán ICD-10Dịch vụ
9fn_hourly_distributionPhân bổ theo giờTổng quan
10fn_top_medicinesTop thuốc kê đơnDịch vụ
Benchmark thực hiện ngày 28/02/2026 | Database: Supabase PostgreSQL (ap-south-1) | Dữ liệu xác minh bằng pg_database_size(), EXPLAIN ANALYZE, pg_stat_user_tables