Pragmatic Systems & AI Performance

Building fast, zero-bloat systems with real numbers.

Engineering stories straight from production repositories: how we cut LLM token burn by 80–90% with zero-dependency AST search, tuned generative GPU cost down to ~$0.02 / image via 45-second cold-scaling, and modernized legacy Firebird 2.5 databases into sub-1.5s Cloudflare Edge APIs.

Case Study #1 • Agent Architecture & Retrieval

Code Memory Skill: Cutting AI Token Spend by 90% Without ChromaDB or PyTorch

MIT License Python 3.7+ Zero External Dependencies
babych/code-memory-skill

The Bottleneck: Monolithic Files Burning AI Quotas

When AI coding assistants (Antigravity, Cursor, Claude Code, Windsurf, Aider) refactor code, their default behavior is reading entire files into context. In projects with 3,000–4,000 line components or giant controllers:

  • Reading a single file costs 15,000 to 35,000 tokens per prompt.
  • Developer AI quotas burn out within minutes of active session work.
  • Long contexts degrade reasoning quality due to the Lost-in-the-Middle phenomenon.

The Solution: Pure Standard-Library BM25 Sparse Search

Instead of dragging in heavy 2GB external dependency chains (PyTorch, sentence-transformers, ChromaDB, Hugging Face, or paying for OpenAI embedding API calls), I implemented a zero-dependency search engine using only Python's standard library (re, math, json, pathlib).

It tokenizes camelCase, snake_case, and punctuation, indexing files into overlapping syntactic chunks with an offline BM25/TF-IDF sparse-vector algorithm. The AI queries the index and retrieves only the exact 20–30 lines it needs, dropping token consumption to ~500–1,500 tokens.

