A Practical Guide to LLM-Driven Vibe Coding: From Code Snippets to Architecture Collaboration

    This article explains how large language models shift software development from generating isolated code snippets to collaborating on system architecture. It covers a four-layer framework for describing requirements, an architecture-first workflow that produces reviewable technical plans, and implementation patterns for a mini-program project, including cursor-based pagination, client-side image compression with direct uploads, structured multimodal prompt generation, and asynchronous task state machines. It also outlines context management practices, quality gates, and common pitfalls, helping developers turn LLM output into maintainable, production-grade software.

    1. From Snippet Generation to Architecture Collaboration

    When developers first adopt LLM-powered coding tools, the biggest change is not “writing faster” but a shift in where interaction happens. We used to break requirements into fine-grained, syntax-level tasks such as “write a carousel component” or “write a pagination API.” The model returned a code block, and humans still handled the assembly, debugging, and gap-filling. Once a model has strong long-context understanding and structured planning, it is better suited to a “skeleton first, then flesh” workflow.

    The essence of this shift is that the model makes implicit engineering decisions explicit. A reliable senior collaborator does not jump straight to implementation when given a vague requirement. Instead, it clarifies boundaries, compares technology options, lists modules and dependencies, and only then starts coding. For developers, this moves the review point earlier: you can reject a wrong direction at the architecture level in a few minutes, rather than inspecting thirty files line by line.

    Keep in mind that model output is a “candidate solution,” not an established fact. In practice, treat it as a conversational senior colleague: conclusions must withstand follow-up questions, technology choices must come with reasons, and interfaces must be constrained. For the capability boundaries, quotas, and pricing of any specific cloud product, always refer to the official documentation and do not assume unverified parameters in prompts.

    2. Four Layers of Requirement Description

    To get a model into architecture mode, how you organize the prompt matters more than polished wording. Break the requirement into four layers:

    1. Business goals and user roles: who uses it, what task they complete, and what success looks like.
    2. Feature list and priorities: what is mandatory, what can be deferred, and what is explicitly out of scope.
    3. Non-functional constraints: performance targets, compatibility, offline degradation, privacy and compliance, observability.
    4. Delivery format: directory structure, naming conventions, code style, testing and documentation requirements.

    Take a mini-program project as an example. The requirement could be expressed as follows: the goal is an image wallpaper and AI image generation tool with three main flows: browsing, upload management, and generation. The home page handles waterfall browsing and album details; the second page handles upload, analysis, prompt editing, and generation; the third page handles the user center and works management. Non-functionally, it must work on weak networks, load images on demand, and allow generation tasks to be retried. For delivery, it requires clear layering, cloud functions split by responsibility, and comments and unit tests for critical logic.

    When constraints are written clearly, the architecture the model produces is usually closer to a maintainable form, instead of piling all logic into a single entry file.

    3. Architecture First: Make the Model Output a Reviewable Technical Plan

    The output of the architecture phase should be a “checkable technology selection table + module diagram + data model,” not code. A typical generalized solution skeleton looks like this:

    • Client: use the native framework of the target mini-program platform, with three main pages switched via bottom navigation, and shared capabilities (request wrapping, login state, analytics) pushed down into a unified module.
    • Server: adopt a cloud integrated development model using managed databases, cloud functions, and object storage to avoid self-managed operations; file resources go to object storage while metadata goes into the database.
    • Model capabilities: call multimodal capabilities through a server-side proxy, where the vision model handles image understanding, the text model handles prompt rewriting and structured output, and the image generation model produces images; keys are held only on the server.
    • Data model: four entity types: users, assets, albums, and generation tasks. The task table records a state machine (queued, processing, succeeded, failed) and error codes.

    A sample schema (pseudocode, expressing field intent only):

    1. -- Asset table: holds both user uploads and generation results
    2. asset(id, owner_id, source_type, storage_key, width, height, size, created_at)
    3. -- Album table: supports topic-based aggregation
    4. album(id, owner_id, title, cover_asset_id, sort_weight)
    5. -- Generation task table: drives the async flow and retries
    6. generation_task(id, owner_id, asset_id, model_stage, prompt_json, status, error_code, updated_at)

    Cloud functions are divided into four types by responsibility: authentication and user initialization, asset read/write and paginated queries, generation task orchestration, and callbacks and status synchronization. The benefit of this split is clear permission boundaries, and each function can be load-tested and canary-released independently.

    4. Module Implementation Highlights (with General Code Samples)

    1. Waterfall Layout and Pagination

    The core of a waterfall layout is not the layout itself but the data rhythm. It is recommended that the server provide a cursor-based pagination API, while the client maintains a “loaded watermark” and column height estimates, avoiding fetching everything at once.

    1. // Cloud function: cursor-based pagination to avoid deep-pagination performance degradation
    2. exports.listAssets = async (event) => {
    3. const { cursor, size = 20, albumId } = event;
    4. const db = cloud.database();
    5. let q = db.collection('asset').orderBy('created_at', 'desc').limit(size);
    6. if (albumId) q = q.where({ album_id: albumId });
    7. if (cursor) q = q.startAfter(cursor);
    8. const res = await q.get();
    9. return {
    10. list: res.data,
    11. nextCursor: res.data.length ? res.data[res.data.length - 1].created_at : null,
    12. };
    13. };

    On the client side, combine image lazy loading with placeholder images, and prefetch the next page before scrolling reaches the threshold. This significantly reduces the perception of blank screens.

    2. Upload Flow and Image Compression

    The most common pitfall in mobile uploads is that oversized original images cause timeouts and waste bandwidth. The general practice is to compress locally first and then upload, preferably using the platform’s built-in image compression capability. The server issues short-lived credentials for direct upload to object storage, then writes back the metadata.

    1. // Client: compress, then get a temporary credential for direct upload
    2. const { tempFilePath } = await wx.compressImage({ src, quality: 80 });
    3. const { token, path } = await callFn('getUploadToken', { size: 1024 * 512 });
    4. await uploadFile({ url: token.uploadUrl, filePath: tempFilePath, name: path });
    5. await callFn('saveAssetMeta', { storageKey: path, width, height });

    The key points are: credentials are short-lived, paths are unpredictable, metadata and file writes remain eventually consistent, and idempotent retries are provided on failure.

    3. Multimodal Analysis and Structured Prompts

    The upper bound of generation quality is determined by the prompt. It is recommended to have the vision model output only structured fields, then have the text model rewrite them into a reusable prompt template, avoiding the instability of free text.

    1. {
    2. "subject": "subject and pose",
    3. "style": "visual style and material",
    4. "detail": "composition, lighting, camera",
    5. "background": "ambient atmosphere and color tone",
    6. "negative": "elements to avoid"
    7. }

    After obtaining the structured result, the frontend highlights key elements and allows users to edit them item by item, then assembles the final prompt and submits the generation task. This three-stage “analyze, edit, generate” flow is more controllable than a single long prompt and is also easier to regression-test.

    4. Asynchronous Tasks and State Machines

    Image generation time is unpredictable, so it should be built as an asynchronous task: after the client submits, it enters polling or receives a subscription message notification, while the server records state transitions and error codes, and decides whether to retry based on the error type. Showing users “queued / generating / retryable” is a better experience than a long spinner.

    5. Context Management and Collaboration Rhythm

    In long projects, the biggest cost is context drift. Three rules can be practiced: first, maintain an “architecture contract” document (technology choices, directories, naming, interface conventions) and feed it as prior input in every conversation round; second, commit in small steps, closing the loop one module at a time, and run and self-test immediately after generation; third, keep a change trail, updating the contract whenever interfaces change, so the model does not keep coding based on outdated assumptions.

    For quality checks, it is recommended to fix four gates: static checks and style consistency, unit tests covering pure logic (pagination cursors, compression parameters, prompt assembly), end-to-end testing of the main flow, and fault injection to verify degradation paths. Models are good at producing output, but boundaries and exceptions still require humans to define acceptance criteria.

    6. Common Pitfalls and Engineering Advice

    • Pitfall 1: treating the model as a search engine and only asking for snippets. Instead, ask for solutions and reasons, moving the review point forward to the architecture level.
    • Pitfall 2: generating the entire project at once. The longer the context, the harder consistency is to guarantee; closing the loop module by module is more stable.
    • Pitfall 3: handing keys and permissions to the client. Any model call should go through a server-side proxy, and the client only gets short-lived credentials.
    • Pitfall 4: ignoring observability. Add logs, metrics, and alerts to the task pipeline so that “intermittent failures” can be located.

    To further align with engineering practice on Baidu AI Cloud, you can map the general capabilities above to product categories such as managed databases, cloud functions, object storage, and monitoring and alerting, and implement them according to the interfaces and quotas in the official documentation.

    7. Conclusion

    The value of large models in coding tools is shifting from “completing code” to “co-designing.” When you can clearly articulate business goals, non-functional constraints, and delivery standards, the model can provide a reviewable architecture and a runnable implementation; when you can manage context, rhythm, and acceptance criteria, the output has engineering credibility. Tools iterate quickly, but the truly stable competitive edge is the ability to clarify requirements, make architecture judgments, and gate quality, which is exactly the part most worth investing in when collaborating with a model.