videogen/docs/reelforge/REPOSITORY_LAYOUT_SPEC.md
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
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

24 KiB

ReelForge Repository Layout Specification

Status: Target file and directory plan, grounded in the current tree. This document defines where new code belongs and how existing code migrates. It does not authorize a big-bang move.

1. Root workspace

videogen/
├── apps/
│   ├── api/                 Python API, workers, and backend-owned generation engine
│   ├── web/                 Next.js web product and embedded editor migration
│   ├── mobile/              Expo native mobile product
│   └── desktop/             Rust/GPUI native desktop product
├── packages/
│   ├── api-contract/        versioned OpenAPI artifact and generated DTOs
│   ├── sdk-typescript/      public TypeScript SDK
│   └── sdk-python/          public Python SDK
├── external/                pinned upstream source/evaluation area; never implicit runtime
├── docs/reelforge/          product, runtime, and architecture documentation
├── tests/reelforge/         backend integration and contract tests
├── migrations/              authoritative Alembic history
├── package.json             npm workspace: web, mobile, TypeScript packages
├── Cargo.toml               Cargo workspace: Rust desktop
└── docker-compose.reelforge.yml

Workspace rules:

  • Root npm workspaces include JavaScript applications and packages only.
  • Root Cargo workspace includes apps/desktop only.
  • Python remains an installable project rooted at apps/api, with migrations and test orchestration at repository scope.
  • external/* projects keep independent dependency graphs and are never added wholesale to the root npm, Cargo, or Python workspace.
  • Generated output (dist, .next, Expo output, Cargo target, Python caches, media runtime state) is not committed as product source.

2. apps/api

2.1 Implemented structure and responsibilities

apps/api/
├── app/
│   ├── asgi.py                 application lifecycle
│   ├── router.py               `/api/v1` router assembly
│   ├── bootstrap.py            startup/bootstrap behavior
│   ├── config/                 TOML/environment configuration
│   ├── core/                   authentication foundations
│   ├── domains/                reels, B-roll, media, and editor boundaries
│   ├── platform/storage/       canonical R2/S3 adapter
│   ├── controllers/v1/         compatibility HTTP controllers by feature
│   ├── services/               business and provider services
│   ├── models/
│   │   ├── schema.py           shared Pydantic DTO collection
│   │   └── db/                 SQLAlchemy models and repositories
│   ├── workers/                Celery application, tasks, and pipeline
│   ├── telemetry/              events, cost, progress, Sentry
│   ├── generation/             internal/legacy generation HTTP/task surface
│   └── utils/                  shared utilities and file safety
├── engine/                     backend-owned Pixelle/video-generation engine
├── assets/                     fonts, hooks, workflows, voices, and media assets
├── runtime/storage/            mutable local runtime data
├── tools/                      operations and smoke utilities
├── Dockerfile
└── pyproject.toml

Implemented strengths:

  • canonical generation, media, and editor flows have domain routers;
  • provider registries exist for avatar and B-roll;
  • Celery queues separate normal/render/generation work;
  • R2 access is behind app/platform/storage;
  • the product API already exposes canonical reel and B-roll resources.

Remaining structural risks:

  • models/schema.py, DB models/repositories, and several controllers are shared append points and create high coupling;
  • app/generation can be mistaken for a second product API;
  • engine carries a large, separate dependency and model surface inside the API source tree;
  • provider adapters, domain rules, and orchestration are not uniformly separated;
  • asset and workflow ownership between assets and engine needs explicit rules.

2.2 Incremental destination structure

Use an incremental domain structure. The reels, B-roll, media, editor, auth, idempotency, capability, and storage seams below are already established. Existing stable imports remain through compatibility modules until callers migrate; unrelated domains are not moved in a big bang.

apps/api/app/
├── asgi.py
├── router.py
├── core/
│   ├── config/                   settings and environment parsing
│   ├── auth/                     Clerk, API keys, principals, session policy
│   ├── db/                       Base, sessions, transaction helpers
│   ├── errors/                   error codes and HTTP mapping
│   ├── idempotency/              reusable reservation/replay primitives
│   ├── capabilities/             client and pilot feature resolution
│   └── observability/            correlation, logging, Sentry setup
├── platform/
│   ├── queue/                    Celery configuration and dispatch primitives
│   ├── storage/                  R2/S3 adapter
│   ├── media/                    FFmpeg/ffprobe execution primitives
│   ├── cache/                    Redis-backed coordination
│   └── providers/                shared HTTP/provider client foundations
├── domains/
│   ├── reels/
│   │   ├── router.py             `/jobs` and job actions
│   │   ├── schemas.py
│   │   ├── models.py
│   │   ├── repository.py
│   │   ├── service.py
│   │   ├── policy.py             costs, caps, retry eligibility
│   │   └── stages/               script, tts, avatar, captions, compose, publish
│   ├── broll/
│   │   ├── router.py             canonical `/generation/broll/*`
│   │   ├── schemas.py
│   │   ├── models.py
│   │   ├── repository.py
│   │   ├── service.py
│   │   └── providers/            comfyui_deploy, pixelle, future adapters
│   ├── media/
│   │   ├── router.py             presign, preview, owned asset access
│   │   ├── schemas.py
│   │   ├── models.py
│   │   ├── repository.py
│   │   └── service.py
│   ├── identity/                 me, SSO, SCIM, external identities
│   ├── workspaces/               membership, RBAC, shared credits
│   ├── billing/                  plans, credits, providers, invoices, usage
│   ├── publishing/               connections, OAuth, schedule, publishers
│   ├── creators/                 profiles, follows, referrals, notifications
│   ├── content/                  ideas, templates, presets, social copy
│   ├── brands/                   brands, voices, avatars, covers
│   ├── marketplace/
│   ├── analytics/
│   ├── compliance/
│   ├── developer/                public keys, webhooks, developer portal
│   └── admin/
└── workers/
    ├── celery_app.py
    ├── routing.py                queue names and task routes
    ├── reel_pipeline.py
    ├── generation_pipeline.py
    └── maintenance.py            scheduler/reconciliation tasks

2.3 API file rules

  • router.py: HTTP parsing and response mapping only.
  • schemas.py: public/domain DTOs; no database access.
  • models.py: ORM tables owned by that domain.
  • repository.py: database queries and row locking.
  • service.py: transactions and domain behavior.
  • policy.py: pure authorization/cost/retry/capability decisions.
  • providers/*: translate upstream protocols into domain results.
  • workers call services; they do not recreate business transactions.
  • cross-domain use goes through the destination domain's public service module.

2.4 apps/api/engine boundary

Target structure:

apps/api/engine/
├── README.md                    supported product capability and runtime contract
├── pyproject.toml               isolated GPU dependency package
├── reelforge_engine/
│   ├── contracts.py             internal generation request/result values
│   ├── registry.py              available pipelines
│   ├── pipelines/               product-approved inference paths
│   ├── models/                  model wrappers, not downloaded weights
│   ├── media/                   frame/video processing
│   └── assets.py                workflow/model asset resolution
└── scripts/                     model preparation and worker diagnostics

Migration constraints:

  • no client imports;
  • no direct database or credit writes;
  • no public authentication logic;
  • accepts an internal typed generation request and returns an internal result;
  • model weights live outside Git and are referenced through configuration;
  • the API image should eventually avoid GPU dependencies; the generation-worker image can add the engine dependency layer.

3. apps/web

3.1 Current structure

apps/web/
├── app/                         Next.js App Router pages
├── components/                  feature-oriented component folders
├── lib/                         API client, types, hooks, helpers
├── editor-module/               OpenCut source migration area
├── editor-bff/                  Cloudflare Worker editor adapter
├── public/
├── middleware.ts               Clerk route protection
├── next.config.mjs
├── wrangler.jsonc
└── package.json

The current components/<feature> grouping is useful, but API calls and feature state are spread between lib/api.ts, lib/types.ts, hooks, and components.

3.2 Implemented web foundation and destination

apps/web/
├── app/                         route composition and server boundaries only
│   ├── (marketing)/
│   ├── (product)/
│   ├── admin/
│   ├── r/[token]/
│   └── api/                     only when a Next-specific server route is required
├── src/
│   ├── features/
│   │   ├── reel-create/
│   │   ├── broll-studio/
│   │   ├── jobs-library/
│   │   ├── editor/
│   │   ├── billing/
│   │   ├── workspace/
│   │   ├── publishing/
│   │   ├── creator/
│   │   └── admin/
│   │       ├── components/
│   │       ├── hooks/
│   │       ├── mapping.ts       UI model ↔ API DTO mapping
│   │       └── index.ts         public feature exports
│   ├── shared/
│   │   ├── api/                 configured contract client, auth, errors
│   │   ├── components/          product-neutral UI primitives
│   │   ├── hooks/
│   │   ├── media/
│   │   └── telemetry/
│   └── config/
├── editor-module/               temporary; shrinks as `src/features/editor` grows
├── editor-bff/                  temporary/stateless adapter
├── public/
└── package.json

Web rules:

  • route files compose feature views; they do not contain raw fetch logic;
  • API DTOs come from @reelforge/api-contract;
  • server-only Clerk configuration never crosses a client boundary;
  • upload code requests presign from API, then uploads directly to R2;
  • React Query keys are feature-owned and include user/workspace identity where cache separation requires it;
  • signed URLs are treated as expiring presentation values;
  • editor-module may reuse shared UI primitives after migration but may not create a second authentication or persistence stack.

4. apps/mobile

4.1 Current structure

apps/mobile/
├── app/                         Expo Router screens and tabs
├── components/<feature>/        feature components
├── lib/
│   ├── api.ts                   large shared API client
│   ├── types.ts                 duplicated API DTOs
│   ├── session.ts               Expo SecureStore credential
│   └── pick-*.ts                native media pickers
├── app.json
└── package.json

4.2 Implemented mobile foundation and destination

apps/mobile/
├── app/                         Expo Router route composition
├── src/
│   ├── features/
│   │   ├── reel-create/
│   │   ├── broll-studio/
│   │   ├── jobs-library/
│   │   ├── account/
│   │   ├── workspace/
│   │   ├── publishing/
│   │   └── creator/
│   │       ├── components/
│   │       ├── hooks/
│   │       ├── mapping.ts
│   │       └── index.ts
│   ├── shared/
│   │   ├── api/                 configured shared contract client
│   │   ├── auth/                SecureStore session abstraction
│   │   ├── media/               picker/upload/preview primitives
│   │   ├── lifecycle/           polling cancellation/background resume
│   │   ├── components/
│   │   └── telemetry/
│   └── config/
├── assets/
├── app.json
└── package.json

Mobile rules:

  • API DTOs migrate from lib/types.ts to the contract package;
  • API keys/session tokens are accessed only through the auth abstraction;
  • B-roll and reel draft state that must survive reload moves to an explicit persisted draft/history store;
  • timers are lifecycle-aware and always cancellable;
  • native file URIs never become API media identifiers; upload completion returns the durable R2 key used by API requests;
  • web-only enterprise/admin surfaces may remain web-only when capabilities say so.

5. apps/desktop

5.1 Implemented structure

apps/desktop/
├── src/
│   ├── main.rs
│   ├── app.rs
│   ├── api/                    typed auth, jobs, B-roll, uploads, polling
│   ├── config/                 capabilities and non-secret preferences
│   ├── security/               OS credential stores
│   ├── domain/                 reel, B-roll, job, and library values
│   ├── workspace/              commands, reducer, persistence, worker
│   ├── media/                  capture, probe, playback
│   ├── telemetry/
│   └── ui/                     GPUI shell and feature views
├── electron-legacy/             reference only
├── Cargo.toml
└── README.md

5.2 Desktop ownership detail

apps/desktop/src/
├── main.rs                       process and GPUI application startup
├── app.rs                        top-level application composition
├── config/
│   ├── mod.rs
│   ├── preferences.rs            non-secret API base and UI preferences
│   └── capabilities.rs           server capability snapshot
├── security/
│   ├── mod.rs
│   └── credentials.rs            Keychain/Credential Manager/Secret Service
├── api/
│   ├── mod.rs
│   ├── client.rs                 typed HTTP execution
│   ├── auth.rs                   header injection without logging secrets
│   ├── errors.rs                 HTTP/domain error mapping
│   ├── uploads.rs                presign + streaming upload orchestration
│   ├── reels.rs                  `/jobs` operations
│   ├── broll.rs                  canonical B-roll operations
│   └── polling.rs                cancellation/backoff/terminal states
├── domain/
│   ├── mod.rs
│   ├── job.rs                    job kinds and state
│   ├── reel.rs                   reel draft and attachment
│   ├── broll.rs                  B-roll draft/result
│   └── library.rs                selection and history model
├── workspace/
│   ├── mod.rs
│   ├── reducer.rs                worker events → UI state
│   ├── commands.rs               submit/upload/poll commands
│   └── persistence.rs            non-secret draft/library cache
├── ui/
│   ├── mod.rs
│   ├── shell.rs
│   ├── create/
│   ├── library/
│   ├── preview/
│   ├── settings/
│   └── components/
├── media/
│   ├── capture.rs                screen/file capture abstraction
│   ├── probe.rs                  local media metadata
│   └── playback.rs               native preview adapter
└── telemetry/
    ├── mod.rs
    └── events.rs

Desktop rules:

  • GPUI rendering never performs blocking network, filesystem, credential, or media work;
  • background commands contain immutable request snapshots;
  • worker updates carry job kind and correlation id;
  • credentials never enter preferences or diagnostic logs;
  • a signed preview URL and durable R2 key remain different types/fields;
  • electron-legacy is read-only migration reference until separately removed.

6. packages

6.1 Implemented package structure

packages/
├── api-contract/
│   ├── openapi/reelforge-v1.json    deterministic exported API schema
│   ├── src/generated/               generated TypeScript DTOs
│   ├── src/errors.ts                stable client error categories
│   ├── src/job-state.ts             terminal/progress helpers
│   ├── src/capabilities.ts
│   ├── scripts/export-openapi.*
│   ├── scripts/check-breaking.*
│   └── package.json
├── sdk-typescript/
│   ├── src/client.ts
│   ├── src/resources/               jobs, uploads, broll, webhooks, workspaces
│   ├── src/index.ts
│   └── package.json
└── sdk-python/
    ├── reelforge_sdk/
    │   ├── client.py
    │   ├── errors.py
    │   ├── models.py
    │   └── resources/
    └── pyproject.toml

6.2 Contract package policy

The committed OpenAPI artifact is produced from the API in a deterministic environment. Generation output is reviewed like code. A schema compatibility check classifies:

  • path/method removal;
  • required request-field addition;
  • response field removal or narrowing;
  • enum narrowing;
  • authentication change;
  • error-envelope change.

Web and mobile can share generated TypeScript DTOs and pure state helpers. They must not share React/React Native components. Rust consumes the same OpenAPI artifact through generated models or a reviewed handwritten mapping until Rust generation is adopted.

7. external

external/
├── REGISTRY.md                    adoption status and governance
├── ComfyUI/                       workflow runtime candidate/reference
├── comfyui-deploy/                remote deployment/control-plane reference
├── Wan2.2/                        primary model/inference candidate
├── Wan2GP/                        low-VRAM inference research
├── VideoTuna/                     multi-model training/inference research
├── VideoX-Fun/                    training/inference research
├── ViewComfy/                     workflow application UI/hosting research
└── hyvideo/                       Hunyuan inference source snapshot

No code moves from external directly into an app. Approved adoption choices:

  1. depend on a published package with an allowed, pinned version;
  2. build an isolated service/container from a pinned upstream commit;
  3. port a small, attributed algorithm behind a product-owned interface after license review;
  4. keep research-only and document the rejected runtime integration.

Copying an entire upstream tree into apps/api is not an approved migration.

8. Cross-directory connection matrix

From To Allowed interface
web API HTTPS /api/v1, signed upload target
mobile API HTTPS /api/v1, signed upload target
desktop API HTTPS /api/v1, signed upload target
TypeScript SDK API public HTTPS API
Python SDK API public HTTPS API
API domain router/controller API service typed in-process call
API service repository typed repository/transaction call
API Redis broker, result/coordination primitives
worker API service typed in-process call
API storage service R2 S3 protocol
generation worker API engine internal typed generation contract
B-roll service provider adapter BrollProvider contract
provider adapter ComfyUI Deploy upstream HTTPS API
product code external source tree forbidden runtime import
editor module web shared UI/API temporary migration-only import
editor BFF API/editor transport stateless adapter only

9. Migration plan by change set

Change set 1 — Documentation and enforcement (implemented)

  • land this layout and platform specification;
  • add/update external/REGISTRY.md;
  • correct Electron references in current documentation;
  • document current and target boundaries in each app README.

Change set 2 — Contract package (implemented)

  • create packages/api-contract;
  • export deterministic OpenAPI;
  • generate initial DTOs;
  • add stable job/error/capability helpers;
  • add package to the root npm workspace.

Change set 3 — Web adoption (core generation flows implemented)

  • configure a shared authenticated API client;
  • migrate reel, B-roll, upload, job, and capability DTOs;
  • create feature boundaries for create/library/B-roll;
  • leave compatibility exports in lib/api.ts and lib/types.ts temporarily.

Change set 4 — Mobile adoption (core generation flows implemented)

  • adopt contract DTOs;
  • centralize auth and error mapping;
  • move polling lifecycle into a shared mobile service;
  • persist B-roll history and reel draft attachment safely.

Change set 5 — Rust desktop foundation (implemented)

  • split API/domain/workspace/UI modules as specified;
  • add HTTP and JSON dependencies intentionally;
  • implement presign upload, create, poll, preview, and attach;
  • integrate secure credentials and visible failure states.

Change set 6 — API domain extraction (foundation implemented; incremental)

  • extract leaf domains before reel orchestration;
  • keep import shims at old paths;
  • preserve table names and migration metadata;
  • move reels and B-roll only after shared core/platform seams exist.

Change set 7 — Engine and external isolation (implemented foundation)

  • define the internal engine request/result contract;
  • split CPU API and GPU worker dependency images;
  • pin approved ComfyUI/Wan deployment inputs;
  • prohibit unregistered external imports.

Change set 8 — Editor migration (active export path implemented; migration continues)

  • integrate editor routes and state into web features;
  • identify BFF calls that belong in the product API;
  • remove editor-owned persistence;
  • retire migration source only after feature parity.

10. Completion definition

  • every source file has one clear owning deployable and domain;
  • public API DTOs have one machine-readable source;
  • client platform code is separate while contract semantics are shared;
  • the Rust application is the only active desktop implementation;
  • GPU dependencies are not required by web, mobile, desktop, or the CPU API image;
  • every external project is pinned, classified, and licensed before adoption;
  • no cross-app source import exists;
  • temporary compatibility paths have owners and removal conditions.