caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

680 lines
52 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ReelForge Vision 2026 — Shared Packages Architecture (Additive)
> **Scope.** An *additive* file+directory manifest for the **new shared packages** that let the
> ReelForge apps (`apps/api` Python, `apps/web` Next.js, `apps/mobile` Expo RN, `apps/desktop`
> Rust/GPUI + its `electron-legacy` React variant) share one source of truth for render specs,
> effect kernels, shot templates, caption styling, publishing clients, trends, growth analytics,
> event schemas, provider adapters, and ComfyUI workflows. It assumes the three existing packages
> already ship — `@reelforge/api-contract`, `@reelforge/sdk` (TS), `reelforge-sdk` (Python) — and
> only designs what is missing. It is the package-layer complement to
> [`apps-api.md`](./apps-api.md) and [`apps-mobile.md`](./apps-mobile.md): those add backend
> domains and mobile features; **this** extracts the cross-app contracts and pure logic they both
> depend on into reusable, versioned packages.
---
## 1. Overview & Design Rules
### 1.1 Why these packages exist (the seam)
Three problems force shared packages rather than per-app copies:
1. **Two authoritative renderers, one spec.** `apps/api/.../services/compose/compose_ffmpeg.py`
(Python) executes the real render; `apps/web` / `apps/desktop` / `apps/mobile` must *preview*
the same composition without a round-trip. A shared, declarative **render spec + filtergraph
builder** (`render-core`) prevents preview/output drift.
2. **Effect kernels defined once.** Camera moves and VFX presets (the backend `vfx.py` concepts)
must be identical in the preview UI and the Python executor. `effects-core` is the single
kernel registry, dual-emitted to TS and Python.
3. **Contracts that outlive any one app.** Shot templates, caption styles, trends, events,
provider metadata, and ComfyUI workflows are consumed by ≥2 apps in ≥2 languages. Each becomes
a **schema package** using the same canonical-schema → codegen pattern `api-contract` already
uses (`scripts/generate_types.py`, drift-check in CI).
### 1.2 Two package archetypes
| Archetype | Source of truth | Emits | Examples |
|---|---|---|---|
| **Schema package** (contract-only, dual-language) | canonical `schema/*.schema.json` | `src/generated/*.ts` **and** `python/<pkg>/*.py` via `scripts/generate_types.py` (drift-checked in CI, mirrors `api-contract`) | `shot-template-schema`, `trends-schema`, `comfy-workflow-schema`, `eventbus-types`, `provider-adapter-kit` |
| **Logic package** (behavior) | hand-written TS (pure, dependency-light) | `dist/*.js` + `.d.ts`; Python parity via a thin generated model layer where the backend also runs the logic | `render-core`, `effects-core`, `caption-engine`, `publishing-connectors`, `growth-analytics`, `ui-kit` |
> **Rule.** Schema packages contain **no behavior beyond pure validation**. Logic packages import
> schema packages, never the reverse. `ui-kit` is the only package allowed React/RN dependencies.
### 1.3 Conventions (match existing packages)
- **Naming:** npm scope `@reelforge/<name>`; Python distribution `reelforge-<name>` importing as
`reelforge_<name>`. MIT-licensed, `"type": "module"`, `"private": true` where not published.
- **Build:** `tsc` → `dist/`; `exports` map `types`+`import` (copy `api-contract/package.json`).
Scripts: `build`, `typecheck`, and for schema packages `contract:export` / `contract:check`.
- **Files 200–400 lines**, one responsibility; many small files over few large ones.
- **Immutability:** all builders return new objects; no in-place mutation (repo rule).
- **Validation at boundaries:** Zod in TS logic packages; Pydantic in generated Python.
- **Money is integer microdollars**; never floats (matches `core/money.py`).
- **No secrets in packages.** `publishing-connectors` takes tokens as inputs; never reads env or
stores keys — the API holds Fernet-encrypted tokens.
- **Workspaces:** add each package to root `package.json` `workspaces`; Python schema outputs are
consumed by `apps/api` via editable path installs (like `sdk-python`).
### 1.4 App/consumer legend
`api` = `apps/api` (Python) · `web` = `apps/web` (Next.js) · `mobile` = `apps/mobile` (Expo RN) ·
`desktop` = `apps/desktop` (Rust/GPUI — consumes **JSON contracts over HTTP**, not TS/React) ·
`electron` = `apps/desktop/electron-legacy` (React) · `sdk-ts` / `sdk-py` = the SDK packages.
> The native Rust desktop cannot import TS/React packages; it consumes the **schema packages'
> JSON Schema + the `/api/v1` contract**. Where a row lists `desktop`, it means "via generated
> JSON Schema / HTTP contract," and a Rust codegen target is noted in §16.
---
## 2. New-Directory Tree
```text
packages/
├── api-contract/ # EXTEND (existing) — new domain DTOs + OpenAPI slices (§14)
├── sdk-typescript/ # REGEN (existing) — new resource groups (§14)
├── sdk-python/ # REGEN (existing) — new resource groups (§14)
│
├── shot-template-schema/ # NEW schema (TS+Py) — Hook/Proof/Payoff/Loop slots (§3)
├── caption-engine/ # NEW logic (TS; Py port) — Hormozi/karaoke ASS builder(§4)
├── render-core/ # NEW logic (TS; Py executor) — filtergraph builder (§5)
├── effects-core/ # NEW schema+logic (TS+Py) — camera + VFX kernels (§6)
├── comfy-workflow-schema/ # NEW schema (TS+Py) — pinned ComfyUI graph artifacts (§7)
├── provider-adapter-kit/ # NEW schema+logic (TS+Py) — provider adapter contract (§8)
├── publishing-connectors/ # NEW logic (TS) — TikTok/YouTube/IG/X client SDK (§9)
├── trends-schema/ # NEW schema (TS+Py) — trend/sound + saturation score (§10)
├── growth-analytics/ # NEW logic (TS) — funnel/retention/A-B analytics lib (§11)
├── eventbus-types/ # NEW schema (TS+Py) — canonical event envelopes (§12)
└── ui-kit/ # NEW logic (TS/React) — shared components web+desktop (§13)
```
Each package's internal skeleton (meta files, common to all):
```text
<package>/
├── package.json
├── tsconfig.json
├── README.md
├── src/index.ts # barrel export
└── src/… # per §
# schema packages additionally:
├── schema/<name>.schema.json # canonical source of truth
├── scripts/generate_types.py # emit src/generated/*.ts + python/… (mirrors api-contract)
├── scripts/check_drift.py # CI drift guard (fail if generated ≠ schema)
├── src/generated/… # generated TS types (checked in)
└── python/reelforge_<name>/… # generated Python models (editable-installed into apps/api)
```
---
## 3. `shot-template-schema` — Genre Segment-Slot Schema (TS + Python) — Phase 1
Canonical schema for genre templates as **named segment slots** (Hook / Proof / Payoff / Loop)
bound to compose tracks, audio layers, caption presets, and transitions. This is the contract the
backend `templates/` domain seeds into DB and the frontends render in the picker — one definition,
no drift.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/shot-template-schema`). | TS | all |
| `src/index.ts` | Barrel: types + presets + validators. | TS | web, mobile, electron |
| `src/roles.ts` | `SlotRole` union (`hook`/`setup`/`proof1`/`proof2`/`rising`/`climax`/`payoff`/`loop`/`cta`) + ordering. | TS+Py | api, web, mobile |
| `src/slots.ts` | `SegmentSlot` type: role, `t_start`/`t_end`, track bindings, audio layers, caption preset ref, transition in/out. | TS+Py | api, web, mobile, render-core |
| `src/track-binding.ts` | Slot→compose track/overlay/PiP-region binding descriptor. | TS+Py | api, render-core |
| `src/audio-layers.ts` | `AudioLayer` spec (narration/sfx/bgm) + duck-target hints. | TS+Py | api, render-core, caption-engine |
| `src/transitions.ts` | Transition kinds (cut/whip/zoom-in/crossfade) + params + frame-nudge (-2/-3). | TS+Py | api, render-core |
| `src/aspect.ts` | Aspect + per-platform safe-zone constants (12–20% TikTok / ~9% Shorts, Y=62–65%). | TS+Py | api, web, mobile, caption-engine |
| `src/genre.ts` | `Genre` union + genre metadata (label, default aspect, faceless flag). | TS+Py | web, mobile |
| `src/template.ts` | `ShotTemplate` + immutable `ShotTemplateVersion` (semver, slot graph, preset refs, changelog). | TS+Py | api, web, mobile |
| `src/instance.ts` | `TemplateInstance` (compiled): template-version id, slot inputs, preset hash, produced reel id. | TS+Py | api, render-core |
| `src/defaults.ts` | Pure per-genre defaults: durations, tension-bump cadence, CTA placement, min-hook clearance. | TS+Py | api, web, mobile |
| `src/validation.ts` | Pure slot-input validators (durations sum, required media, aspect, safe-zone) → typed errors. | TS+Py | api, web, mobile |
| `src/hash.ts` | Deterministic preset/version hashing for immutable instance pinning. | TS+Py | api |
| `src/presets/index.ts` | Preset registry loader + lookup by slug/genre. | TS+Py | api, web, mobile |
| `src/presets/minecraft-reddit-split.ts` | Seed: top ~55% narrated Reddit + bottom ~45% parkour, cold-open-first, 5s bumps, Part-2 loop. | TS+Py | api |
| `src/presets/asmr-loop.ts` | Seed: single ~5s seamless loop, trigger-in mid-action, no voice/music, invisible seam. | TS+Py | api |
| `src/presets/brainrot-meme.ts` | Seed: recurring AI character, 0–1.5s pattern-interrupt, escalating nonsense. | TS+Py | api |
| `src/presets/anime-beat-edit.ts` | Seed: beat-synced montage, hardest frame first, story-beat trims, frame nudge. | TS+Py | api |
| `src/presets/movie-recap.ts` | Seed: specific-angle narration, hook-in-first-20-30s, Hormozi captions. | TS+Py | api |
| `src/presets/fake-podcast.ts` | Seed: 2-host mid-convo hook, speaker-cut turns, Mode A lip-sync / Mode B split. | TS+Py | api |
| `src/presets/gameplay-story.ts` | Seed: any gameplay + narration split-screen, narration-above-mix. | TS+Py | api |
| `src/presets/platform-hook-open.ts` | Seed: composable 0–5s opener prefix (pattern-interrupt + promise + loop-back). | TS+Py | api |
| `src/presets/power-washing-podcast.ts` | Seed: cheap fake-podcast variant (B-roll top + captions bottom). | TS+Py | api |
| `src/presets/glass-cutting-asmr.ts` | Seed: single-trigger ASMR, surreal scale, external-mic audio. | TS+Py | api |
| `src/presets/gta-narration.ts` | Seed: GTA split-screen narration variant. | TS+Py | api |
| `src/presets/trend-audio-remix.ts` | Seed: trending-sound-first (edit muted → relink native sound on upload). | TS+Py | api |
| `src/presets/retention-ab-hook-pack.ts` | Seed: 1-body/N-hooks A/B experiment template. | TS+Py | api |
| `src/presets/episodic-character-series.ts` | Seed: serialized recurring-character format on a fixed lock. | TS+Py | api |
| `schema/shot-template.schema.json` | Canonical JSON Schema (roles, slots, template, instance). | — | api (Pydantic), desktop |
| `scripts/generate_types.py` | Emit `src/generated/*.ts` + `python/reelforge_shot_template/*.py`. | Py | build |
| `scripts/check_drift.py` | CI guard: fail if generated ≠ schema/presets. | Py | CI |
| `src/generated/models.ts` | Generated TS types from schema. | TS | web, mobile |
| `python/reelforge_shot_template/__init__.py` | Python package init + exports. | Py | api |
| `python/reelforge_shot_template/models.py` | Generated Pydantic models. | Py | api |
| `python/reelforge_shot_template/presets.py` | Generated preset seed rows (mirrors `catalog/seed_data.py`). | Py | api |
| `python/reelforge_shot_template/validation.py` | Python parity of `validation.ts`. | Py | api |
**Consumed by:** `api` (`templates/` domain seeds + compiles), `web`/`mobile`/`electron` (picker),
`render-core` (§5, compiles slots→filtergraph), `caption-engine` (§4, resolves caption presets).
---
## 4. `caption-engine` — Hormozi / Karaoke ASS Builder (TS logic; Python port) — Phase 1
Pure caption-styling library: word-level ASR timestamps → styled **ASS** subtitle string. Shared so
the client renders an exact caption preview and the Python worker burns the identical ASS. The
backend `services/captions/` calls a thin Python port that consumes the same style schema.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/caption-engine`). | TS | all |
| `src/index.ts` | Barrel: builders + presets + types. | TS | web, mobile, electron |
| `src/words.ts` | `Word`/`Segment` timestamp DTOs (WhisperX ±50ms shape) — re-exports from api-contract. | TS | web, mobile |
| `src/style.ts` | `CaptionStyle` type (font, weight, fill, highlight color, outline, shadow, size %). | TS | api, web, mobile |
| `src/ass/document.ts` | ASS document assembler ([Script Info]/[V4+ Styles]/[Events]). | TS | api-port, web |
| `src/ass/styles.ts` | ASS style-line builder from `CaptionStyle`. | TS | api-port |
| `src/ass/dialogue.ts` | Per-word dialogue event builder with `\k` karaoke timing tags. | TS | api-port |
| `src/ass/color.ts` | Hex → ASS `&HBBGGRR` color conversion + alpha. | TS | api-port |
| `src/ass/timing.ts` | Word timestamps → centisecond karaoke spans; gap/overlap normalization. | TS | api-port |
| `src/hormozi.ts` | Hormozi preset: Montserrat Black ALL CAPS, white base + `#FFD93D` highlight, 1–2 words. | TS | web, mobile, api-port |
| `src/keyword-highlight.ts` | Pure key-noun/verb selector deciding which word gets the highlight color. | TS | api-port |
| `src/safezone.ts` | Per-platform lower-third safe-zone positioning (imports `shot-template-schema/aspect`). | TS | web, mobile, api-port |
| `src/grouping.ts` | Chunk words into 1–2-word display groups synced to shot cadence. | TS | api-port |
| `src/presets/index.ts` | Caption preset registry (hormozi, karaoke-classic, minimal-top-label, brainrot-popin). | TS | web, mobile |
| `src/presets/karaoke-classic.ts` | Line-highlight karaoke preset. | TS | web, api-port |
| `src/presets/minimal-top-label.ts` | ASMR single-word top-center out-of-focal label. | TS | web, api-port |
| `src/presets/brainrot-popin.ts` | Centered ALL-CAPS 1–2 word pop-in preset. | TS | web, api-port |
| `src/preview.ts` | Style → HTML/canvas preview model (no ASS) for the picker. | TS | web, mobile, electron |
| `src/validate.ts` | Zod boundary validation of incoming word JSON + style. | TS | web, mobile |
| `python/reelforge_caption_engine/__init__.py` | Python port init. | Py | api |
| `python/reelforge_caption_engine/ass_builder.py` | Python ASS builder parity (used by `services/captions`). | Py | api |
| `python/reelforge_caption_engine/style.py` | Pydantic `CaptionStyle` + preset parity. | Py | api |
| `python/reelforge_caption_engine/README.md` | Parity contract note (TS is source; port must match golden fixtures). | Py | api |
| `test/fixtures/golden/*.ass` | Shared golden ASS fixtures asserting TS≡Python byte-parity. | — | CI |
**Consumed by:** `web`/`mobile`/`electron` (live caption preview + preset picker),
`api` (`services/captions` burns identical ASS via the Python port), `render-core` (embeds ASS
overlay in the filtergraph).
---
## 5. `render-core` — Shared FFmpeg / Compose Filtergraph Builder (TS logic; Python executor) — Phase 1
The declarative **RenderSpec** and the pure **filtergraph builder** that turns a spec (tracks,
overlays, PiP split, captions, loop flags, audio bus, ducking) into an FFmpeg filter_complex string
+ input/output plan. The client uses it for preview timing and to *serialize the spec* to the API;
the Python `compose_ffmpeg.py` consumes the **same spec** (via a generated Python model) so preview
matches output. `render-core` owns spec→filtergraph; the executor owns process spawning.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/render-core`). | TS | all |
| `src/index.ts` | Barrel: spec types + builder + serializer. | TS | web, mobile, electron |
| `src/spec/render-spec.ts` | `RenderSpec` root (tracks, overlays, captions, audio bus, loop flags, aspect, output). | TS+Py | api, web, mobile |
| `src/spec/track.ts` | `Track` (video/image/color) with time range, transform, z-order. | TS+Py | api, web |
| `src/spec/overlay.ts` | `Overlay` (text/image/caption/badge) with anchor + safe-zone. | TS+Py | api, web |
| `src/spec/pip.ts` | Picture-in-picture split-region spec (top/bottom %, chromakey). | TS+Py | api, web |
| `src/spec/audio-bus.ts` | Audio bus/mix spec (narration/sfx/bgm gains + sidechain duck targets). | TS+Py | api |
| `src/spec/loop.ts` | Seamless-loop flags (loop-back last=first, loop count, seam-crossfade). | TS+Py | api |
| `src/spec/transform.ts` | Pan/zoom/scale/crop transform primitives (drives camera moves from effects-core). | TS+Py | api, effects-core |
| `src/spec/output.ts` | Output profile (codec, bitrate, fps, aspect, loudness LUFS). | TS+Py | api |
| `src/builder/filtergraph.ts` | Pure `RenderSpec` → FFmpeg `filter_complex` graph string. | TS | api-port, web |
| `src/builder/nodes.ts` | Filter-node primitives (overlay, scale, crop, chromakey, xfade, amix, sidechaincompress). | TS | api-port |
| `src/builder/labels.ts` | Deterministic filter-pad label allocation + graph wiring. | TS | api-port |
| `src/builder/inputs.ts` | Input-plan builder (`-i` ordering, loop/seek flags per source). | TS | api-port |
| `src/builder/captions.ts` | Wire `caption-engine` ASS output as a `subtitles`/`ass` filter node. | TS | api-port |
| `src/builder/audio.ts` | Audio-bus → `amix`/`sidechaincompress` (auto-duck) subgraph. | TS | api-port |
| `src/builder/loops.ts` | Seamless-loop subgraph (seam crossfade / trim to loop point). | TS | api-port |
| `src/builder/command.ts` | Full `ffmpeg` argv assembler (inputs + filtergraph + output map). | TS | api-port |
| `src/preview/timeline.ts` | Spec → preview timeline model (clip rects, durations) for the editor UI. | TS | web, mobile, electron |
| `src/preview/estimate.ts` | Pure render-duration/complexity estimate (drives burn-preview UX hint). | TS | web, mobile |
| `src/serialize.ts` | Canonical JSON (de)serialization of `RenderSpec` for API transport. | TS | web, mobile, api |
| `src/validate.ts` | Zod validation + invariant checks (durations, safe-zone, aspect) before submit. | TS | web, mobile |
| `python/reelforge_render_core/__init__.py` | Python port init. | Py | api |
| `python/reelforge_render_core/spec.py` | Generated Pydantic `RenderSpec` model (source-of-truth for the executor). | Py | api |
| `python/reelforge_render_core/filtergraph.py` | Python parity of the filtergraph builder (feeds `compose_ffmpeg.py`). | Py | api |
| `test/fixtures/golden/*.json→*.txt` | Golden spec→filtergraph fixtures asserting TS≡Python parity. | — | CI |
**Consumed by:** `api` (`services/compose/compose_ffmpeg.py` consumes `RenderSpec` + Python
filtergraph parity), `web`/`mobile`/`electron` (preview timeline + client-side validation),
`shot-template-schema` compiler emits `RenderSpec`, `effects-core` supplies transforms.
> **Seam preserved.** `render-core` does **not** spawn processes or touch storage — it builds specs
> and strings. The existing Celery worker + `compose_ffmpeg.py` remain the only executor.
---
## 6. `effects-core` — Camera + VFX Preset Kernels (TS + Python) — Phase 1
The shared **kernel registry** for camera moves (push-in, orbit, handheld, whip) and VFX presets
(glitch, film-grain, RGB-split, light-leak, shake) — the `vfx.py` concepts, extracted so the
preview UI and the Python executor apply identical math. Kernels are pure parametric functions
producing `render-core` transforms / filter params.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/effects-core`). | TS | all |
| `src/index.ts` | Barrel: kernels + registry + types. | TS | web, mobile, electron |
| `src/types.ts` | `CameraKernel` / `VfxKernel` interfaces (params schema, `apply(t)` → transform/filter). | TS+Py | api, web |
| `src/keyframe.ts` | Keyframe + easing primitives (linear/ease/spring) shared by all kernels. | TS+Py | api, web |
| `src/curve.ts` | Pure interpolation curves (bezier, spring, noise) for motion. | TS | api-port, web |
| `src/registry.ts` | Kernel registry (id → kernel) + lookup/list by category. | TS+Py | api, web, mobile |
| `src/camera/push-in.ts` | Slow push-in / pull-out zoom kernel. | TS+Py | api, web |
| `src/camera/orbit.ts` | Orbit / parallax pan kernel. | TS+Py | api, web |
| `src/camera/handheld.ts` | Handheld micro-shake kernel (noise-driven). | TS+Py | api, web |
| `src/camera/whip-pan.ts` | Whip-pan transition kernel (pairs with cut). | TS+Py | api, web |
| `src/camera/ken-burns.ts` | Ken-Burns pan+zoom over a still. | TS+Py | api, web |
| `src/camera/snap-zoom.ts` | Beat-synced snap-zoom (hook pattern-interrupt). | TS+Py | api, web |
| `src/vfx/glitch.ts` | Digital-glitch/datamosh kernel. | TS+Py | api, web |
| `src/vfx/rgb-split.ts` | Chromatic-aberration RGB-split kernel. | TS+Py | api, web |
| `src/vfx/film-grain.ts` | Film-grain + vignette kernel. | TS+Py | api, web |
| `src/vfx/light-leak.ts` | Light-leak / bloom overlay kernel. | TS+Py | api, web |
| `src/vfx/shake.ts` | Beat-reactive shake/impact kernel. | TS+Py | api, web |
| `src/vfx/speed-ramp.ts` | Speed-ramp (slow-mo / time-remap) kernel. | TS+Py | api, web |
| `src/beat-sync.ts` | Map beat timestamps → kernel trigger schedule (pairs with `render-core`). | TS+Py | api, web |
| `src/to-render.ts` | Adapter: kernel output → `render-core` transform/filter node params. | TS | api-port, web |
| `src/validate.ts` | Zod param validation per kernel. | TS | web, mobile |
| `schema/effect-kernel.schema.json` | Canonical kernel-param schema. | — | api, desktop |
| `scripts/generate_types.py` · `scripts/check_drift.py` | Emit + drift-guard TS/Py kernel params. | Py | build, CI |
| `src/generated/params.ts` | Generated per-kernel param types. | TS | web, mobile |
| `python/reelforge_effects_core/__init__.py` | Python port init. | Py | api |
| `python/reelforge_effects_core/kernels.py` | Python kernel parity (feeds `vfx.py`). | Py | api |
| `python/reelforge_effects_core/registry.py` | Python registry parity. | Py | api |
| `test/fixtures/golden/*.json` | Golden kernel-sample fixtures for TS≡Python parity. | — | CI |
**Consumed by:** `api` (`vfx.py` / compose apply kernels via Python parity), `web`/`mobile`/
`electron` (effect picker + live preview), `render-core` (consumes transform output).
---
## 7. `comfy-workflow-schema` — Pinned ComfyUI Workflow Artifacts (TS + Python) — Phase 4
Contract for treating ComfyUI graphs as **pinned, versioned artifacts** (node commits + weight refs
+ inputs contract locked per version). Shared so the render-farm registry, the provider adapters,
and the desktop/agency endpoint layer all reference the same immutable workflow identity.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/comfy-workflow-schema`). | TS | all |
| `src/index.ts` | Barrel: workflow + version + input types. | TS | web, electron |
| `src/workflow.ts` | `ComfyWorkflow` (slug, category, description). | TS+Py | api |
| `src/version.ts` | `WorkflowVersion` (graph hash, node commit set, weight refs, created_at). | TS+Py | api |
| `src/graph.ts` | ComfyUI graph JSON typing (nodes, links, widget values). | TS+Py | api |
| `src/inputs.ts` | `WorkflowInputContract` (typed input slots + defaults + ranges). | TS+Py | api, web |
| `src/outputs.ts` | `WorkflowOutputContract` (output kinds + asset shapes). | TS+Py | api |
| `src/pin.ts` | Deterministic graph-hash + node-commit pinning (reproducibility). | TS+Py | api |
| `src/catalog/index.ts` | Registry of first-party workflow descriptors. | TS+Py | api |
| `src/catalog/wan-i2v.ts` | Wan 2.2 I2V workflow descriptor + input contract. | TS+Py | api |
| `src/catalog/wan-flf2v.ts` | Wan FLF2V start→end + RIFE/FILM 2x + upscale descriptor. | TS+Py | api |
| `src/catalog/flux-first-frame.ts` | FLUX first-frame T2I/I2I descriptor. | TS+Py | api |
| `src/catalog/lora-train-wan.ts` | Wan 2.2 LoRA-training workflow descriptor (character lock). | TS+Py | api |
| `src/catalog/lipsync-musetalk.ts` | MuseTalk lipsync workflow descriptor. | TS+Py | api |
| `src/catalog/lipsync-latentsync.ts` | LatentSync lipsync workflow descriptor. | TS+Py | api |
| `src/validate.ts` | Zod validation of input contracts against submitted values. | TS | web, api |
| `schema/comfy-workflow.schema.json` | Canonical workflow-artifact schema. | — | api, desktop |
| `scripts/generate_types.py` · `scripts/check_drift.py` | Emit + drift-guard. | Py | build, CI |
| `src/generated/models.ts` | Generated TS types. | TS | web, electron |
| `python/reelforge_comfy_workflow/__init__.py` | Python port init. | Py | api |
| `python/reelforge_comfy_workflow/models.py` | Generated Pydantic models (feeds `services/render/workflows/registry.py`). | Py | api |
| `python/reelforge_comfy_workflow/catalog.py` | Generated first-party workflow descriptors. | Py | api |
**Consumed by:** `api` (`services/render/workflows/registry.py` pins/loads workflows),
`web`/`electron` (agency workflow browser), `provider-adapter-kit` (adapters reference workflow ids).
---
## 8. `provider-adapter-kit` — Provider Adapter Contract + Metadata (TS + Python) — Phase 1→4
The shared **adapter contract** (`ProviderRun`, `NormalizedUsage`, async job envelope) plus the
**license-class** and **deprecation-metadata** registries. Extracted so the routing engine (Python),
the SDKs, and the burn-preview UIs agree on model identity, license class, and sunset dates without
duplication. Behavior (HTTP calls) stays in `apps/api`; this package is the contract + metadata + a
TS reference stub for tests.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/provider-adapter-kit`). | TS | all |
| `src/index.ts` | Barrel: contract types + metadata registries. | TS | web, mobile, sdk-ts |
| `src/contract/provider-run.ts` | `ProviderRun` request/response contract. | TS+Py | api, sdk-ts |
| `src/contract/usage.ts` | `NormalizedUsage` (units, cost microdollars, success flag). | TS+Py | api, sdk-ts |
| `src/contract/envelope.ts` | Unified async job envelope (`IN_QUEUE`/`IN_PROGRESS`/`COMPLETED`/`FAILED`) + poll/webhook shape. | TS+Py | api, web, mobile |
| `src/contract/capabilities.ts` | Provider capability descriptor (modalities, max duration, aspect, audio). | TS+Py | api, web |
| `src/license/classes.ts` | `LicenseClass` union (`commercial-safe`/`non-commercial`/`territorial`) + paying-user exclusion rule. | TS+Py | api, web, mobile |
| `src/license/registry.ts` | Model→license-class map (Wan/LTX safe; XTTS/F5/Hunyuan flagged). | TS+Py | api, web |
| `src/deprecation/lifecycle.ts` | `ModelLifecycle` (active/deprecating/sunset) + sunset dates (Sora 2026-09-24, Runway 2026-07-30). | TS+Py | api, web, mobile |
| `src/deprecation/migrate.ts` | Pure auto-migration hint (deprecating model → recommended replacement). | TS+Py | api, web |
| `src/models/registry.ts` | Provider/model identity registry (id, provider, category, workflow ref). | TS+Py | api, web, mobile |
| `src/models/categories.ts` | Model category enum (t2v/i2v/flf2v/t2i/i2i/tts/music/lipsync/foley). | TS+Py | api, web |
| `src/testkit/fake-backend.ts` | In-memory reference backend implementing the envelope (adapter contract tests). | TS | sdk-ts, CI |
| `src/validate.ts` | Zod validation of envelope transitions + usage. | TS | web, mobile |
| `schema/provider-adapter.schema.json` | Canonical adapter/metadata schema. | — | api, desktop |
| `scripts/generate_types.py` · `scripts/check_drift.py` | Emit + drift-guard. | Py | build, CI |
| `src/generated/models.ts` | Generated TS types. | TS | web, mobile |
| `python/reelforge_provider_adapter/__init__.py` | Python port init. | Py | api |
| `python/reelforge_provider_adapter/contract.py` | Pydantic contract (base for `routing/providers/*`). | Py | api |
| `python/reelforge_provider_adapter/license.py` | License-class registry parity (feeds `_license_class.py`). | Py | api |
| `python/reelforge_provider_adapter/deprecation.py` | Lifecycle/sunset registry parity (feeds `_deprecation.py`). | Py | api |
**Consumed by:** `api` (`routing/providers/*` base + `_license_class.py`/`_deprecation.py`),
`web`/`mobile` (burn-preview license badge + deprecation hint), `sdk-ts` (typed model list),
`comfy-workflow-schema` (workflow refs).
---
## 9. `publishing-connectors` — TikTok/YouTube/IG/X Client SDK (TS logic) — Phase 2
A dependency-light **client SDK** wrapping each platform's publish + analytics API behind one
`Publisher` interface. Tokens are passed **in** (never read from env/store); the API layer holds
Fernet-encrypted tokens and injects them. Used server-side by a Node companion and (read-only OAuth
helpers) client-side; the Python backend mirrors the same request shapes via `sdk-py`-style parity.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/publishing-connectors`). | TS | all |
| `src/index.ts` | Barrel: `Publisher` interface + platform clients + errors. | TS | api(node), web, mobile |
| `src/publisher.ts` | `Publisher` protocol (`publish`, `scheduleSupported`, `caps`, `refresh`, `fetchAnalytics`). | TS | api, web |
| `src/errors.ts` | Typed connector errors (auth/cap/watermark/rate) carrying platform detail. | TS | api, web |
| `src/http.ts` | Tiny `fetch` wrapper (retry, timeout, correlation) — zero deps, matches sdk-ts style. | TS | internal |
| `src/caps.ts` | Per-platform capability/limit table (daily caps, aspect, duration, caption limits). | TS+Py | api, web, mobile |
| `src/watermark-policy.ts` | Foreign-watermark rejection rules per platform (cross-post suppression guard). | TS+Py | api, web, mobile |
| `src/oauth/pkce.ts` | PKCE verifier/challenge helpers (client-safe, no secret). | TS | web, mobile, electron |
| `src/oauth/config.ts` | Per-platform OAuth endpoints, scopes, redirect descriptors. | TS+Py | api, web, mobile |
| `src/oauth/exchange.ts` | Auth-code → token exchange request shapes (executed by API). | TS | api |
| `src/tiktok/client.ts` | TikTok Content Posting API adapter (no native scheduling → ReelForge queue; audit-aware). | TS | api |
| `src/tiktok/analytics.ts` | TikTok analytics/Qualified-View + retention pull. | TS | api |
| `src/instagram/client.ts` | IG Graph container+poll 2-step publish; 25–50/24h cap awareness. | TS | api |
| `src/instagram/analytics.ts` | IG insights (sends/reach) pull. | TS | api |
| `src/youtube/client.ts` | YouTube Data API upload + Shorts metadata. | TS | api |
| `src/youtube/test-compare.ts` | YouTube Test-and-Compare title/thumbnail helper. | TS | api |
| `src/youtube/analytics.ts` | YouTube Analytics (viewed-vs-swiped, watch-time) pull. | TS | api |
| `src/x/client.ts` | X pay-per-use posting ($0.015/post, $0.20 w/link) with usage note for wallet metering. | TS | api |
| `src/x/analytics.ts` | X impression/engagement pull. | TS | api |
| `src/aggregator/client.ts` | Ayrshare/Blotato/Upload-Post fallback behind the same `Publisher`. | TS | api |
| `src/normalize/analytics.ts` | Normalize per-platform analytics → shared retention-curve shape (from api-contract). | TS+Py | api, web |
| `src/validate.ts` | Zod validation of publish requests + platform payloads. | TS | api, web |
| `python/reelforge_publishing_connectors/__init__.py` | Python parity init. | Py | api |
| `python/reelforge_publishing_connectors/caps.py` | Caps + watermark-policy parity (feeds `publishing/policy.py`). | Py | api |
| `python/reelforge_publishing_connectors/oauth_config.py` | OAuth config parity (feeds `connectors/oauth_flows.py`). | Py | api |
**Consumed by:** `api` (`publishing/connectors/*` wrap these clients; `policy.py` uses caps +
watermark rules), `web`/`mobile`/`electron` (PKCE OAuth start + cap-aware composer),
`normalize/analytics` feeds the shared `RetentionCurve` DTO.
> **Security seam.** No token persistence, no env reads. The API decrypts Fernet tokens and passes
> them per-call; connectors are stateless.
---
## 10. `trends-schema` — Trend / Sound + Saturation Score (TS + Python) — Phase 2
Canonical trend/sound DTOs + the **pure saturation/decay/velocity scoring** so the trend feed reads
identically on backend, web, and mobile. Scrapers stay in `apps/api`; scoring math is shared.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/trends-schema`). | TS | all |
| `src/index.ts` | Barrel: types + scorer. | TS | web, mobile |
| `src/snapshot.ts` | `TrendSnapshot` (source, platform, entity type, payload, observed_at). | TS+Py | api, web |
| `src/entity.ts` | `TrendEntity` unions (sound/hashtag/creator) + identity. | TS+Py | api, web, mobile |
| `src/sound.ts` | `TrendingSound` (platform id, title, usage curve, ad-safe flag). | TS+Py | api, web, mobile |
| `src/score.ts` | `TrendScore` (saturation, velocity, decay, computed_at) DTO. | TS+Py | api, web, mobile |
| `src/scoring/saturation.ts` | Pure rising-but-not-peaked saturation from a usage series. | TS+Py | api, web, mobile |
| `src/scoring/velocity.ts` | Pure adoption-velocity computation. | TS+Py | api, web |
| `src/scoring/decay.ts` | Pure decay/half-life computation. | TS+Py | api, web |
| `src/scoring/index.ts` | Composite score aggregator. | TS+Py | api, web, mobile |
| `src/ad-safe.ts` | Cross-platform (Meta-compatible) ad-safe sound classification rules. | TS+Py | api, web |
| `src/validate.ts` | Zod validation of snapshots + scores. | TS | web, mobile |
| `schema/trend.schema.json` | Canonical trend schema. | — | api, desktop |
| `scripts/generate_types.py` · `scripts/check_drift.py` | Emit + drift-guard. | Py | build, CI |
| `src/generated/models.ts` | Generated TS types. | TS | web, mobile |
| `python/reelforge_trends/__init__.py` | Python port init. | Py | api |
| `python/reelforge_trends/models.py` | Generated Pydantic models. | Py | api |
| `python/reelforge_trends/scoring.py` | Scoring parity (feeds `trends/scoring.py`). | Py | api |
| `test/fixtures/golden/*.json` | Golden series→score fixtures for TS≡Python parity. | — | CI |
**Consumed by:** `api` (`trends/` domain scoring + DTOs), `web`/`mobile` (trend feed + create-from-
trend), `growth-analytics` (trend adoption inputs).
---
## 11. `growth-analytics` — Funnel / Retention / A-B Analytics Lib (TS logic) — Phase 3→5
Pure client-and-server analytics utilities: activation-funnel modeling, retention-curve normalization
+ reach-tier mapping, hook-strength scoring, and A/B winner selection. No I/O — takes data, returns
verdicts — so web, mobile, and the Python backend compute identical numbers.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/growth-analytics`). | TS | all |
| `src/index.ts` | Barrel: funnel + retention + hook + ab utilities. | TS | web, mobile |
| `src/retention/curve.ts` | Normalize per-second retention samples → 0..1 curve. | TS+Py | api, web, mobile |
| `src/retention/thresholds.ts` | Reach-tier mapping (<60% minimal / 70–85% 2.2x / >85% viral). | TS+Py | api, web, mobile |
| `src/retention/dropoff.ts` | Detect biggest drop-off points + first-3s subscore. | TS+Py | api, web |
| `src/hook/score.ts` | Hook-strength score (first-3s motion/contrast/text/audio-onset heuristics) vs 70% gate. | TS+Py | api, web, mobile |
| `src/hook/suggestions.ts` | Cold-open rewrite suggestion selector when below threshold. | TS+Py | api, web |
| `src/ab/winner.ts` | Retention-weighted winner selection (completion + avg watch, not vanity). | TS+Py | api, web |
| `src/ab/spread.ts` | Auto-schedule spread planner (variants over days/accounts). | TS+Py | api, web |
| `src/funnel/activation.ts` | Activation-funnel model (capture→create→approve→publish, time-to-first-clip). | TS+Py | api, web, mobile |
| `src/funnel/expansion.ts` | Expansion-loop (NRR) math (seat/volume/shared-credit signals). | TS+Py | api, web |
| `src/cadence/planner.ts` | Cadence recommendation by account maturity (warmed vs new). | TS+Py | api, web, mobile |
| `src/cadence/cannibalization.ts` | Self-cannibalization spacing/throttle decision. | TS+Py | api, web |
| `src/best-time.ts` | Best-time-to-post estimator from first-hour data. | TS+Py | api, web |
| `src/burn/preview.ts` | Per-model burn preview math (credits/$/keepers-left) — reads price DTOs. | TS+Py | api, web, mobile |
| `src/validate.ts` | Zod validation of analytics inputs. | TS | web, mobile |
| `python/reelforge_growth_analytics/__init__.py` | Python parity init. | Py | api |
| `python/reelforge_growth_analytics/retention.py` | Retention/threshold parity (feeds `publishing/analytics/retention.py`). | Py | api |
| `python/reelforge_growth_analytics/hook.py` | Hook-score parity (feeds `services/loops/hook_predictor.py`). | Py | api |
| `python/reelforge_growth_analytics/ab.py` | Winner-selection parity (feeds `experiments/winner.py`). | Py | api |
| `test/fixtures/golden/*.json` | Golden analytics fixtures for TS≡Python parity. | — | CI |
**Consumed by:** `web`/`mobile` (hook gauge, retention chart, cadence hints, burn preview),
`api` (analytics/loops/experiments parity), `telemetry` funnels.
---
## 12. `eventbus-types` — Canonical Event Envelopes (TS + Python) — Phase 2
The shared **event catalog** so the backend outbox, the SDK webhook types, and the client
notification router all agree on event names + payloads. Transport (outbox/dispatch) stays in
`apps/api`; only the schema is shared.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/eventbus-types`). | TS | all |
| `src/index.ts` | Barrel: envelope + event union + guards. | TS | web, mobile, sdk-ts |
| `src/envelope.ts` | `EventEnvelope<T>` (id, type, occurred_at, workspace, dedupe key, payload). | TS+Py | api, web, mobile, sdk |
| `src/event-type.ts` | Canonical `EventType` union (single source for names). | TS+Py | api, web, mobile, sdk |
| `src/events/job.ts` | `JobCompleted` / `JobFailed` payloads. | TS+Py | api, web, mobile, sdk |
| `src/events/publish.ts` | `PublishSucceeded` / `PublishFailed` payloads. | TS+Py | api, web, mobile, sdk |
| `src/events/analytics.ts` | `RetentionIngested` / `PerformanceIngested` payloads. | TS+Py | api, web, sdk |
| `src/events/experiment.ts` | `WinnerSelected` payload. | TS+Py | api, web, sdk |
| `src/events/gateway.ts` | `KeySpendExceeded` / `PlanChanged` payloads. | TS+Py | api, web, sdk |
| `src/events/marketplace.ts` | `SubmissionApproved` / `PayoutPaid` payloads. | TS+Py | api, web, mobile, sdk |
| `src/guards.ts` | Type guards / discriminated-union narrowing per event. | TS | web, mobile, sdk-ts |
| `src/push-map.ts` | Event→push/notification/deep-link mapping table (client). | TS | web, mobile |
| `schema/event.schema.json` | Canonical event schema (all payloads). | — | api, desktop |
| `scripts/generate_types.py` · `scripts/check_drift.py` | Emit + drift-guard. | Py | build, CI |
| `src/generated/events.ts` | Generated TS types. | TS | web, mobile, sdk-ts |
| `python/reelforge_eventbus/__init__.py` | Python port init. | Py | api |
| `python/reelforge_eventbus/events.py` | Generated Pydantic events (feeds `events/types.py`). | Py | api |
**Consumed by:** `api` (`events/types.py`, outbox payloads), `sdk-ts`/`sdk-py` (webhook event
types), `web`/`mobile` (notification router + deep-link dispatch).
---
## 13. `ui-kit` — Shared React Components (TS/React) — Phase 1→ongoing
The shared component + design-token library for the **React** surfaces: `apps/web` (Next.js) and
`apps/desktop/electron-legacy` (React). It also exports **framework-free design tokens** (JSON) that
`apps/mobile` (via its own `src/shared/ui`) and `apps/desktop` (Rust/GPUI theme) re-map, so all four
apps share one palette/scale even where components can't be shared. Web-only components are
`.tsx`; tokens are plain TS/JSON.
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `package.json` · `tsconfig.json` · `README.md` | Package meta (`@reelforge/ui-kit`); peer-deps `react`, `react-dom`. | TS | web, electron |
| `src/index.ts` | Barrel: components + hooks + tokens. | TS | web, electron |
| `src/tokens/colors.ts` | Named color tokens (base/surface/border/accent/success/error/muted + platform brand). | TS | web, electron |
| `src/tokens/spacing.ts` | 4pt spacing scale. | TS | web, electron |
| `src/tokens/typography.ts` | Type scale + weights. | TS | web, electron |
| `src/tokens/radii.ts` · `src/tokens/z-index.ts` | Radius + z-index tokens. | TS | web, electron |
| `src/tokens/tokens.json` | Framework-free token export (re-mapped by mobile + Rust desktop). | JSON | mobile, desktop |
| `src/theme/ThemeProvider.tsx` | Theme context + dark-theme default (`#0b0b12`/`#15151f`/`#6a5bff`). | TS | web, electron |
| `src/primitives/Button.tsx` | Primary/secondary/ghost/danger button + loading. | TS | web, electron |
| `src/primitives/IconButton.tsx` | Icon-only pressable. | TS | web, electron |
| `src/primitives/Card.tsx` · `src/primitives/Divider.tsx` | Surface card + hairline. | TS | web, electron |
| `src/primitives/TextField.tsx` · `src/primitives/TextArea.tsx` | Themed inputs + label + error. | TS | web, electron |
| `src/primitives/Select.tsx` · `src/primitives/SegmentedControl.tsx` | Selects + segmented control. | TS | web, electron |
| `src/primitives/Chip.tsx` · `src/primitives/ChipRow.tsx` | Selectable chips + wrap row. | TS | web, electron |
| `src/primitives/Toggle.tsx` · `src/primitives/Slider.tsx` · `src/primitives/Stepper.tsx` | Toggle/slider/stepper. | TS | web, electron |
| `src/primitives/Badge.tsx` · `src/primitives/Pill.tsx` · `src/primitives/Tag.tsx` | Status badges/pills/tags. | TS | web, electron |
| `src/primitives/Modal.tsx` · `src/primitives/Sheet.tsx` | Modal + bottom-sheet. | TS | web, electron |
| `src/primitives/Toast.tsx` · `src/primitives/ToastProvider.tsx` | Toast view + queue context. | TS | web, electron |
| `src/feedback/EmptyState.tsx` · `src/feedback/ErrorState.tsx` · `src/feedback/LoadingState.tsx` | Empty/error(+correlationId)/loading. | TS | web, electron |
| `src/feedback/Skeleton.tsx` · `src/feedback/ProgressBar.tsx` · `src/feedback/CircularProgress.tsx` | Skeleton + progress. | TS | web, electron |
| `src/data/StatTile.tsx` · `src/data/KeyValueRow.tsx` · `src/data/ListRow.tsx` | Metric tile + rows. | TS | web, electron |
| `src/data/MoneyText.tsx` · `src/data/CreditText.tsx` | Microdollar/credit renderers. | TS | web, electron |
| `src/data/RelativeTime.tsx` · `src/data/Countdown.tsx` | Relative time + countdown. | TS | web, electron |
| `src/domain/PlatformIcon.tsx` | TikTok/IG/YouTube/X icon + brand color. | TS | web, electron |
| `src/domain/BurnPreviewBadge.tsx` | Credits/$/keepers badge (uses `growth-analytics`). | TS | web, electron |
| `src/domain/HookScoreGauge.tsx` | 0–100 hook gauge vs 70% gate (uses `growth-analytics`). | TS | web, electron |
| `src/domain/RetentionCurveChart.tsx` | Per-second retention chart + 3s/loop markers. | TS | web, electron |
| `src/domain/SafeZoneOverlay.tsx` | Caption safe-zone overlay (uses `shot-template-schema/aspect`). | TS | web, electron |
| `src/domain/SegmentSlotBar.tsx` | Segment-slot timeline bar (Hook/Proof/Payoff/Loop). | TS | web, electron |
| `src/domain/CaptionPreview.tsx` | Live caption preview (uses `caption-engine/preview`). | TS | web, electron |
| `src/hooks/useDebounce.ts` · `src/hooks/useToast.ts` · `src/hooks/useTheme.ts` | Shared hooks. | TS | web, electron |
| `src/format/index.ts` | Shared formatting re-exports (money/duration/percent/number). | TS | web, electron |
**Consumed by:** `web` + `electron` (components), `mobile` + `desktop` (tokens JSON re-mapped).
Domain components deliberately reuse `growth-analytics`, `caption-engine`, and
`shot-template-schema` so metrics render identically to the backend.
> **Note.** Native `apps/desktop` (Rust/GPUI) consumes only `tokens.json` (via a small build step
> into a Rust theme module, §16) — it cannot import React components. `electron-legacy` is the full
> React consumer alongside `web`.
---
## 14. Expanded `api-contract` + Regenerated SDK Types — Phase 1→5
The existing `@reelforge/api-contract` gains DTO modules + OpenAPI slices for the new domains; both
SDKs regenerate resource groups. This keeps the "one backend contract" rule the mobile doc mandates.
### 14.1 `packages/api-contract/src/` (new DTO modules)
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `src/templates.ts` | Template/slot/instance + compile DTOs (re-exports `shot-template-schema`). | TS | web, mobile, sdk-ts |
| `src/captions.ts` | Caption job/style/hook-score/loop-check DTOs. | TS | web, mobile, sdk-ts |
| `src/render.ts` | `RenderSpec` transport + render-job DTOs (re-exports `render-core`). | TS | web, mobile, sdk-ts |
| `src/burn.ts` | `BurnEstimate` DTO (credits/$/keepers/license/deprecation). | TS | web, mobile, sdk-ts |
| `src/publishing.ts` | Connection/post/schedule/retention/experiment DTOs. | TS | web, mobile, sdk-ts |
| `src/trends.ts` | Trend/sound/score DTOs (re-exports `trends-schema`). | TS | web, mobile, sdk-ts |
| `src/gateway.ts` | Provisioning key/plan/markup/reseller DTOs. | TS | web, mobile, sdk-ts |
| `src/marketplace.ts` | Campaign/submission/payout/affiliate DTOs. | TS | web, mobile, sdk-ts |
| `src/film.ts` | Film project/shot/character/storyboard DTOs. | TS | web, mobile, sdk-ts |
| `src/series.ts` | Series/episode/batch/cadence DTOs. | TS | web, mobile, sdk-ts |
| `src/events.ts` | Webhook event DTOs (re-exports `eventbus-types`). | TS | web, mobile, sdk-ts |
| `src/devices.ts` | Push-device registration DTOs. | TS | mobile, sdk-ts |
| `openapi/reelforge-v1.json` (regen) | Regenerated OpenAPI incl. new domains (existing `export_openapi.py`). | — | all |
| `scripts/generate_types.py` (extend) | Emit new generated slices to TS + `sdk-python`. | Py | build |
### 14.2 `packages/sdk-typescript/src/resources/` (new resource groups)
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `resources/templates.ts` | Template list/get/compile/instantiate. | TS | web, mobile |
| `resources/captions.ts` | Transcribe/style/hook-score/loop-check. | TS | web, mobile |
| `resources/publishing.ts` | Connections/OAuth/posts. | TS | web, mobile |
| `resources/scheduler.ts` | Schedule/cadence/best-time. | TS | web, mobile |
| `resources/experiments.ts` | A/B create/list/winner. | TS | web, mobile |
| `resources/retention.ts` | Retention curves. | TS | web, mobile |
| `resources/trends.ts` | Trend feed + attach sound. | TS | web, mobile |
| `resources/gateway.ts` | Keys/plans/markup/reseller. | TS | web |
| `resources/marketplace.ts` | Campaigns/submissions/earnings/affiliate. | TS | web, mobile |
| `resources/film.ts` | Film/storyboard/shots/characters. | TS | web |
| `resources/series.ts` | Series/episodes/batch. | TS | web, mobile |
| `resources/devices.ts` | Push registration. | TS | mobile |
### 14.3 `packages/sdk-python/reelforge_sdk/resources/` (parity)
| Path | Responsibility | Lang | Consumers |
|---|---|---|---|
| `resources/templates.py` … `resources/series.py` | Python parity of each resource group above (mirrors TS 1:1). | Py | agents, api-consumers |
| `resources/__init__.py` | Resource registry attached to `ReelForgeClient`. | Py | sdk-py |
> Counted as **12 TS resource files + 12 Python resource files + 1 Python registry** plus the 12
> api-contract DTO modules and 2 extended tooling entries.
---
## 15. Phasing (aligns with digest build sequencing)
| Phase | Packages shipped | Why now |
|---|---|---|
| **1 — Fastest ROI** | `shot-template-schema`, `caption-engine`, `render-core`, `effects-core`, `provider-adapter-kit` (contract+license), `ui-kit` (tokens+primitives), `api-contract` (templates/captions/render/burn) | Powers the template engine + caption/loop/hook + preview parity that reuse existing compose. |
| **2 — The Wedge** | `publishing-connectors`, `trends-schema`, `eventbus-types`, `api-contract` (publishing/trends/events), SDK publishing/trends/scheduler groups, `ui-kit` domain publishing components | Completes create→publish→measure→regenerate. |
| **3 — Resellable Platform** | `growth-analytics` (burn/expansion), `api-contract` (gateway), SDK gateway group, `provider-adapter-kit` (deprecation/migrate) | Turns the wallet into a resellable, metered platform. |
| **4 — Deep Moat** | `comfy-workflow-schema`, `provider-adapter-kit` (full model registry), `render-core` (LoRA/lipsync builders), `api-contract` (film/series), SDK film/series groups | Film pipeline + character lock + render farm. |
| **5 — Compounding Acquisition** | `growth-analytics` (funnel/cadence full), `api-contract` (marketplace), SDK marketplace/devices, `ui-kit` growth components | Clipping marketplace + affiliate + onboarding funnels. |
---
## 16. Integration Seams (explicit)
1. **One render spec, two executors.** `render-core.RenderSpec` is the single wire format; the
Python `filtergraph.py` parity feeds `services/compose/compose_ffmpeg.py`; golden fixtures gate
TS≡Python byte-parity in CI. Clients build the spec, never spawn FFmpeg.
2. **Effect kernels once.** `effects-core` kernels emit `render-core` transforms; the Python parity
backs `vfx.py`. Kernel params are schema-generated so preview ≡ output.
3. **Templates compile to specs.** `shot-template-schema` presets seed the `templates/` DB
(`presets.py`) and, in the browser, compile via `render-core` for preview; the backend compiler
produces the authoritative spec.
4. **Captions burned identically.** `caption-engine` (TS) previews; its Python port burns the same
ASS in `services/captions`; `render-core` wires the ASS as a filter node.
5. **Contracts codegen like `api-contract`.** Every schema package reuses the
`generate_types.py` + `check_drift.py` pattern; Python outputs are editable-installed into
`apps/api` exactly as `sdk-python` is today.
6. **Provider metadata is shared, behavior is not.** `provider-adapter-kit` supplies the contract +
license + deprecation registries to `routing/providers/*` (Python) and to burn-preview UIs;
actual HTTP adapters stay in `apps/api`.
7. **Publishing stays tokenless in the package.** `publishing-connectors` receives Fernet-decrypted
tokens from the API per-call; caps + watermark policy are shared to `publishing/policy.py`.
8. **Events unify webhooks + push.** `eventbus-types` is the single event catalog for the outbox
(`events/types.py`), SDK webhook types, and the mobile notification router.
9. **Design tokens reach all four apps.** `ui-kit` exports `tokens.json`; `web`/`electron` consume
React components, `mobile` re-maps tokens into `src/shared/ui`, and a tiny build step compiles
`tokens.json` into a Rust theme module for native `apps/desktop` (the only desktop codegen target;
Rust cannot import TS).
10. **Analytics numbers match.** `growth-analytics` backs both the client gauges/charts and the
Python `retention/hook/ab` modules via golden-fixture parity, so a hook score shown on device
equals the server's gate decision.
---
## 17. New File Count (by package)
| Package | Files |
|---|---|
| `shot-template-schema` | 41 |
| `caption-engine` | 27 |
| `render-core` | 31 |
| `effects-core` | 33 |
| `comfy-workflow-schema` | 26 |
| `provider-adapter-kit` | 27 |
| `publishing-connectors` | 30 |
| `trends-schema` | 24 |
| `growth-analytics` | 25 |
| `eventbus-types` | 22 |
| `ui-kit` | 52 |
| `api-contract` expansion | 14 |
| SDK regen (TS + Python resource groups) | 25 |
| **Total new files** | **377** |
> Counts include per-package meta (`package.json`, `tsconfig.json`, `README.md`), barrels, generated
> TS/Python outputs, codegen scripts, and golden-fixture directories (counted as one entry each).
> All eleven net-new packages are added to root `package.json` `workspaces`; the five Python schema
> outputs are editable-installed into `apps/api` alongside `sdk-python`.