ARCHITECTURE RETROSPECTIVE · MONOLITH TO DISTRIBUTED MICROSERVICES

Mutiara PAUD: Refactoring a 207,000-Line AI Monolith into 7 Production-Ready Microservices

From a rapid AI vibe-coded Cloudflare prototype to a sovereign multi-tenant school SaaS on private VPS. A factual engineering account of decoupling architecture, bridging AI Studio dev mocks with relational databases, patching critical security flaws, and automating CI/CD with daily WhatsApp backups.

Domain School ERP, QR Biometrics, Tuition Billing, Academic Grading & E-Office
Origin Stack Cloudflare Monolith (D1 SQLite, R2 Storage, In-Memory Dev Mocks)
Target VPS Hostinger KVM VPS
Database PostgreSQL 16 (pgvector)
Timeline 4 Weeks Architecture Refactor & Security Hardening
Architecture 7 Microservices (Node 24)
207,937 LOC
Clean Codebase Asset 170,339 logic LOC across 498 monorepo files
7 Services
Autonomous Microservices Auth, Academic, Attendance, Finance, Document, Portal, SaaS
104 Screens
Full React SPA Frontend Comprehensive dashboards and operational modules
CVSS 9.8
Critical Security Patched 100% remediation of mock auth bypass and zero-auth routes
0 MB Residual
Zero-Disk VPS Cloud Backup Automated Google Drive GFS sync with WhatsApp alerts
ENGINEERING RETROSPECTIVE · FACTUAL PRODUCTION DOSSIER

Behind the Architecture: Engineering a Resilient, Production-Ready Platform

Prototyping with AI accelerates early development, but running in production demands architectural rigor. Here is a factual engineering account of decoupling, runtime alignment, security hardening, and deployment automation across 207,000+ lines of code.

Chapter 01 · Decoupling Architecture

Escaping Vendor Lock-in: Why a Sprawling Monolith Needed Architectural Decoupling

Mutiara was originally prototyped through rapid AI vibe-coding on Cloudflare Workers. As the system expanded to 104 views and 71 API endpoints, the business encountered strict infrastructural limits.

The original backend was tightly coupled to Cloudflare D1 (SQLite) and proprietary R2 object storage. School clients required full data sovereignty on private server infrastructure (PostgreSQL 16) without third-party vendor lock-in. Furthermore, running disparate school functions—from daily student attendance to academic assessments, tuition billing, and digital correspondence—in a single monorepo backend made independent team iterations risky. Decoupling into 7 autonomous Hono microservices allowed Mutiara's developers to continue prompt-driven feature iteration in Google AI Studio while Samkarsa hardened backend stability and production deployments.

Data Sovereignty & Zero Vendor Lock-in: Migrated from proprietary Cloudflare D1/R2 to open-standard PostgreSQL 16 and host-secured volume storage.

Autonomous Service Boundaries: Grouped 71 endpoints into 7 single-responsibility services (Auth Core, Academic, Attendance, Finance, Document, Portal, SaaS).

Parallel Development Model: Front-line developers iterate features in AI Studio while backend microservices remain safely isolated behind container perimeters.

Before · Vendor Locked Cloudflare Workers

Initial Cloudflare Monolith

Tied to Cloudflare D1 SQLite & R2 APIs. Single process failure risks all school features simultaneously.

D1 SQLite R2 Storage API Single Failure Risk
Decoupled by Samkarsa ↓
After · Sovereign Microservices Hostinger VPS

Decoupled Hono Microservices

7 isolated containers on private VPS. 100% PostgreSQL data sovereignty with independent release lifecycles.

PostgreSQL 16 (pgvector) Node.js 24 + Hono Isolated Containers
Chapter 02 · Dev Mock Illusions vs Production Reality

The 5,600-Line Mock Illusion in AI Studio and Eliminating 'Debugging in Production'

When building applications with AI assistance, features that appear to function flawlessly in dev previews often conceal major architectural gaps once deployed to production.

