HomeCase studiesMulti-Tenant AI Website Builder with Schema-Driven Layout...

Case study · Melbourne, Australia

Multi-Tenant AI Website Builder with Schema-Driven Layout Compilation

No-Code Web Publishing & SMB SaaS

Small businesses often abandon traditional drag-and-drop site editors because blank canvases demand copywriting, visual hierarchy, and responsive CSS judgment they do not have time to master. We engineered a multi-tenant AI website builder powered by Next.js, a Python orchestration service, and PostgreSQL that compiles user business briefs into typed page-section ASTs rather than brittle raw HTML. Site owners refine copy, palettes, and media inside a live visual editor, then publish immediately to custom domains with edge caching and automatic SSL provisioning.

Industry
No-Code Web Publishing & SMB SaaS
Solution
A full-stack multi-tenant website generation and publishing platform pairing a Next.js visual editor and edge renderer with Python AI synthesis services and PostgreSQL.
Platforms
Web & API
Stack
Next.js · React · TypeScript · Python · FastAPI · PostgreSQL
Location
Melbourne, Australia · delivered remotely
Role
Engineering, with the team behind for mobile and QA

Delivered remotely for a business based in Melbourne, Australia. Names withheld by agreement.

Project Overview

Launching a credible web presence remains unexpectedly hard for local trades, clinics, hospitality venues, and solo consultancies. Conventional no-code builders still confront users with hundreds of empty grid containers, typography sliders, and placeholder Latin text. Meanwhile, naive prompt-to-HTML prototypes produce fragile markup that collapses on mobile viewports and cannot be safely edited after initial generation.

We built a production multi-tenant AI website builder anchored on Next.js, Python, and PostgreSQL. Instead of emitting arbitrary HTML strings, the Python synthesis engine translates a brief intake questionnaire into a strongly typed page-section graph paired with curated design tokens. Owners inspect, rewrite, reorder, and re-theme every section inside a browser-based React studio, then publish instantaneously to custom domains served through Next.js edge routing.

Publishing Friction

Early discovery across SMB onboarding workflows revealed four recurring failure modes in automated site builders:

  • Uneditable AI output: Generating raw HTML/CSS blobs locks users out of structured visual editing because moving a call-to-action button or swapping a hero layout breaks inline styles.
  • Brand inconsistency across pages: Independent prompts for Home, Services, and Contact pages routinely drift in tone, color contrast, and navigation structure.
  • Custom domain propagation delays: Requiring manual server blocks or slow static rebuilds stalls launch momentum right when a business owner is ready to go live.
  • Mixed draft and live state: Editing a live marketing page directly without atomic snapshot publishing risks exposing half-finished copy to visitors.

Architectural Strategy

Our central architectural choice was decoupling semantic content synthesis from presentational component rendering. The Python backend never touches JSX or CSS; it outputs a validated site manifest describing navigation links, page slugs, section types, copy slots, and palette tokens.

Next.js consumes that manifest and renders production pages from a library of accessible, responsive React components styled with Tailwind CSS variables. Because both the visual editor and the public edge renderer share the exact same component primitives, what a business owner sees inside the Melbourne studio canvas matches the live published site pixel for pixel.

Core Capabilities

  • Guided Multi-Page Synthesis: A short intake flow captures business category, service offerings, geographic focus, and tone, producing a coherent multi-page site architecture in one pass.
  • Block-Level AI Regeneration: Users can regenerate a single hero headline, pricing tier, or FAQ accordion without disturbing adjacent sections or manual edits.
  • Design Token Theme Engine: Global font pairings, spacing scales, and WCAG-checked color palettes update the entire site atomically via CSS custom properties.
  • Atomic Draft & Snapshot Publishing: Background edits auto-save into draft revisions while live traffic continues reading the latest immutable published snapshot.
  • Zero-Rebuild Custom Domain Routing: Tenants bind apex or subdomain records via guided DNS verification and receive automated TLS termination.

Technical Architecture

The platform splits interactive authoring from heavy model inference and public content delivery. The Next.js frontend communicates with FastAPI endpoints in Python for prompt orchestration, sitemap planning, and image selection, while PostgreSQL serves as the authoritative store for tenant schemas, JSONB page trees, and domain mappings. Redis coordinates async generation jobs and caches domain-to-tenant lookups so public page requests avoid cold database round-trips.

Flow: Next.js Studio Intake → Python FastAPI Orchestrator (Pydantic AST + Design Tokens) → PostgreSQL Draft JSONB Storage → Visual Editor Refinement → Atomic Snapshot Publish → Redis Cache Invalidation → Next.js Middleware Custom Domain Edge Render

Within PostgreSQL, sites are modeled with normalized tenant and domain tables alongside versioned JSONB document payloads for page trees. Separating structural metadata (domains, TLS status, publishing state) from section payloads allows fast routing queries in middleware while preserving full rollback history across published revisions.

Technology Stack

