Building AIOU Assignment Studio: A Full-Stack AI Document Engine & Edge-Protected LMS Study Platform
AIOU Assignment Studio: A production AI typesetting, mathematical rendering, and LMS study companion platform, engineered by Muhammad Zubair.
Students and academic centers across Pakistan face a recurring formatting bottleneck: converting dense mathematical proofs, truth tables, statistical charts, and formal Nastaleeq Urdu prose into university-compliant Microsoft Word (.docx) and PDF submissions with consistent cover pages and zero layout corruption. Most generic AI tools output broken Markdown, raw LaTeX dollar signs, or scrambled right-to-left (RTL) Urdu text.
To solve this end-to-end, I engineered AIOU Assignment Studio—a live production SaaS platform combining a custom Python / Streamlit document synthesis engine, Firebase Auth & Firestore billing/telemetry, Cloudflare Workers edge API routing, and Manifest V3 Chrome Extensions for real-time LMS study assistance.
Rather than wrapping a single LLM call, the platform orchestrates multi-model quota failover, XSLT-based LaTeX-to-OMML equation compilation, 35–60 page automatic document rebalancing, and sub-second edge-cached authentication with full per-request FinOps cost telemetry.
The Tech Stack: Full-Stack AI & Edge Matrix
Building a reliable academic SaaS for real paying users required decoupling heavy document synthesis from low-latency edge authentication and browser-level study assistance.
| Layer | Technology Used | Production Role / Capability |
| :------------------------- | :------------------------------------- | :------------------------------------------------------- |
| **Web Application** | Python, Streamlit, Custom CSS/JS | Live 30-template cover designer, scanner & admin console |
| **Document & Math Engine** | python-docx, MML2OMML.XSL, Matplotlib | Native Word OMML equations, charts & LibreOffice PDF |
| **Urdu RTL Pipeline** | Custom Regex Guards, Nastaleeq CSS/Font| Pure Urdu script enforcement & repetition-loop protection|
| **AI Failover Engine** | Multi-Model Gemini Lite Pool | Automatic 429/quota rotation across Lite model tiers |
| **Edge API Gateway** | Cloudflare Workers (Custom Subdomain) | Zero-cold-start REST API with 30-min in-memory auth cache|
| **Auth, DB & Telemetry** | Firebase Auth, Cloud Firestore | Separate Web/Ext credits, device binding & PKR cost logs |
| **Browser Companion** | Chrome Extensions (Manifest V3) | Automated & Manual Highlight Assist with misclick guard |
Platform Architecture & Dual-Path Request Flow
The system splits traffic into two independent planes: a heavy document-rendering backend for full .docx/.pdf generation, and a low-latency Cloudflare Edge plane for real-time browser extension requests:
[ Student / User ]
│
┌───────────────────────┴───────────────────────┐
│ Web Portal (www.aiouassignments.online) │ Browser Extension (MV3)
▼ ▼
┌─────────────────────────────┐ ┌─────────────────────────────┐
│ STREAMLIT STUDIO BACKEND │ │ CHROME / EDGE EXTENSION │
│ - PDF/DOCX/Image Scanner │ │ - Automated Study Mode │
│ - 30-Template Designer │ │ - Manual Highlight + │
│ - Live Graphic Preview │ │ Misclick Guard Mode │
└──────────────┬──────────────┘ └──────────────┬──────────────┘
│ │ POST (JSON)
│ ▼
│ ┌─────────────────────────────┐
│ │ CLOUDFLARE EDGE GATEWAY │
│ │ api.aiouassignments.online │
│ │ - 30-Min Edge Session Cache│
│ │ - Single-Device Binding │
│ │ - Dual-Key Model Failover │
│ └──────────────┬──────────────┘
│ │
├───────────────────────┬───────────────────────┘
▼ ▼
┌─────────────────────────────┐ ┌─────────────────────────────┐
│ FIREBASE & FIRESTORE │ │ MULTI-MODEL AI POOL │
│ - Email Verification │ │ - Primary: Flash-Lite │
│ - Web & Ext Credit Ledger │ │ - Backup 1 & 2 Failover │
│ - Per-Query Cost (PKR) │ │ - Async Telemetry Logging │
└──────────────┬──────────────┘ └─────────────────────────────┘
│
▼ (Assignment Rendering Pipeline)
┌─────────────────────────────────────────────────────────────┐
│ TYPESETTING & EXPORT PIPELINE │
│ 1. Math/Urdu/Theory Prompt Router + Anti-Loop Guard │
│ 2. LaTeX -> MathML -> Word OMML (MML2OMML.XSL) + Plots │
│ 3. Auto 35-60 Page Rebalancer + LibreOffice PDF Export │
└─────────────────────────────────────────────────────────────┘
Core Pillars of AIOU Assignment Studio
1. Live 30-Template Cover Designer & Document Scanner
Students upload question papers in PDF, DOC/DOCX, PNG, or JPG formats. The scanner normalizes legacy .doc files via headless LibreOffice, filters out institutional boilerplate or restricted research prompts, splits multi-assignment papers ([A1], [A2]), and renders a real-time graphic cover preview supporting 30 official templates, 10 font families, custom color palettes, and configurable logo positioning.
2. Native LaTeX-to-Word OMML & Automated Graph Plotting
Instead of pasting unreadable raw LaTeX (\frac{a}{b}) into Word documents, the solver enforces strict $...$ and $$...$$ formatting alongside structured plot tags ([NUMBER_LINE:], [PLOT_FUNCTION:], [BAR_CHART:], [PIE_CHART:], [HISTOGRAM:]). During compilation, equations are transformed into native Microsoft Word OMML objects using MML2OMML.XSL, while analytical charts are rendered cleanly via Matplotlib and embedded inline.
3. Pure Urdu RTL Pipeline & 35–60 Page Auto-Rebalancer
Urdu assignments frequently suffer from LLM script drift (stray English parentheticals or Devanagari tokens) and decoding repetition loops. A dedicated post-processing pipeline strips foreign scripts outside math blocks, detects low-diversity repetition loops, and regenerates clean Nastaleeq prose. For full-length submissions, a closed-loop PDF page counter automatically rebalances solution length if the rendered PDF falls outside the 35–60 page academic threshold.
4. Zero-Bloat Cloudflare Workers Edge API (api.aiouassignments.online)
To keep real-time LMS study companion queries under a second without hitting Streamlit's Python runtime, extension traffic routes through a dedicated Cloudflare Worker. The Worker validates credentials against Firebase Auth REST APIs, caches verified sessions in edge memory for 30 minutes to minimize Firestore reads, enforces single-device binding (extension_device_id), manages separate 45-minute quiz session credits, and logs telemetry asynchronously via ctx.waitUntil().
5. Dual-Mode MV3 Extensions & FinOps Cost Telemetry
Users can choose between an Automated Mode extension and a Manual Highlight Mode extension featuring an interactive misclick alert that compares user radio selections against AI suggestions in real time. On the backend, an Admin Analytics dashboard tracks per-student request latency, API key distribution, and exact Google API spend in USD and PKR with automated card-billing safeguards.
Visual Tour & Production Verification
1. Live Cover Designer & Assignment Studio
The interactive studio featuring mobile-optimized controls, 30 cover templates, question/answer/heading color pickers, and real-time HTML cover rendering.

