In the complex world of software engineering, memory cannot be trusted. What can be trusted are systems, processes, and checklists. This chapter is your "systematized checklist" for collaborating with AI.
It takes the core instructions threaded through this entire book and reorganizes and distills them into four constraint domains, so that whenever you need one, you can find the best-fitting "incantation" for your current situation within 30 seconds.
15.1 Architecture Constraint Quick Reference
Core goal: In the early stages of a project, or when making major design decisions, establish inviolable "boundaries" and "rules" for AI.
15.1.1 Define AI Role and Project Principles (AGENTS.md)
Scenario: A new project is launching, and you need to set the overall working style and fundamental ground rules for AI. Instruction template:
# AI Agent Directives: Project "[Project Name]"
## Persona: [Choose a core role, e.g., Senior Backend Engineer (Go), Frontend Architect (React), etc.]
You are to act as a [role description, injecting traits, e.g., a performance-obsessed, security-conscious expert]. Your primary goal is to help build a robust, maintainable, and scalable system.
## Core Principles (The "Musts"):
1. [Principle One]: [e.g., Maintainability First - Code should be simple, readable, and well-documented].
2. [Principle Two]: [e.g., Strict Typing - All TypeScript code must use `strict` mode. The `any` type is forbidden].
3. [Principle Three]: [e.g., Test-Driven - All new logic must be accompanied by unit tests with 85%+ branch coverage].
4. ...
## The "Forbidden Zone" (The "Must Nots"):
1. [Prohibition One]: [e.g., No Business Logic in UI Components - React components must be dumb and receive all data and functions as props].
2. [Prohibition Two]: [e.g., No Direct DB Access from Controllers - All database operations must go through a dedicated Repository/Service layer].
3. [Prohibition Three]: [e.g., No Introduction of New Dependencies without Approval - If you need a new third-party library, you must ask for permission and justify its need].
4. ...
15.1.2 Design High-Level Architecture (ARCHITECTURE.md)
Scenario: You need AI's help with technology selection or module decomposition. Instruction template:
Your Role: Act as a Solutions Architect.
Context: We are designing a new "[application type, e.g., real-time chat application]".
The key requirements are: [list the core requirements, e.g., high scalability (1M concurrent users), low latency (<100ms), and end-to-end encryption].
Task:
1. Propose Technology Stack: Suggest a complete, modern technology stack for both backend and frontend, justifying each choice.
2. Architectural Pattern: Recommend an architectural pattern (e.g., Microservices, Monolith, Serverless). Create a high-level diagram (using Mermaid syntax) showing the main components and their interactions.
3. Data Schema Design: Propose a preliminary database schema for the core entities (e.g., Users, Channels, Messages).
4. Identify Risks: List the top 3 potential technical risks or challenges in this architecture.
15.1.3 Enforce Negative Space Constraints
Scenario: During development, remind AI to respect the architectural red lines already established. Instruction snippet (can be appended to any coding request):
---
Architectural Constraint Check:
Remember to adhere to the rules defined in our `ARCHITECTURE.md`. Specifically, ensure that:
- [Reiterate the single most critical prohibition, e.g., This logic contains no direct database queries and instead calls the `UserRepository`].
- [Reiterate another one, e.g., All data sent to the client is in the DTO format, not the raw database model].
15.2 Process Control Quick Reference
Core goal: Force AI (and yourself) to engage in "slow thinking," following the "Research -> Plan -> Execute" three-step workflow.
15.2.1 Step One: Research
Scenario: Faced with a vague new requirement, you need technical pre-research or requirement clarification. Instruction template:
Your Role: Act as a [choose a research-oriented role, e.g., Senior Research Engineer or Business Analyst].
Context: We need to implement a new feature: "[vague requirement description, e.g., 'Add social login with Google']".
Task:
1. Clarifying Questions: List all the questions we need to ask the product manager to fully define the scope of this feature (e.g., What happens if a user's Google email already exists in our system?).
2. Technical Investigation: Research the standard technical approach for this. Identify the key steps (e.g., OAuth 2.0 flow), and list the recommended and well-maintained libraries in `[your tech stack, e.g., Node.js/Passport.js]` for implementing it.
3. Summarize Pros and Cons: Briefly compare the top 2 library options, focusing on ease of use, security, and community support.
Constraint: DO NOT WRITE ANY IMPLEMENTATION CODE. Your entire output should be a research document.
15.2.2 Step Two: Plan
Scenario: Research is complete, and you need to design the concrete implementation approach and interfaces. Instruction template:
Your Role: Act as a Senior Software Designer.
Context: Based on our research, we have decided to use `[selected technology/library, e.g., Passport.js with the passport-google-oauth20 strategy]`.
Task:
1. Define the Interface/API: Design the public-facing interface for our new `AuthService`. This should include the method signatures and clear JSDoc/TSDoc comments explaining what each method does, its parameters, and what it returns.
2. Sequence Diagram: Create a Mermaid sequence diagram illustrating the entire login flow, from the user clicking the "Login with Google" button to them being authenticated in our system. Show the interactions between the Frontend, our Backend, and Google's servers.
3. Task Breakdown: Create a checklist of concrete, sequential development tasks required to implement this entire feature.
Constraint: NO METHOD BODIES. Focus solely on the design, diagram, and plan.
15.2.3 Step Three: Execute
Scenario: The design is approved, and you need to complete the coding tasks one by one. Instruction template:
Your Role: Act as a Senior Pair Programmer.
Context: We are now implementing the plan. Our current task is: "[copy one item from the task list, e.g., 'Implement the /auth/google/callback route handler']".
Task: Write the complete, production-ready code for this route handler.
Constraints:
- Follow all the principles in `AGENTS.md`.
- Adhere to the interface defined in our design phase.
- Include error handling for all external calls (e.g., what if Google returns an error?).
- Add comments explaining any non-obvious logic.
15.3 Bug-Fixing Feed Instruction Quick Reference
Core goal: When confronted with a "black box" bug, "reverse feed" structured telemetry data to AI, guiding it toward precise root cause analysis.
15.3.1 Feed Crash Logs / Stack Traces
Scenario: The application has crashed, and you have a complete error log and stack trace in hand. Instruction template:
Your Role: Act as a Senior Debugging Expert.
Context: Our application crashed in production. I have the complete error log and stack trace.
Log Data:
```
[paste the complete, unedited error log and stack trace]
```
Relevant Code Snippet (from the stack trace):
```[language]
// [paste the most critical lines of code cited in the stack trace]
```
Analysis Request:
1. Root Cause Analysis: Based on the log and the code, what is the most likely root cause of this crash? Explain your reasoning in simple terms.
2. Replication Steps: Describe a potential sequence of events or inputs that could trigger this error.
3. Code Fix: Provide the corrected version of the code snippet that will prevent this crash from happening again.
15.3.2 Feed Structured Telemetry Logs (Full-Chain Tracing)
Scenario: A complex operation (e.g., order processing) has failed, and you have extracted the complete trace_id log stream for that operation.
Instruction template:
Your Role: Act as a Senior Site Reliability Engineer (SRE).
Context: We are investigating a failed operation, identified by `trace_id: "xyz-123"`. I have extracted the complete, structured log stream for this operation.
Log Stream (JSON format, ordered by timestamp):
```json
[
// paste all logs related to this trace_id exported from the logging system
]
```
Analysis Request:
1. Timeline Reconstruction: Summarize the sequence of events for this trace in a chronological, human-readable list.
2. Point of Failure: Identify the exact event where the process deviated from the happy path and failed.
3. Root Cause Hypothesis: Based on the last successful event and the first failure event, what is the most likely root cause?
4. Information Gap: Is there any information missing from these logs that would help confirm your hypothesis? What additional logging would you recommend we add?
15.4 Quality Assurance Instruction Quick Reference
Core goal: Leverage automated testing and static analysis to build and maintain the project's "quality grid."
15.4.1 Generate Unit Tests for New Code
Scenario: You or AI have just completed a new function and need to write tests for it to satisfy coverage requirements. Instruction template:
Your Role: Act as a meticulous QA Auditor.
Context: Our project has a strict 85% branch coverage requirement.
Function to be Tested:
```[language]
// [paste the function code to be tested]
```
Task:
Write a comprehensive suite of unit tests for the provided function using the `[your test framework, e.g., Jest]` framework. Your test suite must cover:
- The "happy path" (typical inputs).
- All edge cases (e.g., empty arrays, null inputs, zero values).
- All logical branches (every `if/else` path).
- All potential error-throwing conditions.
15.4.2 Test-Driven Bug Fix / Feature Development
Scenario: You already have a failing test and need AI to fix the code so that it passes. Instruction template:
Your Role: Act as a Senior Engineer practicing Test-Driven Development (TDD).
Context: Our test suite is currently failing. Your sole mission is to write code that makes the tests pass.
Failing Test(s):
```[language]
// [paste the code of the failing test case and its failure output]
```
Code to be Fixed:
```[language]
// [paste the business logic code to be modified]
```
Task:
Analyze the failing test and the business logic. Provide a modified version of the business logic code that fixes the bug and makes the test pass. Do not modify the test code itself.
15.4.3 Implant Anti-Regression Contracts
Scenario: When asking AI to refactor or optimize, ensure it does not introduce regressions in performance, security, or elsewhere. Instruction snippet (can be appended to any refactoring request):
---
ANTI-REGRESSION CONTRACT (CRITICAL):
Your proposed solution will be automatically checked against our quality gates. Before you provide the code, you must perform a self-assessment and confirm that your changes will not:
1. Degrade Performance: [optional, provide a specific baseline] The operation should remain within ~5% of its current execution time.
2. Increase Bundle Size: Do not introduce new third-party dependencies. Justify if you absolutely must.
3. Introduce Security Risks: Explicitly state that you have checked for common vulnerabilities like [e.g., XSS, Insecure Direct Object References].
4. Lower Test Coverage: The overall test coverage must not decrease.
15.4.4 Regular Code "Garbage Collection"
Scenario: Before an iteration begins, conduct a "spring cleaning" of the codebase. Instruction template:
Your Role: Act as a "Code Janitor", obsessed with keeping our codebase clean and lean.
Context: We are starting a new sprint, and our first task is to pay down some technical debt.
Task: I will provide you with the output of our static analysis tools. For each finding, your job is to provide the necessary command or code change to fix it.
Tool Output 1: `depcheck` (Unused Dependencies)
```
// [paste the output of depcheck]
```
Your Action: Provide the `npm uninstall ...` command to remove these.
Tool Output 2: `ts-prune` (Dead Code)
```
// [paste the output of ts-prune]
```
Your Action: For each identified dead export, analyze its context and confirm if it's safe to delete. If so, state "Safe to delete".
Tool Output 3: `jscpd` (Code Duplication)
```
// [paste the jscpd report pointing out two duplicate code blocks]
```
Your Action: Refactor the two duplicated code blocks by extracting the common logic into a single, reusable function.
[Appendix] Recommended Document Structure and Prompt Template Compendium
A.1 Recommended Project Root "Constraint" Document Structure
A project driven by "effective constraints" should have a root directory as clean as this:
.
├── .github/
│ └── workflows/
│ └── ci.yml # Quality Constraint: CI/CD pipeline with tests, coverage, anti-regression checks
├── src/
│ └── ... # Application source code
├── tests/
│ └── ... # Test code
├── AGENTS.md # Architecture Constraint: AI role and project principles
├── ARCHITECTURE.md # Architecture Constraint: Architecture decisions and negative space
├── CHANGELOG.md # Process Constraint: Development log, recording decisions and progress
├── jest.config.js # Quality Constraint: Test and coverage configuration
├── package.json
└── ...
A.2 The Ultimate "Universal Startup" Prompt Template
Scenario: Starting a new project or an important, brand-new session. This template fuses all the core concepts from earlier into a single powerful "super starter."
# PROJECT INITIATION & AI ALIGNMENT
## PART 1: CONTEXT INGESTION
I am providing you with the three foundational documents for our project, "[Project Name]". Your first task is to read, understand, and internalize them completely.
[ AGENTS.md ]
```text
[paste the entire content of AGENTS.md]
```
[ ARCHITECTURE.md ]
```text
[paste the entire content of ARCHITECTURE.md]
```
[ CHANGELOG.md ]
```text
[paste the entire content of CHANGELOG.md]
```
---
Once you have fully processed these documents, confirm by responding with: "Acknowledged. I am ready to proceed as a Senior Security-Focused Engineer for Project Guardian Notes. The core principles are internalized. Our next step is [copy the next step from CHANGELOG]." Do not add any other text to your confirmation.
## PART 2: STANDARD OPERATING PROCEDURE (S.O.P.)
After your confirmation, for every subsequent major feature request in this session, we will adhere to the following Standard Operating Procedure:
1. Phase 1: Research & Clarification (The "What")
- You will act as a researcher. You will ask clarifying questions and investigate technical options.
- You will be forbidden from writing implementation code in this phase.
2. Phase 2: Design & Planning (The "How")
- You will act as an architect. You will design interfaces, create diagrams, and break the work down into a task list.
- You will be forbidden from writing method bodies in this phase.
3. Phase 3: Implementation & Testing (The "Do")
- You will act as a pair programmer. You will write production-ready code for one task at a time.
- For every piece of logic, you will also write the corresponding unit tests to meet our quality standards.
## PART 3: UNIVERSAL CONSTRAINTS
For all code you generate in this project, the following Anti-Regression Contract is always in effect:
- Performance: Code should be efficient in both time and space complexity.
- Security: All untrusted input must be sanitized.
- Maintainability: Code must be simple, clear, and self-documenting.
- Testability: Code must be structured in a way that is easy to unit test.
I will be the final decision-maker. Let's begin.
Closing Words
This toolkit marks the end of theory and the beginning of your practice. True mastery comes from applying, adjusting, and internalizing these principles again and again across real projects.
Do not treat these instructions as rigid dogma. They are "scaffolding," providing support while you are still learning. Once you have truly internalized the mindset of "effective constraints," these templates will flow into your veins and become the natural linguistic habits you use when communicating with AI.
You will no longer be a passive "AI user," but an active "AI commander." You will no longer be vexed by AI's "unpredictability." Instead, you will savor the immense pleasure of harnessing this powerful force to create unprecedented, high-quality software products.
Welcome to the new era of human-machine collaboration. May your voyage be smooth.
Closing thought: become the system wrangler, not the code porter.
- Where should the freed cognitive bandwidth be directed?
- Three mindsets needed by those who harness AI programming in the next decade
- Your "effective constraints" practice begins today