SBScriptBox docs

System & API reference

Subsystems, HTTP API, and stack

This page is for engineers extending ScriptBox. Filmmakers should start on the homepage. Here: how the application is layered, what each subsystem owns, which HTTP endpoints exist, and which technologies it depends on. For the design rationale see Architecture; for setup and hosting see Run & deploy.

01Layers at a glance

Four layers: vanilla browser UI, FastAPI server, Python engines, and local files Browser · vanilla HTML / CSS / JS (no build step) Project library Script editor Storyboard studio Review board Homepage & docs fetch JSON / multipart HTTP server · single-worker FastAPI process Basic auth gate (hosted) Writing API Storyboard API Voice, motion & feedback API Python domain engines & playbooks Writing engine PDF import · review · drafts · PDF export Storyboard & video engine analysis · breakdown · beat plan · verify · audit · motion Shared playbooks generic JSON rules as data atomic JSON & media key-gated HTTPS Local filesystem (default drafts dir or $SCRIPTBOX_DATA_DIR) drafts · versions · project bundles · stills · receipts · audit ledger Optional external services (env keys only) OpenAI · xAI · Pollinations · ElevenLabs · Seedance · Google CSE · yt-dlp

Every layer is plain Python and JSON: no database, no external broker, and no frontend build step. Project state lives directly on disk.

02Subsystems

The repository is organized by domain rather than by framework boilerplate. Private project data, local scripts, credentials, screenplays, and generated media are always excluded from git.

AreaResponsibilities
HTTP entry & security gateLoads local environment config before imports, enforces HTTP Basic auth when hosted, adds security headers, serves browser pages and allowlisted HTML guides, and mounts API routers at / and /screenplay.
Writing subsystemDeterministic PDF geometry parsing into typed screenplay elements, optional Check-import element-type suggestions, versioned draft storage (up to 50 snapshots per project), and ReportLab A4 screenplay PDF export with bundled Courier Prime fonts.
Story analysis & breakdownWhole-script story bible, timeline, scene staging, shot plan, and consistency review; deterministic project breakdown into beats, camera plans, continuity locks, base prompts, verification checklists, and production shoot boards.
Wardrobe & movie lookGlobal wardrobe catalog with CONTINUED scene inheritance, optional LLM wardrobe extraction, garment plates and virtual try-ons, YouTube look-frame extraction converted to text lighting/grade notes, and SSRF-guarded cast likeness search.
Beat planning, generation & verificationSchema-validated per-beat semantic planner (cached by context hash), structured prompt compiler with labeled reference roles, multi-provider image fallback chain, vision verification with per-criterion receipts, bounded repair, atomic checkpoints, and append-only cost auditing.
Human review & campaignsScene-by-scene review board, defect tagging and repair brief export, second-pass review checkpoints, best-available collection exports, and frozen replacement campaigns.
Voice & motionConsent-gated ElevenLabs voice cloning/design/TTS, masked subtitle clean-plate removal, Seedance 2.5 image-to-video rendering in a persistent background worker with hard spend caps, and ffmpeg animatic/motion assembly with loudness normalization.
Browser UIFive standalone vanilla HTML/CSS/JS views (project library, script editor, 8-step storyboard studio, review board, and overview homepage) sharing one design-token stylesheet.

03Playbooks — rules as data

Tunable cinematography, continuity, and policy rules live as JSON playbooks read at runtime. Updating a playbook changes pipeline behavior without editing Python code, and every active playbook hash is recorded inside each generation receipt. Committed playbooks remain story-agnostic; per-project story packs overlay generated and hand-edited rules locally.

Playbook groupWhat it controls
Generation policy & promptsCore rules (beat scope, identity, continuity, physics, framing, text), prompt section order, brief schema, lighting by time of day, and semantic planner instructions.
Cinematography & stagingShot sizes and glossary, camera angles, movements, coverage rules, default focal lengths by space, declarative blocking templates, and micro-atmosphere beat filtering.
Continuity & aestheticsAnatomy/posture/prop physics triggers, binding spatial locks, location alias normalization, aesthetic clause packs by space/time, film style templates, color LUT presets, and production clustering.
Motion & story analysisVideo motion prompt rules, audio routing heuristics, and generic story-analysis vocabulary.
Per-project overlays (local only)Generated and hand-editable story rules and per-scene plans kept inside each project's gitignored folder.

04HTTP API catalog

All endpoints are mounted at / and again under /screenplay/… for embedding. Storyboard endpoints accept project_id as a query parameter.

Pages and health

MethodPathPurpose
GET/Project library
GET/edit?p=<id>Screenplay editor
GET/prepro?p=<id>8-step storyboard & video studio
GET/feedback?p=<id>Human review board & repair brief export
GET/landingHomepage for filmmakers & engineers
GET/guides/{name}Allowlisted HTML documentation pages
GET/healthzLiveness probe (unauthenticated)

Writing API

MethodPathPurpose
POST/api/import-pdfParse an uploaded PDF into beats (≤ 35 MB)
GET/api/draftsList projects
GET / POST / DELETE/api/draftRead, autosave, or delete a draft
POST / GET/api/draft/version, /api/draft/versionsSave or list named snapshots
POST/api/draft/restore-versionRestore a snapshot into the active draft
POST/api/draft/import-review, /api/draft/import-review/applySuggest or apply element-type repairs without rewriting text
POST/api/export-pdfRender a formatted screenplay PDF

