Building and Open-Sourcing an AI Comic Drama App in 8 Days

    This article documents the process of building and open-sourcing a minimum viable AI comic drama application in eight days. It covers the rationale behind choosing content generation as a testbed for LLM engineering, the core model selection criteria, a decoupled architecture built around a single main pipeline, and implementation details for script planning, structured validation, token cost control, and asynchronous resource handling. It also explains the observability and rate-limiting measures required before public launch, the reasoning behind open-sourcing the project, and the key takeaway that cost and stability in AI content applications are primarily determined by architecture rather than model capability alone.

    1. Project Background and Goals: Why AI Comic Drama

    As generative AI adoption accelerates, content production applications have become a high-value scenario for developers to validate LLM engineering skills. An “AI comic drama” app takes a text script as input and uses a model to automatically plan the story structure, break it into shots, generate image prompts, and assemble the output into a continuous, comic-style short drama. It touches four typical engineering problems at once: long-text understanding, structured output, multimodal content organization, and frontend rendering, which makes it a strong candidate for an end-to-end technical exercise.

    The goal was explicit: deliver a runnable, demonstrable, and extensible minimum viable product within eight days, then open-source the code so other developers can contribute. The eight-day window is not a performance metric but a record of delivery cadence under a constraint. With limited time, the priority was closing the main pipeline loop rather than achieving feature completeness.

    2. Core Selection Decision: Treating the LLM as a Content Production Engine

    The application’s core generation capability comes from a large language model service provided by a cloud vendor. During development I tracked token consumption, which fell into two parts: calls made while building the application, and calls used at runtime for actual script planning. The final bill was roughly 20 RMB, with some complimentary quota granted during a promotional period.

    The lesson matters more than the number: in content generation applications, the real cost driver is usually not debugging the model while writing code, but every user request once the product is live. Cost controllability therefore has to sit alongside functionality as a first-class architectural concern.

    Three general capability dimensions drove the selection:

    • Structured output stability: a script requires nested structures of chapters, scenes, and shots, and the model must reliably produce formats that programs can parse.
    • Long-context handling: a short drama’s setting, character profiles, and prior plot must be continuously injected, and context management directly determines content consistency.
    • Call cost and rate-limiting strategy: a publicly available application needs a fallback plan, otherwise a single promotion push can trigger uncontrolled spending.

    3. Overall Architecture: One Main Pipeline and Three Decoupled Layers

    The application is split into one main pipeline and three decoupled layers so each can evolve independently.

    Main pipeline: user inputs genre and setting → script planning → shot and prompt generation → image generation → content assembly → display and export.

    Three decoupled layers:

    1. Model access layer: wraps requests, retries, timeouts, rate limiting, and billing statistics uniformly, so business logic above it is unaware of specific model differences.
    2. Content structure layer: defines scripts and shots with a strict schema, and all model output must pass validation before moving to the next step.
    3. Resource and presentation layer: handles storage, access, and frontend rendering of assets such as images.

    A schematic structure definition follows (illustrating the general approach only):

    1. {
    2. "title": "Episode title",
    3. "characters": [{ "name": "Character name", "profile": "Character profile" }],
    4. "episodes": [{
    5. "summary": "Episode summary",
    6. "shots": [{
    7. "index": 1,
    8. "narration": "Narration text",
    9. "prompt": "Image prompt",
    10. "assetRef": "Asset identifier"
    11. }]
    12. }]
    13. }

    assetRef stores only an asset identifier rather than a hardcoded address. Assets live in an object storage service and are delivered through temporary access, avoiding the exposure of long-lived public links.

    4. Implementation Details of Key Stages

    4.1 Script Planning: Turning Creation into Constrained Generation

    Asking the model directly to “write a comic script” produces highly unstable output. What worked in practice was decomposing the creative task into three steps: first produce character settings and the worldview, then produce per-episode summaries, then expand shots episode by episode. Each step injects the previous result as a hard constraint and explicitly forbids modifying settings that are already fixed.

    Temperature is also used to separate tasks: a lower value during the setting stage for stability, and a higher value during the image prompt stage to increase visual variety.

    4.2 Structured Validation and Automatic Repair

    Occasional malformed model output is the norm, not an exception. The engineering approach is a validate–feedback–retry loop: when parsing fails, the error reason is sent back to the model with an instruction to output only the corrected fragment, retried a limited number of times, and beyond that threshold the output degrades to a human-editable draft. This mechanism significantly reduced the failure rate of the whole pipeline.

    4.3 Token and Cost Management

    Cost management is a design-time constraint, not an after-the-fact statistic:

    • Cache reuse: identical settings and prompts are not regenerated; results are persisted and reused.
    • Segmented calls: long scripts are split by episode to avoid a single oversized context.
    • Quota dashboard: instrumentation is centralized in the access layer to track consumption by user and by feature, with threshold alerts.
    • Fallback path: when quota is exhausted, the system switches to a lighter generation mode or a queueing mechanism to keep the service running.

    4.4 Resources and Performance

    Image assets are large, so they go through object storage paired with content delivery acceleration. The frontend uses pagination and lazy loading to avoid fetching a whole episode’s assets at once. Generation is time-consuming, so tasks are made asynchronous with a message queue, and the frontend obtains progress via polling or push so API responses are not blocked.

    5. Observability and Stability

    Three things were completed before launch: a logging service to collect call-chain logs centrally, making it easier to determine whether a failure came from parsing or a missing asset; monitoring and alerting covering error rate, average latency, and quota usage; and a rate-limiting strategy that distinguishes anonymous from logged-in users to prevent abuse. These three items are the dividing line between “it runs” and “it is safe to open up.”

    6. Open Source and Community Contribution

    The project was ultimately open-sourced for three reasons: prompts and workflows in content generation applications need long-term refinement, which is hard to achieve with closed source and insufficient feedback; different genres impose very different structural requirements, making plugin-based extension more reasonable than built-in enumerations; and open source lets developers swap the model access layer locally while reusing the entire content production pipeline.

    Open-source preparation included removing sensitive configuration and keys, completing minimal runnable configuration instructions, clarifying directory responsibilities, providing sample inputs and outputs, and establishing issue feedback and contribution guidelines. Suggested contribution priorities are structured template expansion, multi-style visual adaptation, and evaluation set construction.

    7. Lessons Learned

    The central takeaway is this: cost and stability in AI content applications are determined mainly by architecture, not by model capability alone. Structured constraints, cache reuse, asynchronization, and quota governance typically deliver more benefit than switching models. For developers building similar applications, the recommendation is to validate content quality with a minimal pipeline first, then gradually add observability and cost governance, and finally use open source to obtain feedback from real-world scenarios.