# chatfire-ai/huobao-drama architecture

> Architecture diagram of the GitHub repository chatfire-ai/huobao-drama, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chatfire-ai/huobao-drama
- Repository: https://github.com/chatfire-ai/huobao-drama

## Overview

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: [`backend/src/routes`](https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/routes) (API Routes), [`backend/src/services/adapters`](https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/services/adapters) (Provider Adapters), [`backend/src/utils/storage.ts`](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/utils/storage.ts) (Asset Store), [`backend/src/index.ts`](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/index.ts) (Server Entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["Studio UI<br/>Nuxt 3 app"]
  node_frontend_api["API Composables<br/>client boundary"]
  node_frontend_pages["Work Pages<br/>routes/ui"]
end

subgraph group_backend["Backend"]
  node_backend_entry["Server Entry<br/>Hono entrypoint<br/>[index.ts]"]
  node_backend_routes["API Routes<br/>resource routes"]
  node_backend_db[("Data Model<br/>Drizzle schema")]
  node_backend_agents["Agent Layer<br/>Mastra agents"]
  node_backend_skills["Skill Loader<br/>prompt loader<br/>[skills.ts]"]
  node_backend_image["Image Gen<br/>media service"]
  node_backend_video["Video Gen<br/>media service"]
  node_backend_tts["Voice Gen<br/>media service<br/>[tts-generation.ts]"]
  node_backend_compose["Compose Export<br/>ffmpeg pipeline<br/>[ffmpeg-compose.ts]"]
  node_backend_adapters["Provider Adapters<br/>vendor registry"]
  node_backend_grid["Grid Split<br/>media utility<br/>[grid-split.ts]"]
end

subgraph group_infra["Runtime"]
  node_backend_storage[("Asset Store<br/>filesystem storage<br/>[storage.ts]")]
  node_backend_runtime["Config Runtime<br/>yaml config"]
  node_backend_logger["Task Logger<br/>observability<br/>[task-logger.ts]"]
end

subgraph group_skills["Skills"]
  node_skill_files["Skill Prompts<br/>prompt assets"]
end

node_frontend_pages -->|"uses"| node_frontend_api
node_frontend_api -->|"requests"| node_backend_routes
node_backend_entry -->|"mounts"| node_backend_routes
node_backend_routes -->|"reads/writes"| node_backend_db
node_backend_routes -->|"orchestrates"| node_backend_agents
node_backend_agents -->|"loads"| node_backend_skills
node_backend_skills -->|"reads"| node_skill_files
node_backend_routes -->|"triggers"| node_backend_image
node_backend_routes -->|"triggers"| node_backend_video
node_backend_routes -->|"triggers"| node_backend_tts
node_backend_image -->|"delegates"| node_backend_adapters
node_backend_video -->|"delegates"| node_backend_adapters
node_backend_tts -->|"delegates"| node_backend_adapters
node_backend_routes -->|"exports"| node_backend_compose
node_backend_routes -->|"splits"| node_backend_grid
node_backend_routes -->|"stores"| node_backend_storage
node_backend_compose -->|"reads/writes"| node_backend_storage
node_backend_routes -.->|"traces"| node_backend_logger
node_backend_routes -.->|"configured by"| node_backend_runtime
node_frontend_app -->|"contains"| node_frontend_pages
node_backend_entry -->|"uses"| node_backend_storage

click node_frontend_app "https://github.com/chatfire-ai/huobao-drama/tree/master/frontend/app"
click node_frontend_api "https://github.com/chatfire-ai/huobao-drama/tree/master/frontend/app/composables"
click node_frontend_pages "https://github.com/chatfire-ai/huobao-drama/tree/master/frontend/app/pages"
click node_backend_entry "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/index.ts"
click node_backend_routes "https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/routes"
click node_backend_db "https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/db"
click node_backend_agents "https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/agents"
click node_backend_skills "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/agents/skills.ts"
click node_backend_image "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/image-generation.ts"
click node_backend_video "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/video-generation.ts"
click node_backend_tts "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/tts-generation.ts"
click node_backend_compose "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/ffmpeg-compose.ts"
click node_backend_adapters "https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/services/adapters"
click node_backend_grid "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/grid-split.ts"
click node_backend_storage "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/utils/storage.ts"
click node_backend_runtime "https://github.com/chatfire-ai/huobao-drama/blob/master/configs/config.example.yaml"
click node_backend_logger "https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/utils/task-logger.ts"
click node_skill_files "https://github.com/chatfire-ai/huobao-drama/tree/master/skills"

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_app,node_frontend_api,node_frontend_pages toneBlue
class node_backend_entry,node_backend_routes,node_backend_db,node_backend_agents,node_backend_skills,node_backend_image,node_backend_video,node_backend_tts,node_backend_compose,node_backend_adapters,node_backend_grid toneAmber
class node_backend_storage,node_backend_runtime,node_backend_logger toneMint
class node_skill_files toneRose
```

## Components

### Frontend

Nuxt 3 studio UI for drama workflows

- [Studio UI](https://github.com/chatfire-ai/huobao-drama/tree/master/frontend/app): Nuxt 3 app · Main Vue/Nuxt frontend that orchestrates drama production actions · `frontend/app`
- [API Composables](https://github.com/chatfire-ai/huobao-drama/tree/master/frontend/app/composables): client boundary · Shared frontend access layer for backend requests and agent calls · `frontend/app/composables`
- [Work Pages](https://github.com/chatfire-ai/huobao-drama/tree/master/frontend/app/pages): routes/ui · Drama list, drama detail, episode workspace, and settings pages · `frontend/app/pages`

### Backend

Hono API, domain model, agents, and media pipeline

- [Server Entry](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/index.ts): Hono entrypoint · Bootstraps the backend HTTP server and mounts route modules · `backend/src/index.ts`
- [API Routes](https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/routes): resource routes · Domain routes for dramas, episodes, scenes, media, config, skills, and webhooks · `backend/src/routes`
- [Data Model](https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/db): Drizzle schema · SQLite schema and database initialization for core production entities · `backend/src/db`
- [Agent Layer](https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/agents): Mastra agents · Structured AI agents that rewrite scripts, extract data, break storyboards, assign voices, and generate grid prompts · `backend/src/agents`
- [Skill Loader](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/agents/skills.ts): prompt loader · Loads SKILL.md definitions and prompt assets into agents at runtime · `backend/src/agents/skills.ts`
- [Image Gen](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/image-generation.ts): media service · Coordinates image creation through provider adapters · `backend/src/services/image-generation.ts`
- [Video Gen](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/video-generation.ts): media service · Coordinates video creation through provider adapters · `backend/src/services/video-generation.ts`
- [Voice Gen](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/tts-generation.ts): media service · Coordinates TTS generation through provider adapters · `backend/src/services/tts-generation.ts`
- [Compose Export](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/ffmpeg-compose.ts): ffmpeg pipeline · Assembles generated assets into episode media and mergeable exports · `backend/src/services/ffmpeg-compose.ts`
- [Provider Adapters](https://github.com/chatfire-ai/huobao-drama/tree/master/backend/src/services/adapters): vendor registry · Normalizes multiple external AI vendors behind a common generation interface · `backend/src/services/adapters`
- [Grid Split](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/services/grid-split.ts): media utility · Splits grid or composite sources for downstream generation workflows · `backend/src/services/grid-split.ts`

### Runtime

Config, storage, and deployment boundaries

- [Asset Store](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/utils/storage.ts): filesystem storage · Local storage for database files, uploads, generated media, and exports · `backend/src/utils/storage.ts`
- [Config Runtime](https://github.com/chatfire-ai/huobao-drama/blob/master/configs/config.example.yaml): yaml config · Server, storage, CORS, and default provider settings for deployment · `configs/config.example.yaml`
- [Task Logger](https://github.com/chatfire-ai/huobao-drama/blob/master/backend/src/utils/task-logger.ts): observability · Logger and task tracing for long-running generation workflows · `backend/src/utils/task-logger.ts`

### Skills

Prompt skill definitions loaded by agents

- [Skill Prompts](https://github.com/chatfire-ai/huobao-drama/tree/master/skills): prompt assets · Runtime skill definitions and reference prompts used by agents · `skills`

## Connections

- 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
