Regulatory-Compliant Weighing System

Industrial IoT & Compliance

Regulatory-Compliant Weighing System cover image

Problem & Solution

The Challenge:

Legacy weighing systems in agricultural procurement are highly vulnerable to internal fraud. Employees can easily tamper with local databases (like Microsoft Access) to manually adjust weights before records are finalized. This lack of data integrity not only leads to significant financial losses but also fails to meet the strict legal standards required by the Department of Internal Trade of Thailand. Furthermore, manual data entry between isolated systems creates massive operational lag and human error.

The Solution:

I architected a dual-module microservices system that establishes a 'Chain of Trust' from the physical scale to the cloud. By isolating hardware communication into a dedicated .NET Core service, I ensured that weight data can only originate from the scale device itself—completely removing the ability for manual human overrides. Every record is protected by MD5 cryptographic validation, making any attempt at tampering immediately detectable. This solution transforms a high-risk manual process into a legally defensible, automated workflow that integrates directly with the FPN-OS System.

Key Features & Business Impact

  • Zero-Manual-Entry Workflow: Direct hardware-to-cloud data streaming to eliminate human tampering.
  • Cryptographic Tamper Detection: MD5 hashing on every record to ensure legal data integrity.
  • Automated Ticket Integration: Real-time queue ticket scanning to automatically link weights with operational data.
  • Department of Internal Trade Compliance: Engineered specifically to meet Thailand's legal standards for weighing records.
  • Resilient Microservices Design: Dedicated .NET service for RS232 stability and high-availability Next.js UI.
  • Comprehensive Audit Trail: Full-history reporting with secure CSV export capabilities for government inspections.

Technical Deep Dive

Microservices: Secure Hardware Abstraction

The system utilizes a specialized Microservices Architecture to decouple low-level serial communication from high-level business logic. Module 1 (Device Service) is a .NET Core application that maintains a persistent listener on the RS232 serial port, parsing raw data streams directly from the scale hardware. This 'Edge' module communicates exclusively with Module 2 (Business Logic) via secure internal APIs. This separation ensures that even during UI updates or server restarts, the hardware connection remains stable and the data source remains immutable.

Security: JWT & Multi-Module Authentication

To ensure the system cannot be bypassed, I implemented a Dual-Layer Authentication strategy. Module 1 utilizes service-level JWT tokens to sign data packets before they are transmitted to the business logic layer. On the human-facing side, the Next.js application utilizes NextAuth.js with secure HTTP-only cookies to manage administrative sessions. This ensures that only authorized devices can send data, and only authorized supervisors can generate reports, creating a closed-loop secure environment.

Integrity: Cryptographic MD5 Validation

The core of the system's fraud prevention is the Tamper-Evident Data Pipeline. As weight data is captured from the RS232 port, the system instantly generates an MD5 cryptographic hash combined with a unique transaction salt. This hash acts as a 'Digital Seal.' Before any record is written to PostgreSQL or synced to the operational cloud, the system re-calculates the hash; if a single bit of data has been modified manually in the database, the validation fails, the transaction is locked, and a security alert is triggered.

Reporting: PostgreSQL & Audit-Ready Analytics

The database is engineered for Regulatory Compliance and High-Speed Retrieval. I utilized PostgreSQL with optimized indexing to handle rapid throughput during peak harvest seasons. To meet government audit requirements, I implemented Incremental Materialized Views that pre-calculate daily tonnage and transaction counts. This allows for instantaneous generation of CSV audit logs and legal reports without impacting the real-time weighing operations.

Technology Stack

NextJSNextJS
TypescriptTypescript
TailwindCSSTailwindCSS
Dotnet CoreDotnet Core
PostgreSQLPostgreSQL
Drizzle ORMDrizzle ORM