How jorguzman100/ghostwriter-rev works
Purpose and Entry Points
Ghostwriter is a client-side content-generation application for blog posts, emails, stories, and social posts. Users select a format, supply structured inputs, generate AI or template content, edit it, then export it. Browser bootstrap is src/main.tsx; application state and screen-level orchestration live in src/App.tsx.
UI Composition
src/App.tsx selects the active content type, collects generation settings/API credentials, invokes the generation pipeline, and holds editable output state. Type-specific forms isolate each input schema:
• src/components/BlogPostForm.tsx
• src/components/EmailForm.tsx
• src/components/StoryForm.tsx
• src/components/SocialMediaForm.tsx
src/components/OutputEditor.tsx is the post-generation editing boundary; src/components/ExportBar.tsx exports that edited state rather than immutable raw model output.
Typed Generation Contract
src/types.ts defines content-type inputs, normalized data, generation options/results, API settings, processed output, validation checks, and safety results. This is the contract between React components and generation utilities, preventing the four distinct form shapes from leaking into API/prompt code.
Generation Orchestrator and Fallback Boundary
src/utils/generators.ts is the central async workflow: validate input, optionally call an AI provider, post-process and safety-check the result, or return an immediate built-in template. Invalid inputs do not reach the network; API failures also degrade to templates. This makes external AI optional and preserves a usable offline/no-key mode.
Validation and Prompt Construction
src/utils/validation.ts validates required fields, normalizes input into common context/specification/generation-parameter structures, averages word-count ranges, and clamps model parameters. src/utils/prompts.ts maps normalized content types to separate system/user prompts and few-shot examples. The boundary here is deliberate: prompts consume normalized typed data, not raw form values.
AI Provider Integration
src/utils/api.ts calls an OpenAI-compatible chat-completions endpoint from the browser using user-provided base URL, model, and credentials. It applies timeout handling, response validation, rate-limit/server retries, and parameter clamping. Compatible remote or local services include OpenAI-style providers and an Ollama endpoint; no backend or credential persistence layer is present.
Output Processing, Safety, and Export
src/utils/postprocessing.ts removes common AI framing, extracts title/sections, derives metadata, and evaluates structural and word-count checks. src/utils/safety.ts scans both AI and template output for blocked or suspicious patterns. src/utils/exporters.ts creates browser-side TXT, Markdown, HTML, PDF/print, and clipboard output.
Runtime and Deployment
The runtime is a React 19 + TypeScript single-page application built and served by Vite during development (vite.config.ts). Production is static assets: Dockerfile builds with Node 20 Alpine and serves dist through nginx Alpine on port 80. It can therefore deploy to any static host; AI access is a direct browser-to-provider network dependency.
Main entry points: App.tsx App Orchestrator · generators.ts Generation Orchestrator · main.tsx React Bootstrap · api.ts AI Provider Client
Components 21
React Client
Browser-side application and editing flow.
- React Bootstrap
src/main.tsx - App Orchestrator · Selects formats, holds settings and editable generated output.
src/App.tsx - Content Forms · Separate schemas for blog, email, story, and social content.
- Blog Post Form
src/components/BlogPostForm.tsx - Email Form
src/components/EmailForm.tsx - Story Form
src/components/StoryForm.tsx - Social Media Form
src/components/SocialMediaForm.tsx - Output Editor · Edits processed output before export.
src/components/OutputEditor.tsx - Export Bar
src/components/ExportBar.tsx
Generation Pipeline
Typed normalization, generation, and output checks.
- Generation Contract · Shared typed contract for inputs, options, results, checks, and safety.
src/types.ts - Generation Orchestrator · Validates, generates or falls back, then processes and safety-checks output.
src/utils/generators.ts - Validation & Normalization · Rejects invalid input and produces clamped normalized generation data.
src/utils/validation.ts - Prompt Builder · Builds content-specific prompts and examples from normalized data.
src/utils/prompts.ts - AI Provider Client · Browser client with timeout, response validation, retry, and parameter limits.
src/utils/api.ts - Post-processing · Cleans output, extracts structure and metadata, and runs structural checks.
src/utils/postprocessing.ts - Safety Scan · Checks AI and template output for blocked or suspicious patterns.
src/utils/safety.ts - Browser Exporters · Creates TXT, Markdown, HTML, PDF/print, and clipboard output.
src/utils/exporters.ts
Build and Delivery
Static SPA build and serving runtime.
- Vite Build/Dev Server
vite.config.ts - Static Container Delivery · Builds the SPA with Node 20 and serves static dist assets on port 80.
Dockerfile
Other components
- User Browser · Hosts the SPA and directly contacts configured AI providers.
- Compatible AI Provider · OpenAI-compatible remote or local chat-completions service.
Connections 24
- User Browser → React Bootstrap: loads SPA
- React Bootstrap → App Orchestrator: mounts
- App Orchestrator → Content Forms: selects active format
- Content Forms → Blog Post Form: blog input
- Content Forms → Email Form: email input
- Content Forms → Story Form: story input
- Content Forms → Social Media Form: social input
- App Orchestrator → Generation Orchestrator: submits inputs and settings
- Generation Contract → App Orchestrator: shared state contract
- Generation Contract → Generation Orchestrator: workflow contract
- Generation Orchestrator → Validation & Normalization: validate and normalize
- Validation & Normalization → Prompt Builder: normalized data
- Generation Orchestrator → AI Provider Client: valid AI request
- Prompt Builder → AI Provider Client: system and user prompts
- AI Provider Client → Compatible AI Provider: direct browser request
- Generation Orchestrator → Post-processing: AI or template output
- Post-processing → Safety Scan: processed content
- Safety Scan → App Orchestrator: safe processed output
- App Orchestrator → Output Editor: editable output
- Output Editor → Export Bar: edited state
- Export Bar → Browser Exporters: selected export format
- Vite Build/Dev Server → React Bootstrap: builds client entry
- Static Container Delivery → Vite Build/Dev Server: build stage
- Static Container Delivery → User Browser: serves static assets