# ddean2009/moneyprinterplus architecture

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

- Interactive diagram: https://gitdiagram.com/ddean2009/moneyprinterplus
- Repository: https://github.com/ddean2009/moneyprinterplus

## Overview

##### Project Type & Purpose
- This is a full-stack Python application with a Streamlit GUI (“frontend”) that orchestrates video production workflows:
- AI-driven short-video generation (text→TTS→clips→ffmpeg)
- Batch video “mix-clips” assembly
- Automated video publishing via Selenium to platforms (抖音, 快手, 小红书, 视频号).
- It organizes code into a GUI entry point (`gui.py`/`main.py`), a “pages” layer for individual workflows, a service layer encapsulating domain logic, and various tool & config modules.

##### File-Structure Analysis & Architectural Patterns
- Top-level:
- `gui.py` / `main.py` – start Streamlit app
- `pages/` – UI pages (01_auto_video, 02_mix_video, 03_auto_publish)
- `services/` – modular backend services (audio, captioning, video, publisher, resource, llm, sd, …)
- `tools/` – shared utilities (file, font, sys utils)
- `config/`, `const/` – configuration management
- `bgmusic/`, `fonts/`, `chattts/`, `work/`, `final/` – static assets & output
- `docker/`, `setup/`, start scripts – deployment automation
- Pattern: Layered (UI → Orchestrator → Service layer → External systems & local resources)

##### Key Architectural Components
a. Frontend (Streamlit GUI)
- Components: `gui.py`, `pages/common.py`, `pages/01_*`, etc.
- Role: collect user inputs, display progress & results, invoke orchestration.
b. Orchestration / Controller
- Lives in page scripts & modules under `services/` that wire together calls to low-level services.
c. Service Layer (domain modules in `services/`)
- Audio services: speech recognition (faster-whisper, cloud providers), TTS (Azure, Tencent, chatTTS local)
- Captioning services: generate subtitles
- Video services: clip merging, transitions, ffmpeg orchestration
- LLM services: prompt→text generation via OpenAI, Azure, Baichuan, local Ollama, etc.
- Resource services: fetch stock clips from Pixabay/Pexels
- SD service: stable diffusion/WebUI API (future)
- Publisher services: Selenium-based upload to each platform
d. External Dependencies & Local Models
- External REST/WebSocket APIs: Azure Cognitive Services, Alibaba NLS, Tencent Cloud, OpenAI, …
- Local models & files: faster-whisper embeddings, chatTTS `.pt`, fonts, background music.
- ffmpeg CLI for video encoding & merging.
- Selenium WebDriver for browser automation.
e. Data Storage & Outputs
- `final/` for generated videos
- Local folders for assets (`bgmusic/`, `fonts/`, `chattts/`)
- Logs under Streamlit / Docker setups

##### Relationships & Data Flows
- User → Streamlit UI → Orchestrator
- Orchestrator → Service Layer modules
- Text prompts → LLM → video script
- Script → TTS service → audio track
- video assets → Video service (ffmpeg) → merged clips + subtitles
- background music selection
- Output → `final/` → displayed in UI
- For publishing:
- UI settings → Publisher service → Selenium → Browser (Chrome/Firefox) → Platform websites

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "UI Layer"
        gui["gui.py"]:::internal
        main["main.py"]:::internal
    end

    subgraph "Orchestrator (Pages)"
        common["pages/common.py"]:::internal
        auto1["pages/01_auto_video.py"]:::internal
        mix2["pages/02_mix_video.py"]:::internal
        merge2["pages/02_merge_video.py"]:::internal
        publish3["pages/03_auto_publish.py"]:::internal
    end

    subgraph "Service Layer"
        audio["services/audio/audio_service.py"]:::internal
        cap["services/captioning/captioning_service.py"]:::internal
        video["services/video/video_service.py"]:::internal
        llm["services/llm/llm_service.py"]:::internal
        res["services/resource/resource_service.py"]:::internal
        pub["services/publisher/publish_video.py"]:::internal
        sd["services/sd/sd_service.py"]:::internal
    end

    subgraph "External APIs & Tools"
        azureASR["Azure Cognitive Services"]:::external
        openai["OpenAI API"]:::external
        ffmpeg["ffmpeg CLI"]:::external
        selenium["Selenium WebDriver"]:::external
    end

    subgraph "Local Resources & Models"
        bgmusic["bgmusic/"]:::local
        fonts["fonts/"]:::local
        chattts["chattts/"]:::local
    end

    subgraph "Storage"
        final["final/"]:::storage
    end

    gui --> main
    main --> common
    common --> auto1
    common --> mix2
    common --> merge2
    common --> publish3

    auto1 -->|"prompt text"| llm
    auto1 -->|"audio file"| audio
    auto1 -->|"assets request"| res
    auto1 -->|"video clip"| video

    mix2 -->|"clip list"| video
    merge2 -->|"clips"| video

    publish3 -->|"video file"| pub

    llm -->|"API call"| openai
    audio -->|"TTS/ASR request"| azureASR
    audio -->|"local model"| chattts
    video -->|"encode/merge"| ffmpeg
    pub -->|"browser automation"| selenium

    video --> final
    pub --> final
    final -->|"display output"| main

    classDef internal fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef external fill:#DFF6DD,stroke:#2C662D,color:#2C662D;
    classDef local fill:#FFEFD5,stroke:#CC6600,color:#CC6600;
    classDef storage fill:#F0F0F0,stroke:#888888,color:#444444;

    click gui "https://github.com/ddean2009/moneyprinterplus/blob/main/gui.py"
    click main "https://github.com/ddean2009/moneyprinterplus/blob/main/main.py"
    click common "https://github.com/ddean2009/moneyprinterplus/blob/main/pages/common.py"
    click auto1 "https://github.com/ddean2009/moneyprinterplus/blob/main/pages/01_auto_video.py"
    click mix2 "https://github.com/ddean2009/moneyprinterplus/blob/main/pages/02_mix_video.py"
    click merge2 "https://github.com/ddean2009/moneyprinterplus/blob/main/pages/02_merge_video.py"
    click publish3 "https://github.com/ddean2009/moneyprinterplus/blob/main/pages/03_auto_publish.py"
    click audio "https://github.com/ddean2009/moneyprinterplus/blob/main/services/audio/audio_service.py"
    click cap "https://github.com/ddean2009/moneyprinterplus/blob/main/services/captioning/captioning_service.py"
    click video "https://github.com/ddean2009/moneyprinterplus/blob/main/services/video/video_service.py"
    click llm "https://github.com/ddean2009/moneyprinterplus/blob/main/services/llm/llm_service.py"
    click res "https://github.com/ddean2009/moneyprinterplus/blob/main/services/resource/resource_service.py"
    click pub "https://github.com/ddean2009/moneyprinterplus/blob/main/services/publisher/publish_video.py"
    click sd "https://github.com/ddean2009/moneyprinterplus/blob/main/services/sd/sd_service.py"
```
