# gokul7904231/shortforge architecture

> Architecture diagram of the GitHub repository gokul7904231/shortforge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gokul7904231/shortforge
- Repository: https://github.com/gokul7904231/shortforge

## Overview

#### Purpose and Entry Points
FactoryVids is an AI-operated short-form video production system: it turns a topic or quiz request into a vertical, narrated, subtitled video, then stores and publishes it. The primary control plane is the Next.js application at `apps/web/app/page.js`, with operator UI under `apps/web/app/(os)/` and server APIs under `apps/web/app/api/`. Video generation enters through `apps/web/app/api/generate-video/route.ts`; job progress is read via `apps/web/app/api/job-status/[id]/route.ts` and factory state can stream through `apps/web/app/api/factory-state/sse/route.ts`.

#### Control Plane, Identity, and State
The Node/Next runtime is the user-facing boundary: it authenticates users, applies role/capability and quota controls, accepts generation requests, and exposes operational dashboards. Authentication implementation is concentrated in `apps/web/lib/auth/AuthService.ts`, `apps/web/lib/auth/firebase-admin.ts`, and route middleware at `apps/web/middleware.ts`. Persistent state spans Firestore-oriented user/quota records, MongoDB or disk/in-memory FactoryOS state, and SQLite-backed render queues; queue persistence is represented by `apps/web/lib/core/SQLiteRenderQueue.ts` and `apps/web/lib/queue-db.ts`.

#### AI and Content Planning Layer
Provider-agnostic AI routing selects configured models and capabilities rather than binding pipeline stages directly to one vendor. Core routing/factory abstractions are `apps/web/ai/factory.ts`, `apps/web/ai/intelligent-router.ts`, and `apps/web/ai/capability-registry.ts`; concrete providers include Gemini, Groq, OpenRouter, Hugging Face, NVIDIA, and local AI under `apps/web/ai/providers/`. Content engines define domain-specific workflows—such as quiz, facts, story, and news—loaded and executed through `apps/web/content-engines/_loader/index.ts` and `apps/web/content-engines/_runtime/workflow-runtime.ts`.

#### Production Orchestration and Governance
FactoryOS is the durable autonomous orchestration core. `apps/web/factoryos/core/runtime/FactoryRuntime.ts` composes workflows; `apps/web/factoryos/core/production/ProductionRunner.ts` executes production jobs and state transitions; `apps/web/factoryos/core/controller/AutonomousFactoryController.ts` manages autonomous operation. The Overseer control plane plans task DAGs, records decisions, and accepts operator commands through `apps/web/factoryos/core/overseer/OverseerControlPlane.ts`, `apps/web/factoryos/core/overseer/TaskDAGPlanner.ts`, and `apps/web/lib/overseer/OverseerToolGateway.ts`. Guardian, validator, watchdog, recovery, and cost-governor subsystems form policy/safety boundaries before or after work is committed.

#### Video Assembly and Render Fabric
The application plans scripts, scenes, assets, voice, subtitles, and timelines using modules such as `apps/web/lib/content-pipeline.ts`, `apps/web/lib/voice/AudioPipeline.ts`, and `apps/web/lib/core/TimelineOrchestrator.ts`. Render jobs are queued/routed by `apps/web/lib/rendering/RenderQueueManager.ts` and `apps/web/lib/rendering/AzureWorkerManager.ts`. The physical rendering boundary is Python/FastAPI in `services/rendering-engine/main.py`, with worker execution in `services/rendering-engine/basic_render_worker.py`; it uses Pillow and FFmpeg to produce media. Local generation alternatives live in `apps/web/local-ai/scripts/`.

#### Pipeline Floors and Handoffs
A parallel Python “floor” architecture models staged handoffs: strategy, scripting, asset realization, media synthesis, timeline composition, and rendering. Representative service boundaries are `services/pipeline/floor01_strategy/app/pipeline.py`, `services/pipeline/floor02_scripting/app/pipeline.py`, and `services/pipeline/floor04_media_synthesis/app/services/pipeline.py`. Each floor owns domain handoff contracts, logical workers, validation/reconciliation, and provider adapters; the shared guardian at `services/pipeline/guardian/core/guardian.py` applies policy, verification, transaction, circuit-breaker, and recovery decisions across floors.

