# jorguzman100/ghostwriter-rev architecture

> Architecture diagram of the GitHub repository jorguzman100/ghostwriter-rev, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jorguzman100/ghostwriter-rev
- Repository: https://github.com/jorguzman100/ghostwriter-rev

## Overview

#### 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: [`src/App.tsx`](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/App.tsx) (App Orchestrator), [`src/utils/generators.ts`](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/generators.ts) (Generation Orchestrator), [`src/main.tsx`](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/main.tsx) (React Bootstrap), [`src/utils/api.ts`](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/api.ts) (AI Provider Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["React Client"]
  node_main["React Bootstrap<br/>entry point<br/>[main.tsx]"]
  node_app["App Orchestrator<br/>screen state<br/>[App.tsx]"]
  node_forms["Content Forms<br/>input forms"]
  node_blog_form["Blog Post Form<br/>content form<br/>[BlogPostForm.tsx]"]
  node_email_form["Email Form<br/>content form<br/>[EmailForm.tsx]"]
  node_story_form["Story Form<br/>content form<br/>[StoryForm.tsx]"]
  node_social_form["Social Media Form<br/>content form"]
  node_editor["Output Editor<br/>editing boundary<br/>[OutputEditor.tsx]"]
  node_export_bar["Export Bar<br/>export UI<br/>[ExportBar.tsx]"]
end

subgraph group_pipeline["Generation Pipeline"]
  node_types["Generation Contract<br/>TypeScript types<br/>[types.ts]"]
  node_generators{{"Generation Orchestrator<br/>async workflow<br/>[generators.ts]"}}
  node_validation["Validation &amp; Normalization<br/>input boundary<br/>[validation.ts]"]
  node_prompts["Prompt Builder<br/>prompt mapping<br/>[prompts.ts]"]
  node_api["AI Provider Client<br/>chat-completions client<br/>[api.ts]"]
  node_postprocessing["Post-processing<br/>output processor<br/>[postprocessing.ts]"]
  node_safety["Safety Scan<br/>content guard<br/>[safety.ts]"]
  node_exporters["Browser Exporters<br/>export service<br/>[exporters.ts]"]
end

subgraph group_runtime["Build and Delivery"]
  node_vite["Vite Build/Dev Server<br/>build tool<br/>[vite.config.ts]"]
  node_docker["Static Container Delivery<br/>Docker + nginx"]
end

node_browser(("User Browser<br/>runtime"))
node_provider{{"Compatible AI Provider<br/>external API"}}

node_browser -->|"loads SPA"| node_main
node_main -->|"mounts"| node_app
node_app -->|"selects active format"| node_forms
node_forms -.->|"blog input"| node_blog_form
node_forms -.->|"email input"| node_email_form
node_forms -.->|"story input"| node_story_form
node_forms -.->|"social input"| node_social_form
node_app -->|"submits inputs and settings"| node_generators
node_types -.->|"shared state contract"| node_app
node_types -.->|"workflow contract"| node_generators
node_generators -->|"validate and normalize"| node_validation
node_validation -->|"normalized data"| node_prompts
node_generators -->|"valid AI request"| node_api
node_prompts -->|"system and user prompts"| node_api
node_api -->|"direct browser request"| node_provider
node_generators -->|"AI or template output"| node_postprocessing
node_postprocessing -->|"processed content"| node_safety
node_safety -->|"safe processed output"| node_app
node_app -->|"editable output"| node_editor
node_editor -->|"edited state"| node_export_bar
node_export_bar -->|"selected export format"| node_exporters
node_vite -->|"builds client entry"| node_main
node_docker -->|"build stage"| node_vite
node_docker -->|"serves static assets"| node_browser

click node_main "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/main.tsx"
click node_app "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/App.tsx"
click node_blog_form "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/BlogPostForm.tsx"
click node_email_form "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/EmailForm.tsx"
click node_story_form "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/StoryForm.tsx"
click node_social_form "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/SocialMediaForm.tsx"
click node_editor "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/OutputEditor.tsx"
click node_export_bar "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/ExportBar.tsx"
click node_types "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/types.ts"
click node_generators "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/generators.ts"
click node_validation "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/validation.ts"
click node_prompts "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/prompts.ts"
click node_api "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/api.ts"
click node_postprocessing "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/postprocessing.ts"
click node_safety "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/safety.ts"
click node_exporters "https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/exporters.ts"
click node_vite "https://github.com/jorguzman100/ghostwriter-rev/blob/main/vite.config.ts"
click node_docker "https://github.com/jorguzman100/ghostwriter-rev/tree/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_app,node_forms,node_blog_form,node_email_form,node_story_form,node_social_form,node_editor,node_export_bar toneBlue
class node_types,node_generators,node_validation,node_prompts,node_api,node_postprocessing,node_safety,node_exporters toneAmber
class node_vite,node_docker toneMint
class node_browser,node_provider toneNeutral
```

## Components

### React Client

Browser-side application and editing flow.

- [React Bootstrap](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/main.tsx): entry point · `src/main.tsx`
- [App Orchestrator](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/App.tsx): screen state · Selects formats, holds settings and editable generated output. · `src/App.tsx`
- **Content Forms**: input forms · Separate schemas for blog, email, story, and social content.
- [Blog Post Form](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/BlogPostForm.tsx): content form · `src/components/BlogPostForm.tsx`
- [Email Form](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/EmailForm.tsx): content form · `src/components/EmailForm.tsx`
- [Story Form](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/StoryForm.tsx): content form · `src/components/StoryForm.tsx`
- [Social Media Form](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/SocialMediaForm.tsx): content form · `src/components/SocialMediaForm.tsx`
- [Output Editor](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/OutputEditor.tsx): editing boundary · Edits processed output before export. · `src/components/OutputEditor.tsx`
- [Export Bar](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/components/ExportBar.tsx): export UI · `src/components/ExportBar.tsx`

### Generation Pipeline

Typed normalization, generation, and output checks.

- [Generation Contract](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/types.ts): TypeScript types · Shared typed contract for inputs, options, results, checks, and safety. · `src/types.ts`
- [Generation Orchestrator](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/generators.ts): async workflow · Validates, generates or falls back, then processes and safety-checks output. · `src/utils/generators.ts`
- [Validation & Normalization](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/validation.ts): input boundary · Rejects invalid input and produces clamped normalized generation data. · `src/utils/validation.ts`
- [Prompt Builder](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/prompts.ts): prompt mapping · Builds content-specific prompts and examples from normalized data. · `src/utils/prompts.ts`
- [AI Provider Client](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/api.ts): chat-completions client · Browser client with timeout, response validation, retry, and parameter limits. · `src/utils/api.ts`
- [Post-processing](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/postprocessing.ts): output processor · Cleans output, extracts structure and metadata, and runs structural checks. · `src/utils/postprocessing.ts`
- [Safety Scan](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/safety.ts): content guard · Checks AI and template output for blocked or suspicious patterns. · `src/utils/safety.ts`
- [Browser Exporters](https://github.com/jorguzman100/ghostwriter-rev/blob/main/src/utils/exporters.ts): export service · 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](https://github.com/jorguzman100/ghostwriter-rev/blob/main/vite.config.ts): build tool · `vite.config.ts`
- [Static Container Delivery](https://github.com/jorguzman100/ghostwriter-rev/tree/main/Dockerfile): Docker + nginx · Builds the SPA with Node 20 and serves static dist assets on port 80. · `Dockerfile`

### Other components

- **User Browser**: runtime · Hosts the SPA and directly contacts configured AI providers.
- **Compatible AI Provider**: external API · OpenAI-compatible remote or local chat-completions service.

## Connections

- 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
