Skip to main content

Multi-Level Approval System

Dokumentasi lengkap sistem approval multi-level di MStore Backend dengan support delegation, auto-approve SLA, dan role-based workflow.

🎯 Overview

Sistem approval MStore dirancang dengan prinsip:
  • βœ… Multi-Level: Support approval bertingkat (L1, L2, L3, dst)
  • βœ… Role-Based: Approval berdasarkan role (MAKER, CHECKER, APPROVER)
  • βœ… Delegation: Temporary delegation dengan time range
  • βœ… Auto-Approve SLA: Automatic approval jika melewati SLA
  • βœ… Flexible Rules: Approval rules berdasarkan doc type & amount range
  • βœ… Audit Trail: Complete log untuk setiap action
  • βœ… Merchant-Scoped: Isolasi approval per merchant/branch

πŸ—οΈ Architecture


πŸ“Š Data Model

1. Roles (Global RBAC)


2. Approvers (User-Role Mapping)

Key Concepts:
  • role_order: Urutan approver dalam role yang sama (untuk approval_mode=β€˜all’)
  • Delegation: Temporary delegation ke user lain
  • Scope: Merchant & branch level isolation

3. Approval Flows (Rules Definition)

Approval Modes:
  • all: Semua approver di level harus approve
  • any: Salah satu approver di level cukup approve

4. Approval Requests


5. Approval Logs (Audit Trail)


πŸ”„ Approval Flow

State Machine


Example Flow: Inventory Transfer

Scenario: Transfer senilai Rp 5.000.000 memerlukan 2 level approval Setup:
Flow Execution:

πŸ’» Implementation

1. Create Approval Request


2. Process Approval Action


3. Auto-Approve Scheduler


4. Delegation Handling


πŸ“‘ API Endpoints

1. Create Approval Request


2. Get Pending Approvals (for Approver)

Response:

3. Process Approval Action


4. Get Approval History

Response:

πŸ§ͺ Testing Scenarios

Scenario 1: Two-Level Approval

Scenario 2: Rejection at Level 1

Scenario 3: Auto-Approve SLA


πŸ’‘ Best Practices

DO βœ…

  • Define clear approval flows per document type & amount range
  • Use role-based approvers untuk flexibility
  • Implement delegation untuk coverage saat approver unavailable
  • Set reasonable SLA untuk auto-approve
  • Log semua actions dengan IP & user agent
  • Notify approvers via email/in-app notification
  • Implement approval dashboard untuk monitoring
  • Use transaction untuk atomic operations

DON’T ❌

  • Jangan hardcode approver user IDs
  • Jangan skip audit logging
  • Jangan allow approval tanpa authentication
  • Jangan ignore SLA monitoring
  • Jangan allow self-approval (requester = approver)
  • Jangan skip validation untuk approval permission

πŸ†˜ Troubleshooting

Problem: Approval Stuck

Symptoms: Request tidak bergerak meski sudah approve Solution:

Inventory Flow

Approval untuk inventory transfers

Transaction Flow

Approval untuk void transactions

RBAC System

Role-based access control

Need Help? Contact backend team atau check GitHub Issues