Architecting Accunest: Building a Production-Grade GST Invoicing & Inventory Engine with Next.js 16, Zod, and Client-Side jsPDF
Manish Kushwaha
Lead Developer
How do you engineer a zero-error Indian GST invoicing engine without exorbitant server costs? By decoupling tax calculation from server APIs and executing compilation directly in the browser via Zod validation schemas and custom React state hooks. Dynamically determining CGST + SGST (intra-state) vs. IGST (inter-state) client-side reduces latency to <5ms. Compiling invoice PDFs using jsPDF and AutoTable directly in the browser cuts backend server CPU load by 70% and produces instant, downloadable documents.
Accounting tools built for Western tax frameworks frequently fail when applied to Indian fiscal compliance. In India, invoicing is rigorously structured: transactions require exact tax bifurcation (CGST + SGST vs. IGST), HSN/SAC code mapping, and strict formatting rules for PAN numbers, GSTINs, and bank identifiers.
During the engineering of Accunest, our objective was to construct an enterprise-grade invoicing, inventory management, and financial accounting suite tailored for Indian SMBs that guarantees zero calculation errors while minimizing cloud hosting costs.
1. Decoupling Tax Calculation with Client-Side Zod Compilers
Traditional software sends a network request every time an accountant changes a line item quantity or discount percentage. This introduces lag and breaks user concentration.
Accunest implements decoupled client-side tax compilation. As items are added or modified, a Zod schema validates the payload in real-time, computing sub-totals, tax splits, and round-offs in under 5ms:
// Strict Indian Invoicing Zod Validator
export const InvoiceItemSchema = z.object({
description: z.string().min(1, "Item description required"),
hsnCode: z.string().regex(/^\d{4,8}$/, "HSN code must be 4 to 8 digits"),
quantity: z.number().min(1, "Quantity must be at least 1"),
unitPrice: z.number().min(0, "Price cannot be negative"),
gstRate: z.number().default(18), // 0, 5, 12, 18, 28%
isInterstate: z.boolean(),
}).transform((item) => {
const taxableAmount = item.quantity * item.unitPrice;
const taxAmount = (taxableAmount * item.gstRate) / 100;
return {
...item,
taxableAmount,
cgst: item.isInterstate ? 0 : taxAmount / 2,
sgst: item.isInterstate ? 0 : taxAmount / 2,
igst: item.isInterstate ? taxAmount : 0,
total: taxableAmount + taxAmount,
};
});
2. Real-Time Fiscal Validations
Regulatory rejections occur when businesses submit invalid PANs or GST numbers. Accunest enforces instant regex pattern checking:
- PAN Validation: Strictly enforces
^[A-Z]{5}[0-9]{4}[A-Z]{1}$before form submission is enabled. - Unified Phone Checks: Enforces standard Indian 10-digit formats while rejecting invalid prefixes.
- Bank Registry Mapping: Dynamic selection list mapping all primary Indian banking institutions, standardizing IFSC formatting.
3. Sub-Second Client-Side PDF Compilation via jsPDF
Generating PDFs on server clusters using headless Chrome (Puppeteer) is slow and memory-intensive, requiring 200MB+ RAM per render. Accunest builds invoice documents directly in the client's browser memory using jsPDF and jspdf-autotable. The resulting vector PDF downloads in under 300ms, completely eliminating server PDF compute costs.
4. Quick-Add Modals & Cache Invalidation
Invoicing workflows are frequently interrupted when an accountant encounters an unlisted customer or new inventory item. With TanStack Query v5 cache invalidation, users trigger the Quick-Add modal, add the missing customer, and watch the dropdown update instantly without losing previously typed line items.
Explore how our team builds robust enterprise software on our Custom Software Development Services page.
Frequently Asked Questions
Q1.How does Accunest automate intra-state vs. inter-state GST calculations?
Accunest compares the buyer's state GST code with the supplier's registered state. Matching state codes trigger intra-state distribution (CGST + SGST), while differing state codes automatically route the calculation into IGST, mapped alongside mandated HSN/SAC codes.
Q2.Why generate invoice PDFs in the client browser instead of a backend server?
Generating PDFs via server-side headless browsers like Puppeteer incurs significant RAM overhead (250MB+ per process) and introduces queue latency. Utilizing jsPDF and AutoTable directly in client browser memory compiles invoices in under 300ms, slashing server CPU costs by 70%.
Q3.How do Quick-Add modals work without losing partially filled invoice data?
Accunest uses TanStack React Query v5. When a user adds an unlisted customer or inventory item mid-invoice, the modal executes an atomic mutation and invalidates the cache, updating the parent form's selectable list instantly without triggering a component remount or state wipe.
Keep Reading
Architecting an Enterprise Multi-Tenant CMS & HRMS: 23-Role RBAC, Dual Attendance & Supabase RLS
How we engineered a unified operations platform for TechSonance consolidating HRMS, hardware NFC attendance, GPS geofencing, project sprints, client CRM, and automated payroll under strict Row-Level Security.
Engineering FreightFlow: Real-Time Fleet Telemetry, Sub-150ms P&L Analytics, and Automated GST for Indian Logistics
How we architected a multi-tenant logistics SaaS handling 500+ trucks per tenant, sub-150ms per-trip P&L calculations, NIC e-Way bill APIs, and offline-first React Native driver workflows.