AI-Assisted Mini Program Development: Context Configuration and Prompt Practices

    This guide explains how to use AI coding tools in mini program projects by setting up project rule files, writing task requirements as checkable acceptance criteria, defining shared API contracts, working in phases, and reviewing risks. It also covers verification steps that catch permission, state, and data problems before release.

    1. From “Generating Code” to “Constraining the Development Process”

    AI coding tools can help with page structure, API handling, database access, and styling. However, generated code is not the same as a delivered feature. A page may render correctly and still miss permission checks, lack handling for error states, use inconsistent field names, or allow duplicate submissions.

    These problems are more pronounced in mini program projects. The front end must adapt to the target runtime environment, the back end must keep data consistent, and the client and server must share clear API agreements. If any of these areas lacks constraints, the result can be “locally correct but globally unusable.”

    For this reason, a prompt should be treated as a development task specification, not a one-off instruction. It should answer at least five questions:

    • What business problem is being solved?
    • What technical and structural constraints does the project have?
    • Which existing implementations must be reused?
    • How should the feature behave in exceptional situations?
    • How can you tell the task is complete?

    The real benefit of AI-assisted development should be measured by development time, rework count, defect count, and acceptance pass rate. Avoid promising a fixed efficiency multiplier. The time saved by generated code must account for review, debugging, and fixing costs to reflect the actual effect.

    2. Prepare Project-Level Context First, Rather Than Requesting Features Directly

    1. The Role of Project Rule Files

    A single conversation usually covers only part of a requirement, while project-level rules must stay stable across many tasks. Organizing this information into a separate file helps developers and AI coding tools work from the same basis.

    Rule files can use plain text. The file name matters less than whether the content is accurate and whether the tool can read it. If the tool does not load files automatically, explicitly ask it to read the relevant file at the start of the task, or include the key content in the prompt.

    Project context falls into three categories:

    Long-term rules: directory responsibilities, naming conventions, permission principles, and error handling methods.

    Phase information: current development goals, completed modules, and open issues.

    Task constraints: files that may be modified in this task, shared modules that must not be changed, and specific acceptance criteria.

    Separating these categories prevents one ever-growing file from accumulating everything. It also reduces interference from past tasks on the current implementation.

    2. A Reference Project Rule Template

    1. Project goal:
    2. Develop a mini program for querying and processing business records.
    3. The client handles display and interaction. The server handles permission checks and business validation.
    4. Technical boundaries:
    5. Use the project's existing language, component system, and server framework.
    6. Exact versions follow the project configuration.
    7. Do not add new dependencies or upgrade existing ones without confirmation.
    8. Directory responsibilities:
    9. pages: business pages
    10. components: reusable components
    11. services: client request wrappers
    12. server: server-side business logic
    13. Coding requirements:
    14. Reuse the existing request entry point and error handling mechanism.
    15. Pages must not build database queries directly.
    16. Changes to shared modules must document their impact scope.
    17. Do not hard-code real keys, passwords, or personal information in code.
    18. Security requirements:
    19. The server must verify identity, roles, and data access scope.
    20. Client-side validation is only for improving the user experience.
    21. Key fields such as amounts and statuses are validated by the server according to business rules.
    22. Delivery requirements:
    23. Submit the implementation, necessary tests, and a brief verification summary.
    24. State any unfinished items and anything that could not be verified.
    25. Clean up temporary files created by this task that are no longer needed.

    Adjust this template to fit the real project. Do not present unverified directories, versions, or runtime setups as facts. Incorrect context will keep affecting later code generation.

    3. Rules Should Not Forbid Necessary Verification

    Some prompts try to reduce output by stating “do not write tests, do not run commands, and do not generate explanations.” This may shorten individual responses, but it tends to push defects into integration and release stages.

    A more reasonable constraint is this: do not generate repetitive or unrelated documents, but keep necessary change notes. Explain the purpose of verification before running it. For database migrations, file deletions, or production operations, obtain authorization first.

    AI-assisted development should reduce wasted work, not skip quality assurance.

    3. Turn Vague Requirements into Verifiable Tasks

    “Build a business back office” describes only a general direction. It does not define users, data, workflows, or boundaries. The model can only fill in these gaps on its own, so the output tends to drift from what is actually needed.

    An executable requirement should include six parts:

    1. Users: who operates the feature and what permissions they hold.
    2. Business objects: what data is handled and what the key fields are.
    3. Workflow: the steps from entering the page to completing the operation.
    4. Exception scenarios: how to handle missing permissions, empty data, or request failures.
    5. Out of scope: what this task will not implement.
    6. Acceptance criteria: completion conditions that can be checked directly.

    For example, a “business record list” task can be specified this way:

    Implement a business record query page for logged-in users. Users can only view data within their authorized scope. The page includes status filtering, keyword search, and a paginated list. It supports loading, empty data, request failure, and retry states. When a filter changes, return to the first page. Format times and amounts in the list consistently. Exporting and batch operations are out of scope for this task, and the login flow must not be modified.

    This is more reliable than “add as many features as possible.” That approach easily lets scope get out of control. Explicit “not doing” statements help the tool focus on the current delivery goal.

    4. Define the API Contract Before Generating Front-End and Back-End Code

    1. Give Both Sides the Same Agreement

    Integration problems in mini program development often come from inconsistent interface semantics, not from complex algorithm errors. For example, the client may request data by page number while the server handles cursors. Or the client may assume amounts are in yuan while the server stores them in cents.

    Define the API contract before implementation. It should cover:

    • the type, required status, and default value of each request parameter;
    • the pagination method and the maximum number of items per response;
    • the time format and time zone convention;
    • the amount unit and precision rules;
    • the meaning of null values, missing fields, and empty arrays;
    • the structure of success and failure responses;
    • how insufficient permissions and invalid parameters are handled.

    The following is only an illustrative business contract. It does not represent a fixed interface on any platform.

    1. Endpoint purpose: query business records the current user can access
    2. Request parameters:
    3. page: positive integer, default 1
    4. pageSize: positive integer, default 20, maximum 100
    5. status: optional, accepts only statuses defined by the business
    6. keyword: optional, length must be limited
    7. Response content:
    8. items: array of records
    9. total: total number of records matching the conditions
    10. page: current page number
    11. pageSize: page size used for this response
    12. Constraints:
    13. The server determines the data access scope from the verified identity.
    14. The client must not expand query permissions by passing a user identifier.
    15. When there is no data, return an empty array rather than omitting the list field.

    The default values and limits in this example are design illustrations. Actual projects should set them based on data volume, query cost, and interaction requirements.

    2. Include UI States in the Contract

    A page has more than one state. It is not only “successfully displayed.” Development tasks should cover initial loading, querying in progress, empty results, load failure, partial load failure, and login expiration.

    For example, when loading the next page fails, the data already on screen should usually remain visible. When filter conditions change, earlier responses must not overwrite newer results. Depending on the existing request mechanism, implementation can use request cancellation or request sequence checks. Do not assume every runtime supports the same capability.

    5. Use Phased Prompts Instead of One-Shot Generation

    Phase 1: Analyze First, Do Not Modify Yet

    1. Read the project rules, related pages, the request wrapper, and the server business code first.
    2. Goal for this task:
    3. Implement status filtering and paginated querying for the business record list.
    4. Do not modify any files yet.
    5. Output the following:
    6. 1. Existing implementations that can be reused;
    7. 2. Files that need changes and the reason for each;
    8. 3. API and permission constraints;
    9. 4. Gaps in the current information;
    10. 5. The smallest implementation plan that meets the acceptance criteria.
    11. Do not invent files, interfaces, or dependencies that do not exist.
    12. Clearly mark any information that cannot be confirmed.

    The value of this phase is exposing wrong assumptions. If the tool plans to create a shared module that already exists, or misreads the permission model, correct it before any code is written.

    Phase 2