# fujiwarachoki/moneyprinter architecture

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

- Interactive diagram: https://gitdiagram.com/fujiwarachoki/moneyprinter
- Repository: https://github.com/fujiwarachoki/moneyprinter
- Video tour (about a minute): https://gitdiagram.com/fujiwarachoki/moneyprinter/video

## Overview

- **High-level shape:** MoneyPrinter is a Python-backed, queue-based video generation system with a thin browser UI. The core architecture is split into a **frontend**, an **API service**, an **asynchronous worker**, and a **Postgres-backed job store**.

- **User-facing boundary:** `Frontend/index.html` and `Frontend/app.js` provide a lightweight client that submits a topic, watches job progress, and surfaces results. The UI does not do generation itself; it talks to the backend over HTTP.

- **API service:** `Backend/main.py` is the request entrypoint. Its role is to accept job creation and status requests, persist work in the database, and expose any misc/job endpoints the UI needs. The API is intentionally not the heavy compute layer.

- **Persistent queue and state:** `Backend/db.py` and `Backend/repository.py` form the persistence boundary. They store job records, queue state, progress, and final outputs in Postgres. This is the key reliability feature: jobs survive restarts because the queue is database-backed rather than in-memory.

- **Worker process:** `Backend/worker.py` is the execution engine. It pulls queued jobs from the database, runs them through the pipeline, and writes status/progress back. This decouples submission from long-running generation and makes the system restart-safe.

- **Orchestration layer:** `Backend/pipeline.py` coordinates the end-to-end generation flow. It is the central workflow boundary that ties together model calls, content search, narration, video assembly, and optional publishing steps.

- **LLM integration:** `Backend/gpt.py` is the Ollama-facing adapter. The README makes the project’s AI stance explicit: script generation and metadata are **Ollama-first** and run against local models rather than a hosted LLM API.

- **Media generation subsystem:** `Backend/video.py` handles assembling the final short-form video, likely combining visuals, audio, captions, and timing. `Backend/tiktokvoice.py` provides narration voice generation. The project also expects local media tooling such as ImageMagick, and the Docker/docs suggest standard containerized media processing.

- **Supporting content / integrations:** `Backend/search.py` appears to support topic research or retrieval for content enrichment. `Backend/youtube.py` is the external publishing boundary for YouTube-related actions, while `Backend/utils.py` and `Backend/models.py` provide shared helpers and domain objects used across the pipeline.

- **Observability and progress:** `Backend/logstream.py` exists to stream worker logs or live progress back to the UI. Combined with job polling/status updates, it gives the frontend visibility into a multi-step asynchronous workflow.

- **Runtime and deployment model:** The repo is designed to run with **Python**, **Postgres**, and **Ollama**, typically via `docker-compose.yml` and the provided `Dockerfile`. The system is therefore a small distributed app: browser UI → API → database queue → worker → external/local AI and media tools → persisted output.

- **Verification boundaries:** The test suite (`tests/test_api_jobs.py`, `tests/test_repository.py`, `tests/test_worker.py`, etc.) mirrors the major subsystems, which reinforces the architecture: API behavior, persistence, worker orchestration, and utility functions are tested separately.

