AI Pair-Programming: 6 Rules to Stop Architecture Damage

Constraint sets, slice sizes, and review gates that prevent AI coding assistants from inventing abstractions you'll spend weeks undoing.

Published 2026-11-09 · Updated 2026-11-12 · Translation: VI

The Problem in One Sentence

Ship checklist

Ship checklist

You paste a vague goal, accept a 400-line diff, and discover a week later that half your domain logic now lives in random helper files the model invented.

This guide fixes that. Six rules, one daily loop, zero architectural surprises.


Rule 1: Write Constraints Before the First Prompt

Every AI session starts with three lines, not clever prompts, just boundaries:

Constraint Example
Allowed surfaces Only src/billing and src/shared/money
Forbidden moves No new state libraries; no invented HTTP clients; types stay in src/domain
Definition of done npm test billing passes; Invoice.ts changes; nothing else does

Why this matters: Models optimize to complete your stated task. If you don’t state the architecture, they invent one. Six bullets get followed. A 40-line manifesto gets ignored.

Action: Create AGENTS.md or a Cursor skill file with your project’s top 5 forbidden moves. Paste it at session start.


Rule 2: Slice Work to Two-Minute Diffs

Good slices:

  • “Add validation for this form field and wire the existing error component.”
  • “Extract duplicate date formatting into src/lib/date.ts.”
  • “Write a failing test for the bug in InvoiceService, then fix it.”

Bad slices:

  • “Refactor auth and add OAuth and clean up the API layer.” → Three architectural swings in one prompt.

Ask for the plan first. If the plan lists more than 3 files, split the task.


Rule 3: Give the Map, Not the City

Paste or @-mention:

  • The nearest interfaces and call sites
  • The folder that owns the concern
  • One example of the local pattern (naming, error handling)

Do not dump the entire repository into context. Extra files increase the chance the model “helpfully” rewrites distant code to match a new style.

Explicit pointer: “Follow the pattern in payments/CheckoutForm.tsx; do not touch billing.”


Rule 4: Run Five Review Gates on Every Patch

Stop gates

Stop gates

Human review answers specific questions, not just “does it compile?”

Gate What to check
1. File list Unexpected paths? Reject immediately.
2. Boundary New imports across layers? UI talking to database?
3. Duplication Did model reimplement something under a different name?
4. API surface Public types expanded without request?
5. Test quality Asserting behavior, or just that mocks were called?

Diff hygiene: Reject drive-by renames, comment rewrites, and formatting churn mixed into features. Ask the agent to revert noise and restate the patch.


Rule 5: Use Prompt Patterns That Lock Architecture

Constraint-first prompt:

In src/billing only. Reuse Money and InvoiceStatus. No libraries. Add a function that marks an invoice overdue after dueDate and returns the existing error union. Show the plan in five bullets, then wait.

Diff-limited prompt:

Change at most three files. If you need more, stop and explain why.

Pattern-match prompt:

Match error handling to createSubscription.ts. Same Result type, same logging helper.

Repair prompt (after a bad patch):

Revert the new utils/date2.ts. Use formatDate from src/lib/date.ts. Keep behavior identical.


Rule 6: Tests Are the Contract

Ask for the failing test first when fixing bugs. For features, ask for tests that lock the public behavior you intend to keep.

This does two things:

  1. Forces a clearer interface
  2. Makes it obvious when the model solved a different problem than the one you stated

If your repo lacks tests in the target area: Write a thin characterization test yourself before inviting large AI edits. Uncovered modules are where agents invent structure most aggressively.


The Daily Loop

Workflow

Workflow

1. Pick one outcome (fits in a short PR)
2. Paste constraints + relevant examples
3. Require a brief plan; approve or correct
4. Generate the smallest patch
5. Run five gates: file list → imports → logic → tests → hygiene
6. Commit with intent, not tool name
7. Update constraint notes with new "do not"

After a few weeks, your constraint notes become a lightweight architecture guide. That guide is more valuable than any single generated function.


When to Stop and Switch

Exit the AI session when:

  • The next step needs a product decision, not a code decision
  • You’re about to accept the fourth consecutive fix on the same files
  • The model starts renaming symbols to “clarify” without being asked

At that point: write the decision down, then resume with a narrower prompt.


What “Good” Looks Like After 30 Days

Before After
Large PRs with surprise modules Small PRs, predictable paths
Hours undoing clever abstractions Mistakes stay local and reversible
“The AI wrote it” as excuse Merge author owns the diff
Scattered helpers across folders Architecture constraints compound

The model still makes mistakes. The difference is you never handed it the whole architecture as an open prompt.


Quick Reference Card

Start: Write 3 constraints (allowed, forbidden, done).

Slice: One vertical per turn. Two-minute diff max.

Context: Map, not city. Explicit pointers only.

Review: Five gates. File list first.

Prompts: Constraint-first, diff-limited, pattern-match.

Tests: Failing test before fix. Lock behavior.

Exit: Product decision → stop. Fourth fix → stop.

Share

X Facebook LinkedIn
Educational content only. Rankings reflect stated criteria at the update date—not investment advice or permanent performance guarantees.