How chatfire-ai/huobao-drama works
1. High-level shape
- This is a two-tier TypeScript application: a Nuxt 3 frontend and a Hono-based backend.
- The backend owns the full production pipeline for AI short-drama creation: script processing, character/scene extraction, storyboard generation, image/video/TTS generation, composition, and export.
2. Frontend boundary
- frontend/ is a Nuxt 3 + Vue 3 SPA-style studio UI.
- Pages are organized around drama production objects: drama list/detail, episode workspace, and settings.
- The frontend talks to the backend through composables like useApi and useAgent, and relies on backend-provided data rather than local business logic.
3. Backend API layer
- backend/src/index.ts is the server entrypoint and mounts route modules under backend/src/routes/.
- Routes are split by domain: dramas, episodes, scenes, storyboards, characters, images, videos, compose, merge, grid, upload, skills, AI config/voices, agent configs, and webhooks.
- This suggests a resource-oriented API where the UI orchestrates long-running media workflows through backend endpoints.
4. Core domain model
- The data model lives in backend/src/db/schema.ts and is managed with Drizzle ORM over SQLite.
- The main entities implied by the routes are: drama, episode, scene, storyboard, character, AI config, voice config, and generated media assets.
- backend/src/db/index.ts likely initializes the database and creates tables on first run, matching the repo’s “no manual migrations” workflow.
5. AI agent subsystem
- backend/src/agents/ contains the Mastra-based agent layer.
- There are five main agents: script rewriter, extractor, storyboard breaker, voice assigner, and grid prompt generator.
- Their role is to transform higher-level creative input into structured production artifacts, which the rest of the system consumes.
6. Skill loading boundary
- The skills/ directory contains SKILL.md definitions and reference prompt assets.
- These skills are a runtime extension mechanism for agents: the backend can load prompt/behavior definitions from files instead of hardcoding them.
- This makes the agent layer configurable without changing application code.
7. Media generation services
- backend/src/services/ contains the actual production pipeline: image generation, video generation, TTS generation, grid splitting, FFmpeg-based composition, and merge/export.
- These services are where API requests become generated assets or final episode output.
- ffmpeg-compose.ts and ffmpeg-merge.ts indicate the backend performs local media assembly, not just orchestration of external APIs.
8. Provider adapter layer
- backend/src/services/adapters/ abstracts multiple external AI vendors behind a common interface.
- Supported categories include image, video, and TTS providers; the README lists OpenAI, Gemini, MiniMax, Volcengine/Seedance, Vidu, and Ali.
- The registry pattern here is an important boundary: business logic can request “generate image/video/voice” without knowing the vendor details.
9. Storage and asset handling
- The app uses local filesystem storage under data/ for the SQLite database and generated resources.
- backend/src/utils/storage.ts and upload routes imply a shared asset store for reference images, generated media, and exported files.
- The frontend accesses these assets through backend-served static URLs, so the backend is also the media delivery boundary.
10. Configuration and runtime control
- Deployment/runtime behavior is controlled by configs/config.yaml.
- Key knobs are server host/port, CORS origins, SQLite path, storage base URL, and default AI provider selection.
- Sensitive provider keys and model choices are configured in the UI settings, which are then persisted through the backend config tables.
11. Tasking and observability
- The presence of task-logger and logger middleware suggests generation jobs are traced across long-running workflow steps.
- This is important because generation is not a single request/response path; it spans extraction, asset generation, composition, and export.
12. End-to-end data flow
- A typical flow is: user configures providers → creates/selects a drama → AI agents extract or rewrite structure → scenes/storyboards are generated → images/voices/videos are produced through adapters → FFmpeg composes episode media → final assets are stored locally and served back to the UI.
- The UI is the control plane; the backend is the workflow engine and media processing plane.
13. Deployment boundary
- The repo supports both split development and single-service deployment.
- In Docker or standalone production, the backend can serve the built frontend plus the API from one port, while still relying on local data/ persistence and external AI services.
Main entry points: routes API Routes · adapters Provider Adapters · storage.ts Asset Store · index.ts Server Entry
Components 18
Frontend
Nuxt 3 studio UI for drama workflows
- Studio UI · Main Vue/Nuxt frontend that orchestrates drama production actions
frontend/app - API Composables · Shared frontend access layer for backend requests and agent calls
frontend/app/composables - Work Pages · Drama list, drama detail, episode workspace, and settings pages
frontend/app/pages
Backend
Hono API, domain model, agents, and media pipeline
- Server Entry · Bootstraps the backend HTTP server and mounts route modules
backend/src/index.ts - API Routes · Domain routes for dramas, episodes, scenes, media, config, skills, and webhooks
backend/src/routes - Data Model · SQLite schema and database initialization for core production entities
backend/src/db - Agent Layer · Structured AI agents that rewrite scripts, extract data, break storyboards, assign voices, and generate grid prompts
backend/src/agents - Skill Loader · Loads SKILL.md definitions and prompt assets into agents at runtime
backend/src/agents/skills.ts - Image Gen · Coordinates image creation through provider adapters
backend/src/services/image-generation.ts - Video Gen · Coordinates video creation through provider adapters
backend/src/services/video-generation.ts - Voice Gen · Coordinates TTS generation through provider adapters
backend/src/services/tts-generation.ts - Compose Export · Assembles generated assets into episode media and mergeable exports
backend/src/services/ffmpeg-compose.ts - Provider Adapters · Normalizes multiple external AI vendors behind a common generation interface
backend/src/services/adapters - Grid Split · Splits grid or composite sources for downstream generation workflows
backend/src/services/grid-split.ts
Runtime
Config, storage, and deployment boundaries
- Asset Store · Local storage for database files, uploads, generated media, and exports
backend/src/utils/storage.ts - Config Runtime · Server, storage, CORS, and default provider settings for deployment
configs/config.example.yaml - Task Logger · Logger and task tracing for long-running generation workflows
backend/src/utils/task-logger.ts
Skills
Prompt skill definitions loaded by agents
- Skill Prompts · Runtime skill definitions and reference prompts used by agents
skills
Connections 21
- Work Pages → API Composables: uses · Pages call the shared API boundary for server-backed operations
- API Composables → API Routes: requests · Frontend interactions are fulfilled by resource-oriented backend endpoints
- Server Entry → API Routes: mounts · Server entry registers the route modules
- API Routes → Data Model: reads/writes · Routes persist drama, episode, scene, config, and asset state
- API Routes → Agent Layer: orchestrates · API endpoints trigger structured AI transformations
- Agent Layer → Skill Loader: loads · Agents load runtime prompt definitions and references
- Skill Loader → Skill Prompts: reads · Skill loader resolves SKILL.md and reference assets from disk
- API Routes → Image Gen: triggers · Image endpoints and workflows invoke generation services
- API Routes → Video Gen: triggers · Video endpoints and workflows invoke generation services
- API Routes → Voice Gen: triggers · Voice endpoints and workflows invoke generation services
- Image Gen → Provider Adapters: delegates · Image generation uses provider adapters for vendor-specific calls
- Video Gen → Provider Adapters: delegates · Video generation uses provider adapters for vendor-specific calls
- Voice Gen → Provider Adapters: delegates · TTS generation uses provider adapters for vendor-specific calls
- API Routes → Compose Export: exports · Compose and merge routes build final episode media
- API Routes → Grid Split: splits · Grid workflows prepare sources for downstream generation
- API Routes → Asset Store: stores · Uploads, generated assets, and exports are written to local storage
- Compose Export → Asset Store: reads/writes · FFmpeg assembly consumes stored inputs and writes final outputs
- API Routes → Task Logger: traces · Workflow endpoints emit task logs for long-running jobs
- API Routes → Config Runtime: configured by · Server behavior and provider defaults come from runtime config
- Studio UI → Work Pages: contains · App shell hosts the page-level studio experience
- Server Entry → Asset Store: uses · Backend runtime depends on local persistent storage