# kijai/comfyui-liveportraitkj architecture

> Architecture diagram of the GitHub repository kijai/comfyui-liveportraitkj, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kijai/comfyui-liveportraitkj
- Repository: https://github.com/kijai/comfyui-liveportraitkj

## Overview

##### Main Components (Top Level)
- Rectangle (Blue): Face Detection Systems
- Rectangle (Green): LivePortrait Pipeline
- Rectangle (Orange): ComfyUI Node Interface
- Rectangle (Purple): Media Processing
- Diamond (Gray): External Models/Resources

##### Face Detection Layer
- MediaPipe Detector
- Face Alignment Detector (with subcomponents: BlazeFace, SFD, Dlib)
- Insightface Detector (optional external)
To a "Face Detection Orchestrator" component that manages them.

##### LivePortrait Core (Middle Layer)
Create interconnected components for:
- Appearance Feature Extractor
- Motion Extractor
- Dense Motion Module
- SPADE Generator
- Warping Network
- Stitching Retargeting Network

##### Utility Layer
Supporting components:
- Camera Utils
- Cropping Utils
- Face Analysis
- Landmark Runner
- Timer/Performance Monitoring

##### External Dependencies (Bottom Layer)
External model dependencies:
- SafeTensor Models
- MediaPipe Models
- Face Landmark Models

Key Relationships to Highlight:
Input → Face Detection → Feature Extraction → Motion Processing → Generation → Output

Special Considerations:
##### Interface with ComfyUI's node system

- Blue: Input/Output components
- Green: Processing components
- Orange: Interface components
- Purple: Utility components
- Gray: External dependencies

Labels and Annotations:
##### Hardware requirements (GPU/CPU support)

Level of Detail:
- Face detection pipeline
- LivePortrait core processing
- Real-time processing optimization

Remember to:
- Notes about scaling and performance considerations
- Real-time capabilities (~80-100ms delay)
- Automatic resource downloading mechanism
- Configuration flow from the YAML files

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        A[Processing Component]:::processing
        B[Interface Component]:::interface
        C[Utility Component]:::utility
        D[External Dependency]:::external
    end

    subgraph "Face Detection Systems"
        MP["MediaPipe Detector"]:::processing
        FA["Face Alignment Detector"]:::processing
        IF["Insightface Detector"]:::processing
        FDO["Face Detection Orchestrator"]:::processing
        
        MP --> FDO
        FA --> FDO
        IF --> FDO
    end

    subgraph "LivePortrait Core"
        LP["LivePortrait Pipeline"]:::processing
        LPW["LivePortrait Wrapper"]:::processing
        AFE["Appearance Feature Extractor"]:::processing
        ME["Motion Extractor"]:::processing
        DMM["Dense Motion Module"]:::processing
        SG["SPADE Generator"]:::processing
        WN["Warping Network"]:::processing
        SRN["Stitching Retargeting Network"]:::processing
        
        AFE --> ME
        ME --> DMM
        DMM --> SG
        SG --> WN
        WN --> SRN
        
        LP --> LPW
    end

    subgraph "Utility Layer"
        CU["Camera Utils"]:::utility
        CR["Cropping Utils"]:::utility
        FA_U["Face Analysis"]:::utility
        LR["Landmark Runner"]:::utility
        TM["Timer/Performance Monitor"]:::utility
        CF["Configuration System"]:::utility
    end

    subgraph "External Dependencies"
        STM["SafeTensor Models"]:::external
        MPM["MediaPipe Models"]:::external
        FLM["Face Landmark Models"]:::external
    end

    subgraph "ComfyUI Integration"
        CNI["ComfyUI Node Interface"]:::interface
    end

    FDO --> LP
    LP --> CNI
    
    classDef processing fill:#90EE90
    classDef interface fill:#FFA500
    classDef utility fill:#DDA0DD
    classDef external fill:#808080

    click MP "https://github.com/kijai/ComfyUI-LivePortraitKJ/tree/main/media_pipe"
    click FA "https://github.com/kijai/ComfyUI-LivePortraitKJ/tree/main/face_alignment"
    click LP "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/live_portrait_pipeline.py"
    click LPW "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/live_portrait_wrapper.py"
    click AFE "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/modules/appearance_feature_extractor.py"
    click ME "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/modules/motion_extractor.py"
    click DMM "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/modules/dense_motion.py"
    click SG "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/modules/spade_generator.py"
    click WN "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/modules/warping_network.py"
    click SRN "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/modules/stitching_retargeting_network.py"
    click CU "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/utils/camera.py"
    click CR "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/utils/crop.py"
    click FA_U "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/utils/face_analysis_diy.py"
    click LR "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/utils/landmark_runner.py"
    click TM "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/liveportrait/utils/timer.py"
    click CF "https://github.com/kijai/ComfyUI-LivePortraitKJ/tree/main/liveportrait/config"
    click MPM "https://github.com/kijai/ComfyUI-LivePortraitKJ/tree/main/media_pipe/mp_models"
    click CNI "https://github.com/kijai/ComfyUI-LivePortraitKJ/blob/main/nodes.py"
```
