跪拜 Guibai
← All articles
VibeCoding · Coding Standards · Artificial Intelligence

Plan First, Glue Second: A Three-Step Method That Stops AI from Writing Spaghetti Code

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

AI coding tools default to generating maximum code for minimal prompts, which produces unmaintainable output. A structured planning-and-glue workflow cuts that output down to the minimum viable integration code, making AI-generated projects reviewable, debuggable, and extensible rather than disposable prototypes.

Summary

Treating AI as a code generator produces bloated, hallucination-riddled output. A three-step method flips the relationship: force the model to output a detailed plan with explicit boundaries and data structures before writing any code, then instruct it to act as glue between mature open-source libraries instead of hand-rolling algorithms, and finally have the AI critique your own prompts to close ambiguity gaps. The result is concise, maintainable code where every component and data field is pre-negotiated.

Applied to a React ToDo list, the planning phase locked the tech stack, component tree, and field names before a single line was written. Adding drag-and-drop later took roughly twenty lines of glue code wrapping react-beautiful-dnd, with zero manual coordinate math. A post-hoc prompt review caught an unstable ID generation rule and replaced it with nanoid.

The core shift is from programmer-plus-generator to architect-plus-collaborator. Hard boundaries prevent feature creep, library-first glue reduces surface area for bugs, and meta-review turns prompt writing into a self-improving loop that works across any stack.

Takeaways
Force AI into a plan-only phase that defines tech stack, component boundaries, data structures, and explicit exclusions before any code is written.
Treat the plan as a living constitution: update it whenever requirements change, then let AI execute against the revised plan.
Adopt glue programming: never hand-roll underlying logic when a mature open-source library exists; direct AI to write only the adapter and data-flow code between libraries.
After each feature, ask AI to critique your original prompt for ambiguities and missing constraints, then feed the improved version back into the project.
Predefine field names and data shapes in the planning phase to eliminate field-level hallucinations like title vs. content.
Use tools that support system prompts or memory modules to persist the project plan across every conversation turn.
Conclusions

The method reframes AI from a code generator to a pair-programming colleague, which changes the developer's own behavior: they invest upfront in specifications instead of iterating on bad output.

Glue programming is a deliberate constraint that reduces the surface area for hallucinations; the AI is asked to research a library's API rather than invent one, which plays to its strength in pattern-matching existing documentation.

The meta-review step creates a feedback loop where prompt quality improves without requiring the developer to become a prompt-engineering expert; the AI surfaces its own failure modes.

Hard boundaries like 'no persistence, no filtering, no drag-and-drop' are more effective at preventing scope creep than positive instructions alone, because they explicitly close doors the model would otherwise open.

Concepts & terms
Glue Programming
A coding discipline where the developer writes only the minimum adapter and data-flow code needed to connect mature, community-validated libraries, never hand-rolling underlying algorithms or logic from scratch.
Meta-Counterargument (元反论)
A self-improving prompt-engineering loop: the developer writes an Alpha prompt instructing the AI, and after execution the AI produces an Omega critique identifying ambiguities and suggesting improvements, which the developer feeds back into the next iteration.
Vibe Coding
An AI-assisted programming paradigm where developers describe intent in natural language and collaborate iteratively with AI tools like Claude Code or Cursor, treating the AI as a pair-programming partner rather than a code generator.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