How jorguzman100/ghostwriter works
Purpose and Entry Points
Ghostwriter is a client/server AI drafting tool for blog posts, emails, stories, and social posts. Users submit content-specific inputs, receive a processed draft plus review metadata, edit it, and export locally. The browser starts at frontend/src/main.tsx and renders the application in frontend/src/App.tsx. FastAPI is launched through backend/app/main.py.
Frontend Interaction and Export Boundary
The React/Vite frontend owns content-type selection, dynamic forms, generation settings, draft editing, dashboard presentation, and browser-side exports (plain text, rich text/HTML, Markdown, print/PDF). frontend/src/App.tsx is the primary UI/controller boundary; frontend/src/App.css contains its presentation layer. The frontend sends generation and delayed live-review requests to the API, then treats returned draft/check results as authoritative.
API Orchestration
backend/app/main.py defines the FastAPI application and request lifecycle: accept user payloads, validate them, normalize content-type-specific fields, build prompts, invoke the configured model provider, then return cleaned content and diagnostics. It also supports re-checking edited drafts rather than requiring another model generation. API schemas and stable response/request contracts are defined in backend/app/schemas.py.
Input Canonicalization and Prompt Assembly
Requests cross a normalization boundary before AI use: backend/app/normalizer.py converts differing blog, email, story, and social form shapes into a consistent internal representation. backend/app/prompt_templates.py selects content-specific instructions and examples, incorporating normalized fields plus generation controls such as temperature, token limit, and top-p. This keeps provider-facing prompts separate from UI payload design.
AI Provider Adapter and Configuration
backend/app/ai_client.py encapsulates model calls and provider selection. Runtime configuration is centralized in backend/app/config.py, using environment settings to select local Ollama by default or OpenAI when configured. There is no implied fallback between providers: the configured service is the generation dependency. Environment examples are provided in .env.example.
Post-Generation Quality Pipeline
Raw model output is processed before delivery. backend/app/postprocessor.py cleans formatting, Markdown, punctuation/capitalization, labels, and common AI artifacts; it also derives structure, word-count, platform-fit, and export-readiness feedback. backend/app/safety.py adds local heuristic checks for unsafe or unprofessional language. These checks are also relevant to the edited-draft review flow, separating generated text from final user-edited text.
Deployment Topology
docker-compose.yml composes the frontend, FastAPI backend, and Ollama runtime, with a persistent model volume for the default gemma3:4b download. Container boundaries are defined by frontend/Dockerfile and backend/Dockerfile. In Docker, the frontend is exposed at port 5173; the backend communicates with the configured AI provider over its service/network boundary. Local development can instead run Vite, Uvicorn, and a locally installed Ollama instance independently.
Main entry points: ai_client.py Provider adapter · main.py API lifecycle · App.tsx React app controller · docker-compose.yml Compose topology
Components 19
Frontend
Browser UI and local export.
- Browser user
- React app controller · Owns forms, editing, dashboard, and API calls.
frontend/src/App.tsx - Presentation layer
frontend/src/App.css - Frontend entry
frontend/src/main.tsx - Local exports · Text, HTML, Markdown, and print/PDF exports stay in the browser.
FastAPI backend
Request orchestration and draft review.
- API lifecycle · Validates requests, orchestrates generation, and supports edited-draft review.
backend/app/main.py - API contracts
backend/app/schemas.py - Input normalizer · Converts content-specific form payloads to a shared representation.
backend/app/normalizer.py - Prompt assembly · Builds content-specific provider prompts from normalized inputs and controls.
backend/app/prompt_templates.py
AI and quality pipeline
Configured generation and local checks.
- Provider adapter · Selects and invokes the configured model provider.
backend/app/ai_client.py - Runtime configuration · Selects Ollama by default or OpenAI when configured.
backend/app/config.py - Draft postprocessor · Cleans model output and derives review metadata.
backend/app/postprocessor.py - Safety review · Checks generated and edited drafts for unsafe or unprofessional language.
backend/app/safety.py - OpenAI · Alternative configured generation dependency.
Deployment
Containerized default topology.
- Ollama runtime · Default service hosting gemma3:4b.
- Compose topology · Composes frontend, backend, Ollama, and persistent model storage.
docker-compose.yml - Frontend container · Exposes the frontend on port 5173.
frontend/Dockerfile - Backend container
backend/Dockerfile - Environment example
.env.example
Connections 20
- Browser user → Frontend entry: loads
- Frontend entry → React app controller: renders
- React app controller → Presentation layer: uses
- React app controller → API lifecycle: generate and review requests
- React app controller → Local exports: exports edited draft
- API lifecycle → API contracts: validates contracts
- API lifecycle → Input normalizer: normalizes input
- Input normalizer → Prompt assembly: canonical fields
- Prompt assembly → Provider adapter: provider prompt
- Provider adapter → Runtime configuration: reads provider selection
- Provider adapter → Ollama runtime: default generation
- Provider adapter → OpenAI: when configured
- Provider adapter → Draft postprocessor: raw model output
- Draft postprocessor → Safety review: cleaned draft
- Safety review → API lifecycle: draft and diagnostics
- API lifecycle → Safety review: edited-draft recheck
- Compose topology → Frontend container: builds and runs
- Compose topology → Backend container: builds and runs
- Compose topology → Ollama runtime: runs with model volume
- Environment example → Runtime configuration: documents settings