Storyboard, review, voice & motion API

AreaEndpoints
ProjectGET /api/prepro, POST /api/prepro/compute, POST /api/prepro/bootstrap (upload PDF + compute)
Scenes & beatsPUT /api/prepro/sequence
CastPOST/PUT/DELETE /api/prepro/character, POST/DELETE /api/prepro/character/likeness, POST /api/prepro/character/likeness/search, POST /api/prepro/character/likeness/from-search
LookPOST /api/prepro/look/extract, POST /api/prepro/look/extract-more, GET /api/prepro/look/session/{id}/frame/{index}, POST /api/prepro/look/apply-selection, POST /api/prepro/look/confirm, POST /api/prepro/look/upload
WardrobeGET /api/prepro/wardrobe, POST /api/prepro/wardrobe/analyze, PUT /api/prepro/wardrobe/assignment, POST /api/prepro/wardrobe/item/generate, POST /api/prepro/wardrobe/item/upload, POST /api/prepro/wardrobe/try-on
GeneratePOST /api/prepro/generate (called once per beat)
Audit & reviewPOST /api/prepro/audit/start, GET /api/prepro/audit, POST /api/prepro/audit/finish, GET /api/prepro/story-review
Video & assetsPOST /api/prepro/assemble, GET /api/prepro/asset
FeedbackGET /api/prepro/feedback, PUT /api/prepro/feedback/beat, POST /api/prepro/feedback/mark-ok, GET /api/prepro/feedback/thumb, POST /api/prepro/feedback/export
Voices & MotionGET /api/prepro/voice/config, GET /api/prepro/voice/stock, POST/DELETE /api/prepro/character/voice/sample, POST/DELETE /api/prepro/character/voice, POST /api/prepro/character/voice/preview, GET /api/prepro/motion, POST /api/prepro/motion/estimate, POST /api/prepro/motion/start, GET /api/prepro/motion/job, POST /api/prepro/motion/cancel, GET /api/prepro/motion/timeline, PUT /api/prepro/motion/edit, POST /api/prepro/motion/approve
External board syncPOST /api/prepro/sync-codex

05Testing

Run the full test suite offline with python -m unittest discover -s tests — 379 tests with zero network access (providers are patched with fakes and tests load a fictional demo fixture rather than private user projects).

Coverage areaWhat is verified
Writing & importShort and multi-page PDF geometry parsing, dialogue/parenthetical preservation, Check-import element-type fixes
Story analysis & breakdownHeuristic and LLM bible, timeline, staging, cue-anchored moves, beat splitting, story-pack overlays, day arcs, location remaps
Prompt compiler & beat plannerPronoun/addressee resolution, active cast, performance/silence rules, physics locks, surface-finish rules, JSON schema validation and caching
Generation, repair & auditProvider fallback chain, reference priority, vision verifier inputs, bounded repair, orphan recovery, aspect-ratio checks, append-only cost pricing
Review & campaignsHuman feedback board, repair brief export, second-pass checkpoints, best-available selection, frozen replacement cohorts
Voices, motion & securityConsent-gated voice cloning, clean plates, Seedance audio routing, spend caps, job recovery, SSRF-guarded cast image search

06Technology stack

6.1 Python packages

PackageMin versionLicenseUsed for
FastAPI0.115MITHTTP API, routing, request validation
Uvicorn0.32BSD-3-ClauseASGI server; auto-reload in local development
Starlette (via FastAPI)—BSD-3-ClauseMiddleware, static responses
Pydantic2.0MITRequest bodies and export models
python-multipart0.0.9Apache-2.0PDF, image, and audio uploads
pypdf5.0BSD-3-ClauseScreenplay PDF parsing
ReportLab4.2BSD-styleScreenplay PDF export
Pillow10.0MIT-CMU (HPND)Image checks, LUTs, caption frames, format normalization
python-dotenv1.0BSD-3-ClauseLoading local environment config
openai2.0Apache-2.0OpenAI images/chat/vision, and xAI Grok endpoint
yt-dlp2024.8UnlicenseResolving YouTube streams for look references

6.2 System tools & frontend

ItemDetail
Python3.10+ (Docker uses 3.12; local dev tested on 3.14)
ffmpeg / ffprobeMP4 assembly, audio mixing, voice validation, YouTube frame capture
FrontendVanilla HTML, CSS, and JavaScript — no framework, no bundler, no CDN JavaScript
FontsCormorant Garamond, Outfit, JetBrains Mono (Google Fonts); Courier Prime bundled for PDF export
StorageLocal filesystem (atomic JSON and media files, no database)

6.3 Optional external services (key-gated)

ServiceEnv varsUsed for
OpenAI Images / Chat / VisionOPENAI_API_KEYStills, repairs, try-ons, beat planning, story analysis, vision verification
xAI Grok ImagineXAI_API_KEYSecondary image provider
PollinationsnoneFree text-to-image fallback
Google Programmable SearchGOOGLE_CSE_API_KEY, GOOGLE_CSE_CXCast likeness search
ElevenLabsELEVENLABS_API_KEYConsented character voices (clone, design, TTS, voice changer)
BytePlus ModelArk (Seedance 2.5)ARK_API_KEYImage-to-video motion clips
YouTubenoneMovie-look frame capture via yt-dlp