From Code Completion to System Design: Building Mini Programs with Large Language Models

    This article presents a practical approach to using large language models as architecture partners rather than code snippet generators. Using a wallpaper library mini program as an example, it explains how to define the system architecture, separate cloud services, design efficient media workflows, implement waterfall feeds and lazy loading, and build an asynchronous multimodal pipeline for image analysis and image generation. The architecture uses vendor-neutral cloud capabilities, including object storage, cloud functions, document databases, and temporary credentials.

    As intelligent programming tools become more widely adopted, developers are expecting more from large language models than the completion of a few lines of code. A common workflow used to be highly localized: describe a requirement such as a carousel component, receive a code fragment, and then manually assemble, tune, and troubleshoot the result. This approach is useful, but limited. It often reduces the model to an advanced code snippet generator.

    As context windows, instruction following, and multi-file collaboration improve, newer models are better suited to the role of a senior architecture partner. They can first help with technology selection and boundary definition, then implement a runnable project module by module.

    This article uses a typical application—a wallpaper library mini program with waterfall browsing, user uploads, multimodal analysis, and image-to-image generation—to explain how to ask a model to build the system foundation instead of requesting code immediately. The discussion uses vendor-neutral cloud capabilities, including object storage, cloud functions, document databases, and temporary access credentials. The same architecture can also be implemented in environments such as Baidu AI Cloud by mapping these concepts to object storage, function computing, and managed databases.

    1. Architecture Before Code: Treat the Model as a Technology Advisor

    An effective prompt should describe the target platform, core pages, data boundaries, and external capabilities rather than simply saying, “Build this page.”

    For example, a request might describe a mini program that includes:

    • A wallpaper waterfall feed
    • Upload and moderation workflows
    • An “upload, analyze, edit prompt, and generate” image workflow

    A strong model response will typically begin with the following decisions.

    Frontend structure: Use a native mini program with three primary bottom-navigation entries: Home, Image Generation, and Profile. Avoid introducing a complex cross-platform framework too early.

    Backend structure: Follow a cloud development model. Cloud functions handle authentication and business logic, a document database stores metadata, and object storage stores original images and thumbnails.

    Multimodal workflow: A vision model produces descriptions of the subject, style, and atmosphere. A language model refines prompts and applies safety-related rewriting. An image generation model performs conditional image-to-image generation, such as outfit changes or style transfer.

    Data and interfaces: Define collections, indexes, pagination cursors, upload compression rules, temporary credential retrieval, and credential renewal behavior.

    The value of this process is that it changes the question from “What code should be written?” to “How should the system be divided?”

    Waterfall browsing, category filtering, and download statistics are read-heavy operations. Uploading and image generation are write paths that require quotas, moderation, and asynchronous task processing. If the model defines these boundaries first, the generated code is less likely to mix page logic with cloud-function responsibilities.

    2. Separating Cloud Data and Functions

    Wallpaper metadata should be stored in a dedicated collection. At a minimum, each record should include:

    • Category
    • Tags
    • Width and height
    • Storage key
    • Moderation status
    • Popularity
    • Creation time

    Albums can be stored in a related collection rather than as large nested arrays inside wallpaper documents. This avoids making pagination difficult.

    User uploads should use a separate collection and remain in a pending-review state by default. Once approved, the asset can be added to the public library.

    Cursor-Based Pagination

    Avoid implementing pagination with a simple skip. Instead, sort records by creation time or popularity, use the sort key of the last item on the previous page as a cursor, and combine it with limit. This prevents expensive scans during deep pagination.

    Category filtering should be performed in the database with a composite index, such as category plus the sort key. Do not retrieve the entire dataset and filter it on the client.

    Cloud Function Responsibilities

    Cloud functions should be separated by responsibility, for example:

    • Metadata queries
    • Upload credential issuance
    • Compression callbacks
    • Image-generation task submission
    • Result persistence

    Credentials must be short-lived and follow the principle of least privilege. They should only cover the required storage prefix. After receiving a credential, the client should upload directly to object storage rather than sending binary data through a cloud function. This reduces timeout risks and costs.

    Before an image is saved to the library, apply compression and enforce a maximum dimension. Store a separate thumbnail key as well. The waterfall feed should load thumbnails instead of original images.

    3. Frontend Design: Waterfall Feeds and Lazy Loading

    A two-column virtual list works well for mini program feeds. Card heights can be calculated from each image’s aspect ratio to reduce layout shifts.

    Only request the original or high-resolution image when an item enters the viewport. When it leaves the viewport, nonessential cached data can be released.

    Downloads and previews should use temporary URLs rather than exposing permanent public-read access directly to the client.

    Upload Handling

    The upload component should compress images locally and normalize their format before uploading—for example, by converting them to a common lossy format and limiting the file size. The client then requests temporary credentials and uploads the file directly.

    Retries must be idempotent. A hash generated from the same local file should map to the same storage key, preventing duplicate objects from being created.

    4. Multimodal Image Generation: Analyze, Edit, and Regenerate

    A complete workflow can be modeled as:

    Upload → Vision analysis → Structured prompt display → User editing → Text refinement → Image-to-image generation → Save or discard

    Vision analysis should return structured fields such as:

    • Subject
    • Style
    • Details
    • Background and atmosphere

    Important entities should be highlighted so that users can modify specific elements—for example, changing an outfit or background—without rewriting the entire prompt.

    The language model can merge conversational edits into the full prompt while applying safety and copyright-related constraints. The image-generation service should support general parameters such as seed, generation strength, and reference-image weight. Generated results should first be stored in the user’s private space. Only after confirmation should the system decide whether to publish them.

    Asynchronous Task Processing

    Image-generation tasks should generally be asynchronous. A cloud function submits the task and returns a task ID. The client can then poll for status or subscribe to status updates.

    Timeouts and failures should support retries, and resource consumption should be recorded for quota management. The interface contracts for the entire workflow—analysis JSON, prompt versions, and generation parameters—should be fixed during the architecture phase. Otherwise, the frontend and backend may implement inconsistent field names and data structures.

    5. When Generating Dozens of Files Still Produces a Runnable Project

    Generating more than 30 files in a single pass is not inherently remarkable. It works when the architectural constraints are sufficiently explicit.

    The first prompt should define:

    • Directory conventions
    • Cloud-function naming
    • Collection fields
    • Environment-variable placeholders

    Intelligent programming tools are most effective when used for incremental module generation:

    1. Create the database schema and cloud-function skeleton.
    2. Generate pages and reusable components.
    3. Connect the analysis and image-generation workflow.

    The developer’s responsibility is to review permission boundaries, verify that indexes cover the required queries, and ensure that secrets never leave the server side.

    Common problems include:

    • Direct database access from the frontend with overly broad security rules
    • Missing indexes for pagination and filtering
    • Image-generation results not being recorded in a task table, making accounting impossible
    • Prompts not being versioned, making results difficult to reproduce

    These issues should be listed in the architecture checklist from the beginning rather than discovered during integration testing.

    6. Keeping Pace with Model Iteration

    Large language models change rapidly, and much of the resulting anxiety comes from treating coding speed as the primary competitive advantage.

    A more reliable approach is to strengthen three capabilities:

    1. Describe requirements as verifiable architecture specifications.
    2. Use tests and type constraints to protect interface contracts.
    3. Treat cloud resources—including storage, functions, databases, logs, monitoring, and alerts—as first-class parts of the design.

    A large language model can quickly generate a project structure and populate many files. However, people still need to make the final decisions about quotas, moderation, cost, and security.

    Conclusion

    When a prompt evolves from “write a component” to “provide the technology choices, data model, function boundaries, and multimodal workflow,” large language models can act as capable architecture partners.

    A wallpaper library is particularly suitable for validating this approach because it combines read-heavy and write-heavy paths with substantial media processing and generative AI requirements. Once the foundation is designed correctly, code generation becomes an accelerator rather than a source of technical debt.

    If the application is later deployed in an environment such as Baidu AI Cloud, the object storage, functions, and managed database can be mapped to their corresponding services while preserving the same business abstractions.