AI-Assisted Mini Program Development: Context Configuration and Effective Prompts
This article explains why AI-generated mini program code often fails to run and how project-level context files reduce guesswork. It covers the four dimensions a context file should define—tech stack, code conventions, directory responsibilities, and business terminology—provides a minimal configuration template, and lists environment checks to complete before relying on it.
Introduction: Why AI-generated mini program code often fails to run
Using LLM code assistants to build mini programs has become routine for many teams. Models can quickly generate pages, components, API calls, and database structures, saving a large amount of repetitive coding time. In practice, however, many teams run into the same problems: generated files are placed in the wrong directories, page and component styles are inconsistent, and code that looks logically complete cannot run because dependencies are missing or versions do not match.
These problems usually come from the input information, not from the model’s capability. A model can only work with the information it receives; the less it gets, the more it has to guess. This article discusses two things: how to establish long-lived context configuration for a project, and how to write requirement instructions that reduce guessing and produce results that can be verified. The methods apply to most mini programs and full-stack projects; teams need to measure results using their own criteria.
1. Use project-level context instead of temporary conversations
Context in a chat window gets pushed out or diluted as turns increase. By the tenth turn, the model may have forgotten the framework version used by the project, or that a certain directory is dedicated to utility functions. Restating everything in every new conversation wastes time and easily omits key information.
Project-level context configuration solves this problem. It is a specification file stored in the code repository that AI tools read at the start of each task. The file name and location depend on the tool; some tools support placing rule files in the project root. The configuration should cover at least the following four dimensions.
First, the tech stack. State the frontend framework, backend language, database type, build tools, and version numbers of main dependencies. Version numbers should match the project lockfile; otherwise, the model may call deprecated APIs.
Second, code conventions. Specify naming patterns, such as PascalCase for component names and kebab-case for filenames. Also specify indentation width, comment language, and a unified error-handling pattern.
Third, directory structure. Explain the responsibility of each main directory and indicate where new components, new API wrappers, and new utility functions should go.
Fourth, business context. Briefly describe who the users are, what the core business flows are, and the precise meaning of terms commonly used inside the team. Terms are especially easy to misunderstand. For example, the same “order” may refer to different data tables in different modules.
Below is a minimal usable configuration template; add or remove content based on the project.
# Project Context## Tech Stack- Mini program framework: native framework, base library 3.x (refer to project.config.json)- Frontend language: TypeScript 5.x, UI library Vant Weapp 1.x- Backend: Node.js 18.x, Express 4.x- Database: MySQL 8.0- Package manager: pnpm, version based on pnpm-lock.yaml## Code Conventions- Component files and directories share the same name, using kebab-case, e.g., order-card- Variables and functions use lowerCamelCase; constants use ALL_CAPS_WITH_UNDERSCORES- API responses use a unified structure: { code, message, data }- Pages must not call wx.request directly; all requests go through the services directory## Directory Responsibilities- pages/: pages, one directory per page- components/: components reused across pages- services/: API wrappers, split by business module- utils/: pure utility functions, no dependency on page instances- stores/: global state## Business Terms- Tax entity: an enterprise or sole proprietor registered in the tax system- Alert: abnormal tax behavior determined by system rules; statuses are pending, verified, and resolved## Prohibitions- Do not introduce third-party libraries not declared by the project- Do not write real secrets, phone numbers, or taxpayer data in code
After the configuration file is written, several prerequisites must be completed. Otherwise, the information the model reads may be inconsistent with the actual environment.
- Confirm the development environment. The local versions of Node.js, the developer tools, and the AI assistant plugin should match the team’s agreed setup.
