Technical Reference

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.js with contextIsolation: true and sandbox: 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.

// Chromium Frontend (lib/inference.ts)
const isDirectLocal = provider === 'local' && apiUrl.startsWith('http');
const targetEndpoint = isDirectLocal ? '/api/chat/completions' : `${apiUrl}/chat/completions`;
// Next.js Backend (app/api/chat/completions/route.ts)
if (provider === 'local') {
// Node.js native fetch — zero CORS restrictions!
const localRes = await fetch(endpoint, { ... });
}
Key Advantages:
  • 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:

1. Clone the repository:
git clone https://github.com/theglassdesk/DraftSuite.git
cd DraftSuite/DraftSuite-DesktopApp
2. Install dependencies:
npm install

*Note: On Apple Silicon Macs, lightningcss-darwin-arm64 is included as an optional native dependency for rapid Tailwind compilation.

3. Start desktop app in live development mode:
npm run electron:dev

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.

macOS (.dmg & .app):
npm run electron:build:mac

Outputs to dist-electron/DraftSuite-0.1.0-arm64.dmg and dist-electron/mac-arm64/DraftSuite.app.

Windows (.exe Setup):
npm run electron:build:win
Linux (.AppImage):
npm run electron:build:linux

5. Fiction Writing Guardrails System

DraftSuite differentiates itself from generic AI chat tools through its fiction-first guardrails engine in lib/inference.ts.

CRAFT.md

Enforces sensory grounding, physical room positioning, and show-don't-tell prose rules.

ANTI-SLOP.md

Prohibits AI overused vocabulary ("tapestry", "delve", "testament", "labyrinth").

ANTI-PATTERNS.md

Eliminates moralizing chapter summaries, rhetorical wrap-up questions, and unearned dialogue.