Entity Relationship Diagram
Dokumentasi lengkap database schema dengan ERD (Entity Relationship Diagram) menggunakan Mermaid.π― Database Overview
MStore menggunakan MySQL 9.3.0 sebagai primary database dengan struktur multi-tenant merchant-scoped. Total Tables: 120 tablesTotal 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 hasmerchant_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
- Transactional data: 3 years
- Audit logs: 7 years
- Archived data: S3/cold storage
π‘ Best Practices
DO β
- Always filter by
merchant_idfirst - 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_idfilter - 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