Skip to main content

Entity Relationship Diagram

Dokumentasi lengkap database schema dengan ERD (Entity Relationship Diagram) menggunakan Mermaid.
πŸ’‘ Working with ERD:
  • Zoom: Cmd/Ctrl + Scroll atau klik kanan β†’ β€œOpen Image in New Tab”
  • Download: Copy code ERD β†’ paste ke Mermaid Live Editor β†’ Download PNG/SVG
  • Full Guide: Lihat Mermaid Guide untuk tutorial lengkap

🎯 Database Overview

MStore menggunakan MySQL 9.3.0 sebagai primary database dengan struktur multi-tenant merchant-scoped. Total Tables: 120 tables
Total Foreign Keys: 209 relationships
Migration Tool: Atlas HCL
ORM: GORM v1.30

πŸ“Š Domain Architecture

Database MStore diorganisir dalam 12 domain utama:

πŸ“Š Core Entities

1. Multi-Tenant Core


2. Transaction Flow


3. Inventory & Warehouse


4. Inventory Transfer


5. Product & Bundle


6. Approval Flow


7. Accounting & Journal


πŸ”‘ Key Relationships

Multi-Tenant Isolation

Every table has merchant_id untuk data isolation:

Foreign Key Constraints

Enforced at Database Level:

Unique Constraints

Merchant-Scoped Uniqueness:

πŸ“ˆ Indexing Strategy

Performance Indexes


πŸ” Common Queries

1. Get Branch Stock Summary


2. Transaction with Items


3. Pending Approvals for User


4. Inventory Movement History


πŸ› οΈ Migration Management

Atlas HCL Structure


Running Migrations


πŸ“Š Database Statistics

Table Sizes (Estimated)


Storage Requirements

Per Merchant (Average):
  • Transactions: ~500MB/year
  • Inventory Movements: ~1GB/year
  • Audit Logs: ~200MB/year
  • Total: ~2GB/year per merchant
Retention Policy:
  • Transactional data: 3 years
  • Audit logs: 7 years
  • Archived data: S3/cold storage

πŸ’‘ Best Practices

DO βœ…

  • Always filter by merchant_id first
  • Use composite indexes untuk common queries
  • Implement soft deletes (deleted_at)
  • Use GORM hooks untuk audit fields
  • Implement database connection pooling
  • Use prepared statements (GORM default)
  • Monitor slow query log
  • Regular ANALYZE TABLE untuk statistics

DON’T ❌

  • Jangan skip merchant_id filter
  • Jangan gunakan SELECT * di production
  • Jangan skip indexes untuk FK
  • Jangan hardcode IDs
  • Jangan skip transaction untuk atomic operations
  • Jangan allow NULL di FK columns
  • Jangan skip backup strategy

πŸ”„ Backup & Recovery

Backup Strategy

Point-in-Time Recovery