Skip to content

azharf99/pos-api

Repository files navigation

Modern Point of Sales (POS) Backend API

A high-performance, robust, and secure Point of Sales (POS) backend API designed using Clean Architecture principles in Go. Featuring built-in cybersecurity configurations, Redis-based rate limiting, and an abstract payment gateway integration (supporting Midtrans, extensible to Xendit).

Features

  1. Transaction Processing: Automatic calculations of subtotals, taxes (GST/VAT), discount rates, and real-time inventory updates wrapped in transactional database scopes.
  2. Payment Handling: Modular payment gateway engine integrated with Midtrans (Snap/Core API) for credit/debit card, e-wallet, and cash payments.
  3. Inventory Management: Product catalog tracking, low-stock warnings, and barcode scanner lookup support.
  4. Customer Management: Tracks customer details, purchase histories, and a customer loyalty points system.
  5. Reporting and Analytics: Aggregate sales tracking, product performance analytics, and employee sales reports.
  6. Hardware Compatibility: Supports REST responses ideal for custom POS terminal integrations, barcode scanner keyboard inputs, and print-ready receipt formats.
  7. Production Security:
    • CORS Protection
    • Custom JWT Authentication (Session-based)
    • Redis-based Rate Limiter (IP/Token based)
    • CSRF Protection middleware

Architecture Diagram (Clean Architecture)

       +---------------------------------------------+
       |             HTTP Delivery Layer             |
       |  (Gin Handlers, CORS, JWT, Rate Limiter)     |
       +----------------------+----------------------+
                              |
                              v
       +---------------------------------------------+
       |               Usecase Layer                 |
       | (Transaction logic, Loyalty points engine)   |
       +----------------------+----------------------+
                              |
                              v
       +---------------------------------------------+
       |              Repository Layer               |
       |       (GORM Postgres, Redis Clients)        |
       +---------------------------------------------+

Technical Stack

  • Go (Golang): v1.20+
  • Database: PostgreSQL (GORM ORM)
  • Caching & Rate Limiting: Redis
  • Security & Middlewares: JWT (golang-jwt/jwt), CORS, CSRF, custom Redis limiter.

Setup Instructions

1. Prerequisites

  • Go 1.20+
  • PostgreSQL
  • Redis

2. Environment Variables Configuration

Create a .env file in the root directory:

PORT=8080
ENV=development

# Database Configuration
DB_HOST=gothub_db
DB_USER=pos_user
DB_PASSWORD=pos_password
DB_NAME=pos_db
DB_PORT=5432
DB_SSLMODE=disable

# Redis Configuration
REDIS_ADDR=redis:6379
REDIS_PASSWORD=
REDIS_DB=0

# Security Credentials
JWT_SECRET=super_secret_signing_key_change_me
CSRF_SECRET=csrf_salt_key_change_me_32_bytes_long

# Midtrans Credentials
MIDTRANS_SERVER_KEY=your_midtrans_server_key
MIDTRANS_CLIENT_KEY=your_midtrans_client_key
MIDTRANS_IS_PRODUCTION=false

3. Build & Run

# Get dependencies
go mod tidy

# Run application
go run cmd/server/main.go

About

A high-performance, robust, and secure Point of Sales (POS) backend API designed using Clean Architecture principles in Go. Featuring built-in cybersecurity configurations, Redis-based rate limiting, and an abstract payment gateway integration (supporting Midtrans, extensible to Xendit).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors