# MoneyPrinterTurbo Architecture: A Deep Dive into the FastAPI and Streamlit Video Generation System

> Explore the MoneyPrinterTurbo architecture. Learn how this FastAPI and Streamlit system uses controller-service-model separation for LLM script generation, TTS, and video assembly.

- Repository: [Harry/MoneyPrinterTurbo](https://github.com/harry0703/MoneyPrinterTurbo)
- Tags: architecture
- Published: 2026-03-23

---

**MoneyPrinterTurbo is a modular, FastAPI‑based backend with a Streamlit web UI that orchestrates LLM script generation, text‑to‑speech, and video assembly through a clean controller‑service‑model separation.**

The `harry0703/MoneyPrinterTurbo` repository implements a fully automated short‑video generation pipeline. Its architecture cleanly separates the presentation layer (Streamlit), API routing (FastAPI), business logic (services), and data models (Pydantic), enabling both local development and scalable containerized deployments.

## High‑Level Architecture Overview

MoneyPrinterTurbo follows a **layered MVC‑style pattern** where the Streamlit UI communicates via HTTP with a FastAPI ASGI application, which delegates work to specialized service modules.

The system comprises four primary layers:

- **Presentation Layer**: Streamlit dashboard ([`webui/Main.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/webui/Main.py)) that renders controls, streams logs, and displays results.
- **API Layer**: FastAPI application ([`app/asgi.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/asgi.py)) with CORS, static file mounts, and versioned routers.
- **Business Logic Layer**: Controllers (`app/controllers/v1/`) for request validation and Services (`app/services/`) for pipeline execution.
- **Data & State Layer**: Pydantic models (`app/models/`), configuration (`app/config/`), and task state management ([`app/services/state.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/state.py)).

## Core Components and Responsibilities

### Entry Points and Routing

The application bootstrap occurs in [`main.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/main.py), which launches Uvicorn with the ASGI app defined in [`app/asgi.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/asgi.py). This file instantiates the FastAPI instance, registers CORS middleware, mounts static directories (`/tasks` for generated videos), and includes the root router from [`app/router.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/router.py).

The root router aggregates version‑1 API endpoints, currently grouping video generation routes (`/videos`) and LLM utility routes under separate prefixes.

### Controllers Layer

Controllers act as thin HTTP adapters that validate Pydantic request bodies, extract request IDs, and delegate to services.

- **[`app/controllers/v1/video.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/controllers/v1/video.py)**: Handles the full video lifecycle including `POST /videos` for creation, task status queries, subtitle generation (`/subtitle`), audio synthesis (`/audio`), and material upload endpoints.
- **[`app/controllers/v1/llm.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/controllers/v1/llm.py)**: Exposes endpoints for script generation and keyword extraction, consumed by the Streamlit UI to provide real‑time script suggestions.

### Services Layer

Services encapsulate the core business logic and external integrations. The [`app/services/task.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/task.py) module orchestrates the end‑to‑end pipeline by coordinating calls to specialized service modules.

**Task Orchestration ([`app/services/task.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/task.py))**

The `start()` function executes the generation workflow asynchronously:

1. **Script Generation**: Calls `llm.generate_script()` to produce narration text.
2. **Keyword Extraction**: Invokes `llm.generate_terms()` for video material search.
3. **Text‑to‑Speech**: Uses `voice.tts()` to generate audio and subtitle timing files.
4. **Material Preparation**: `video.prepare_materials()` downloads clips from Pexels/Pixabay or sources local files.
5. **Video Assembly**: `video.concat_clips()` applies transitions and aspect ratio formatting.
6. **Subtitle Overlay**: `video.add_subtitles()` burns text into the video.
7. **Audio Mixing**: `video.mix_background()` combines TTS audio with background music.

**State Management ([`app/services/state.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/state.py))**

Maintains task progress in an in‑memory dictionary by default. When `enable_redis` is configured, the system instantiates `RedisTaskManager` for distributed state persistence, enabling horizontal scaling of worker nodes.

**LLM Service ([`app/services/llm.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/llm.py))**

Abstracts multiple providers (OpenAI, Azure, Moonshot, Gemini, etc.) through a unified interface. Handles prompt templating for script generation and keyword extraction.

**Voice Service ([`app/services/voice.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/voice.py))**

Implements TTS adapters for Azure Cognitive Services, Edge‑TTS, SiliconFlow, and Gemini. Returns audio file paths and subtitle timing metadata compatible with the video service.

**Video Service ([`app/services/video.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/video.py))**

Handles the complete video processing pipeline: HTTP client for stock footage APIs (Pexels/Pixabay), FFmpeg‑based clip manipulation, transition effects, subtitle rendering with configurable fonts, and audio mixing.

### Models and Utilities

**Data Models ([`app/models/schema.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/models/schema.py))**

Defines Pydantic schemas for type‑safe request/response handling, including `TaskVideoRequest`, `AudioRequest`, and response wrappers.

**Configuration ([`app/config/config.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/config/config.py))**

Loads TOML configuration from [`config.toml`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/config.toml) (copied from [`config.example.toml`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/config.example.toml) at runtime), exposing sections for application settings, Azure credentials, SiliconFlow keys, and UI defaults.

**Utilities ([`app/utils/utils.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/utils/utils.py))**

Provides cross‑cutting concerns: UUID generation, filesystem path helpers, JSON serialization, logging wrappers, and string manipulation functions used throughout the services.

## Data Flow: How a Video Generation Request Works

Understanding the request lifecycle clarifies how the architectural layers interact:

1. **Client Request**: The Streamlit UI ([`webui/Main.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/webui/Main.py)) collects user parameters and POSTs a JSON payload to `POST /videos` with a `TaskVideoRequest` body.

2. **Controller Handling**: `app/controllers/v1/video.py:create_video()` validates the request, generates a UUID for the task, initializes the state in [`app/services/state.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/state.py), and invokes `task.start()`.

3. **Pipeline Execution**: The task orchestrator in [`app/services/task.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/task.py) executes the generation steps asynchronously:
   - Generates script and keywords via [`app/services/llm.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/llm.py)
   - Synthesizes speech via [`app/services/voice.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/voice.py)
   - Downloads or sources video materials via [`app/services/video.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/video.py)
   - Concatenates, adds subtitles, and mixes audio

4. **State Updates**: Progress is written to the state manager (in‑memory or Redis). The UI polls `GET /tasks/{task_id}` to retrieve status and final video URLs.

5. **Delivery**: Completed videos are served from the static mount at `/tasks/{task_id}/` defined in [`app/asgi.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/asgi.py), returning direct MP4 URLs to the client.

## Extensibility Points

The modular design enables customization without core modifications:

- **Custom LLM Providers**: Extend [`app/services/llm.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/llm.py) with new provider clients and update the UI configuration to expose the option.
- **Additional TTS Engines**: Implement new voice adapters in [`app/services/voice.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/voice.py) following the existing interface pattern.
- **Redis Task Queue**: Set `enable_redis = true` in [`config.toml`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/config.toml) to switch from `InMemoryTaskManager` to `RedisTaskManager` for distributed deployments.
- **Local Video Materials**: Upload custom clips to `storage/local_videos/` or use the `/video_materials` endpoint to bypass stock footage APIs.

## Deployment Options

MoneyPrinterTurbo supports multiple deployment scenarios:

- **Local Development**: Run `python webui/Main.py` for the UI and `uvicorn app.asgi:app --reload` for the API on separate terminals.
- **Docker Deployment**: Use the provided `Dockerfile` and [`docker-compose.yml`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/docker-compose.yml) to containerize both the FastAPI backend and Streamlit frontend.
- **Production Scaling**: Enable Redis state management and deploy multiple API workers behind a load balancer, with the Streamlit UI configured to point to the load‑balanced endpoint.

## Summary

- MoneyPrinterTurbo uses a **FastAPI backend** with **Streamlit frontend**, communicating via REST API.
- The architecture follows **MVC separation**: Controllers handle HTTP requests, Services contain business logic, and Models define data contracts.
- **Task orchestration** in [`app/services/task.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/task.py) coordinates LLM script generation, TTS synthesis, video material fetching, and FFmpeg assembly.
- **State management** supports both in‑memory and Redis backends for scalability.
- The system is **extensible** via modular service classes for LLM providers, TTS engines, and video sources.

## Frequently Asked Questions

### What is MoneyPrinterTurbo built with?

MoneyPrinterTurbo is built with **FastAPI** for the backend REST API and **Streamlit** for the web user interface. The video processing pipeline uses **FFmpeg** for media manipulation, while **Pydantic** handles data validation and **Uvicorn** serves the ASGI application.

### How does MoneyPrinterTurbo handle concurrent video generation tasks?

By default, MoneyPrinterTurbo uses an **in‑memory task manager** (`InMemoryTaskManager`) to track generation progress. For production deployments requiring horizontal scaling, you can enable **Redis** by setting `enable_redis = true` in [`config.toml`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/config.toml), which switches the system to use `RedisTaskManager` for distributed state synchronization across multiple worker nodes.

### Can I use my own LLM provider with MoneyPrinterTurbo?

Yes. The LLM integration in [`app/services/llm.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/services/llm.py) is designed to support multiple providers including OpenAI, Azure, Moonshot, and Gemini. To add a custom provider, extend the service module with your provider's client implementation and update the configuration schema in [`app/config/config.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/config/config.py) to expose the new provider options in the UI.

### Where are generated videos stored in MoneyPrinterTurbo?

Generated videos are stored in the `storage/tasks/<task_id>/` directory on the filesystem. The FastAPI application mounts this directory as a static route (`/tasks`) in [`app/asgi.py`](https://github.com/harry0703/MoneyPrinterTurbo/blob/main/app/asgi.py), allowing direct HTTP access to final MP4 files via URLs like `http://localhost:8080/tasks/<task_id>/final-1.mp4`.