Chapter 15

AI Prompt Architectures

This is the level where AI programming stops being improvisation and starts being engineering. Instead of writing random prompts, you design prompt architectures — structured systems that produce predictable, high-quality results every time.


What Is a Prompt Architecture?

A prompt architecture is a reusable structure for AI communication that produces consistent, predictable results. Think of it the same way you think about software design patterns — not a specific piece of code, but a proven structure that solves a recurring problem.

The problem with ad-hoc prompting:

Prompt architectures solve all of these by giving you a consistent framework. The structure stays the same; only the content changes per task.


The Six-Part Prompt Blueprint

This is the master structure for advanced prompts. Every section serves a specific purpose, and together they give AI everything it needs to produce excellent output on the first pass.

Role
Who should AI be? A senior React engineer, a security auditor, a database architect? The role activates a specific knowledge domain and analytical style.
Context
What's the project? What exists already? What decisions have been made? This grounds AI in your specific situation instead of generic advice.
Goal
What should be achieved? Not "write code" but "create a reusable filter component that integrates with the existing useSchedule hook."
Requirements
Technical constraints: language, framework, patterns to follow, patterns to avoid, performance targets, accessibility standards.
Process
How should AI think? "Analyze first, then implement." "Consider three approaches before choosing." "Explain trade-offs before writing code."
Output
What format should the result take? Complete file, code snippet with comments, structured analysis, comparison table?

Not every prompt needs all six sections. Simple tasks might only need Role + Goal + Output. Complex tasks benefit from the full blueprint. The key is having the structure available so you can apply it when it matters.


Blueprint in Practice

Here's the blueprint applied to a real task — building a reusable form component:

ROLE:
Senior React/TypeScript engineer with experience
in accessible form design.

CONTEXT:
Family schedule planner app. React 18, TypeScript,
Zustand for state. Existing components follow a pattern
of custom hooks + presentational components.

GOAL:
Create a reusable ActivityForm component that handles
both creating new activities and editing existing ones.

REQUIREMENTS:
- TypeScript with strict types (no `any`)
- Accessible: proper labels, ARIA attributes, keyboard nav
- Controlled form with validation
- Follow existing hook + component pattern
- Mobile-responsive

PROCESS:
1. First, define the component's props interface
2. Then, design the form state management
3. Implement the component
4. Add validation logic
5. Explain any design decisions

OUTPUT:
Complete TypeScript file with:
- Props interface
- Component implementation
- Inline comments for non-obvious logic

This prompt is longer than a casual request — but it produces a dramatically better result on the first pass. The time spent writing the blueprint is recovered many times over by not needing multiple revision cycles.

The Paradox of Prompt Length

Longer, more structured prompts actually save time. A 30-second casual prompt that requires 3 rounds of revision takes more total time than a 2-minute structured prompt that produces the right output immediately. Invest in the prompt upfront; pay less in revisions later.


Reusable Templates

The real power of prompt architectures emerges when you create reusable templates — prompts with placeholders that you fill in for each specific task. Here are three essential templates:

Template
Component Builder
ROLE: Senior React/TypeScript engineer.

CONTEXT:
[paste project context + relevant existing code]

GOAL:
Create a [COMPONENT_NAME] component that [DESCRIPTION].

REQUIREMENTS:
- TypeScript, strict types
- Follow existing patterns in [REFERENCE_FILE]
- [SPECIFIC_CONSTRAINTS]

PROCESS:
Define interface → implement → add error handling → explain.

OUTPUT: Complete .tsx file with types and comments.
Template
API Endpoint
ROLE: Senior backend engineer focused on security.

CONTEXT:
[paste project context + database schema]

GOAL:
Create [METHOD] [PATH] endpoint that [DESCRIPTION].

REQUIREMENTS:
- Express.js with TypeScript
- Parameterized SQL queries (no string interpolation)
- Input validation with descriptive error messages
- Proper HTTP status codes
- Authentication required: [YES/NO]

PROCESS:
Validate input → authenticate → execute → handle errors.

OUTPUT: Complete route handler with middleware.
Template
Code Review
ROLE: Senior developer conducting code review.

CONTEXT:
[paste the code to review]
This code does: [BRIEF_DESCRIPTION]

GOAL:
Review for quality, correctness, and security.

REQUIREMENTS:
Check: bugs, naming, duplication, performance,
security, TypeScript strictness, error handling.

PROCESS:
Scan for issues → categorize by severity → suggest fixes.

OUTPUT: List of findings with severity (critical/high/
medium/low), location, and suggested fix for each.

Pipeline Architectures

Beyond individual prompt templates, you can design pipeline architectures — sequences of prompts where each step's output feeds into the next step's input. This is prompt engineering at its most powerful.

PIPELINE: New Feature Development

STEP 1 — PLAN (using Architecture template)
  Input: Feature description + project context
  Output: Component design + data flow

STEP 2 — CRITIQUE (using Review template)
  Input: Step 1 output
  Output: List of issues + improvements

STEP 3 — IMPLEMENT (using Component Builder template)
  Input: Improved design from Step 2 + existing code
  Output: Working component code

STEP 4 — TEST (using Test Generator template)
  Input: Step 3 output
  Output: Complete test suite

STEP 5 — REFACTOR (using Review template, quality focus)
  Input: Step 3 output + test results
  Output: Cleaned, optimized code

Each step uses a specific template. The output of each step becomes context for the next. The pipeline is reusable for any feature — only the initial feature description changes.

Pro Tip: Document Your Pipelines

Keep a Markdown file that describes your pipelines: which templates to use at each step, what to pass between steps, and what to verify before proceeding. When the pipeline becomes routine, you execute it almost automatically — each task follows the same proven path to quality.


Team Standardization

Prompt architectures become even more valuable in team settings. When everyone on a team uses the same templates and pipelines, the entire codebase benefits from consistent quality — regardless of which developer wrote which part.


Evolving Your Architecture

Prompt architectures aren't static. Like code, they should be versioned, tested, and improved over time. Track what works, what produces subpar results, and what's missing.


🧪 Practical Exercise

Build your own prompt architecture system:


Key Takeaways

Previous Chapter AI Coding Patterns: 10— Workflows
Next Chapter Cognitive Workflows: Thinking with AI