In Google AI Studio, the frontend was tested against Vite middleware backed by 5,600+ lines of mock handlers and in-memory JSON (storage_db.json). Deleting a parent user executed a simple array slice (.splice()), immediately displaying clean UI state. However, in production VPS, the backend auth-core-service only deleted the users record—leaving relational records in parent_students and parent fields in students completely untouched. Crucially, the frontend button called an unlinked endpoint (/unlink-parent) that had never even been implemented in portal-service. Lacking a local PostgreSQL instance, developers resorted to using production Git Tags (./release.sh) as a trial-and-error debugging tool, triggering repetitive 3–8 minute Docker builds. Samkarsa resolved this by implementing the missing portal routes, fixing cascading relational cleanup in PostgreSQL, and establishing clean release boundaries.

Google AI Studio Preview (5,600+ Mock Lines in vite.config.ts) Mock Memory
Vite Dev Middleware · In-Memory Arrays (storage_db.json)
// apps/admin-frontend/vite.config.ts (Simulasi In-Memory)
const idx = mockUsers.findIndex(u => u.id === req.id);
mockUsers.splice(idx, 1); // Terpotong instan di RAM
⚠️ Antarmuka tampak beres seketika, namun tombol memanggil rute /unlink-parent yang ternyata BELUM DIBUAT sama sekali di backend portal-service.
Karakteristik: Array splice creates an instant UI illusion, but calls an unlinked endpoint (/unlink-parent) that did not exist in backend.
Hostinger Production Server (Hono & PostgreSQL 16) Relational Sync
Multi-Service Container Mesh · PostgreSQL Relational Cleanup
// 1. Implementasi endpoint /unlink-parent di portal-service
// 2. Pembersihan relasi eksplisit di PostgreSQL (auth-core-service)
await db.execute(sql`
DELETE FROM parent_students WHERE parent_user_id = ${pgUser.id}
`);
✅ Seluruh rute backend dilengkapi dan relasi siswa dibersihkan tuntas di database. Kebiasaan debugging via Git Tag produksi resmi dihentikan total.
Karakteristik: Backend routes fully implemented, multi-table records cleaned explicitly, and trial-and-error release cycles eliminated.

Implemented Missing Endpoints: Built out missing portal-service routes (/unlink-parent) that previously only existed in local Vite mocks.

Complete Relational Cleanup: Ensured account deletions in auth-core-service explicitly clean up parent_students relationships in PostgreSQL.

Eliminated Anti-Pattern: Stopped the bad habit of using production Git Tags as a debugging tool, keeping release history pristine.

Chapter 03 · Security Hardening 🛡️ ZERO-TRUST HARDENED

Patching CVSS 9.8 Vulnerabilities: Eradicating Development Mock Backdoors

A comprehensive defensive security audit conducted on October 15, 2026 discovered that rapid AI code generation had left critical development bypasses active in production code.

During early prototyping, AI models introduced convenience branches in authentication middleware. If an incoming HTTP request contained insecure mock authorization headers, the middleware automatically synthesized a super_admin session, granting unauthenticated callers full access to school records. In finance-service, billing routes permitted execution when authorization tokens were omitted entirely. Samkarsa remediated these critical vulnerabilities by enforcing cryptographic JWT HS256 signatures, binding internal databases exclusively to 127.0.0.1, and hardening Docker socket access.

SEC-01 CVSS 9.8 CRITICAL

Universal Auth Bypass (mock token backdoor)

Status Audit: VERIFIED PATCHED
SEC-02 CVSS 9.8 CRITICAL

Zero-Authentication on finance-service

Status Audit: VERIFIED PATCHED
SEC-03 CVSS 8.8 HIGH

Unauthenticated Traefik API & Docker Socket R/W

Status Audit: CLOSED & HARDENED
SEC-04 CVSS 6.5 MEDIUM

PostgreSQL & Redis bound to 0.0.0.0

Status Audit: REBOUND 127.0.0.1

Universal Auth Bypass Neutralized (CVSS 9.8): Purged mock tokens across all services and enforced strict JWT token verification.

Zero-Auth Finance Route Patched (CVSS 9.8): Replaced unprotected fallbacks with mandatory role-based access checks on school ledgers.

Network & Container Defense: Rebound PostgreSQL and Redis services away from public interfaces (0.0.0.0) strictly to localhost, and removed read-write mounting of /var/run/docker.sock to prevent container escape.

