Developer & Contributor Guide
Comprehensive guide for developers and engineers building, contributing to, or modifying DraftSuite. Learn about the hybrid Electron + Next.js App Router architecture, the Zero-CORS server proxy, and release packaging.
1. Architecture Overview
DraftSuite uses a hybrid Electron + Next.js App Router standalone server architecture. This provides the agility of modern React 19 UI development while retaining native operating system capabilities.
Process Structure:
- 1. Electron Main Process:Defined in
electron/main.js. Manages the native browser window, traffic light window controls, multi-display repositioning (moveToNextDisplay), and forks the background Next.js standalone server on an available localhost port. - 2. Secure IPC Bridge:Configured in
electron/preload.jswithcontextIsolation: trueandsandbox: true. Exposes typed methods (window.electronAPI) for native dialogs, filesystem reads/writes, and shell operations. - 3. Next.js App Router Server:Runs in Node.js inside the app bundle. Houses all API route handlers (
/api/chat/completions,/api/models,/api/log) and serves the client UI.
2. Zero-CORS Server-Side Proxy Pipeline
One of the biggest friction points when running local LLMs in desktop web apps is browser cross-origin security: Chromium blocks requests from 127.0.0.1:3000 to 127.0.0.1:11434 unless CORS headers are configured.
How DraftSuite Solves This:
In lib/inference.ts, when provider === 'local', requests are automatically routed through the app’s internal /api/chat/completions route handler rather than fetching directly from the Chromium frontend.
- No CORS configuration required in Ollama or LM Studio.
- Unpacked error diagnostics (detects
ECONNREFUSED, socket closed/OOM, and 10-minute generation timeouts). - Supports both standard OpenAI format (
choices[0].message) and Ollama native responses.
3. Clone & Local Development
Prerequisites:
- Node.js: v20.x or higher
- npm: v10.x or higher
- Git
Setup Steps:
cd DraftSuite/DraftSuite-DesktopApp
*Note: On Apple Silicon Macs, lightningcss-darwin-arm64 is included as an optional native dependency for rapid Tailwind compilation.
This launches Next.js with hot-reloading on port 3000 and opens the Electron desktop window automatically.
4. Compiling & Packaging Release Installers
DraftSuite uses electron-builder to produce standalone desktop packages.
Outputs to dist-electron/DraftSuite-0.1.0-arm64.dmg and dist-electron/mac-arm64/DraftSuite.app.
5. Fiction Writing Guardrails System
DraftSuite differentiates itself from generic AI chat tools through its fiction-first guardrails engine in lib/inference.ts.
Enforces sensory grounding, physical room positioning, and show-don't-tell prose rules.
Prohibits AI overused vocabulary ("tapestry", "delve", "testament", "labyrinth").
Eliminates moralizing chapter summaries, rhetorical wrap-up questions, and unearned dialogue.