TokoFlow

๐Ÿงฑ ERD โ€“ TokoFlow

1. ๐Ÿ“˜ Ringkasan

Entity Relationship Diagram (ERD) TokoFlow menggambarkan struktur database untuk sistem manajemen toko berbasis Software as a Service (SaaS).
Setiap akun pengguna (owner) memiliki satu atau lebih toko (store) dalam satu lingkungan cloud (multi-tenant).
Semua data penjualan, stok, dan user disimpan terisolasi per toko untuk menjaga keamanan dan privasi data antar pengguna.


2. ๐Ÿ“‚ Daftar Entitas & Relasi

2.1 ๐Ÿ‘ค Users

Kolom Tipe Keterangan
id UUID Primary key
fullName string Nama lengkap
email string Unik, digunakan untuk login
passwordHash string Disimpan dalam bentuk hash
role enum owner / admin / kasir
storeId UUID (nullable) FK โ†’ stores.id (user terikat ke toko)
planId UUID (nullable) FK โ†’ subscription_plans.id
isActive boolean Default: true
createdAt datetime -
updatedAt datetime -

๐Ÿ’ก Owner dapat memiliki banyak toko (multi-store), sementara admin dan kasir hanya terikat ke satu toko.


2.2 ๐Ÿฌ Stores

Kolom Tipe Keterangan
id UUID Primary key
ownerId UUID FK โ†’ users.id
name string Nama toko
address string Alamat toko
phone string Opsional
isActive boolean Default: true
createdAt datetime -
updatedAt datetime -

๐Ÿ”— Relasi:


2.3 ๐Ÿ—‚๏ธ Categories

Kolom Tipe Keterangan
id UUID Primary key
storeId UUID FK โ†’ stores.id
name string Unik per toko
createdAt datetime -
updatedAt datetime -

2.4 ๐Ÿ“ฆ Products

Kolom Tipe Keterangan
id UUID Primary key
storeId UUID FK โ†’ stores.id
sku string Unik per toko
name string Nama produk
categoryId UUID (nullable) FK โ†’ categories.id
unit string pcs / box / pack
costPrice decimal Harga modal
salePrice decimal Harga jual
barcode string Opsional
isActive boolean Default: true
createdAt datetime -
updatedAt datetime -

2.5 ๐Ÿ“ˆ Inventory (Mutasi Stok)

Kolom Tipe Keterangan
id UUID Primary key
storeId UUID FK โ†’ stores.id
productId UUID FK โ†’ products.id
type enum IN / OUT / ADJUST / TRANSFER
quantity integer Jumlah stok berubah
reference string Referensi transaksi / dokumen
reason string Keterangan opsional
createdBy UUID FK โ†’ users.id
createdAt datetime -

2.6 ๐Ÿ’ฐ Sales (Transaksi Penjualan)

Kolom Tipe Keterangan
id UUID Primary key
storeId UUID FK โ†’ stores.id
userId UUID FK โ†’ users.id (kasir/admin)
customerId UUID (nullable) FK โ†’ customers.id
total decimal Total transaksi
paymentMethod enum cash / transfer / qris
status enum SAVED / DRAFT / CANCELLED
notes string Opsional
createdAt datetime -
updatedAt datetime -

2.7 ๐Ÿงพ Sales Details

Kolom Tipe Keterangan
id UUID Primary key
saleId UUID FK โ†’ sales.id
productId UUID FK โ†’ products.id
sku string Duplikat dari produk
name string Duplikat dari produk
quantity integer Jumlah barang
unitPrice decimal Harga per item
discount decimal Opsional
total decimal (quantity ร— unitPrice) - discount

2.8 ๐Ÿ” Audit Trail

Kolom Tipe Keterangan
id UUID Primary key
userId UUID FK โ†’ users.id
module string PRODUCT / SALES / INVENTORY / AUTH
action string CREATE / UPDATE / DELETE / LOGIN
before JSON Data sebelum perubahan
after JSON Data sesudah perubahan
meta JSON IP, userAgent
createdAt datetime -

2.9 ๐Ÿ’ณ Subscription Plans (SaaS Specific)

Kolom Tipe Keterangan
id UUID Primary key
name string Nama paket (Free, Basic, Pro)
price decimal Harga per bulan
storeLimit integer Jumlah toko maksimum
productLimit integer Jumlah produk maksimum
userLimit integer Jumlah user maksimum
features JSON Daftar fitur aktif
createdAt datetime -

2.10 ๐Ÿ“† Subscriptions

Kolom Tipe Keterangan
id UUID Primary key
userId UUID FK โ†’ users.id (owner)
planId UUID FK โ†’ subscription_plans.id
status enum ACTIVE / EXPIRED / CANCELLED
startDate datetime -
endDate datetime -
paymentReference string ID dari Midtrans / Xendit
createdAt datetime -

3. ๐Ÿ”— Hubungan Antar Entitas (Ringkasan)

Relasi Jenis Deskripsi
Users โ†” Stores One-to-Many Owner bisa punya banyak toko
Stores โ†” Products One-to-Many Tiap toko punya daftar produk sendiri
Products โ†” Inventory One-to-Many Setiap produk memiliki mutasi stok
Sales โ†” SalesDetails One-to-Many Setiap transaksi punya banyak item
Sales โ†” Users Many-to-One Transaksi dilakukan oleh kasir/admin
Users โ†” SubscriptionPlans Many-to-One Tiap owner terikat ke satu paket langganan
AuditTrail โ†” Users Many-to-One Log aktivitas oleh user tertentu

4. ๐Ÿ—๏ธ Model Multi-Tenant

TokoFlow menggunakan pendekatan single database, isolated by storeId:

Keuntungan:


5. ๐Ÿง  Catatan Implementasi


๐Ÿ“˜ ERD ini dirancang agar fleksibel dan siap dikembangkan sebagai sistem SaaS multi-tenant dengan opsi langganan (freemium โ†’ premium).
Struktur ini menjaga keseimbangan antara skalabilitas, performa, dan kemudahan pengembangan backend menggunakan Express + Sequelize + PostgreSQL.