# vchitect/rapo architecture

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

- Interactive diagram: https://gitdiagram.com/vchitect/rapo
- Repository: https://github.com/vchitect/rapo

## Overview

RAPO++ is a prompt-optimization framework for text-to-video generation. Its documented workflow builds or extends a relation graph, retrieves modifiers and refines prompts (Stage 1), then iteratively generates videos, scores alignment, and rewrites prompts using feedback (Stage 2). Stage 2 feedback can also support fine-tuning a prompt refiner (Stage 3). The tree exposes Stage 1 scripts and one Stage 2 example; Stage 3 is documented but has no implementation path shown. Relationships below follow README descriptions, not inspected runtime call sites.

Main entry points: [`examples/Stage2_SSPO/phyaware_wan2.1.py`](https://github.com/vchitect/rapo/blob/main/examples/Stage2_SSPO/phyaware_wan2.1.py) (SSPO orchestration), [`examples/Stage1_RAPO/data/graph_test1.csv`](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/data/graph_test1.csv) (Graph input data), [`examples/Stage1_RAPO/construct_graph.py`](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/construct_graph.py) (Build relation graph), [`examples/Stage1_RAPO/add_to_graph.py`](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/add_to_graph.py) (Extend relation graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_stage1["RAPO prompt refinement"]
  node_graph_inputs["Graph input data<br/>[graph_test1.csv]"]
  node_graph_build["Build relation graph<br/>[construct_graph.py]"]
  node_graph_extend["Extend relation graph<br/>[add_to_graph.py]"]
  node_relation_graph[("Relation graph")]
  node_modifier_retrieval["Retrieve modifiers"]
  node_word_augment["Word augmentation<br/>[word_augment.py]"]
  node_refactoring["Sentence refactoring<br/>[refactoring.py]"]
  node_instruction_rewrite["Instruction rewrite"]
end

subgraph group_stage2["SSPO test-time loop"]
  node_stage2_inputs["Prompt and rules<br/>[examples.csv]"]
  node_sspo_loop["SSPO orchestration<br/>[phyaware_wan2.1.py]"]
  node_video_model["Wan2.1 generation"]
  node_alignment_model["Video alignment scoring"]
  node_physics_rewriter["Physics-aware rewriting"]
  node_generated_video["Generated video"]
end

subgraph group_stage3["Refiner training"]
  node_feedback_data[("SSPO feedback")]
  node_refiner_training["LLM fine-tuning"]
  node_prompt_refiner["Fine-tuned refiner"]
end

node_user(("Prompt author"))

node_user -->|"provides examples"| node_graph_inputs
node_graph_inputs -->|"builds from"| node_graph_build
node_graph_build -->|"creates"| node_relation_graph
node_user -->|"adds graph data"| node_graph_extend
node_graph_extend -->|"updates"| node_relation_graph
node_relation_graph -->|"retrieves from"| node_modifier_retrieval
node_modifier_retrieval -->|"supplies modifiers"| node_word_augment
node_word_augment -->|"augments prompt"| node_refactoring
node_refactoring -->|"precedes rewrite"| node_instruction_rewrite
node_user -->|"provides prompt"| node_stage2_inputs
node_stage2_inputs -->|"configures iteration"| node_sspo_loop
node_sspo_loop -->|"requests generation"| node_video_model
node_video_model -->|"produces"| node_generated_video
node_sspo_loop -->|"requests scoring"| node_alignment_model
node_generated_video -->|"scores alignment"| node_alignment_model
node_sspo_loop -->|"rewrites prompts"| node_physics_rewriter
node_alignment_model -->|"returns feedback"| node_sspo_loop
node_physics_rewriter -->|"returns revision"| node_sspo_loop
node_sspo_loop -->|"collects feedback"| node_feedback_data
node_feedback_data -->|"fine-tunes from"| node_refiner_training
node_refiner_training -->|"updates"| node_prompt_refiner

click node_graph_inputs "https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/data/graph_test1.csv"
click node_graph_build "https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/construct_graph.py"
click node_graph_extend "https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/add_to_graph.py"
click node_modifier_retrieval "https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/retrieve_modifiers.py"
click node_word_augment "https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/word_augment.py"
click node_refactoring "https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/refactoring.py"
click node_instruction_rewrite "https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/rewrite_via_instruction.py"
click node_stage2_inputs "https://github.com/vchitect/rapo/blob/main/examples/Stage2_SSPO/examples.csv"
click node_sspo_loop "https://github.com/vchitect/rapo/blob/main/examples/Stage2_SSPO/phyaware_wan2.1.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_graph_inputs,node_graph_build,node_graph_extend,node_relation_graph,node_modifier_retrieval,node_word_augment,node_refactoring,node_instruction_rewrite toneBlue
class node_stage2_inputs,node_sspo_loop,node_video_model,node_alignment_model,node_physics_rewriter,node_generated_video toneAmber
class node_feedback_data,node_refiner_training,node_prompt_refiner toneMint
class node_user toneIndigo
```

## Components

### RAPO prompt refinement

- [Graph input data](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/data/graph_test1.csv): `examples/Stage1_RAPO/data/graph_test1.csv`
- [Build relation graph](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/construct_graph.py): `examples/Stage1_RAPO/construct_graph.py`
- [Extend relation graph](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/add_to_graph.py): `examples/Stage1_RAPO/add_to_graph.py`
- **Relation graph**
- [Retrieve modifiers](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/retrieve_modifiers.py): `examples/Stage1_RAPO/retrieve_modifiers.py`
- [Word augmentation](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/word_augment.py): `examples/Stage1_RAPO/word_augment.py`
- [Sentence refactoring](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/refactoring.py): `examples/Stage1_RAPO/refactoring.py`
- [Instruction rewrite](https://github.com/vchitect/rapo/blob/main/examples/Stage1_RAPO/rewrite_via_instruction.py): `examples/Stage1_RAPO/rewrite_via_instruction.py`

### SSPO test-time loop

- [Prompt and rules](https://github.com/vchitect/rapo/blob/main/examples/Stage2_SSPO/examples.csv): `examples/Stage2_SSPO/examples.csv`
- [SSPO orchestration](https://github.com/vchitect/rapo/blob/main/examples/Stage2_SSPO/phyaware_wan2.1.py): `examples/Stage2_SSPO/phyaware_wan2.1.py`
- **Wan2.1 generation**
- **Video alignment scoring**
- **Physics-aware rewriting**
- **Generated video**

### Refiner training

- **SSPO feedback**
- **LLM fine-tuning**
- **Fine-tuned refiner**

### Other components

- **Prompt author**

## Connections

- Prompt author → Graph input data: provides examples (evidence: `README.md`)
- Graph input data → Build relation graph: builds from (evidence: `README.md`)
- Build relation graph → Relation graph: creates (evidence: `README.md`)
- Prompt author → Extend relation graph: adds graph data (evidence: `README.md`)
- Extend relation graph → Relation graph: updates (evidence: `README.md`)
- Relation graph → Retrieve modifiers: retrieves from (evidence: `README.md`)
- Retrieve modifiers → Word augmentation: supplies modifiers (evidence: `README.md`)
- Word augmentation → Sentence refactoring: augments prompt (evidence: `README.md`)
- Sentence refactoring → Instruction rewrite: precedes rewrite (evidence: `README.md`)
- Prompt author → Prompt and rules: provides prompt (evidence: `README.md`)
- Prompt and rules → SSPO orchestration: configures iteration (evidence: `README.md`)
- SSPO orchestration → Wan2.1 generation: requests generation (evidence: `README.md`)
- Wan2.1 generation → Generated video: produces (evidence: `README.md`)
- SSPO orchestration → Video alignment scoring: requests scoring (evidence: `README.md`)
- Generated video → Video alignment scoring: scores alignment (evidence: `README.md`)
- SSPO orchestration → Physics-aware rewriting: rewrites prompts (evidence: `README.md`)
- Video alignment scoring → SSPO orchestration: returns feedback (evidence: `README.md`)
- Physics-aware rewriting → SSPO orchestration: returns revision (evidence: `README.md`)
- SSPO orchestration → SSPO feedback: collects feedback (evidence: `README.md`)
- SSPO feedback → LLM fine-tuning: fine-tunes from (evidence: `README.md`)
- LLM fine-tuning → Fine-tuned refiner: updates (evidence: `README.md`)
