Back to Case Studies
AI & Prototype/B2B SaaS Startup (Series A, ~30 Staff)

Re-Architecting an AI-Built MVP into a Multi-Tenant Enterprise SaaS

Author: Ujjwal MishraIndustry: B2B SaaS Startup (Series A, ~30 Staff)
3 Weeks
Passed Enterprise Security Review
-62%
Reduction in Average API Latency
-35%
Monthly Cloud & LLM Cost Reduction
01. CHALLENGE

Stalled at a 120-item enterprise security check sheet due to missing tenant isolation, no SSO, and exposed client-side API keys.

02. APPROACH

3-week OWASP audit and modular rebuild introducing PostgreSQL RLS, Entra ID SSO, AWS KMS secrets, and a governed LLM gateway.

03. OUTCOME

Passed enterprise security review in 3 weeks, cut average API latency by 62%, and reduced monthly cloud & LLM costs by 35%.

01. Business & Technical Challenge

  • A Series A B2B SaaS startup (~30 employees) rapidly built a working MVP using AI coding tools (Cursor/v0), quickly generating pilot interest from major enterprise buyers.
  • At procurement, the buyer IT security team rejected the 120-item security check sheet due to weak multi-tenant isolation, lack of SAML/OIDC SSO, and unverified LLM data privacy.
  • Our codebase audit revealed hardcoded LLM API keys in the client bundle, monolithic 3,000-line files, and unvalidated prompts vulnerable to prompt injection attacks.
  • Unoptimized prompt chains and missing response caching also caused sluggish API latency and rapidly escalating monthly cloud and LLM token costs.
ARCHITECTURE TRANSITION
Risk State to Hardened Production Target
BEFORE: LEGACY / EXPOSUREAT RISK
AUTH & CLIENT LAYER
Monolithic AI-Generated Bundle & Basic Auth
Exposed client-side API keys, no SSO, and fragile 3,000-line files
DATABASE & ACCESS
Unscoped Queries Without Tenant Isolation
Single query bug risks cross-company data leakage (IDOR)
AI CALLS & INFRA
Direct External LLM Calls & Manual Deploys
Prompt injection exposure, zero audit logs, and runaway LLM spend
AFTER: HARDENED PRODUCTIONVERIFIED
IDENTITY & ACCESS
Microsoft Entra ID (SAML/OIDC) SSO + RBAC
Enterprise SSO, role-based access control, and AWS KMS secret isolation
TENANT ISOLATION & API
Modular TypeScript / Next.js + PostgreSQL RLS
Database-enforced Row-Level Security (RLS) guaranteeing strict tenant boundaries
GOVERNED AI & IAC
Zero-Retention LLM Gateway + AWS ECS / Terraform
PII masking, rate limiting, and caching cut latency 62% and costs 35%

02. Delivery & Engineering Approach

PHASE 01
Week 1: Audited the full codebase against OWASP ASVS and OWASP Top 10 for LLMs, mapping every finding to the buyer 120-item security check sheet to create a prioritized hardening plan.
PHASE 02
Week 2: Decomposed monolithic files into modular TypeScript/Next.js services and implemented PostgreSQL Row-Level Security (RLS) so tenant isolation is enforced directly at the database layer.
PHASE 03
Week 3 (Early): Implemented Microsoft Entra ID SAML/OIDC SSO and RBAC, migrated all secrets to AWS KMS, and deployed a zero-data-retention LLM gateway with PII masking and rate limiting.
PHASE 04
Week 3 (Late): Codified AWS ECS infrastructure in Terraform (IaC), completed security re-verification and load tests, and handed over the system alongside completed enterprise security documentation.

03. Key Deliverables & Handover

01

Hardening Blueprint & OWASP Audit Report

Architecture diagrams and OWASP remediation evidence mapped directly to enterprise check sheets.

02

Modular Source Code & Automated Tests

Clean TypeScript/Next.js codebase with automated test suites verifying tenant isolation.

03

Terraform (IaC) & CI/CD Pipelines

Reproducible AWS ECS, KMS, and audit-logging definitions with automated CI/CD workflows.

04

Operations Runbooks & Team Handover

Key-rotation and incident-response runbooks plus hands-on walkthroughs for internal engineers.

KEY TAKEAWAY

Preserving the validated UX of the AI MVP while engineering database-level tenant isolation, SSO, and governed AI gateways in 3 weeks unblocked enterprise procurement without a full rewrite.

NEXT STEP

Talk through your system or prototype in a 30-minute call.

Share your current challenges or plans and we will outline a practical path forward. A company and services overview is also available for internal review.