kasapro

Arsitektur Teknis

Overview arsitektur teknis Kasapro untuk developers dan power users.


System Architecture Overview

High-Level Architecture

graph TB
    subgraph Client["Client Layer"]
        Browser["Web Browser"]
        Mobile["Mobile Browser<br/>(PWA)"]
    end
    
    subgraph Nginx["Nginx Reverse Proxy"]
        SSL["SSL/TLS<br/>Termination"]
        Routing["Request Routing"]
    end
    
    subgraph Application["Application Layer"]
        Frontend["Frontend<br/>(Next.js)"]
        Backend["Backend API<br/>(Go + Gin)"]
    end
    
    subgraph Data["Data Layer"]
        Postgres["PostgreSQL<br/>Database"]
        Redis["Redis<br/>Cache"]
    end
    
    Browser --> SSL
    Mobile --> SSL
    SSL --> Routing
    Routing --> Frontend
    Routing --> Backend
    Frontend --> Backend
    Backend --> Postgres
    Backend --> Redis

Components Overview

1. Client Layer:

2. Nginx Reverse Proxy:

3. Frontend (Next.js):

4. Backend API (Go):

5. Data Layer:


Technology Stack

Backend

Key Libraries:

Frontend

Key Libraries:

Infrastructure


Database Schema

Core Tables

Organizations:

- id (UUID)
- name (VARCHAR)
- store_name (VARCHAR)
- store_address (TEXT)
- store_phone (VARCHAR)
- setup_completed (BOOLEAN)
- created_at, updated_at

Users:

- id (UUID)
- organization_id (UUID, FK)
- username (VARCHAR, UNIQUE)
- full_name (VARCHAR)
- pin_hash (VARCHAR)
- role (VARCHAR: cashier, supervisor, owner)
- created_at, updated_at

Products:

- id (UUID)
- organization_id (UUID, FK)
- name (VARCHAR)
- sku (VARCHAR, UNIQUE)
- barcode (VARCHAR)
- price_cents (INTEGER)
- cost_cents (INTEGER)
- status (VARCHAR: active, inactive)
- stock (INTEGER)
- low_stock_threshold (INTEGER)
- created_at, updated_at

Transactions:

- id (UUID)
- organization_id (UUID, FK)
- shift_id (UUID, FK)
- cashier_id (UUID, FK)
- gross_amount_cents (INTEGER)
- discount_cents (INTEGER)
- net_amount_cents (INTEGER)
- payment_method (VARCHAR)
- payment_status (VARCHAR)
- created_at, updated_at

Transaction Items:

- id (UUID)
- transaction_id (UUID, FK)
- product_id (UUID, FK)
- product_name (VARCHAR)
- quantity (INTEGER)
- unit_price_cents (INTEGER)
- discount_cents (INTEGER)
- subtotal_cents (INTEGER)
- created_at

Relationships

Organizations (1) ──< Users (N)
Organizations (1) ──< Products (N)
Organizations (1) ──< Transactions (N)
Organizations (1) ──< Shifts (N)
Transactions (1) ──< Transaction Items (N)
Products (1) ──< Transaction Items (N)
Users (1) ──< Transactions (N) [as cashier]

Indexes

Semua tabel memiliki index pada:


API Overview

Authentication Flow

sequenceDiagram
    participant Client
    participant Frontend
    participant Backend
    participant DB
    
    Client->>Frontend: Login (username, PIN)
    Frontend->>Backend: POST /api/auth/login
    Backend->>DB: Verify user & PIN
    DB-->>Backend: User data
    Backend->>Backend: Generate JWT tokens
    Backend-->>Frontend: Access + Refresh tokens
    Frontend-->>Client: Store tokens

Main Endpoints

Authentication:

Products:

Transactions:

Inventory:

Reports:

Request/Response Format

Request:

Response:


Deployment Models

Self-Hosted (Current)

Architecture:

Characteristics:

Cloud-Hosted (Future)

Architecture:

Characteristics:

Managed Services (Future)

Architecture:

Characteristics:


Security Architecture

Authentication & Authorization

JWT Token Structure:

{
  "user_id": "uuid",
  "organization_id": "uuid",
  "role": "cashier|supervisor|owner",
  "exp": 1234567890
}

Token Types:

Password Security:

Data Security

Multi-Tenancy:

Data Encryption:

Security Best Practices


Offline Mode Architecture

Storage

IndexedDB Stores:

Sync Mechanism

sequenceDiagram
    participant Client
    participant ServiceWorker
    participant IndexedDB
    participant Backend
    
    Client->>IndexedDB: Save transaction (offline)
    Client->>ServiceWorker: Register background sync
    ServiceWorker->>Backend: POST /api/checkout (retry)
    Backend-->>ServiceWorker: Success
    ServiceWorker->>IndexedDB: Remove from pending

Sync Strategy:


Performance Considerations

Backend

Frontend

Database


Scalability

Current Limitations

Future Scalability


Note: Dokumentasi ini memberikan overview moderate detail. Untuk detail implementation yang lebih dalam, lihat source code (private repository).