Overview arsitektur teknis Kasapro untuk developers dan power users.
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
1. Client Layer:
2. Nginx Reverse Proxy:
3. Frontend (Next.js):
4. Backend API (Go):
5. Data Layer:
Key Libraries:
github.com/gin-gonic/gin - HTTP frameworkgorm.io/gorm - ORMgolang.org/x/crypto - Password hashinggithub.com/golang-jwt/jwt/v5 - JWT authenticationKey Libraries:
next - React frameworkreact - UI librarytailwindcss - CSS framework@radix-ui/* - UI components@zxing/browser - Barcode scanningOrganizations:
- 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
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]
Semua tabel memiliki index pada:
organization_id (untuk multi-tenancy filtering)created_at (untuk sorting)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
Authentication:
POST /api/auth/login - Login dengan username + PINPOST /api/auth/refresh - Refresh access tokenProducts:
GET /api/products - List produk (search, pagination)POST /api/products - Create produkGET /api/products/:id - Get produk detailPUT /api/products/:id - Update produkDELETE /api/products/:id - Delete produkTransactions:
POST /api/checkout - Checkout transaksiGET /api/transactions - List transaksiGET /api/transactions/:id - Get transaksi detailInventory:
GET /api/inventory/adjustments - List adjustmentsPOST /api/inventory/adjustments - Create adjustmentReports:
GET /api/reports/dashboard - Dashboard dataGET /api/reports/sales - Sales reportsRequest:
Authorization: Bearer <token>Response:
{ "data": {...}, "message": "...", "error": "..." }Architecture:
Characteristics:
Architecture:
Characteristics:
Architecture:
Characteristics:
JWT Token Structure:
{
"user_id": "uuid",
"organization_id": "uuid",
"role": "cashier|supervisor|owner",
"exp": 1234567890
}
Token Types:
Password Security:
users.pin_hashMulti-Tenancy:
organization_idData Encryption:
IndexedDB Stores:
pending_transactions - Transaksi offline yang belum synccached_products - Product catalog untuk offline accesssync_metadata - Metadata sync statussequenceDiagram
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:
Note: Dokumentasi ini memberikan overview moderate detail. Untuk detail implementation yang lebih dalam, lihat source code (private repository).