2. Multi-Assignment Question Scanner & Bilingual Support
Automatic extraction and grouping of multi-part English, Quantitative Math, and RTL Urdu question papers with one-click assignment selection.

3. Super Admin Telemetry & FinOps Billing Guard
Real-time monitoring of model traffic distribution, key rotation percentages, per-student API cost in PKR, and monthly billing threshold alerts.

4. Dual MV3 Chrome Extension Licensing & Misclick Guard
End-user portal with EULA gating, automated/manual extension downloads, and live in-browser status HUDs.

Engineering War Stories: Real-World Production Incidents
Shipping a live product to users across different Pakistani ISPs uncovered bugs that never showed up on a US development VPS:
War Story 1: Pakistan ISP ERR_CONNECTION_RESET on workers.dev & HTTP/3 QUIC
- The Incident: The Chrome extension worked reliably from US servers and Microsoft Edge, yet desktop Chrome users in Pakistan suddenly hit
net::ERR_CONNECTION_RESETonPOSTrequests to*.workers.dev—even when opening the same URL in a normal browser tab returned200/405JSON. - Root-Cause Analysis: Two network behaviors collided: Pakistani ISP/SNI filters intermittently reset connections to shared
*.workers.devsubdomains, and Chrome's aggressive upgrade to HTTP/3 (QUIC) and Encrypted Client Hello (ECH) on subsequentfetch()requests triggered middlebox connection resets. - The Engineering Fix:
- Migrated the Worker endpoint from
*.workers.devto a dedicated custom domain on Cloudflare (https://api.aiouassignments.online/) while keeping the legacy route active for backward compatibility. - Disabled HTTP/3 (with QUIC) and Encrypted Client Hello (ECH) at the Cloudflare Zone level so Chrome negotiated clean HTTP/2 TLS connections reliably across Pakistani ISPs.
- Migrated the Worker endpoint from
War Story 2: The Manifest V3 Obfuscator Storage-Key Mismatch
- The Incident: After scrambling extension scripts for intellectual property protection, users could save their login credentials inside
popup.html, yetcontent.jsexited silently on quiz pages. - Root-Cause Analysis: A regex-based identifier mangler renamed
"userEmail","userPass", and"deviceId"insidepopup.js(including string keys insidechrome.storage.local.set()), while the updatedcontent.jsqueried the unmangled key names. Additionally, earliernew Function()wrappers violated Manifest V3's strictunsafe-evalContent Security Policy. - The Engineering Fix: Replaced regex mangling and dynamic code evaluation with a Manifest V3–compliant Base64 +
TextDecoderstring table (_0xt/_0xs) and automated ZIP verification assertions that validate matching storage keys and zeroeval/new Functionusage before every release:
for zip_out in ["aiou_quiz_extension.zip", "aiou_manual_extension.zip"]:
z = zipfile.ZipFile(zip_out)
c = z.read("content.js").decode("utf-8")
p = z.read("popup.js").decode("utf-8")
assert new_b64 in c, f"Missing production API URL in {zip_out}"
assert "userEmail" in p and "userPass" in p and "userEmail" in c
assert "new Function" not in c and "eval(" not in c
War Story 3: The 35–60 Page PDF Rebalancer & Pure Urdu Script Guard
- The Incident: Theoretical essays occasionally compiled into 28-page or 68-page PDFs depending on question complexity, while Urdu outputs occasionally leaked English parenthetical terms or entered repetitive phrasing loops.
- The Engineering Fix: Built a closed-loop PDF inspector (
get_pdf_page_count) that dynamically scales target word budgets (_tot_w * (46.0 / _pgs)) and rebalances sections when an assignment falls outside35–60pages, paired with regex script sanitization and token-diversity loop detection (len(set(w)) / len(w) < 0.22).
The Operational Production Runbook
When diagnosing live edge API or extension packaging issues in production, this 60-second read-only checklist isolates client, edge, and package failures without mutating live state:
# 1. Verify Cloudflare Worker edge routing & CORS headers
curl -i --max-time 10 -X POST -H "Content-Type: application/json" \
-d '{}' https://api.aiouassignments.online/
# 2. Inspect public DNS resolution & Cloudflare proxy edge IPs
curl -s "https://cloudflare-dns.com/dns-query?name=api.aiouassignments.online&type=A" \
-H "accept: application/dns-json"
# 3. Read-only verification of packaged MV3 extension ZIPs
python3 -c 'import zipfile; [print(f, zipfile.ZipFile(f).namelist()) for f in ["aiou_quiz_extension.zip", "aiou_manual_extension.zip"]]'
Future Horizon: AIOU Studio V2 Roadmap
With the core document synthesizer, edge API, and FinOps dashboards running in production, the next engineering milestones focus on scaling reliability and observability:
- Background Service Worker Fetch Proxy: Move extension
fetch()calls into a dedicated MV3background.jsservice worker with explicithost_permissionsto isolate API requests completely from host-page Content Security Policies. - Distributed Job Queue for Bulk Exports: Decouple long-running 40-page LibreOffice PDF conversions from Streamlit user sessions using an asynchronous worker queue with real-time progress polling.
- Automated Canary Health Checks: Run scheduled synthetic checks from Pakistani edge probes against
api.aiouassignments.onlineandwww.aiouassignments.onlineto detect ISP routing anomalies before users do.
The Business & Engineering Impact
AIOU Assignment Studio demonstrates what it takes to ship and operate a revenue-generating AI SaaS under real-world constraints. By combining multi-model failover, native Office XML math rendering, shift-left FinOps cost tracking, and resilient Cloudflare Edge architecture, the platform delivers consistent academic formatting at near-zero marginal API cost while handling real ISP and browser edge cases in production.
About the Developer
I am Muhammad Zubair, a Software Engineer from Pakistan specializing in cloud-native infrastructure, Kubernetes, and full-stack AI systems. I build resilient, automated platforms that solve real-world production and distributed systems challenges.
- Live Product: AIOU Assignment Studio (aiouassignments.online)
- GitHub: github.com/Muhammad-Zubair796
- LinkedIn: Connect with me on LinkedIn
- Portfolio: mzubair.online