#### External Infrastructure and Delivery Flow
A generation request reserves user capacity, creates a queue/job record, then targets a warm FastAPI render service or GitHub Actions fallback through `apps/web/app/api/rendering/github/dispatch/route.ts`. Workers claim work and callback through `apps/web/app/api/rendering/claim/route.ts` and `apps/web/app/api/rendering/callback/route.ts`; callbacks must be idempotent and update durable job state. Artifacts are stored or delivered through Cloudinary/Google Drive abstractions in `apps/web/storage/storage-registry.ts` and `apps/web/lib/drive/DriveConnectionManager.ts`, while publishing is provider-based in `apps/web/publishing/publishing-registry.ts`. Deployment targets include Docker, GitHub Actions workflows, Firebase Hosting, Vercel, and Azure infrastructure defined in `apps/web/azure/main.bicep`.

Main entry points: [`apps/web/app/api/generate-video/route.ts`](https://github.com/gokul7904231/shortforge/blob/main/apps/web/app/api/generate-video/route.ts) (Generation API), [`apps/web/factoryos/core/production/ProductionRunner.ts`](https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/production/ProductionRunner.ts) (Production runner), [`apps/web/lib/content-pipeline.ts`](https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/content-pipeline.ts) (Media planning), [`services/rendering-engine/basic_render_worker.py`](https://github.com/gokul7904231/shortforge/blob/main/services/rendering-engine/basic_render_worker.py) (Render worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js Control Plane"]
  node_operator_ui["Operator UI<br/>Next.js UI"]
  node_generation_api["Generation API<br/>Next.js route<br/>[route.ts]"]
  node_status_streams["Job status &amp; SSE<br/>Next.js routes<br/>[route.ts]"]
  node_identity_controls["Identity &amp; quotas<br/>auth middleware<br/>[AuthService.ts]"]
  node_render_queue["Durable render queue<br/>SQLite queue"]
end

subgraph group_ai["AI &amp; Content"]
  node_ai_router["AI capability router<br/>provider-agnostic AI"]
  node_content_workflows["Content workflows<br/>workflow runtime"]
end

subgraph group_factory["FactoryOS Governance"]
  node_factory_runtime["Factory runtime<br/>orchestration runtime<br/>[FactoryRuntime.ts]"]
  node_production_runner["Production runner<br/>job executor"]
  node_autonomous_controller["Autonomous controller<br/>FactoryOS controller"]
  node_overseer["Overseer control plane<br/>governance control plane"]
end

subgraph group_production["Production &amp; Render"]
  node_media_planning["Media planning<br/>content pipeline"]
  node_audio_pipeline["Voice &amp; audio<br/>audio pipeline<br/>[AudioPipeline.ts]"]
  node_timeline_orchestrator["Timeline composition<br/>timeline orchestrator"]
  node_render_dispatch["Render dispatcher<br/>render queue manager"]
  node_render_service{{"Render service<br/>FastAPI<br/>[main.py]"}}
  node_render_worker["Render worker<br/>Python worker"]
  node_pipeline_floors["Pipeline floors<br/>Python staged pipeline<br/>[pipeline.py]"]
  node_pipeline_guardian["Shared guardian<br/>policy &amp; recovery<br/>[guardian.py]"]
end

subgraph group_delivery["Storage &amp; Publishing"]
  node_artifact_storage[("Artifact storage<br/>storage registry")]
  node_publishing["Publishing providers<br/>publishing registry"]
end

node_operator_ui -->|"submits request"| node_generation_api
node_operator_ui -->|"reads progress"| node_status_streams
node_generation_api -->|"authorizes and reserves capacity"| node_identity_controls
node_generation_api -->|"creates job"| node_render_queue
node_generation_api -->|"starts workflow"| node_factory_runtime
node_factory_runtime -->|"composes execution"| node_production_runner
node_autonomous_controller -->|"operates"| node_factory_runtime
node_overseer -->|"plans and commands"| node_autonomous_controller
node_production_runner -->|"requests AI capabilities"| node_ai_router
node_ai_router -->|"supplies selected models"| node_content_workflows
node_content_workflows -->|"produces content plan"| node_media_planning
node_media_planning -->|"creates narration"| node_audio_pipeline
node_media_planning -->|"supplies scenes and assets"| node_timeline_orchestrator
node_audio_pipeline -->|"supplies voice"| node_timeline_orchestrator
node_timeline_orchestrator -->|"submits timeline"| node_render_dispatch
node_render_queue -->|"provides queued job"| node_render_dispatch
node_render_dispatch -->|"routes render"| node_render_service
node_render_service -->|"executes job"| node_render_worker
node_pipeline_floors -->|"policy and recovery checks"| node_pipeline_guardian
node_production_runner -.->|"staged handoffs"| node_pipeline_floors
node_render_worker -->|"stores output"| node_artifact_storage
node_artifact_storage -->|"delivers artifact"| node_publishing
node_render_worker -->|"idempotent job updates"| node_status_streams

click node_generation_api "https://github.com/gokul7904231/shortforge/blob/main/apps/web/app/api/generate-video/route.ts"
click node_status_streams "https://github.com/gokul7904231/shortforge/blob/main/apps/web/app/api/job-status/%5Bid%5D/route.ts"
click node_identity_controls "https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/auth/AuthService.ts"
click node_render_queue "https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/core/SQLiteRenderQueue.ts"
click node_ai_router "https://github.com/gokul7904231/shortforge/blob/main/apps/web/ai/intelligent-router.ts"
click node_content_workflows "https://github.com/gokul7904231/shortforge/blob/main/apps/web/content-engines/_runtime/workflow-runtime.ts"
click node_factory_runtime "https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/runtime/FactoryRuntime.ts"
click node_production_runner "https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/production/ProductionRunner.ts"
click node_autonomous_controller "https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/controller/AutonomousFactoryController.ts"
click node_overseer "https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/overseer/OverseerControlPlane.ts"
click node_media_planning "https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/content-pipeline.ts"
click node_audio_pipeline "https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/voice/AudioPipeline.ts"
click node_timeline_orchestrator "https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/core/TimelineOrchestrator.ts"
click node_render_dispatch "https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/rendering/RenderQueueManager.ts"
click node_render_service "https://github.com/gokul7904231/shortforge/blob/main/services/rendering-engine/main.py"
click node_render_worker "https://github.com/gokul7904231/shortforge/blob/main/services/rendering-engine/basic_render_worker.py"
click node_pipeline_floors "https://github.com/gokul7904231/shortforge/blob/main/services/pipeline/floor01_strategy/app/pipeline.py"
click node_pipeline_guardian "https://github.com/gokul7904231/shortforge/blob/main/services/pipeline/guardian/core/guardian.py"
click node_artifact_storage "https://github.com/gokul7904231/shortforge/blob/main/apps/web/storage/storage-registry.ts"
click node_publishing "https://github.com/gokul7904231/shortforge/blob/main/apps/web/publishing/publishing-registry.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_operator_ui,node_generation_api,node_status_streams,node_identity_controls,node_render_queue toneBlue
class node_ai_router,node_content_workflows toneAmber
class node_factory_runtime,node_production_runner,node_autonomous_controller,node_overseer toneMint
class node_media_planning,node_audio_pipeline,node_timeline_orchestrator,node_render_dispatch,node_render_service,node_render_worker,node_pipeline_floors,node_pipeline_guardian toneRose
class node_artifact_storage,node_publishing toneIndigo
```

## Components

### Next.js Control Plane

Operator-facing API, identity, and durable queue boundary.

- **Operator UI**: Next.js UI
- [Generation API](https://github.com/gokul7904231/shortforge/blob/main/apps/web/app/api/generate-video/route.ts): Next.js route · Accepts video generation requests. · `apps/web/app/api/generate-video/route.ts`
- [Job status & SSE](https://github.com/gokul7904231/shortforge/blob/main/apps/web/app/api/job-status/%5Bid%5D/route.ts): Next.js routes · Exposes job progress and factory state. · `apps/web/app/api/job-status/[id]/route.ts`
- [Identity & quotas](https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/auth/AuthService.ts): auth middleware · Authenticates users and enforces capabilities and capacity. · `apps/web/lib/auth/AuthService.ts`
- [Durable render queue](https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/core/SQLiteRenderQueue.ts): SQLite queue · Persists render jobs for worker claiming. · `apps/web/lib/core/SQLiteRenderQueue.ts`

### AI & Content

Model routing and content workflow execution.

- [AI capability router](https://github.com/gokul7904231/shortforge/blob/main/apps/web/ai/intelligent-router.ts): provider-agnostic AI · Selects configured providers and model capabilities. · `apps/web/ai/intelligent-router.ts`
- [Content workflows](https://github.com/gokul7904231/shortforge/blob/main/apps/web/content-engines/_runtime/workflow-runtime.ts): workflow runtime · Runs quiz, facts, story, and news engines. · `apps/web/content-engines/_runtime/workflow-runtime.ts`

### FactoryOS Governance

Durable orchestration, autonomous control, and oversight.

- [Factory runtime](https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/runtime/FactoryRuntime.ts): orchestration runtime · Composes durable production workflows. · `apps/web/factoryos/core/runtime/FactoryRuntime.ts`
- [Production runner](https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/production/ProductionRunner.ts): job executor · Executes production jobs and state transitions. · `apps/web/factoryos/core/production/ProductionRunner.ts`
- [Autonomous controller](https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/controller/AutonomousFactoryController.ts): FactoryOS controller · Manages autonomous factory operation. · `apps/web/factoryos/core/controller/AutonomousFactoryController.ts`
- [Overseer control plane](https://github.com/gokul7904231/shortforge/blob/main/apps/web/factoryos/core/overseer/OverseerControlPlane.ts): governance control plane · Plans task DAGs, records decisions, and accepts commands. · `apps/web/factoryos/core/overseer/OverseerControlPlane.ts`

### Production & Render

Media planning, distributed rendering, and pipeline floors.

- [Media planning](https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/content-pipeline.ts): content pipeline · Plans scripts, scenes, assets, voice, subtitles, and timelines. · `apps/web/lib/content-pipeline.ts`
- [Voice & audio](https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/voice/AudioPipeline.ts): audio pipeline · `apps/web/lib/voice/AudioPipeline.ts`
- [Timeline composition](https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/core/TimelineOrchestrator.ts): timeline orchestrator · `apps/web/lib/core/TimelineOrchestrator.ts`
- [Render dispatcher](https://github.com/gokul7904231/shortforge/blob/main/apps/web/lib/rendering/RenderQueueManager.ts): render queue manager · Routes jobs to workers or fallback infrastructure. · `apps/web/lib/rendering/RenderQueueManager.ts`
- [Render service](https://github.com/gokul7904231/shortforge/blob/main/services/rendering-engine/main.py): FastAPI · Physical media rendering boundary using Pillow and FFmpeg. · `services/rendering-engine/main.py`
- [Render worker](https://github.com/gokul7904231/shortforge/blob/main/services/rendering-engine/basic_render_worker.py): Python worker · Executes claimed media render jobs. · `services/rendering-engine/basic_render_worker.py`
- [Pipeline floors](https://github.com/gokul7904231/shortforge/blob/main/services/pipeline/floor01_strategy/app/pipeline.py): Python staged pipeline · Strategy, scripting, asset, synthesis, composition, and rendering handoffs. · `services/pipeline/floor01_strategy/app/pipeline.py`
- [Shared guardian](https://github.com/gokul7904231/shortforge/blob/main/services/pipeline/guardian/core/guardian.py): policy & recovery · Applies verification, transaction, circuit-breaker, and recovery decisions. · `services/pipeline/guardian/core/guardian.py`

### Storage & Publishing

Artifact delivery and publication providers.

- [Artifact storage](https://github.com/gokul7904231/shortforge/blob/main/apps/web/storage/storage-registry.ts): storage registry · Delivers artifacts through Cloudinary and Google Drive abstractions. · `apps/web/storage/storage-registry.ts`
- [Publishing providers](https://github.com/gokul7904231/shortforge/blob/main/apps/web/publishing/publishing-registry.ts): publishing registry · `apps/web/publishing/publishing-registry.ts`

## Connections

- Operator UI → Generation API: submits request
- Operator UI → Job status & SSE: reads progress
- Generation API → Identity & quotas: authorizes and reserves capacity
- Generation API → Durable render queue: creates job
- Generation API → Factory runtime: starts workflow
- Factory runtime → Production runner: composes execution
- Autonomous controller → Factory runtime: operates
- Overseer control plane → Autonomous controller: plans and commands
- Production runner → AI capability router: requests AI capabilities
- AI capability router → Content workflows: supplies selected models
- Content workflows → Media planning: produces content plan
- Media planning → Voice & audio: creates narration
- Media planning → Timeline composition: supplies scenes and assets
- Voice & audio → Timeline composition: supplies voice
- Timeline composition → Render dispatcher: submits timeline
- Durable render queue → Render dispatcher: provides queued job
- Render dispatcher → Render service: routes render
- Render service → Render worker: executes job
- Pipeline floors → Shared guardian: policy and recovery checks
- Production runner → Pipeline floors: staged handoffs
- Render worker → Artifact storage: stores output
- Artifact storage → Publishing providers: delivers artifact
- Render worker → Job status & SSE: idempotent job updates
