How Samkarsa engineered an on-the-fly SQL AST compiler and mock infrastructure layer to achieve 100% application preservation, zero rewrite cost, and enterprise PostgreSQL reliability with continuous Google AI Studio evolution.
Temuya POS was rapidly prototyped and deployed via Mocha.app—an AI vibe-coding generator. Cashiers across retail stores relied on it daily for barcode scanning, receipt printing, inventory tracking, and shift balancing. But when Mocha.app announced platform shutdown and exported a raw code archive, the business discovered a catastrophic vendor lock-in reality:
The database calls were hardwired to Cloudflare's proprietary `env.DB.prepare().bind().run()` SQLite dialect, which does not run on standard database servers.
Product images and receipt files were stored on temporary Mocha R2 URLs slated for permanent deletion upon service shutdown.
Authentication was delegated to Mocha's closed user service with no access to password hashing algorithms or local credential stores.
Traditional software agencies quoted $15,000+ and 3–4 months to rewrite the system from scratch, demanding operational downtime and massive financial risk.
Instead of succumbing to the rewrite trap, Samkarsa's software architects engineered an infrastructure abstraction layer around the application. By leaving the original application code 100% untouched and virtualizing the underlying runtime, we brought the system to enterprise production in just 5 days.
“Don't touch the application code that the business already loves. Re-architect the world around it.”
How Samkarsa decoupled the application from proprietary Cloudflare bindings to a hardened Linux KVM VPS without rewriting code.
An in-process SQL dialect compiler in TypeScript that implements Cloudflare's exact D1Database and D1PreparedStatement interfaces on top of enterprise node-postgres (pg).
Cloudflare's proprietary R2 object storage was replaced with a zero-cost, hardened local disk wrapper.
Replaced Cloudflare's edge proxy with a self-hosted, cloud-native Traefik v3 reverse proxy on Hostinger KVM VPS.
The holy grail of AI vibe-coding: retaining rapid AI prototyping while securing rock-solid enterprise production stability.
Inspect the exact TypeScript AST SQL compiler and Docker orchestration used in production on Hostinger KVM VPS.
import { Pool, types } from 'pg';
// Parse PostgreSQL BIGINT (type ID 20) & NUMERIC (1700) directly to JS Number
types.setTypeParser(20, (val: string) => parseInt(val, 10));
types.setTypeParser(1700, (val: string) => parseFloat(val));
export class PostgresD1Wrapper {
private activePool: Pool;
constructor(connectionString: string) {
this.activePool = new Pool({ connectionString });
}
prepare(query: string) {
let pgQuery = query;
// 1. Rewrite SQLite PRAGMA table_info → PostgreSQL information_schema
const pragmaMatch = pgQuery.trim().match(/^PRAGMA\s+table_info\s*\(\s*['"]?([a-zA-Z0-9_]+)['"]?\s*\)/i);
if (pragmaMatch) {
const tableName = pragmaMatch[1].toLowerCase();
pgQuery = `SELECT column_name AS name FROM information_schema.columns WHERE table_name = '${tableName}'`;
return new PostgresD1Statement(this, pgQuery);
}
// 2. Map positional placeholders: '?' → '$1, $2, ...'
let paramCount = 1;
pgQuery = pgQuery.replace(/\?/g, () => `$${paramCount++}`);
// 3. Temporal functions: datetime('now', '+1 day') → CURRENT_TIMESTAMP + INTERVAL
pgQuery = pgQuery.replace(/datetime\('now',\s*'([^']+)'\)/gi, "CURRENT_TIMESTAMP + INTERVAL '$1'");
pgQuery = pgQuery.replace(/datetime\('now'\)/gi, 'CURRENT_TIMESTAMP');
// 4. Formatting: strftime('%Y-%m-%d', col) → TO_CHAR(col, 'YYYY-MM-DD')
pgQuery = pgQuery.replace(/strftime\(\s*'([^']+)'\s*,\s*([^)]+)\)/gi, (_m, fmt, col) => {
const pgFmt = fmt.replace(/%Y/g, 'YYYY').replace(/%m/g, 'MM').replace(/%d/g, 'DD');
return `TO_CHAR(${col.trim()}, '${pgFmt}')`;
});
// 5. Case-insensitive LIKE → ILIKE
pgQuery = pgQuery.replace(/\bLIKE\b(?=\s+['%])/gi, 'ILIKE');
return new PostgresD1Statement(this, pgQuery);
}
}
services:
temuya-service:
container_name: temuya-service-mutiara
image: node:22-alpine
restart: unless-stopped
working_dir: /app
volumes:
- ./dist:/app/dist:ro
- ./uploads:/app/uploads
env_file:
- .env
command: ["node", "/app/dist/server.cjs"]
ports:
- "127.0.0.1:3000:3000"
networks:
- temuya_api_net
- prod_infra_net
labels:
- "traefik.enable=true"
- "traefik.docker.network=temuya_api_net"
- "traefik.http.routers.temuya.rule=Host(`temuyapos.id`) || Host(`app.temuyapos.id`)"
- "traefik.http.routers.temuya.entrypoints=websecure"
- "traefik.http.routers.temuya.tls=true"
- "traefik.http.services.temuya.loadbalancer.server.port=3000"
networks:
temuya_api_net:
external: true
prod_infra_net:
external: true
Objective trade-off matrix comparing the original locked-in platform, a standard software agency rewrite, and Samkarsa's infrastructure virtualization model.
| Engineering Dimension | Original Mocha / Cloudflare | Traditional Agency Rewrite | Samkarsa Infra Virtualization |
|---|---|---|---|
| Delivery Timeline | Instant (Sandbox only) | 3–4 Months |
5 Business Days
|
| Capital Expenditure | Low initial, high lock-in | $15,000 – $25,000 |
Fractional (< 20%)
|
| Application Logic Preserved | 100% (Locked in) | 0% (Complete rewrite) |
100% (Zero rewrite)
|
| Data Sovereignty | 0% (Vendor cloud lock-in) | 100% On-Premise |
100% Sovereign on Hostinger VPS
|
| Database Engine | SQLite Cloudflare D1 | PostgreSQL / MySQL |
Enterprise PostgreSQL (ACID)
|
| Continuous AI Evolution | Platform dependent | Lost (Hard-coded) |
Active (Google AI Studio + CI/CD)
|
| Commercial SLA | None (Best effort) | Standard warranty |
99.9% Legal Commercial SLA
|
“When Mocha announced shutdown, we thought our entire POS investment was gone. Samkarsa didn't just save our business in under a week—they made the app faster, 100% self-hosted on our own Hostinger VPS, and our cashiers experienced zero workflow disruption.”
Samkarsa deploys enterprise vibe-coding migrations on dedicated Hostinger KVM VPS instances. Experience dedicated vCPU power, NVMe storage performance, automated snapshots, and predictable monthly infrastructure costs.
Deploy your sovereign VPS instance with verified zero-trust networking.
Explore Hostinger KVM VPSDon't spend months rewriting working software. Partner with Samkarsa to virtualize your infrastructure, deploy to dedicated Hostinger KVM VPS, and secure enterprise commercial SLAs.