Chapter 04 · Sovereign Mail Infrastructure

Self-Hosted Enterprise Mailserver: Bypassing ISP Port Blocks via HTTPS Relays

Delivering one-time password (OTP) verification emails is essential for school onboarding. However, standard SMTP ports (25 and 587) are routinely blocked by internet service provider (ISP) firewalls.

To eliminate dependency on expensive third-party email APIs, Samkarsa deployed a self-hosted Docker Mailserver (Postfix + Dovecot) configured with complete domain reputation records: SPF, DKIM (mail._domainkey), and DMARC for @mutiarapaud.id. For container-to-container communication, auth-core-service transmits email payloads over an internal HTTPS endpoint (Port 443) behind Traefik SSL, completely bypassing ISP SMTP port blocks.

End-to-End OTP Delivery Pipeline (HTTPS Port 443 Relay)
Webmail Portal (Encrypted TLS)
1

User Request

Teacher / Parent enters email on web login

2

Auth Core Service

Generates secure OTP & calls internal relay

3 Kebal Blokir

HTTPS Relay (Port 443)

Internal encrypted call immune to SMTP port blocks

Bypass Port 25/587 via TLS
4

Docker Mailserver

Postfix + Dovecot signs SPF, DKIM & DMARC

5

Primary Inbox Delivery

Arrives in Gmail / Yahoo inbox within seconds

Internal HTTPS Mail Relay (Port 443): Dispatches OTP emails through encrypted HTTPS requests, immune to outward SMTP port filtering.

Primary Inbox Deliverability: Full SPF, DKIM, and DMARC compliance ensures verification codes land reliably in parent and teacher inboxes.

Integrated Roundcube Webmail: Configured a secure webmail client with end-to-end TLS encryption for direct administrative correspondence.

Chapter 05 · Intelligent CI/CD Automation

Selective Matrix Build: Slashing Release Cycles by 50% with Telegram Telemetry

In a 7-service monorepo, recompiling all containers for a small fix wastes CPU cycles and risks Out-Of-Memory (OOM) crashes on the production server.

Samkarsa structured GitHub Actions workflows to parse monorepo git diffs. When a release tag is pushed, the pipeline detects exactly which microservice directories experienced code changes. If only academic-service was updated, only that container is compiled and deployed. This optimization reduced release times from ~15 minutes down to ~7 minutes, accompanied by instant deployment status notifications delivered directly to the developer's Telegram account.

Git Diff Change Detection: Compiles only the specific Docker containers that changed, avoiding unnecessary full-stack rebuilds.

Zero-Downtime Rolling Deployment: Swaps production containers sequentially behind Traefik reverse proxy without dropping active sessions.

Instant Telegram Telemetry: Notifies developers immediately with commit hash, author, tag, build duration, and failure traces.

🤖
Samkarsa CI/CD Telemetry Bot BOT
GitHub Actions CI/CD Webhook
✅ DEPLOYMENT SUCCEEDED: academic-service
🏷️ Release: v1.0.285
👤 Commit Author: dev-mutiara
⏱️ Build Duration: 6m 42s (Selective Matrix)
ℹ️ Rolling update applied behind Traefik without downtime.
14:32 WIB · Delivered ✓✓
Chapter 06 · Zero-Disk Cloud Data Protection

Zero-Disk GFS Backup Strategy: Multi-Tier Cloud Archiving with Automated WhatsApp Reports

Multi-tenant school data requires reliable historical backups without consuming limited NVMe disk space on the production server.

Samkarsa engineered a Zero-Disk VPS Backup Strategy. Database dumps stream directly to ephemeral /tmp memory, upload to encrypted Google Drive storage via rclone, and are immediately purged from host disk upon completion (0 MB residual storage on VPS). The system follows the Grandfather-Father-Son (GFS) retention model: daily snapshots (Son) are kept for 14 days, weekly snapshots (Father) for 8 weeks, and monthly archives (Grandfather) for 1 year with auto-pruning. Every morning at 02:00 WIB, the BiZETO engine sends an automated confirmation message directly to the system owner's WhatsApp number.

Son Tier (Daily)

Retained for 14 Days

Short-term recovery snapshots with automated cleanup.

