跪拜 Guibai
← All articles
Frontend · Trae

TRAE Wrote Every Line of This WeChat Mini Game Collection, Then WeChat Forced a Full Rewrite

By PBitW ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Building a game inside WeChat's Mini Program category fails at release, because WeChat only allows games under the Mini Game category, and the two runtimes are incompatible. The refactor cost here, 141 files and 33k deleted lines, is the price of that mistake, and TRAE absorbed it entirely.

Summary

TRAE, an AI coding assistant, wrote every line of a WeChat mini game collection starting from an empty directory. The first generation used Taro + React + TypeScript, chosen by TRAE to validate gameplay quickly. Three games came out of it: a QR-code maze whose walls form a real scannable QR code, a gravity balance-ball game, and a vertical shooter with squad mechanics, arithmetic gates, elite monsters, and boss fights. PBitW's role stayed on the product side: describing requirements, setting acceptance criteria, playtesting, and sending screenshots.

Publishing hit a platform wall. WeChat does not allow games under the Mini Program category, so the account had to switch to the Mini Game category with a new AppID. Taro-generated Mini Program code does not run in the Mini Game runtime, which has no pages or components and draws all UI on a Canvas. TRAE evaluated the options and recommended a native Mini Game rewrite. The refactor touched 141 files with +24,332/−33,181 lines, preserving gameplay while rebuilding the architecture around game.js and Canvas rendering.

Two pieces of TRAE output stand out. One is a hand-written QR Model 2 encoder, byte-mode UTF-8, error correction level L, versions 1–8, validated by feeding its matrices to jsQR and checking the decoded string matches the input. The other is a deterministic level factory: every level derives from a mulberry32 seed, so the same level number always produces the same maze, shooter waves, and balance-ball layout. A Node smoke test injects a wx stub and runs level factory, QR derivation, and shooting engine checks without WeChat. The same workload, done by hand with research and debugging, was estimated at over a month; TRAE finished it in a few days. The takeaway: the ceiling on AI coding is the clarity of the requirements and the strength of the acceptance tests.

Takeaways
— WeChat does not allow games to be published under the Mini Program category; the account must switch to the Mini Game category with a new AppID.
— Taro-built Mini Program code does not run in the Mini Game runtime, which has a single game.js entry, no pages or components, and Canvas-only UI.
— The refactor from Taro Mini Program to native Mini Game touched 141 files, with +24,332/−33,181 lines changed.
— TRAE implemented a QR Model 2 encoder from scratch: Byte mode UTF-8, error correction level L, versions 1–8, with GF(256) RS error correction using primitive polynomial 0x11D.
— The QR encoder was verified by a decode loop: the 0/1 matrix was rasterized to RGBA, fed to jsQR, and the decoded string had to match the original 8-character level code.
— A deterministic level factory uses mulberry32(seed) so level N always produces the same QR version, maze strategy, minimum steps, shooter waves, and balance-ball layout.
— A Node smoke test (scripts/minigame-smoke.cjs) injects a wx stub and runs regression checks on the level factory, QR derivation, and shooter engine without WeChat.
— The two architectures lived on separate branches: main held the Taro + React + TypeScript Mini Program, and feature/minigame held the native Mini Game rewrite.
— Total code changes across both generations were around 57,000 lines; the same work by hand was estimated at over a month, and TRAE finished it in a few days.
Conclusions

Cross-file structural changes are where TRAE earned its keep: translating a 226-line TypeScript timeline to CommonJS across 20+ files in one session is the kind of work that usually costs a human days.

The deterministic level factory is what made the whole workflow safe. Because every level is a pure function of its level number and the logic layer runs under a wx stub in Node, TRAE's output had a machine-checkable definition of done, and the human only had to verify feel.

The rewrite was driven by a WeChat category rule, not by performance or code quality. That shows a platform constraint can wipe out an entire stack choice regardless of how well the code was written.

Concepts & terms
Taro
A cross-platform framework that lets developers write React/TypeScript code and compile to WeChat Mini Programs, H5, and other platforms. The first architecture used it for componentized UI development.
WeChat Mini Game runtime
A separate runtime from WeChat Mini Programs. It exposes only a single game.js entry point, has no pages or WXML components, and expects all rendering to happen on a Canvas.
mulberry32
A small, deterministic pseudorandom number generator. Given the same integer seed, it always produces the same sequence, which the level factory uses so level N is identical on every device.
wx stub
A mock of WeChat's global wx object injected into Node, so game logic that normally depends on WeChat APIs can run in a plain Node test environment.
jsQR
A JavaScript QR code decoding library used in the article as the verification oracle: the encoder's output is fed to jsQR and must decode back to the original string.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