This file is the operating manual for coding agents working in this repository. Follow it before making changes.
Backend/: Flask API, DB-backed job queue, and video generation pipeline.Frontend/: static HTML/JS client served bypython -m http.server.docs/: source-of-truth setup and runtime docs.fonts/,Songs/,subtitles/,temp/: runtime assets/output folders.- Root output artifact:
output.mp4.
- No
.cursor/rules/directory found. - No
.cursorrulesfile found. - No
.github/copilot-instructions.mdfile found. - If any of the above appear later, treat them as higher-priority constraints and update this file.
- Python version:
>=3.11(frompyproject.toml). - Dependency manager used in docs:
uv. - Create local env file:
cp .env.example .env. - Install dependencies:
uv sync. - Run backend:
uv run python Backend/main.py. - Run worker (new terminal):
uv run python Backend/worker.py. - Run frontend (new terminal):
python3 -m http.server 3000 --directory Frontend. - Docker workflow:
docker compose up --build.
This project has a baseline pytest setup for backend repository tests.
Use the commands below as the expected agent workflow.
- Backend syntax check:
uv run python -m compileall Backend. - Frontend syntax sanity (lightweight): open
Frontend/index.htmlin browser and run generation flow. - API smoke check after backend start:
curl http://localhost:8080/api/models. - Queue smoke check:
curl -X POST http://localhost:8080/api/generate -H "Content-Type: application/json" -d '{"videoSubject":"test","voice":"en_us_001","paragraphNumber":1,"customPrompt":""}'. - Full local run: backend + worker + frontend servers, then generate a short sample video.
- There is no enforced formatter in-repo today.
- Follow existing style and keep diffs minimal.
- If linting is requested, prefer adding tooling in a separate PR.
- Suggested ad-hoc checks when available locally:
uv run python -m py_compile Backend/*.pyuv run python -m compileall Backend
- Run all tests:
uv run pytest - Run one file:
uv run pytest tests/test_file.py - Run a single test:
uv run pytest tests/test_file.py::test_name - Run a single class test:
uv run pytest tests/test_file.py::TestClass::test_name - Current suite location:
tests/.
These conventions are inferred from current source and should guide new changes.
- Prefer standard library imports first, then third-party, then local modules.
- Use one import per line for readability in long modules.
- Avoid wildcard imports in new code (
from module import *), even if legacy files use them. - Prefer explicit local imports, e.g.
from utils import ENV_FILE, TEMP_DIR.
- Use 4-space indentation in Python.
- Keep line length readable; split long calls across multiple lines.
- Favor small helper functions for distinct pipeline stages.
- Keep side-effectful startup logic near application boot (
load_dotenv, env checks).
- Add type hints to all new/modified function signatures.
- Reuse
Optional,List,Tuple,dicttyping already used in backend. - Prefer explicit return types (
-> str,-> None,-> Tuple[...]). - Use
Pathfor filesystem paths where practical.
- Python functions/variables:
snake_case. - Constants/env keys:
UPPER_SNAKE_CASE. - JS variables/functions in frontend:
camelCase. - Keep API route names simple and verb-oriented (
/api/generate,/api/cancel).
- Fail fast on missing critical env vars (current code exits early in startup checks).
- Catch exceptions at boundary layers (HTTP handlers, external API calls, file IO).
- Return user-safe JSON error messages from Flask endpoints.
- Log actionable context with existing logger/log-stream helpers.
- Do not swallow exceptions silently; at minimum emit error logs.
- Prefer
pathlib.Pathoperations. - Ensure directories exist before writing (
mkdir(parents=True, exist_ok=True)). - Sanitize uploaded filenames (
os.path.basename) before save. - Avoid hardcoded OS-specific paths; rely on env vars and
Path.resolve().
- Keep endpoint payloads consistent with
{"status": "success|error", ...}. - Use appropriate HTTP status codes for conflict/client errors (e.g.,
409,400). - Long-running work should run in worker process from DB queue, not on request thread.
- Preserve cancellation semantics using per-job cancellation and persisted job events.
- Use centralized API helper (
apiRequest) for backend calls. - Validate required fields before firing requests.
- Keep user feedback explicit via toasts and status area toggles.
- Preserve localStorage key patterns (
<fieldId>Value).
- Make minimal, targeted edits.
- Do not rename files/modules unless required by task.
- Do not introduce new frameworks/toolchains without request.
- Keep backward compatibility for existing API payload shape when possible.
- Update docs in
docs/when setup, env vars, or runtime behavior changes.
- Ran relevant command(s) from section 4.
- Confirmed backend still starts (
uv run python Backend/main.py). - Confirmed worker still starts (
uv run python Backend/worker.py). - Confirmed frontend still loads (
python3 -m http.server 3000 --directory Frontend). - Verified changed endpoints still return JSON and preserve
statusfield. - Checked no secrets were added to tracked files.
- Keep tests standardized on
pytestand document exact paths/selectors here. - If adding linting, prefer
rufffor lint + format and commit config files. - If adding type checks, document command and strictness level (
mypyor equivalent). - Keep this file updated whenever workflow commands change.
- Prefer minimal diffs and preserve current behavior unless the task requires changes.
- Keep API responses machine-parseable and consistent for frontend consumers.
- Avoid checking in generated media/output artifacts unless explicitly requested.
- Before returning work, include what was validated and what was not validated.
- When adding commands or tooling, update this file and
docs/together.