Main entry points: [`Backend/pipeline.py`](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/pipeline.py) (Pipeline), [`Frontend/app.js`](https://github.com/fujiwarachoki/moneyprinter/blob/main/Frontend/app.js) (UI Logic), [`Backend/main.py`](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/main.py) (API Service), [`Backend/worker.py`](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/worker.py) (Job Worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_index["Browser UI<br/>html client<br/>[index.html]"]
  node_frontend_app["UI Logic<br/>js client<br/>[app.js]"]
end

subgraph group_backend_api["Backend API"]
  node_api_main{{"API Service<br/>HTTP server<br/>[main.py]"}}
  node_api_logstream["Live Stream<br/>progress stream<br/>[logstream.py]"]
end

subgraph group_backend_worker["Worker"]
  node_worker{{"Job Worker<br/>async runner<br/>[worker.py]"}}
  node_pipeline["Pipeline<br/>workflow coordinator<br/>[pipeline.py]"]
end

subgraph group_backend_data["Persistence"]
  node_db[("DB Layer<br/>postgres access<br/>[db.py]")]
  node_repository[("Job Store<br/>[repository.py]")]
  node_models["Domain Models<br/>schemas<br/>[models.py]"]
end

subgraph group_backend_media["Media & Integrations"]
  node_gpt["Ollama Adapter<br/>llm client<br/>[gpt.py]"]
  node_search["Research<br/>retrieval<br/>[search.py]"]
  node_video{{"Video Assembly<br/>media pipeline<br/>[video.py]"}}
  node_voice["Voice Synth<br/>narration<br/>[tiktokvoice.py]"]
  node_youtube["YouTube<br/>publishing adapter<br/>[youtube.py]"]
  node_utils["Shared Utils<br/>helpers<br/>[utils.py]"]
end

subgraph group_runtime["Runtime & Deploy"]
  node_dockerfile["Dockerfile<br/>container build"]
  node_compose["Compose Setup<br/>deployment<br/>[docker-compose.yml]"]
  node_env["Env Example<br/>config template<br/>[.env.example]"]
end

node_frontend_index -->|"loads"| node_frontend_app
node_frontend_app -->|"HTTP"| node_api_main
node_frontend_app -->|"stream"| node_api_logstream
node_api_main -->|"persists"| node_repository
node_api_main -->|"uses"| node_models
node_worker -->|"claims"| node_repository
node_worker -->|"executes"| node_pipeline
node_pipeline -->|"generates"| node_gpt
node_pipeline -->|"researches"| node_search
node_pipeline -->|"narrates"| node_voice
node_pipeline -->|"assembles"| node_video
node_pipeline -->|"publishes"| node_youtube
node_pipeline -->|"shares"| node_utils
node_repository -->|"stores in"| node_db
node_db -->|"maps"| node_models
node_api_logstream -.->|"observes"| node_worker
node_compose -->|"builds"| node_dockerfile
node_compose -.->|"configures"| node_env

click node_frontend_index "https://github.com/fujiwarachoki/moneyprinter/blob/main/Frontend/index.html"
click node_frontend_app "https://github.com/fujiwarachoki/moneyprinter/blob/main/Frontend/app.js"
click node_api_main "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/main.py"
click node_api_logstream "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/logstream.py"
click node_worker "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/worker.py"
click node_pipeline "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/pipeline.py"
click node_db "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/db.py"
click node_repository "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/repository.py"
click node_models "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/models.py"
click node_gpt "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/gpt.py"
click node_search "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/search.py"
click node_video "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/video.py"
click node_voice "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/tiktokvoice.py"
click node_youtube "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/youtube.py"
click node_utils "https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/utils.py"
click node_dockerfile "https://github.com/fujiwarachoki/moneyprinter/tree/main/Dockerfile"
click node_compose "https://github.com/fujiwarachoki/moneyprinter/blob/main/docker-compose.yml"
click node_env "https://github.com/fujiwarachoki/moneyprinter/blob/main/.env.example"

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_frontend_index,node_frontend_app toneBlue
class node_api_main,node_api_logstream toneAmber
class node_worker,node_pipeline toneMint
class node_db,node_repository,node_models toneRose
class node_gpt,node_search,node_video,node_voice,node_youtube,node_utils toneIndigo
class node_dockerfile,node_compose,node_env toneTeal
```

## Components

### Frontend

Thin browser client for job submission and progress display

- [Browser UI](https://github.com/fujiwarachoki/moneyprinter/blob/main/Frontend/index.html): html client · Minimal page for submitting topics and viewing status · `Frontend/index.html`
- [UI Logic](https://github.com/fujiwarachoki/moneyprinter/blob/main/Frontend/app.js): js client · Client-side job polling and progress updates · `Frontend/app.js`

### Backend API

HTTP entrypoints and job-facing endpoints

- [API Service](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/main.py): HTTP server · Job creation, status, and misc endpoints · `Backend/main.py`
- [Live Stream](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/logstream.py): progress stream · Streams worker logs or live progress to the UI · `Backend/logstream.py`

### Worker

Asynchronous execution and orchestration layer

- [Job Worker](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/worker.py): async runner · Dequeues jobs and executes the generation pipeline · `Backend/worker.py`
- [Pipeline](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/pipeline.py): workflow coordinator · End-to-end generation flow across content, media, and publishing · `Backend/pipeline.py`

### Persistence

Database-backed queue, job state, and domain models

- [DB Layer](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/db.py): postgres access · Database connection and low-level persistence support · `Backend/db.py`
- [Job Store](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/repository.py): repository · Job records, queue state, progress, and outputs · `Backend/repository.py`
- [Domain Models](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/models.py): schemas · Shared job and content objects used across the backend · `Backend/models.py`

### Media & Integrations

Content generation, narration, search, and publishing adapters

- [Ollama Adapter](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/gpt.py): llm client · Local-model script and metadata generation · `Backend/gpt.py`
- [Research](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/search.py): retrieval · Topic enrichment and content lookup · `Backend/search.py`
- [Video Assembly](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/video.py): media pipeline · Builds the final short-form video output · `Backend/video.py`
- [Voice Synth](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/tiktokvoice.py): narration · Generates narration audio for videos · `Backend/tiktokvoice.py`
- [YouTube](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/youtube.py): publishing adapter · External publishing boundary for YouTube actions · `Backend/youtube.py`
- [Shared Utils](https://github.com/fujiwarachoki/moneyprinter/blob/main/Backend/utils.py): helpers · Common backend helper functions · `Backend/utils.py`

### Runtime & Deploy

Containerization, environment, and local tooling

- [Dockerfile](https://github.com/fujiwarachoki/moneyprinter/tree/main/Dockerfile): container build · Builds the application image · `Dockerfile`
- [Compose Setup](https://github.com/fujiwarachoki/moneyprinter/blob/main/docker-compose.yml): deployment · Local multi-service runtime for app, database, and Ollama · `docker-compose.yml`
- [Env Example](https://github.com/fujiwarachoki/moneyprinter/blob/main/.env.example): config template · Documented environment variables for local setup · `.env.example`

## Connections

- Browser UI → UI Logic: loads · HTML bootstraps the client script
- UI Logic → API Service: HTTP · Submits jobs and polls status
- UI Logic → Live Stream: stream · Receives live progress updates
- API Service → Job Store: persists · Creates and updates job records
- API Service → Domain Models: uses · Serializes and validates domain objects
- Job Worker → Job Store: claims · Reads queued jobs and writes back state
- Job Worker → Pipeline: executes · Runs the end-to-end workflow
- Pipeline → Ollama Adapter: generates · Creates scripts and metadata with local models
- Pipeline → Research: researches · Enriches topics with retrieval or search
- Pipeline → Voice Synth: narrates · Produces spoken audio tracks
- Pipeline → Video Assembly: assembles · Combines media into final output
- Pipeline → YouTube: publishes · Optionally sends finished content outward
- Pipeline → Shared Utils: shares · Uses common helpers during workflow steps
- Job Store → DB Layer: stores in · Backed by Postgres persistence
- DB Layer → Domain Models: maps · Stores structured job data
- Live Stream → Job Worker: observes · Surfaces worker progress and logs
- Compose Setup → Dockerfile: builds · Compose uses the application image
- Compose Setup → Env Example: configures · Environment values drive local runtime
