Skip to content

02 Architecture Deep Dive

John Williams edited this page Mar 16, 2026 · 1 revision

Architecture Deep Dive

Ghost Writer uses a 5-stage pipeline to generate content that passes AI detection. This document explains each stage, data flow, the revision loop, and how detection APIs are orchestrated.


The 5-Stage Pipeline

Every piece of content flows through five sequential stages:

┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐
│ Profile  │───▶│  Writer  │───▶│    QA    │───▶│ Adapter  │───▶│  Polish  │
└──────────┘    └──────────┘    └──────────┘    └──────────┘    └──────────┘

Stage 1: Profile

Purpose: Load voice profile, set perplexity/burstiness targets, identify platform constraints.

What happens:

  • Voice profile is loaded (built-in or custom)
  • Perplexity target range is set (e.g., 30–45 for john-williams)
  • Burstiness target is set (high, medium, or low)
  • Platform spec is loaded (character limits, format, structure)
  • Phrase blacklist (120+ banned phrases) is injected into the prompt

Output: A fully parameterized generation context.


Stage 2: Writer

Purpose: Generate content using GPT-5.4 with the Ghost Protocol system prompt.

What happens:

  • System prompt includes: Ghost Protocol laws, voice profile, platform spec, detection evasion rules
  • Temperature: 0.85–0.95 (varies per variant for diversity)
  • Model: GPT-5.4
  • Max tokens: 4096

Ghost Protocol laws in the prompt:

  1. Controlled Chaos — Deliberate imperfection: fragments, unexpected metaphors, varied paragraph length
  2. Signature Voice — Write as the defined persona (tone, vocabulary, structure)
  3. Invisible Architecture — Detection evasion baked into generation, not post-processing

Output: Raw generated text.


Stage 3: QA Engine

Purpose: Validate content against the 40-point QA system.

What happens:

  • 40 checks run across 10 blocks (A–J)
  • Hard checks must pass; soft checks inform quality
  • Pass criteria: 0 hard fails, ≤3 soft fails
  • If failed: blacklist hits are replaced, then a revision prompt is sent to GPT

Revision loop:

  1. Run QA checks
  2. If blacklist hits: replace with random replacement from phrase list
  3. If hard fails or >3 soft fails: send revision prompt to GPT with failed check details
  4. Re-run QA on revised content
  5. Repeat up to 3 times

Output: QA-passing content or best-effort after max revisions.


Stage 4: Adapter

Purpose: Format content for the target platform.

What happens:

  • Text is normalized (Unicode, smart quotes, em-dashes)
  • Truncation applied if over platform max (e.g., LinkedIn 3000 chars)
  • Platform-specific formatting:
    • Email: Split into subject, preheader, body (subject <60, preheader <90)
    • Others: Plain text or markdown per platform spec

Output: Platform-ready content.


Stage 5: Polish

Purpose: Human-pass simulation with small edits.

What happens:

  • Detection APIs run in parallel (GPTZero, Pangram, Originality)
  • If any detector fails: sentences with >80% AI probability are identified
  • Failed sentences are rewritten via a focused revision prompt
  • Content is re-checked by detectors
  • Up to 3 revision cycles for detector failures

Output: Final content with detection scores.


Agent Roles

Role Responsibility
Profile Loader Loads voice + platform spec, builds prompt context
Writer (GPT-5.4) Generates content under Ghost Protocol
QA Engine Runs 40 checks, triggers revision loop
Adapter Applies platform formatting rules
Polish / Detector Calls external APIs, revises flagged sentences

Data Flow

Topic + Context + Voice + Type
         │
         ▼
   buildGhostPrompt()
         │
         ▼
   callGPT54(prompt, temp)
         │
         ▼
   normalizeText() → formatForPlatform()
         │
         ▼
   runQAChecks() ──▶ [fail] ──▶ revise ──▶ loop
         │
         ▼ [pass]
   callDetectors() ──▶ [fail] ──▶ reviseFailedSentences() ──▶ loop
         │
         ▼ [pass]
   Return { content, qa, detection, stats }

Revision Loop

QA Revision

When QA fails:

  1. Blacklist replacement: Each blacklisted phrase is replaced with a random alternative from the replacement list
  2. Structural revision: If hard fails or >3 soft fails remain, a revision prompt is sent:
    • Lists failed checks with targets
    • Asks GPT to fix only those issues
    • Temperature increased by 0.05 for more variation

Detector Revision

When a detector flags content:

  1. GPTZero sentences with AI probability >80% are collected
  2. A focused prompt rewrites only those sentences
  3. Rewritten sentences are spliced back into the content
  4. Content is re-normalized and re-checked by all detectors

Detection APIs in Parallel

All three detectors are called with Promise.all():

// Pseudocode
const [gptzero, pangram, originality] = await Promise.all([
  fetch(gptzeroUrl, { body: text }),
  fetch(pangramUrl, { body: text }),
  fetch(originalityUrl, { body: text }),
]);

Pass criteria:

  • GPTZero: completely_generated_prob < 0.30
  • Pangram: prediction is Human or AI-Assisted (not AI)
  • Originality.ai: ai score < 0.30, plagiarism < 0.05

Content passes only when all configured detectors pass.


Platform Formatting

The Adapter applies rules from PLATFORM_SPECS:

Rule Type Example
Truncation LinkedIn: first 140 chars visible before "see more"
Hashtags LinkedIn: max 3; Instagram: max 5
Structure Reddit: TL;DR if >300 words
Format Email: subject + preheader + body; Blog: H2/H3, meta <160
Character limits Twitter: 280 (25K premium); Threads: 500

See Platform Adapters for the full spec per platform.

Clone this wiki locally