videogen/ARCHITECTURE-2026-10-23.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

12 KiB

Menivor (videogen / "reelforge-monorepo") — Architecture, 2026-10-23

Scope: real components only, read from the repo at /Users/arhansubasi/products/videogen on 2026-10-23. No PLAN-2026-10-23-DEEP.md existed at the time this was written, so this file does not duplicate a pages/APIs/features plan — it covers competitive positioning context (see STRATEGY-2026-10-23.md), real system architecture, data flow, risks, and next-build priorities.

1. System diagram

flowchart TB
    subgraph Clients
        WEB[apps/web: Next.js 15 + OpenNext]
        MOBILE[apps/mobile: Expo/React Native 0.81]
        WATCH[apps/watch: Expo + cast-receiver]
        DESKTOP[apps/desktop: Rust/Electron-legacy]
    end

    subgraph Cloudflare
        CFW[Cloudflare Workers\n menivor.com / www.menivor.com\n OpenNext adapter]
        KV[Workers KV\n WAITLIST namespace]
        RL[Workers Rate Limiting\n TOOLS_IP_LIMITER / TOOLS_GLOBAL_LIMITER]
        R2[Cloudflare R2\n bucket: videogen\n public via pub-*.r2.dev]
    end

    subgraph ExternalSaaS
        CLERK[Clerk\n auth, pk_live_ + sk_live_]
        RELAY[Railyard Relay\n relay.ereboslab.com\n Claude Haiku via OpenRouter-style proxy]
        LISTMONK[Listmonk\n letters.ereboslab.com\n newsletter]
        GLITCHTIP[GlitchTip\n errors.ereboslab.com\n browser error reporting]
        NEON[(Neon Postgres\n ep-restless-band-*.neon.tech)]
        PROVIDERS[AI providers\n Anthropic / ElevenLabs / HeyGen /\n Kling / Whisper / etc, keyed per-stage]
        SOCIAL[TikTok / Instagram / YouTube / X\n OAuth + publish APIs]
    end

    subgraph OracleBox["Oracle box 'box' (130.61.180.42)\ndocker compose -p menivor"]
        API[FastAPI\n apps/api\n :8080 behind Caddy TLS]
        WORKER[Celery worker(s)\n queues: celery/render/housekeeping]
        BEAT[Celery beat\n periodic ticks: growth_poll, funnel, OTT sweep, etc]
        REDIS[(Redis\n broker + result backend)]
    end

    WEB -- deployed as --> CFW
    CFW -- NEXT_PUBLIC_API_BASE --> API
    CFW -- waitlist signup --> KV
    CFW -- /api/tools/generate --> RL
    CFW -- /api/tools/generate --> RELAY
    RELAY --> PROVIDERS
    CFW -- sign-in/session --> CLERK
    CFW -- client error events --> GLITCHTIP
    CFW -- double opt-in --> LISTMONK

    MOBILE -- REELFORGE_API_BASE --> API
    WATCH --> API
    DESKTOP --> API

    API -- SQLAlchemy 2.0 / psycopg --> NEON
    API -- enqueue chain/chord --> REDIS
    REDIS --> WORKER
    REDIS --> BEAT
    WORKER -- script/tts/avatar/captions/compose --> PROVIDERS
    WORKER -- presigned PUT/GET (boto3) --> R2
    WORKER -- publish job --> SOCIAL
    API -- presigned GET for preview --> R2
    API -- auth/session verify --> CLERK
    API -- Sentry SDK (DSN optional) --> GLITCHTIP

2. Data flow for key user actions

