Lewati ke isi

Sentra Rental — Architecture & Tech Stack Delta

System Architecture

SentraRental Share menggunakan arsitektur Hybrid Modern dengan API Gateway, microservices untuk domain ketersediaan tinggi, dan modul core monolitik termodularisasi untuk menjamin keandalan data.

3.1 C4 Container Diagram

graph TB
    subgraph "Client Application Layer"
        A["Next.js Web Portal — Pelanggan"]
        B["Electron Desktop App — Admin Cabang"]
        C["React Native App — Field Inspector Mobile"]
    end

    subgraph "API & Gateway Layer"
        GW["Kong API Gateway & Rate Limiter"]
    end

    subgraph "Microservices & Core Modules"
        AuthSvc["Auth & Identity Service"]
        BookSvc["Booking & Availability Service"]
        AssetSvc["Asset Inventory Service"]
        PaySvc["Billing & Payment Service"]
        MaintSvc["Maintenance Scheduler"]
    end

    subgraph "Cache & Storage Layer"
        Redis[("Redis Cluster: Redlock & Calendar State")]
        Postgres[("PostgreSQL: Main DB with Branch Partitioning")]
        S3[("AWS S3: Photo Assets & Signed Contracts")]
    end

    A --> GW
    B --> GW
    C --> GW

    GW --> AuthSvc
    GW --> BookSvc
    GW --> AssetSvc
    GW --> PaySvc
    GW --> MaintSvc

    BookSvc --> Redis
    BookSvc --> Postgres
    AssetSvc --> Postgres
    PaySvc --> Postgres
    MaintSvc --> Postgres
    C -- "Offline Sync Queue" --> GW

3.2 High-Concurrency Calendar Lock Workflow (Redis & DB Transaction)

sequenceDiagram
    autonumber
    actor Customer_A as Pelanggan A
    actor Customer_B as Pelanggan B
    participant Redis as Redis Cache
    participant DB as Postgres Database

    Note over Customer_A, Customer_B: Mencoba memesan Mobil Avanza B-1234-XYZ tanggal 25 Mei 2026
    Customer_A->>Redis: SETNX "lock:asset:avanza:2026-05-25" (TTL 10 Menit)
    Redis-->>Customer_A: OK (Lock Acquired)
    Customer_B->>Redis: SETNX "lock:asset:avanza:2026-05-25"
    Redis-->>Customer_B: FAIL (Already Locked)
    Note over Customer_B: "Aset sedang dipesan pengguna lain. Silakan tunggu 10 menit."

    Customer_A->>DB: START TRANSACTION
    Customer_A->>DB: Insert Booking (Status: PENDING_PAYMENT)
    Customer_A->>DB: COMMIT TRANSACTION
    Customer_A->>Redis: UPDATE STATE "calendar:avanza:2026-05-25" = "RESERVED"
    Customer_A->>Redis: DEL "lock:asset:avanza:2026-05-25"

Tech Stack — Rental Delta

Baseline: _shared/tech-stack-baseline.md

Overrides

  • Admin Cabang ClientElectron + React (alasan: akses native printer untuk surat jalan & digital agreement, serial port untuk QR scanner hardware)

Tambahan Sistem-Spesifik

  • Redis Bitmask Calendar: Setiap aset direpresentasikan oleh bit array harian di Redis dengan key format avail:<SKU>:<AssetID>:<YearMonth>. Setiap bit melambangkan satu hari dalam bulan; operasi bitwise BITOP AND mengecek ketersediaan, BITOP SET atomik mencegah race condition.
  • Redis Redlock: Distributed lock multi-node (redlock library) untuk mencegah double booking pada transaksi simultan dari branch berbeda. TTL lock = 10 menit (durasi window pembayaran).
  • Redis Sorted Set Waitlist: waitlist:<SKU>:<Date> dengan bobot berdasarkan tier keanggotaan + timestamp untuk antrean unit populer.
  • Payment Gateway Pre-Auth (Hold): Xendit atau Midtrans CC pre-authorisation API — menahan limit kartu kredit/e-wallet tanpa mendebet saldo. Capture dilakukan saat kerusakan/keterlambatan dikonfirmasi; release otomatis maksimal 24 jam setelah COMPLETED.
  • Inspector Mobile Offline Sync: React Native + Expo app dengan SQLite lokal (Expo SQLite). Foto tersimpan offline dengan antrean upload ke AWS S3 via multipart. Sinkronisasi otomatis saat koneksi pulih.
  • Dukcapil KTP API: Integrasi OCR KTP + Face Match liveness test (Verihubs / PrivyID) untuk verifikasi identitas pelanggan anti-fraud.
  • SHA-256 Tamper-Proof Hash: Setiap payload inspeksi handover (JSON checklist + URL foto + tanda tangan) di-hash SHA-256 dan disimpan di kolom tamper_proof_hash untuk audit integritas.