Jadwal: Every Day at 02:00 WIB

Father Tier (Weekly)

Retained for 8 Weeks (56 Days)

Medium-term checkpoints for weekly rollback safety.

Jadwal: Every Sunday

Grandfather Tier (Monthly)

Retained for 1 Year (365 Days)

Long-term historical compliance and regulatory archive.

Jadwal: 1st of Each Month
💬
BiZETO System Telemetry Notifikasi Otomatis Subuh
✅ DATABASE BACKUP VERIFIED
Cycle: GFS (Daily Son + Weekly Father)
Snapshot Size: mutiara_db (640 KB) + temuya_db (1.6 MB)
✨ VPS Residual Footprint: 0 MB (Zero-Disk Clean)
02:01 WIB ✓✓

Zero-Disk VPS Footprint: Database dumps are wiped from the host immediately after upload, leaving 0 MB of residual backup files on the server.

Grandfather-Father-Son (GFS) Retention: Combines 14 daily, 8 weekly, and 12 monthly snapshots, using under 80 MB of Google Drive storage.

Automated WhatsApp Notifications: Every morning, an automated BiZETO alert reports file sizes, backup duration, and disk cleanliness directly to WhatsApp.

DISTRIBUTED SERVICES TOPOLOGY

7 Autonomous Hono Microservices in Production

Each service runs in its own isolated Docker container on Node.js 24 with dedicated network boundaries, Redis queues, and JWT authorization.

Zero-Trust Container Security Principle: All internal container ports are strictly locked inside the private Docker bridge network and never exposed to the public Internet. Traefik reverse proxy on Port 443 (HTTPS) is the only external gateway, performing zero-trust routing to internal services.
auth-core-service /api/v1/auth/*

JWT HS256 Identity, Session Management, RBAC & Multi-Tenant Context

Internal Mesh Traefik SSL 443
academic-service /api/v1/academic/*

Curriculum KOSP, Student Development, Classes & Digital Report Cards

Internal Mesh Traefik SSL 443
attendance-service /api/v1/attendance/*

Biometric QR Scanner, Geofencing GPS Verification & Daily Attendance

Internal Mesh Traefik SSL 443
finance-service /api/v1/finance/*

Tuition Invoicing, Cashflow Ledgers, Expense Tracking & Payment Cards

Internal Mesh Traefik SSL 443
document-service /api/v1/documents/*

Official School Letters, Digital Signatures, Dispositions & Archiving

Internal Mesh Traefik SSL 443
portal-service /api/v1/portal/*

Parent-Teacher Communication, Knowledge Base & Activity Feed

Internal Mesh Traefik SSL 443
saas-service /api/v1/saas/*

School Tenant Provisioning, Resource Quotas & Membership Tiers

Internal Mesh Traefik SSL 443
“Refactoring our monolithic prototype into microservices on a sovereign VPS gave us the stability our schools needed. We can continue innovating rapidly in Google AI Studio while our production infrastructure runs reliably on PostgreSQL, backed by automated GitHub deployments and daily WhatsApp backup confirmations.”
DI
Director of Technology & Operations Mutiara PAUD Integrated Educational Network
PRODUCTION CLOUD ARCHITECTURE

Enterprise Microservices Deployed on Hostinger KVM VPS

Samkarsa deploys resilient multi-container distributed architectures on dedicated Hostinger KVM VPS instances. Benefit from AMD EPYC high-frequency computing, enterprise NVMe storage, and automated GitHub CI/CD delivery with zero vendor lock-in.

AMD EPYC Compute Cores for Asymmetric Concurrency
Hardened Traefik v3 Zero-Trust Edge Gateway
Automated WAL Streaming & Ephemeral GFS Cloud Sync
100% Data Sovereignty with Predictable Flat Monthly Costs
Special Partner Route Hostinger KVM

Deploy your sovereign VPS instance with verified zero-trust networking.

Explore Hostinger KVM VPS
Enterprise Partnership

Have an AI Monolith Hitting Architectural & Security Limits?

Don't gamble operational continuity on fragile monolithic code. Partner with Samkarsa to deconstruct your application into resilient microservices, harden your network perimeter, and automate continuous delivery.