2.1 Free SEO/growth tool run (e.g. /tools/tiktok-hook-generator), unauthenticated

  1. Browser loads the (marketing)/tools/* page from Cloudflare Workers (static/SSR via OpenNext).
  2. Form POST hits the same Worker's own route app/api/tools/generate/route.ts — this runs inside the Workers runtime, not on the FastAPI box.
  3. That route checks RELAY_URL/RELAY_API_KEY (Worker secrets) and applies the two Workers Rate Limiting bindings (TOOLS_IP_LIMITER 5/min per IP, TOOLS_GLOBAL_LIMITER 40/min global).
  4. Request forwards to relay.ereboslab.com (Railyard Relay, a separate owned service), which calls an LLM (Claude Haiku class) and returns generated text.
  5. Response renders directly in the page; no database row, no R2 object, no FastAPI involvement. This is why the /tools/* pages are cheap to run at zero marginal cost and are the natural place to add the "vs Creatify/Arcads" comparison content from the strategy doc — it is the same code path already serving 14 live pages.

2.2 Authenticated reel generation ("hook script -> TTS -> avatar -> captions -> compose")

  1. Signed-in browser (Clerk session) on menivor.com calls NEXT_PUBLIC_API_BASE (https://api.menivor.com/api/v1) — this leaves Cloudflare entirely and hits the FastAPI process on Oracle box box (130.61.180.42), reverse-proxied by Caddy.
  2. FastAPI checks launch-phase policy (app/core/launch/policy.py): signup_enabled / checkout_enabled / publishing_enabled are computed from REELFORGE_LAUNCH_MODE + REELFORGE_SIGNUP_ENABLED / REELFORGE_CHECKOUT_ENABLED / REELFORGE_PUBLISHING_ENABLED env flags (default in .env.example: internal_pilot, all three false) plus a pilot-staff allowlist override. This is the real mechanism behind the "waitlist mode" the strategy doc describes — it is a backend feature flag read live via GET /launch/status, not only the frontend's NEXT_PUBLIC_WAITLIST_MODE build-time override.
  3. On success, FastAPI writes a Job row to Neon Postgres (SQLAlchemy 2.0, psycopg v3 driver, pooled endpoint ep-restless-band-ay40rg56-pooler).
  4. app/workers/pipeline.py builds the canonical DAG as a Celery chain: script -> tts -> chord(avatar, captions) -> compose -> upload(optional), routes the GPU/render-heavy avatar/compose stages to the render queue, and enqueues onto Redis (same box, "existing MPT Redis instance").
  5. The Celery worker process (same box) pulls each stage, calling external AI providers (script: Anthropic; TTS: ElevenLabs-class; avatar: HeyGen/Kling-class) as configured per .env, writes intermediate and final media to Cloudflare R2 via boto3 presigned PUT (bucket videogen).
  6. compose stage remuxes an AI-generated-content provenance tag into the final MP4, marks the job complete in Postgres.
  7. Browser polls job status via the API; on completion it reads the final MP4 from a 7-day presigned R2 GET URL (or the public pub-*.r2.dev domain) — R2 serves the byte stream directly, Cloudflare Workers/FastAPI are out of the hot path for playback.
  8. If the job requested direct publish, upload hands off to app/domains/multipost / packages/publishing-connectors (TikTok/Instagram/YouTube/X OAuth clients) which post the asset to the creator's connected social account.

2.3 Waitlist signup (pre-launch CTA on marketing pages)

  1. Visitor submits email on a marketing page served by the Cloudflare Worker.
  2. A Worker route writes directly to the WAITLIST KV namespace (id 5ad25698b2554f51881ff4e76001eee8, verified real via wrangler kv namespace list).
  3. No FastAPI, no Postgres, no queue involved — if the KV binding is ever missing the route degrades to a 503 + mailto: fallback (per the inline comment in wrangler.jsonc).
  4. Separately, the public newsletter opt-in goes to Listmonk (letters.ereboslab.com, list menivor-updates), not the waitlist KV — these are two different capture mechanisms living on two different services.

3. Real architectural risks / bottlenecks (current scale, zero budget)

  • Single Oracle VM is the whole backend tier. API, Celery worker, Celery beat, and Redis all run as one docker compose -p menivor stack on one box (130.61.180.42). There is no secondary API node, no Redis replica, no managed queue. A box-level outage (already happened: sshd dropped on 2026-10-21, blocking a deploy until an OCI console/restart path) takes down generation, auth-adjacent API calls, and publishing simultaneously, with the public marketing site (Cloudflare) staying up and silently making promises the backend can't fulfill.
  • CPU-only render host vs. a GPU-shaped pipeline. box is an Oracle VM.Standard.A1.Flex (ARM CPU, no GPU). The Celery DAG's avatar and compose stages are routed to a dedicated render queue specifically because they are the slow/heavy stages — but the repo also has apps/api/Dockerfile.generation, a worker-gpu image target in CI (build-images.yml), and infra/render-workers/ (e.g. infinitetalk/handler.py) implying a GPU-backed render path was designed but is not confirmed wired to a live GPU host. If avatar/ compose currently execute on the CPU box, per-job latency and concurrent-job throughput are both a hard ceiling under any real traffic spike — directly undercutting the "ships in minutes" promise implied by competing with Creatify/HeyGen.
  • GitHub Actions is fully blocked (billing failure on caelum0x/videogen), so build-images (web/api/worker-gpu images) and deploy.yml have not produced a successful run since at least 2026-10-16. The web frontend still deploys fine (separate Cloudflare path), but any backend/API fix can only reach production via the manual build/ship-image.sh --host box SSH path — one human credential is now a hard dependency for every backend release.
  • Launch-phase flags, not infra, gate revenue. REELFORGE_LAUNCH_MODE=internal_pilot with signup/checkout/publishing all false by default means the single biggest conversion blocker the strategy doc identifies is a config flip on box, not a code change — but it is also a config flip that is easy to leave off indefinitely since nothing in the repo forces it back on.
  • Shared, over-scoped credentials. apps/api/DEPLOY.md documents that the live R2 API token in .env is the same account-scoped token shared with the calori-ai product's .env — a leak or bug in one product's R2 usage has blast radius into the other's bucket.
  • Domain sprawl inside one FastAPI monolith. apps/api/app/domains/ has over 90 subdirectories (ads, ott, ott_live, ott_commerce, clipmarket, affiliate, wallet, social_inbox, …) sharing one process, one Postgres database, and one deploy unit. Given the owner's own standing note that most products "almost none...get users," a large fraction of this surface is plausibly unused code adding build time, migration risk, and onboarding cost to the handful of flows (reel generation, tools, billing) that actually need to be reliable.
  • No automated health/alerting loop found for the box itself. SENTRY_DSN defaults to empty ("NO-OP") in .env.example; GlitchTip is wired for the browser (Next.js) side only. If the Celery worker silently stops consuming the render queue, nothing in the repo pages anyone — the only readiness signal is the manual /readyz curl documented in apps/api/DEPLOY.md.

4. Prioritized next-build list

  1. Flip the launch-phase flags for the free tier, behind the existing policy gate (very low effort, highest impact). REELFORGE_SIGNUP_ENABLED / REELFORGE_CHECKOUT_ENABLED already exist as real, tested flags (app/core/launch/policy.py, GET /launch/status); this is a .env edit + container recreate on box, not new code. This directly unblocks the strategy doc's #1 precondition ("resolve waitlist mode before differentiation claims can convert").
  2. Ship /from-app-store reusing the already-built appaudit + ingest domains (low-medium effort, high impact). The backend already has app/domains/appaudit (packaging/visibility/ rewrite checks) and app/domains/ingest (metadata extraction) plus a live /tools/app-store- audit page — none of it currently renders a pre-signup reel preview. Wiring a thin public route that calls the existing audit/ingest services and pipes the result into a one-shot preview render is mostly glue, not new product surface.
  3. Convert the 14 live /tools/* pages into sourced competitor-comparison pages (low effort, content-only, no backend change). These already run through the zero-cost Workers+Relay path (2.1 above); adding "Menivor vs Creatify/Arcads/AdCreative.ai/HeyGen" variants is a content/routing change inside apps/web/app/(marketing)/tools, with no new infra.
  4. Add a liveness alert for the Celery render queue on box (medium effort, reliability). Today the only check is a manual curl /readyz. A cheap cron (on box itself, or a Cloudflare Worker Cron Trigger hitting /readyz and posting to an existing channel) would catch the "worker stopped consuming" failure mode before a user notices a stuck render — cheap relative to the single-box blast radius identified in Section 3.
  5. Decide the GPU-render question explicitly (higher effort, do only once paid volume justifies it). Either confirm worker-gpu is live somewhere and route render-queue jobs there, or formally accept CPU-only avatar/compose for now and set user-facing render-time expectations accordingly. Left ambiguous, this is the risk most likely to produce a bad first paid-user experience once Section 4.1 reopens checkout.