# zai-org/realvideo architecture

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

- Interactive diagram: https://gitdiagram.com/zai-org/realvideo
- Repository: https://github.com/zai-org/realvideo

## Overview

RealVideo is a WebSocket text-to-talking-video service. A browser client configures an avatar or cloned voice, sends text, and receives synchronized audio and generated frames. The sampled entry point assigns rank zero to the application and other ranks to DiT inference; the application handler queues speech and audio, while lip-sync coordinates audio conditioning, latent generation, VAE decoding and frame delivery. The graph includes the documented TTS, voice-cloning and real-time communication capabilities. Several implementation details are unsampled, so uncertain subsystem links are omitted.

Main entry points: [`core/lip_sync.py`](https://github.com/zai-org/realvideo/blob/main/core/lip_sync.py) (Lip-sync coordinator), [`self_forcing/utils/wan_wrapper.py`](https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/wan_wrapper.py) (Wan diffusion wrapper), [`core/app_interface.py`](https://github.com/zai-org/realvideo/blob/main/core/app_interface.py) (WebSocket application), [`self_forcing/wan/modules/causal_model_s2v.py`](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/causal_model_s2v.py) (Causal audio-video model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Client interface"]
  node_interface["WebSocket application<br/>[app_interface.py]"]
  node_connection["Connection handling<br/>[connection.py]"]
  node_handler["Session model handler<br/>[model_handler.py]"]
end

subgraph group_speech["Speech generation"]
  node_tts["Text-to-speech<br/>[tts_pipeline.py]"]
  node_voice["Voice cloning<br/>[voice_clone.py]"]
end

subgraph group_video["Video synthesis"]
  node_lip["Lip-sync coordinator<br/>[lip_sync.py]"]
  node_dit["DiT inference service<br/>[dit_service.py]"]
end

subgraph group_runtime["Distributed runtime"]
  node_entry["Service entry<br/>[app.py]"]
  node_config["Service configuration<br/>[config.py]"]
  node_parallel["Sequence parallel state<br/>[parallel_state.py]"]
  node_distributed["Rank communication<br/>[distributed.py]"]
  node_alltoall["Parallel all-to-all<br/>[all_to_all.py]"]
end

subgraph group_wan["Wan model internals"]
  node_vae["Wan VAE wrapper<br/>[wan_wrapper.py]"]
  node_diffusion["Wan diffusion wrapper<br/>[wan_wrapper.py]"]
  node_s2v["Causal audio-video model"]
  node_model["Wan transformer<br/>[model.py]"]
  node_attention["Attention layers<br/>[attention.py]"]
  node_audioenc["Audio encoder<br/>[audio_encoder.py]"]
  node_audio_utils["Audio utilities<br/>[audio_utils.py]"]
  node_textenc["Text encoder<br/>[t5.py]"]
  node_clip["Image-text encoder<br/>[clip.py]"]
  node_tokenizers["Tokenizers<br/>[tokenizers.py]"]
  node_scheduler["Flow-match scheduler<br/>[scheduler.py]"]
  node_solver["Diffusion solvers<br/>[fm_solvers.py]"]
end

node_browser(("Browser client"))
node_external_api(("GLM services"))

node_browser -->|"opens session"| node_interface
node_interface -->|"dispatches messages"| node_handler
node_interface -->|"uses connection"| node_connection
node_handler -->|"starts speech tasks"| node_tts
node_handler -->|"forwards audio"| node_lip
node_handler -->|"supports cloning"| node_voice
node_browser -->|"sends text"| node_interface
node_tts -.->|"requests speech"| node_external_api
node_lip -->|"queues conditions"| node_dit
node_dit -.->|"sends latent blocks"| node_lip
node_lip -->|"decodes frames"| node_vae
node_lip -.->|"encodes audio"| node_audioenc
node_lip -.->|"conditions prompts"| node_textenc
node_lip -.->|"streams frames"| node_interface
node_entry -->|"loads settings"| node_config
node_entry -->|"launches ranks"| node_distributed
node_entry -->|"starts rank zero"| node_interface
node_entry -->|"starts workers"| node_dit
node_distributed -->|"initializes groups"| node_parallel
node_distributed -.->|"transfers tensors"| node_dit
node_dit -.->|"runs inference"| node_diffusion
node_diffusion -->|"invokes model"| node_s2v
node_diffusion -->|"uses transformer"| node_model
node_diffusion -->|"uses VAE"| node_vae
node_diffusion -->|"uses scheduler"| node_scheduler
node_diffusion -->|"uses tokenizers"| node_tokenizers
node_s2v -->|"reuses components"| node_model
node_s2v -->|"uses audio ops"| node_audio_utils
node_s2v -->|"uses attention"| node_attention
node_model -.->|"uses attention"| node_attention
node_clip -->|"uses tokenizers"| node_tokenizers
node_textenc -->|"uses tokenizers"| node_tokenizers
node_s2v -->|"uses sequence groups"| node_parallel
node_model -->|"uses sequence groups"| node_parallel
node_model -->|"redistributes tensors"| node_alltoall

click node_entry "https://github.com/zai-org/realvideo/blob/main/app.py"
click node_config "https://github.com/zai-org/realvideo/blob/main/config/config.py"
click node_interface "https://github.com/zai-org/realvideo/blob/main/core/app_interface.py"
click node_connection "https://github.com/zai-org/realvideo/blob/main/core/connection.py"
click node_handler "https://github.com/zai-org/realvideo/blob/main/core/model_handler.py"
click node_tts "https://github.com/zai-org/realvideo/blob/main/core/tts_pipeline.py"
click node_voice "https://github.com/zai-org/realvideo/blob/main/core/voice_clone.py"
click node_lip "https://github.com/zai-org/realvideo/blob/main/core/lip_sync.py"
click node_dit "https://github.com/zai-org/realvideo/blob/main/core/dit_service.py"
click node_vae "https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/wan_wrapper.py"
click node_diffusion "https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/wan_wrapper.py"
click node_s2v "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/causal_model_s2v.py"
click node_model "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/model.py"
click node_attention "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/attention.py"
click node_audioenc "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/audio_encoder.py"
click node_audio_utils "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/audio_utils.py"
click node_textenc "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/t5.py"
click node_clip "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/clip.py"
click node_tokenizers "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/tokenizers.py"
click node_scheduler "https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/scheduler.py"
click node_solver "https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/utils/fm_solvers.py"
click node_parallel "https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/parallel_state.py"
click node_distributed "https://github.com/zai-org/realvideo/blob/main/core/distributed.py"
click node_alltoall "https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/all_to_all.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_interface,node_connection,node_handler,node_browser toneBlue
class node_tts,node_voice toneAmber
class node_lip,node_dit toneMint
class node_entry,node_config,node_parallel,node_distributed,node_alltoall toneRose
class node_vae,node_diffusion,node_s2v,node_model,node_attention,node_audioenc,node_audio_utils,node_textenc,node_clip,node_tokenizers,node_scheduler,node_solver,node_external_api toneIndigo
```

## Components

### Client interface

- [WebSocket application](https://github.com/zai-org/realvideo/blob/main/core/app_interface.py): `core/app_interface.py`
- [Connection handling](https://github.com/zai-org/realvideo/blob/main/core/connection.py): `core/connection.py`
- [Session model handler](https://github.com/zai-org/realvideo/blob/main/core/model_handler.py): `core/model_handler.py`

### Speech generation

- [Text-to-speech](https://github.com/zai-org/realvideo/blob/main/core/tts_pipeline.py): `core/tts_pipeline.py`
- [Voice cloning](https://github.com/zai-org/realvideo/blob/main/core/voice_clone.py): `core/voice_clone.py`

### Video synthesis

- [Lip-sync coordinator](https://github.com/zai-org/realvideo/blob/main/core/lip_sync.py): `core/lip_sync.py`
- [DiT inference service](https://github.com/zai-org/realvideo/blob/main/core/dit_service.py): `core/dit_service.py`

### Distributed runtime

- [Service entry](https://github.com/zai-org/realvideo/blob/main/app.py): `app.py`
- [Service configuration](https://github.com/zai-org/realvideo/blob/main/config/config.py): `config/config.py`
- [Sequence parallel state](https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/parallel_state.py): `self_forcing/utils/parallel_state.py`
- [Rank communication](https://github.com/zai-org/realvideo/blob/main/core/distributed.py): `core/distributed.py`
- [Parallel all-to-all](https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/all_to_all.py): `self_forcing/utils/all_to_all.py`

### Wan model internals

- [Wan VAE wrapper](https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/wan_wrapper.py): `self_forcing/utils/wan_wrapper.py`
- [Wan diffusion wrapper](https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/wan_wrapper.py): `self_forcing/utils/wan_wrapper.py`
- [Causal audio-video model](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/causal_model_s2v.py): `self_forcing/wan/modules/causal_model_s2v.py`
- [Wan transformer](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/model.py): `self_forcing/wan/modules/model.py`
- [Attention layers](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/attention.py): `self_forcing/wan/modules/attention.py`
- [Audio encoder](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/audio_encoder.py): `self_forcing/wan/modules/audio_encoder.py`
- [Audio utilities](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/audio_utils.py): `self_forcing/wan/modules/audio_utils.py`
- [Text encoder](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/t5.py): `self_forcing/wan/modules/t5.py`
- [Image-text encoder](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/clip.py): `self_forcing/wan/modules/clip.py`
- [Tokenizers](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/modules/tokenizers.py): `self_forcing/wan/modules/tokenizers.py`
- [Flow-match scheduler](https://github.com/zai-org/realvideo/blob/main/self_forcing/utils/scheduler.py): `self_forcing/utils/scheduler.py`
- [Diffusion solvers](https://github.com/zai-org/realvideo/blob/main/self_forcing/wan/utils/fm_solvers.py): `self_forcing/wan/utils/fm_solvers.py`

### Other components

- **Browser client**
- **GLM services**

## Connections

- Browser client → WebSocket application: opens session (evidence: `README.md`)
- WebSocket application → Session model handler: dispatches messages (evidence: `core/app_interface.py`)
- WebSocket application → Connection handling: uses connection (evidence: `core/app_interface.py`)
- Session model handler → Text-to-speech: starts speech tasks (evidence: `core/model_handler.py`)
- Session model handler → Lip-sync coordinator: forwards audio (evidence: `core/model_handler.py`)
- Session model handler → Voice cloning: supports cloning (evidence: `core/app_interface.py`)
- Browser client → WebSocket application: sends text (evidence: `README.md`)
- Text-to-speech → GLM services: requests speech (evidence: `README.md`)
- Lip-sync coordinator → DiT inference service: queues conditions (evidence: `core/lip_sync.py`)
- DiT inference service → Lip-sync coordinator: sends latent blocks
- Lip-sync coordinator → Wan VAE wrapper: decodes frames (evidence: `core/lip_sync.py`)
- Lip-sync coordinator → Audio encoder: encodes audio (evidence: `core/lip_sync.py`)
- Lip-sync coordinator → Text encoder: conditions prompts (evidence: `core/lip_sync.py`)
- Lip-sync coordinator → WebSocket application: streams frames (evidence: `README.md`)
- Service entry → Service configuration: loads settings (evidence: `app.py`)
- Service entry → Rank communication: launches ranks (evidence: `app.py`)
- Service entry → WebSocket application: starts rank zero (evidence: `app.py`)
- Service entry → DiT inference service: starts workers (evidence: `app.py`)
- Rank communication → Sequence parallel state: initializes groups (evidence: `core/distributed.py`)
- Rank communication → DiT inference service: transfers tensors (evidence: `core/distributed.py`)
- DiT inference service → Wan diffusion wrapper: runs inference (evidence: `core/dit_service.py`)
- Wan diffusion wrapper → Causal audio-video model: invokes model (evidence: `self_forcing/utils/wan_wrapper.py`)
- Wan diffusion wrapper → Wan transformer: uses transformer (evidence: `self_forcing/utils/wan_wrapper.py`)
- Wan diffusion wrapper → Wan VAE wrapper: uses VAE (evidence: `self_forcing/utils/wan_wrapper.py`)
- Wan diffusion wrapper → Flow-match scheduler: uses scheduler (evidence: `self_forcing/utils/wan_wrapper.py`)
- Wan diffusion wrapper → Tokenizers: uses tokenizers (evidence: `self_forcing/utils/wan_wrapper.py`)
- Causal audio-video model → Wan transformer: reuses components (evidence: `self_forcing/wan/modules/causal_model_s2v.py`)
- Causal audio-video model → Audio utilities: uses audio ops (evidence: `self_forcing/wan/modules/causal_model_s2v.py`)
- Causal audio-video model → Attention layers: uses attention (evidence: `self_forcing/wan/modules/causal_model_s2v.py`)
- Wan transformer → Attention layers: uses attention (evidence: `self_forcing/wan/modules/model.py`)
- Image-text encoder → Tokenizers: uses tokenizers (evidence: `self_forcing/wan/modules/clip.py`)
- Text encoder → Tokenizers: uses tokenizers (evidence: `self_forcing/wan/modules/t5.py`)
- Causal audio-video model → Sequence parallel state: uses sequence groups (evidence: `self_forcing/wan/modules/causal_model_s2v.py`)
- Wan transformer → Sequence parallel state: uses sequence groups (evidence: `self_forcing/wan/modules/model.py`)
- Wan transformer → Parallel all-to-all: redistributes tensors (evidence: `self_forcing/wan/modules/model.py`)
