# bj0703/viraldna architecture

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

- Interactive diagram: https://gitdiagram.com/bj0703/viraldna
- Repository: https://github.com/bj0703/viraldna

## Overview

ViralDNA is an AI-assisted short-video editing platform: creators provide a reference video, their own footage, and an editing request; the system analyzes reusable structure, matches footage to structural slots, resolves gaps, plans a timeline, and can render a video demo. The graph preserves that principal workflow, the editing and knowledge-base capabilities, and the separate sample-analysis API. Several agent implementations are listed but not excerpted, so documented or configured relationships are shown only where supported; unsampled internals are not inferred.

Main entry points: [`backend/app/api/routes/orchestration.py`](https://github.com/bj0703/viraldna/blob/main/backend/app/api/routes/orchestration.py) (Orchestration API), [`backend/app/agents/orchestrator.py`](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/orchestrator.py) (Workflow orchestrator), [`backend/app/core/shared_memory.py`](https://github.com/bj0703/viraldna/blob/main/backend/app/core/shared_memory.py) (Shared job memory), [`backend/app/agents/gap_resolver.py`](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/gap_resolver.py) (Gap resolution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_creation["Creation workflow"]
  node_intent["Intent planner<br/>[intent_planner.py]"]
  node_reference["Reference analysis"]
  node_indexer["Asset indexing<br/>[asset_indexer.py]"]
  node_matcher["Slot matching<br/>[slot_matcher.py]"]
  node_gap["Gap resolution<br/>[gap_resolver.py]"]
  node_sample_service["Sample analysis<br/>[sample_analysis.py]"]
  node_sample_provider["Analysis provider"]
end

subgraph group_runtime["Orchestration and state"]
  node_api["Orchestration API<br/>[orchestration.py]"]
  node_orchestrator["Workflow orchestrator<br/>[orchestrator.py]"]
  node_memory[("Shared job memory<br/>[shared_memory.py]")]
  node_redis_memory[("Redis memory")]
  node_sample_api["Sample analysis API<br/>[sample_analysis.py]"]
  node_sample_store[("Analysis repository")]
end

subgraph group_editing["Editing capabilities"]
  node_planner["Timeline planning<br/>[edit_planner.py]"]
  node_renderer["Video rendering"]
  node_ffmpeg["FFmpeg timeline<br/>[ffmpeg_timeline.py]"]
  node_timeline_edit["Timeline editing<br/>[timeline_editor.py]"]
  node_knowledge["Editing knowledge base"]
  node_capcut["CapCut draft export"]
end

subgraph group_workbench["Creator workbench"]
  node_workbench["Web workbench<br/>[App.tsx]"]
  node_sidebar["Video inputs"]
  node_live_ui["Progress and results"]
  node_sse["Event stream client"]
end

node_creator(("Creator"))

node_creator -->|"provides inputs"| node_workbench
node_workbench -->|"shows inputs"| node_sidebar
node_sidebar -->|"uploads videos"| node_api
node_workbench -.->|"submits job"| node_api
node_api -->|"plans intent"| node_intent
node_api -->|"starts workflow"| node_orchestrator
node_orchestrator -->|"reads and writes"| node_memory
node_orchestrator -->|"dispatches"| node_reference
node_orchestrator -->|"dispatches"| node_indexer
node_orchestrator -->|"dispatches"| node_matcher
node_orchestrator -->|"dispatches"| node_gap
node_orchestrator -->|"dispatches"| node_planner
node_orchestrator -->|"dispatches"| node_renderer
node_reference -->|"writes analysis"| node_memory
node_indexer -->|"writes index"| node_memory
node_matcher -->|"writes matches"| node_memory
node_gap -->|"writes resolutions"| node_memory
node_planner -->|"writes timeline"| node_memory
node_renderer -->|"writes render metadata"| node_memory
node_renderer -->|"renders timeline"| node_ffmpeg
node_api -->|"edits segments"| node_timeline_edit
node_gap -.->|"retrieves guidance"| node_knowledge
node_api -->|"exports draft"| node_capcut
node_api -->|"loads job state"| node_redis_memory
node_redis_memory -->|"backs memory"| node_memory
node_sse -->|"subscribes and polls"| node_api
node_live_ui -->|"displays events"| node_sse
node_api -->|"serves analysis routes"| node_sample_api
node_sample_api -->|"requests analysis"| node_sample_service
node_sample_service -->|"analyzes sample"| node_sample_provider
node_sample_service -->|"stores results"| node_sample_store

click node_workbench "https://github.com/bj0703/viraldna/blob/main/frontend/src/App.tsx"
click node_sidebar "https://github.com/bj0703/viraldna/blob/main/frontend/src/layouts/LeftSidebarContent.tsx"
click node_live_ui "https://github.com/bj0703/viraldna/blob/main/frontend/src/components/AgentConversationPanel.tsx"
click node_sse "https://github.com/bj0703/viraldna/blob/main/frontend/src/hooks/useSSEEventSource.ts"
click node_api "https://github.com/bj0703/viraldna/blob/main/backend/app/api/routes/orchestration.py"
click node_intent "https://github.com/bj0703/viraldna/blob/main/backend/app/services/intent_planner.py"
click node_orchestrator "https://github.com/bj0703/viraldna/blob/main/backend/app/agents/orchestrator.py"
click node_memory "https://github.com/bj0703/viraldna/blob/main/backend/app/core/shared_memory.py"
click node_redis_memory "https://github.com/bj0703/viraldna/blob/main/backend/app/core/shared_memory_redis.py"
click node_reference "https://github.com/bj0703/viraldna/blob/main/backend/app/agents/reference_analyzer.py"
click node_indexer "https://github.com/bj0703/viraldna/blob/main/backend/app/agents/asset_indexer.py"
click node_matcher "https://github.com/bj0703/viraldna/blob/main/backend/app/agents/slot_matcher.py"
click node_gap "https://github.com/bj0703/viraldna/blob/main/backend/app/agents/gap_resolver.py"
click node_planner "https://github.com/bj0703/viraldna/blob/main/backend/app/agents/edit_planner.py"
click node_renderer "https://github.com/bj0703/viraldna/blob/main/backend/app/agents/final_video_renderer.py"
click node_ffmpeg "https://github.com/bj0703/viraldna/blob/main/backend/app/renderers/ffmpeg_timeline.py"
click node_timeline_edit "https://github.com/bj0703/viraldna/blob/main/backend/app/services/timeline_editor.py"
click node_knowledge "https://github.com/bj0703/viraldna/blob/main/backend/app/services/knowledge_base_service.py"
click node_capcut "https://github.com/bj0703/viraldna/blob/main/backend/app/services/capcut_draft_generator.py"
click node_sample_api "https://github.com/bj0703/viraldna/blob/main/backend/app/api/routes/sample_analysis.py"
click node_sample_service "https://github.com/bj0703/viraldna/blob/main/backend/app/services/sample_analysis.py"
click node_sample_provider "https://github.com/bj0703/viraldna/blob/main/backend/app/providers/heuristic_video_analysis.py"
click node_sample_store "https://github.com/bj0703/viraldna/blob/main/backend/app/repositories/in_memory_sample_analysis.py"

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_intent,node_reference,node_indexer,node_matcher,node_gap,node_sample_service,node_sample_provider toneBlue
class node_api,node_orchestrator,node_memory,node_redis_memory,node_sample_api,node_sample_store toneAmber
class node_planner,node_renderer,node_ffmpeg,node_timeline_edit,node_knowledge,node_capcut toneMint
class node_workbench,node_sidebar,node_live_ui,node_sse toneRose
class node_creator toneIndigo
```

## Components

### Creation workflow

- [Intent planner](https://github.com/bj0703/viraldna/blob/main/backend/app/services/intent_planner.py): `backend/app/services/intent_planner.py`
- [Reference analysis](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/reference_analyzer.py): `backend/app/agents/reference_analyzer.py`
- [Asset indexing](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/asset_indexer.py): `backend/app/agents/asset_indexer.py`
- [Slot matching](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/slot_matcher.py): `backend/app/agents/slot_matcher.py`
- [Gap resolution](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/gap_resolver.py): `backend/app/agents/gap_resolver.py`
- [Sample analysis](https://github.com/bj0703/viraldna/blob/main/backend/app/services/sample_analysis.py): `backend/app/services/sample_analysis.py`
- [Analysis provider](https://github.com/bj0703/viraldna/blob/main/backend/app/providers/heuristic_video_analysis.py): `backend/app/providers/heuristic_video_analysis.py`

### Orchestration and state

- [Orchestration API](https://github.com/bj0703/viraldna/blob/main/backend/app/api/routes/orchestration.py): `backend/app/api/routes/orchestration.py`
- [Workflow orchestrator](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/orchestrator.py): `backend/app/agents/orchestrator.py`
- [Shared job memory](https://github.com/bj0703/viraldna/blob/main/backend/app/core/shared_memory.py): `backend/app/core/shared_memory.py`
- [Redis memory](https://github.com/bj0703/viraldna/blob/main/backend/app/core/shared_memory_redis.py): `backend/app/core/shared_memory_redis.py`
- [Sample analysis API](https://github.com/bj0703/viraldna/blob/main/backend/app/api/routes/sample_analysis.py): `backend/app/api/routes/sample_analysis.py`
- [Analysis repository](https://github.com/bj0703/viraldna/blob/main/backend/app/repositories/in_memory_sample_analysis.py): `backend/app/repositories/in_memory_sample_analysis.py`

### Editing capabilities

- [Timeline planning](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/edit_planner.py): `backend/app/agents/edit_planner.py`
- [Video rendering](https://github.com/bj0703/viraldna/blob/main/backend/app/agents/final_video_renderer.py): `backend/app/agents/final_video_renderer.py`
- [FFmpeg timeline](https://github.com/bj0703/viraldna/blob/main/backend/app/renderers/ffmpeg_timeline.py): `backend/app/renderers/ffmpeg_timeline.py`
- [Timeline editing](https://github.com/bj0703/viraldna/blob/main/backend/app/services/timeline_editor.py): `backend/app/services/timeline_editor.py`
- [Editing knowledge base](https://github.com/bj0703/viraldna/blob/main/backend/app/services/knowledge_base_service.py): `backend/app/services/knowledge_base_service.py`
- [CapCut draft export](https://github.com/bj0703/viraldna/blob/main/backend/app/services/capcut_draft_generator.py): `backend/app/services/capcut_draft_generator.py`

### Creator workbench

- [Web workbench](https://github.com/bj0703/viraldna/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Video inputs](https://github.com/bj0703/viraldna/blob/main/frontend/src/layouts/LeftSidebarContent.tsx): `frontend/src/layouts/LeftSidebarContent.tsx`
- [Progress and results](https://github.com/bj0703/viraldna/blob/main/frontend/src/components/AgentConversationPanel.tsx): `frontend/src/components/AgentConversationPanel.tsx`
- [Event stream client](https://github.com/bj0703/viraldna/blob/main/frontend/src/hooks/useSSEEventSource.ts): `frontend/src/hooks/useSSEEventSource.ts`

### Other components

- **Creator**

## Connections

- Creator → Web workbench: provides inputs (evidence: `README.md`)
- Web workbench → Video inputs: shows inputs (evidence: `frontend/src/App.tsx`)
- Video inputs → Orchestration API: uploads videos (evidence: `frontend/src/layouts/LeftSidebarContent.tsx`)
- Web workbench → Orchestration API: submits job
- Orchestration API → Intent planner: plans intent (evidence: `backend/app/api/routes/orchestration.py`)
- Orchestration API → Workflow orchestrator: starts workflow (evidence: `backend/app/api/routes/orchestration.py`)
- Workflow orchestrator → Shared job memory: reads and writes (evidence: `backend/app/agents/orchestrator.py`)
- Workflow orchestrator → Reference analysis: dispatches (evidence: `backend/app/dependencies.py`)
- Workflow orchestrator → Asset indexing: dispatches (evidence: `backend/app/dependencies.py`)
- Workflow orchestrator → Slot matching: dispatches (evidence: `backend/app/dependencies.py`)
- Workflow orchestrator → Gap resolution: dispatches (evidence: `backend/app/dependencies.py`)
- Workflow orchestrator → Timeline planning: dispatches (evidence: `backend/app/dependencies.py`)
- Workflow orchestrator → Video rendering: dispatches (evidence: `backend/app/dependencies.py`)
- Reference analysis → Shared job memory: writes analysis (evidence: `backend/app/dependencies.py`)
- Asset indexing → Shared job memory: writes index (evidence: `backend/app/dependencies.py`)
- Slot matching → Shared job memory: writes matches (evidence: `backend/app/dependencies.py`)
- Gap resolution → Shared job memory: writes resolutions (evidence: `backend/app/dependencies.py`)
- Timeline planning → Shared job memory: writes timeline (evidence: `backend/app/dependencies.py`)
- Video rendering → Shared job memory: writes render metadata (evidence: `backend/app/dependencies.py`)
- Video rendering → FFmpeg timeline: renders timeline (evidence: `README.md`)
- Orchestration API → Timeline editing: edits segments (evidence: `backend/app/api/routes/orchestration.py`)
- Gap resolution → Editing knowledge base: retrieves guidance (evidence: `README.md`)
- Orchestration API → CapCut draft export: exports draft (evidence: `backend/app/api/routes/orchestration.py`)
- Orchestration API → Redis memory: loads job state (evidence: `backend/app/api/routes/orchestration.py`)
- Redis memory → Shared job memory: backs memory (evidence: `backend/app/core/shared_memory_redis.py`)
- Event stream client → Orchestration API: subscribes and polls (evidence: `frontend/src/hooks/useSSEEventSource.ts`)
- Progress and results → Event stream client: displays events (evidence: `frontend/src/components/AgentConversationPanel.tsx`)
- Orchestration API → Sample analysis API: serves analysis routes (evidence: `backend/app/main.py`)
- Sample analysis API → Sample analysis: requests analysis (evidence: `backend/app/api/routes/sample_analysis.py`)
- Sample analysis → Analysis provider: analyzes sample (evidence: `backend/app/services/sample_analysis.py`)
- Sample analysis → Analysis repository: stores results (evidence: `backend/app/services/sample_analysis.py`)