Category Technology detail
Frontend & Edge Rendering Next.js App Router with React Server Components and middleware domain routing
Visual Editor & UI React and TypeScript block inspector with Tailwind CSS design tokens
AI Generation Service Python FastAPI service orchestrating structured JSON layout and copy synthesis
Primary Database PostgreSQL storing tenant sites, JSONB component trees, and revision snapshots
Caching & Job Queues Redis for generation job state, rate limiting, and published page invalidation
Media Pipeline Object storage with server-side image resizing and aspect-ratio enforcement
Domain & TLS Layer Automated CNAME verification and on-demand TLS certificate provisioning
Schema Validation Pydantic models in Python mirrored by Zod schemas in TypeScript
Observability Structured trace IDs linking prompt synthesis latency to editor save events

Engineering Trade-offs & Solutions

Engineering Challenge Solution & Trade-off
Raw LLM HTML output breaks responsive layouts and complicates editing Enforced a closed catalog of typed section schemas validated by Pydantic and Zod; trades arbitrary freeform canvas positioning for guaranteed mobile responsiveness and clean editing.
Full-site regeneration overwrites user edits on untouched pages Scoped regeneration endpoints to individual section UUIDs and locked manual overrides in PostgreSQL, adding state-merging logic in exchange for safe iterative AI assistance.
Static site rebuilds per tenant do not scale to thousands of custom domains Adopted Next.js dynamic multi-tenant routing backed by on-demand ISR and Redis tag invalidation, avoiding CI build queues at the cost of careful cache-key isolation.
Streaming a full multi-page site over a single HTTP call hits gateway timeouts Moved initial site compilation to Redis-backed Python worker jobs with Server-Sent Events progress updates to the Next.js studio.

Security & Reliability

Multi-tenant publishing platforms carry significant cross-tenant and abuse risks, ranging from phishing page generation to host-header spoofing. Incoming requests pass strict host validation against verified domain records in PostgreSQL before any tenant content resolves. Every tenant workspace enforces row-level ownership checks in both FastAPI and Next.js API routes.

To prevent malicious script injection on published custom domains, rich-text fields permit only a constrained subset of inline formatting nodes rather than raw HTML fragments. Uploaded media goes through server-side transcoding to strip EXIF payloads and neutralize polyglot files, while automated content moderation hooks inspect newly generated copy before custom domains activate.

Performance & Scale

Public tenant traffic is decoupled entirely from the AI generation and editor control planes. Published pages render from cached Next.js Server Components using immutable snapshot IDs; when an owner hits Publish, only that tenant's cache tags purge.

During initial onboarding bursts, Python workers stream partial section completions over SSE so users watch their homepage assemble progressively instead of staring at a spinner. Rate limiters in Redis cap expensive LLM regeneration calls per tenant tier without ever throttling public visitors browsing published sites.

Operational Outcomes

Consolidating structured AI synthesis, visual block editing, and edge domain routing into one coherent stack eliminated the typical friction between "generated demo" and "production business site":

  • Editable, resilient layouts: Small business owners can adjust text, reorder sections, and swap color themes indefinitely without breaking mobile breakpoints or CSS alignment.
  • Instantaneous launch path: Connecting a custom domain and publishing updates requires no static rebuild pipeline or developer intervention.
  • Safe iterative experimentation: Immutable revision snapshots in PostgreSQL let non-technical users test seasonal promotions or AI rewrites with confidence that live pages remain intact until published.
  • Predictable platform maintainability: Engineering teams add new industry section templates by registering a single React component and Pydantic schema pair, immediately expanding both the visual editor and the AI compiler.

01 — Questions

asked about this kind of project

Why generate a structured JSON component tree instead of having the AI write raw HTML and CSS?

Raw LLM-generated HTML frequently breaks responsive grids, mixes inconsistent class names, and creates XSS risks when rendered on tenant domains. Compiling prompts into a strict JSON AST mapped to vetted React and Tailwind CSS section components guarantees mobile responsiveness, accessible contrast ratios, and deterministic visual editing.

How does Next.js serve thousands of custom tenant domains from a single deployment?

Next.js Edge Middleware inspects the incoming Host header on every request, resolves the custom domain or subdomain against a Redis-backed routing table populated from PostgreSQL, and internally rewrites the request to a dynamic multi-tenant route without exposing tenant IDs in the URL.

How do you prevent concurrent edits in the visual studio from overwriting published site state?

Each site maintains separate draft and published revision pointers in PostgreSQL. Edits mutate only the active draft JSONB tree using optimistic version numbers, while publishing creates an immutable snapshot and triggers targeted cache invalidation.

What happens if the Python AI pipeline stalls or returns malformed JSON during site creation?

Site generation runs asynchronously via queued workers using strict Pydantic schema validation and constrained decoding. If a section fails validation, only that block falls back to a curated industry blueprint rather than failing the entire site build.

How are tenant-uploaded assets and third-party embed scripts isolated for security?

User-uploaded images pass through server-side MIME validation and re-encoding to strip embedded metadata, while custom embed blocks are restricted to sanitized allowlists and strict Content Security Policy headers on published tenant sites.

03 — Similar project?

describe what is different about yours

Build yours.

Tell me what exists, what you need and the deadline. Fixed price for a defined scope, or $55/day (8–9 hours work) with a written plan first.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.