I wasn’t meant to be coding enterprise workflows. By all accounts, I should be diagnosing patients.
I’m Mohamed Fakhry, a technologist whose path wasn’t linear. At six, I fell in love with the 90s tech stack, Access, Visual Basic, FrontPage, dreaming of Gates or the Egyptian novelist Nabil Farouk. But in Egypt, family plans trump passion, so I became a doctor at Kasr Al-Ainy.
Inside, the coder never died. I spent years teaching digital marketing at the very college I was told I couldn’t attend. After graduation, I ran a government medical center in Cairo, learning a brutal truth:
Manual systems breed waste and corruption. You can’t fix that with willpower, so you engineer it out.
I pivoted to tech, architected SpiderSEO, and built an Agency Operating System: a digital backbone that prevents bottlenecks, enforces transparency, and automates the mundane.
This is the full case study of how Google Apps Script + OpenAI turned a chaotic service business into a semi-autonomous, code-governed machine, and why the best CEO can be an engineer at heart.
The Challenge: Scaling Operations Without Chaos
When I took the helm at SpiderSEO, I stepped into a logistical minefield. We were a remote-first agency across Egypt and Saudi Arabia, managing SEO project managers, writers, sales, and support.
We weren’t handling a few clients. We were scaling to hundreds of e-commerce stores, each needing dozens of unique product descriptions, blog posts, and technical audits monthly.
The Old Reality
Manual spreadsheets + endless WhatsApp threads. Tracking one piece of content, from brief to publication, required constant human pinging. Deadlines slipped. Quality was luck-based.
But the chaos wasn’t just operational, but was structural. The owner routinely mixed personal and business funds. Servers went down because domain renewals weren’t paid. Payroll was delayed because liquidity vanished overnight.
I’d seen this movie in the government clinic I managed: when everything depends on human diligence, it becomes permissive of corruption.
The Goal: A "Zero-Trust" Architecture
I realized we didn’t need better managers. We needed a better machine.
My goal: build a Zero-Trust Agency Operating System, where every action is verified, every state is enforced, and chaos is impossible by design.
- →A writer doesn’t tell us they’re done. The system detects submission, checks word count, validates format.
- →Financial health and project status on live dashboards. No more subjective reports.
- →Contracts generated programmatically. Zero chance of tampering.
The Architecture: A Serverless "Agency OS"
No DevOps team. No AWS budget. We lived in Google Workspace, so I turned it into our backend.
I built a fully serverless Agency OS using Google Apps Script.
Zero Infrastructure Cost
No servers, no databases, no bills. Everything runs on Google’s cloud for free.
Native Superpowers
One script can read Sheets, create Docs, convert to PDF, save to Drive, and email, ll with one OAuth scope.
Core Stack Breakdown
- Database: Google Sheets as strict relational tables
- Backend: Google Apps Script (JavaScript V8)
- AI Brain: Direct OpenAI API via UrlFetchApp
- Frontend: HTML Service Web Apps
- Triggers: Time-driven + Event-driven (onEdit, onFormSubmit)
The AI Content Factory (Hybrid Automation)
The biggest bottleneck: producing thousands of pieces of content without losing quality.
I built the “Content Machine”, a hybrid engine combining AI speed with human judgment.
var blogPostIntro = introGenerator(
`Craft a captivating blog post introduction incorporating a compelling analogy related to ${primaryKeyword}.
Tone: ${toneOfVoice}.
Reflect the UVP: ${uniqueValueProposition}`,
"gpt-4o-mini",
0.7
);Human-in-the-Loop: Smart Auto-Assignment
if (row[1].toString() === "8660") {
writerToAssign = 'writerNameHere'; // VIP client rule
} else {
lastAssignedWriterIndex = (lastAssignedWriterIndex + 1) % writers.length;
writerToAssign = writers[lastAssignedWriterIndex]; // Round-robin
}Assignment → instant personalized email with direct Google Doc link. No PM middleman.
Quality Assurance: The Silent Auditor
The contentcPanel script runs in the background catching:
- Missing URLs
- Incomplete briefs
- Empty delivery timestamps
The "Sophisticated" Translation System
Generic translation kills Arabic SEO. We needed cultural localization, not word-for-word.
var batchPrompt = `Translate with fluent, sophisticated, culturally resonant Arabic... Example: Original: Think of a complex clock where every tiny part must work in perfect harmony... Preferred: تخيل ساعة معقدة يجب أن تتناسق جميع أجزائها الصغيرة لتعرض الوقت بدقة...`;
The system splits long articles into JSON, processes section-by-section, reassembles, formats as Google Doc, and notifies the editor, and all in one click.
Client Transparency & Data Visualization
Clients hated the monthly PDF “black box.” I built a secure client portal using GAS HTML Service.
Plus a full OAuth2 app that pulls live Google Search Console data (Impressions, Clicks, CTR, Position) without sharing root credentials.
Governance & Financial Logic
Speed is useless if the ship is leaking. I codified governance in code:
- Immutable contract PDFs (no editable Docs ever leave the system)
- Programmatic cell protection via
protectRanges() - Nightly data validation enforcement
- Automatic archiving = immutable audit trail
body.replaceText('{{PartnerCoName}}', formData.partnerCoName);
// ...
var blob = copyDoc.getAs('application/pdf');
var pdfFile = DriveApp.createFile(blob).setName('عقد تعاون.pdf');The Pivot: From Scripting to Real Engineering
GAS hit its limits with high-concurrency AI workloads. So I taught myself Python, FastAPI, Asyncio, RAG, and agentic workflows.
That journey landed me at Boubyan Digital Factory as a Prompt & AI Engineer, turning banking operations into code, at enterprise scale.
The Hardest Lesson: Founder-Executive Alignment
No system survives financial chaos. All my automation was undermined by commingled funds and unpredictable cash flow.
The most critical API in any startup isn’t OpenAI. It’s alignment between founder and executive on governance.
If you want to solve a problem permanently, don’t just manage it, but engineer it.
