Cash Managment Local System
POS & APIs

Problem & Solution
The Challenge: While cashless payments are growing in Thailand, cash transactions still represent 50% of payments outside Bangkok. Retail shops face critical challenges: manual cash management is time-consuming and error-prone, staff cash handling lacks proper tracking and accountability, fraud risks exist without real-time inventory validation, and unreliable internet connectivity in many areas disrupts operations. Traditional cloud-only systems fail when connectivity drops, leaving shops unable to process sales, refunds, or manage cash during outages. Additionally, integrating with specialized hardware like Glory Cash Infinity machines requires complex, low-level communication protocols that most POS systems cannot handle natively.
The Solution: I architected and built a local-first cash management system that operates completely offline while maintaining seamless synchronization with the cloud when connectivity is available. The system integrates directly with Glory Cash Infinity cash dispensers (CI10, CI10X, CI50, RK10) using TCP event-driven protocols, enabling shops to manage cash operations—sales, refunds, daily expense dispensing, and staff change tracking—without internet dependency. The platform validates cash inventory consistency between transactions to prevent fraud, provides REST APIs for easy POS integration, and automatically syncs all data with the Cweetlabs cloud platform. This hybrid architecture ensures zero operational downtime, reduces cash management time by 70%, and enables building automated kiosk solutions on top of the system, as demonstrated in the LPG Self-Ordering system.
Key Features & Business Impact
- Complete cash management for shop operations: sales, refunds, and shift closures with full transaction history
- Daily expense dispensing with configurable limits and approval workflows for shop owners
- Individual staff change tracking with detailed audit trails for accountability and reconciliation
- Seamless integration with Glory Cash Infinity machines (CI10, CI10X, CI50, RK10) via TCP event-driven communication
- REST API architecture enabling POS systems to integrate with minimal development effort and standardized endpoints
- Real-time fraud prevention through cash inventory validation that checks consistency between every transaction
- Automatic data synchronization with Cweetlabs cloud platform for centralized monitoring and reporting
- Extensible architecture that scales to custom frontend solutions, proven with LPG Self-Ordering kiosk system
Technical Deep Dive
System Architecture: Hybrid Cloud-Local Model
The system is built on a local-first paradigm, prioritizing offline operation while maintaining cloud synchronization capabilities. The core architecture uses TCP event-driven programming to communicate with Glory Cash Infinity machines, handling real-time events like cash dispense confirmations, error states, and machine status updates. The local system runs on .NET Core with a PostgreSQL database, ensuring all critical operations (sales, refunds, cash dispensing) function independently of internet connectivity. When connectivity is available, the system uses HTTP/HTTPS to synchronize transaction data with the cloud platform. The event-driven TCP layer processes machine events asynchronously, ensuring responsive UI updates and reliable hardware communication. This architecture eliminates single points of failure and enables shops to continue operations during network outages, with automatic conflict resolution when reconnecting to the cloud.
Authentication & Authorization (OAuth + RBAC)
Security is implemented through JWT (JSON Web Token) authentication between the local system and cloud platform. Each local system authenticates with the cloud using service credentials, receiving a JWT token that includes system identity, permissions, and expiration. The token is validated on every API request to ensure only authorized systems can sync data. For local operations, the system maintains its own user authentication for staff access control, with role-based permissions for different operations (e.g., cashier, manager, owner). JWT tokens are refreshed automatically before expiration, and the system handles token refresh failures gracefully by queuing operations until authentication is restored. This dual-layer authentication ensures both local security and secure cloud communication without exposing sensitive credentials.
Real-Time Data Pipeline & Consistency
The data synchronization pipeline is designed for reliability and efficiency. Local transactions are immediately written to the local PostgreSQL database with full ACID guarantees, ensuring no data loss even during system crashes. A background synchronization service monitors connectivity and batches transactions for efficient transmission to the cloud via REST APIs. The pipeline implements idempotency keys to prevent duplicate transactions during retries, handles network timeouts gracefully, and queues failed syncs for retry. When connectivity is restored, the system performs incremental synchronization, only transmitting changes since the last successful sync. The cloud platform validates incoming data, performs deduplication, and updates centralized dashboards in near real-time. This design ensures data consistency across all systems while minimizing bandwidth usage and handling edge cases like extended offline periods, network interruptions during sync, and concurrent modifications.
Database & Performance Optimization
The database schema is optimized for high-frequency transaction processing and analytical queries. Cash transactions are stored in a normalized schema with strategic indexes on (staff_id, created_at) for fast staff change tracking queries, (transaction_type, created_at) for filtering sales vs refunds, and (machine_id, status) for monitoring hardware integration status. To prevent fraud, the system maintains a cash_inventory table that tracks expected vs actual cash levels, with triggers that validate consistency on every transaction. Materialized views pre-compute daily summaries (total sales, refunds, expenses per staff) for fast reporting without impacting transaction performance. Connection pooling ensures the system can handle concurrent requests from multiple POS integrations and the web frontend without database connection exhaustion. Query optimization focuses on index usage, avoiding full table scans, and using EXPLAIN ANALYZE to identify and eliminate slow queries. The schema supports horizontal scaling and can be extended for multi-shop deployments with proper partitioning strategies.
Technology Stack
NextJS
Typescript
TailwindCSS
Dotnet Core
PostgreSQL
Drizzle ORM