// Sample Agent Query Output: python scripts/code_memory.py search "jwt refresh token expiry middleware"
🔍 Top relevant code locations for: 'jwt refresh token expiry middleware'
============================================================
📍 src/middleware/auth.js (Lines 42 - 78) [Score: 0.315]
| export async function verifyRefreshToken(token) {
|   const decoded = await jwt.verify(token, SECRET);
|   if (Date.now() >= decoded.exp * 1000) throw new Error("Expired");
📍 src/controllers/authController.js (Lines 112 - 145) [Score: 0.284]

Verified Benchmarks from README

Indexing 10k LoC
< 0.20s
Query Latency
< 0.02s
Context Drop
80–90%
500–1,500 vs 35k
Architecture & Execution Flow Local Runtime • Zero Cloud Egress
1. AI Coding Agent
Antigravity / Cursor / Claude
▼
2. CLI Stdio Hook
scripts/code_memory.py
▼
3. Local Sparse Index
.code_index.json (Disk Cache)
▼
4. Surgical Range
Exact 20–30 lines to LLM
Language: Python 3.7+ (stdlib)
Hosting/Env: Local (Win / Linux / Mac)
Encodings: UTF-8, cp1251, cp1252
Agent Standards: SKILL.md / AGENTIC.md

Skill Specifications

  • Zero External Dependencies
  • Multilingual & camelCase Parser
  • Cross-Platform Console Encodings
  • Drop-in single file integration
Resume Takeaway

"Built an autonomous local code retrieval skill utilizing BM25 sparse vectoring in Python stdlib, cutting agent token consumption by 80–90% across 10,000+ line codebases."

Case Study #2 • Serverless Generative AI Platform

AuraStudio: Qwen 2.5 DiT Inpainting with ~$0.02 GPU Cost & Zero-Downtime Failover

Qwen 2.5 DiT 20B (FP8) Cloudflare Workers + D1 + R2 Telegram Stars Monetization

The Pitfall: 2D Cutouts, Plastic Skin, & Expensive Idle GPUs

Standard AI clothing transformation apps either produce visible edge seams and lighting mismatches by pasting 2D face cutouts on top of generated bodies, or inflate CFG values resulting in waxy, plastic skin textures.

On the infrastructure side, keeping dedicated Nvidia L40S/A10G GPU instances running 24/7 drains hundreds of dollars per month even when completely idle.

The Solution: DiT Latent Anchoring + Dual-Pool Modal Failover

We established an architectural standard: Pure Generative Synthesis with Transformer Latent Anchoring at strict CFG 1.8–2.1 (22 steps on L40S), preserving 100% original facial identity, micro-pores, and sub-surface scattering without pasting tricks.

On the compute layer, we orchestrated a serverless dual-pool GPU pipeline on Modal Cloud with automatic failover (callModalWithFallback) between primary (dmytrobbch) and secondary (memory1024) workspaces upon error or quota exhaustion. GPU containers scale down to zero after 45 seconds of inactivity, driving costs down to ~$0.02 (~80 kopiykas) per generation.

Platform Capabilities from README

⭐️ Telegram Stars Engine
Frictionless 1-click checkout (10 Stars photo, 40 Stars video). Automatic identity merge linking Google Web sessions with Telegram Stars payments.
📊 Telemetry Dashboard
Live business analytics (/dashboard) tracking active users, generation volumes, and capturing silent D1 error logs.

Operational Economics & Reliability

Cost / Generation
~$0.02
~80 kopiykas on L40S
GPU Scaledown
45 sec
Aggressive cold-sleep
Failover Latency
0 ms downtime
Auto dual-workspace pool
Distributed Inpainting Data Flow Edge Gateway + Serverless GPU
1. Clients
Telegram Bot / TMA / Web
▼
2. CF Worker API
D1 Auth + Stars + R2 Photo
▼
3. Modal Failover Pool
Primary ($30) ⇄ Backup ($11)
▼
4. Qwen DiT GPU
L40S / A10G (45s sleep)
Languages: JavaScript (V8), Python 3.11
Hosting/Cloud: Cloudflare Workers + Modal
Edge Storage: Cloudflare D1 (SQLite) + R2
Billing & Auth: Telegram Stars + Google OAuth

Full-Stack Tech Stack

  • Qwen 2.5 DiT 20B (FP8 / CUDA)
  • Cloudflare Workers Edge Gateway
  • Cloudflare D1 (Edge SQLite) & R2
  • Telegram Stars Payment Engine
  • Automated GitHub Actions CI/CD
Resume Takeaway

"Architected a serverless generative AI platform with Qwen 2.5 DiT, driving per-generation GPU costs to ~$0.02 via 45-second cold-scaling and implementing zero-downtime multi-pool failover on Cloudflare Workers."

Case Study #3 • Legacy Modernization & High-Throughput Edge

DairyERP: Modernizing 20-Year-Old Firebird 2.5 DBs into a Sub-1.5s Edge Platform

Google Cloud Run (Frankfurt) Cloudflare Pages + D1 Edge SQLite Firebird 2.5 Converter
dairy-farm-portal.pages.dev

The Challenge: 20-Year-Old Desktop Databases & Slow Rural Internet

In industrial dairy operations, farms rely on desktop legacy software (Uniform-Agri) running on archaic Firebird 2.5 databases. Farm specialists had no mobile access in the barns, and veterinary antibiotic withholdings (каренція) were tracked manually on whiteboards.

The Solution: Stateless Cloud Run Microservice + Cloudflare D1 Edge PWA

We engineered a stateless Parser-as-a-Service on Google Cloud Run (POST /api/convert/uniform in europe-west3, Frankfurt) that unpacks compressed `.fdb` archives in-memory and extracts full reproductive, lactation, and livestock history in ~1.5 seconds.

The front facing system is an offline-capable PWA deployed on Cloudflare Pages + D1, providing real-time Calving Interval trends, ECI conception curves, Days in Milk (DIM), and automated biological countdown timers for antibiotic quarantine.

Technical Deep-Dive: Architecture & Mathematical Engines

Pure Math Engine (zootech.js)

Hermetic biological calculation engine isolated from database layers. Computes Days in Milk (DIM), expected calving (Date.UTC + 280d), dry-off dates, and physiological state transitions (Inseminated ➔ Pregnant ➔ Dry ➔ Fresh).

100% unit-tested via Node test runner in <15ms.
Google Cloud Run Serverless (europe-west3)

Stateless extraction container built via Google Cloud Build with layered base caching (Dockerfile.base + Artifact Registry). Packages Firebird 2.5 Classic binaries with xinetd daemon, scaling to zero on idle and building changes in <10s.

Frankfurt region collocated with Cloudflare European Edge.
V8 Edge WebCrypto (crypto.js)

Runs directly inside Cloudflare Workers V8 isolates without heavyweight npm crypto dependencies. Implements PBKDF2 (SHA-256) key derivation for credentials and signed HMAC-SHA256 JWT sessions using crypto.subtle.

Zero plaintext credentials; sub-1ms crypto operations.
Barn Floor PWA (sw.js)

Tri-tier caching strategy: Cache-First for UI shell, Stale-While-Revalidate for animal registers, and localized IndexedDB outbox queue. Automatically purges obsolete caches on automated version stamp (stamp-sw.js).

Full CRUD responsiveness even with zero cell connectivity.

Audited Edge & Ingestion Benchmarks

DB Ingestion Time
~1.5 sec
Stateless Cloud Run
Initial Page Load
< 350 ms
Edge PWA cache + SW
Edge API TTFB
~25–45 ms
Cloudflare D1 (EEUR)
Core JS Runtime
16.6 KB
Zero-bloat petite-vue
CI Test Suite: 150 ms (21 zootech & security tests) • Zero heavy client-side frameworks • Complete offline barn floor operation
Hybrid Edge & Cloud Run Ingestion Flow Edge PWA + Container Microservice
1. Legacy Backup
Uniform-Agri (.zip / .fdb)
▼
2. Google Cloud Run
FastAPI + Firebird 2.5 Classic (~1.5s)
▼
3. Cloudflare D1
Frankfurt Edge SQLite Schema
▼
4. Barn Floor PWA
Service Worker Offline Sync
Languages: Python 3.11, JavaScript ES2024
Hosting/Cloud: Cloudflare Pages + Cloud Run
Databases: Cloudflare D1 + Firebird 2.5
Security/Crypto: WebCrypto PBKDF2 & HMAC

Hybrid Stack

  • Cloudflare Pages & D1 Edge SQLite
  • Google Cloud Run (Frankfurt)
  • Firebird 2.5 in-memory parsing
  • Native WebCrypto (HMAC-SHA256)
Resume Takeaway

"Modernized legacy desktop dairy ERP by building a stateless Firebird 2.5 extraction microservice on Google Cloud Run (~1.5s conversion) paired with an offline-first Cloudflare Edge PWA with biological quarantine tracking."

📋 Ready-to-Paste Resume Bullets (STAR Format)

Formatted for senior software & AI engineering CVs or LinkedIn experience sections.

• Code Memory Skill (Agent Retrieval Layer):
  - Architected a zero-dependency local sparse retrieval engine in Python stdlib, reducing AI agent token consumption by 80–90% (~600 tokens vs. 30,000+ per prompt).
  - Designed AST-aware symbol and multilingual tokenization indexing 10,000+ LoC in <0.2s with sub-20ms query latency, eliminating context amnesia during refactoring.

• AuraStudio AI (Serverless Generative AI & DiT Engine):
  - Built an end-to-end generative portrait platform on Qwen 2.5 DiT 20B with latent anchoring, preserving 100% facial identity and natural micro-pore skin physics.
  - Slashed GPU infrastructure costs to ~$0.02 per generation by tuning Modal serverless containers to a 45s scaledown window and deploying an automated dual-workspace failover gateway on Cloudflare Workers.

• DairyERP Cloud (AgroTech ERP & Legacy Modernization):
  - Modernized 20-year-old desktop ERP by creating a stateless Firebird 2.5 extraction microservice on Google Cloud Run, converting encrypted farm archives in ~1.5s.
  - Engineered an offline-capable Cloudflare Pages & D1 Edge PWA featuring real-time reproductive KPIs and biological antibiotic withholding countdowns.
Copied to clipboard!