AI-Native Product Engineering

    A Beginner-to-Production Handbook for Building Scalable, Maintainable, Collaborative Products with AI Agents

    Status: Reusable master handbook Audience: Absolute beginners through experienced developers joining an AI-assisted project Scope: Product discovery → specification → design → AI reference generation → repository/bootstrap → agent system → architecture → implementation → testing → collaboration → CI/CD → release → production operations → continuous improvement Technology stance: Technology-agnostic core. Current framework/runtime/package choices are selected through a documented freshness audit at project start. Current-date note: Current ecosystem facts referenced in this handbook should be re-verified at the beginning of every new project. Do not copy version numbers from this book blindly.


    Table of Contents

    1. How to Use This Book
    2. The Core Philosophy
    3. The SDLC Operating Model
    4. The AI Agent Mental Model
    5. The Source-of-Truth Hierarchy
    6. Product Discovery Before Coding
    7. The Grill-Me Skill
    8. Product Context and Product Specification
    9. Project Terminology
    10. Requirements, Scope, Non-Goals, and Acceptance Criteria
    11. Technology Freshness and Current-Stack Research
    12. Environment and Developer Machine Setup
    13. Git, GitHub, Identity, and Repository Governance
    14. Repository Bootstrap and Structure
    15. The Agent Constitution: AGENTS.md
    16. Rules, Skills, References, and Progressive Disclosure
    17. The AI Agent Operating Protocol
    18. Architecture and Module Boundaries
    19. Collaborative Development Without Team Chaos
    20. Independent Workspaces and Worktrees
    21. Contract-First and Dependency-Ready Development
    22. Task Packets and Change Packets
    23. Collaboration for Teams with Unequal Skill Levels
    24. Design Philosophy and Product Feel
    25. Design Tokens
    26. AI-Generated HQ UI Mockups
    27. Mockup Refinement, Approval, and Reference Tiers
    28. UI Foundation and Component Laboratory
    29. Application Shell and Scaffold
    30. UI Implementation with Reference Fidelity
    31. UX Psychology, Visual Hierarchy, and Motion
    32. Accessibility and WCAG
    33. Security and OWASP
    34. Data, API, and Integration Contracts
    35. Vertical Delivery and Phase Planning
    36. Testing Strategy
    37. CI/CD and Merge Gates
    38. Release and Deployment Engineering
    39. Production Operations and Incident Response
    40. Dependency Management and Technology Upgrades
    41. Refactoring and Architecture Evolution
    42. AI Review and Independent Verification
    43. Metrics and Engineering Health
    44. Master Prompt Library
    45. Master Templates
    46. Project Completion Checklist
    47. Final Operating Rules
    48. Appendix: Current-Technology Research Sources

    1. How to Use This Book

    This handbook is intended to be executed in order. A beginner should not jump directly to the application-feature chapters.

    The workflow is:

    text
    IDE + Machine Setup
        ↓
    Product Discovery
        ↓
    Product Specification
        ↓
    Terminology
        ↓
    Technology Freshness Audit
        ↓
    Architecture
        ↓
    Repository Bootstrap
        ↓
    Agent Constitution
        ↓
    Skills + Rules
        ↓
    Design Philosophy
        ↓
    Design Tokens
        ↓
    HQ UI Reference Generation
        ↓
    Component Laboratory
        ↓
    Application Shell
        ↓
    Contracts + Dependency Readiness
        ↓
    Implementation
        ↓
    Testing + Security + Accessibility
        ↓
    CI/CD
        ↓
    Staging
        ↓
    Production
        ↓
    Monitor / Debug / Upgrade
        ↺
    

    1.1 Non-negotiable execution rule

    Never skip a phase because "AI can figure it out later."

    AI is very useful at implementation, transformation, research, analysis, testing, and iteration. It is not a substitute for establishing the project's source of truth.

    1.2 Phase gates

    Every phase has:

    • Inputs
    • Work
    • Outputs
    • Verification
    • Exit criteria

    If the exit criteria are not met, the phase is not complete.


    2. The Core Philosophy

    2.1 The product is a system, not a pile of pages

    A strong product is the combination of:

    text
    Product intent
    + UX model
    + visual system
    + architecture
    + code
    + tests
    + security
    + deployment
    + operational feedback
    

    2.2 AI should operate inside a system

    Do not design your workflow as:

    text
    Human prompt → AI → code → done
    

    Use:

    text
    Human intent
        ↓
    Project context
        ↓
    Rules
        ↓
    Specialized skill
        ↓
    Current documentation
        ↓
    Canonical examples
        ↓
    AI implementation
        ↓
    Automated checks
        ↓
    Independent review
        ↓
    Human approval
    

    2.3 Separate soft guidance from hard enforcement

    Soft / model-interpreted

    • design philosophy
    • architectural guidance
    • coding conventions
    • UX heuristics
    • product personality

    Hard / machine-verifiable

    • formatting
    • linting
    • type checking
    • test results
    • dependency constraints
    • branch protection
    • required approvals
    • accessibility checks
    • security scanning
    • build success
    • deployment health

    A project is robust when important rules exist in both layers where possible.

    2.4 "Latest" does not mean "highest version number"

    The project follows:

    Latest stable + production-supported + officially recommended + compatible.

    Do not adopt a canary, nightly, beta, or release candidate simply because it has a newer number.


    3. The SDLC Operating Model

    The entire lifecycle is divided into gates.

    text
    G0 Idea Gate
    G1 Product Gate
    G2 Technology Gate
    G3 Architecture Gate
    G4 Design Gate
    G5 Foundation Gate
    G6 Contract Gate
    G7 Feature Gate
    G8 Quality Gate
    G9 Release Gate
    G10 Production Gate
    G11 Operations Gate
    

    Each gate answers one question:

    Is the project ready for the next kind of risk?

    Examples:

    • Do not build detailed pages before the design system exists.
    • Do not build dependent APIs before the contract is stable.
    • Do not release before CI is enforcing the quality checks.
    • Do not make destructive production changes without rollback planning.

    4. The AI Agent Mental Model

    An AI coding agent generally combines:

    text
    Instructions
    + Context
    + Tools
    + Model reasoning
    + Repository state
    + Feedback
    

    Your repository therefore needs to become self-describing.

    4.1 What the agent knows

    The agent may have access to:

    • system instructions
    • repository instructions
    • task prompt
    • selected files
    • search results
    • tool outputs
    • images/screenshots
    • skills
    • existing code
    • test failures

    4.2 What the agent does not automatically guarantee

    The agent does not automatically guarantee that it will:

    • read every line of every document
    • invoke every available skill
    • use current APIs
    • reproduce a screenshot exactly
    • recognize every security issue
    • prefer your architecture over patterns it sees elsewhere
    • notice that a package is outdated
    • preserve every design constraint

    Therefore the workflow must make these actions visible and verifiable.

    4.3 Context selection is a project concern

    If the agent receives only part of a large document, important rules may never become active context.

    Use:

    text
    docs/INDEX.md
    

    with a trigger map:

    text
    Task type                 Read these first
    -------------------------------------------------------
    UI                        design + UX + motion + UI refs
    API                       architecture + contracts + security
    Database                  architecture + data model + migration policy
    Authentication            security + architecture + contracts
    Production bug           operations + architecture + incident process
    Dependency update        technology policy + dependency policy
    

    This is better than one giant document.

    4.4 Progressive disclosure

    Keep high-priority instructions small. Put detail into references and skills. Current agent-skill guidance recommends concise skill bodies and moving detailed material into referenced resources; it also recommends clear trigger descriptions and deterministic scripts when exact behavior matters.


    5. The Source-of-Truth Hierarchy

    Use this hierarchy consistently.

    text
    1. Explicit product requirements
    2. Approved product decisions
    3. Approved design references
    4. Current official technology documentation
    5. Project architecture
    6. Project design system
    7. Canonical implementation examples
    8. External standards
    9. General model knowledge
    10. AI preference / aesthetic intuition
    

    5.1 Domain-specific authority

    Different decisions have different sources of truth.

    text
    Product behavior     → Product Spec
    Terminology          → Product Terminology
    Visual appearance    → Approved Design Reference
    Exact tokens         → Design Tokens
    Architecture         → Architecture document + ADRs
    API boundary         → API Contract
    Database structure   → Data Model + migrations
    Security             → Security Policy + automated checks
    Accessibility        → Accessibility Policy + tests
    Current API syntax   → Official current docs
    

    5.2 Conflict rule

    If a lower-priority source conflicts with a higher-priority source, the higher-priority source wins unless an explicit architectural decision changes it.


    6. Product Discovery Before Coding

    The first conversation with AI must not be:

    "Build my app."

    It should be a structured product interview.

    6.1 Discovery domains

    The agent should investigate:

    1. Vision
    2. Problem
    3. Users
    4. Roles
    5. User environments
    6. Jobs-to-be-done
    7. Primary workflows
    8. Secondary workflows
    9. Pain points
    10. Business rules
    11. Data
    12. Permissions
    13. Integrations
    14. Notifications
    15. UX
    16. Accessibility
    17. Security
    18. Performance
    19. Reliability
    20. Analytics
    21. Administration
    22. Deployment
    23. Compliance
    24. Non-goals
    25. Future extensibility

    6.2 Discovery output

    The session produces:

    text
    docs/
    ├── 00-project-context.md
    ├── 01-product-spec.md
    ├── 02-product-terminology.md
    └── adr/
    

    7. The Grill-Me Skill

    This is a reusable AI skill for requirements discovery.

    7.1 Mission

    The skill must continuously question the user until the requirements are implementation-ready or every remaining unknown is explicitly accepted as risk.

    7.2 Behaviour rules

    The skill must:

    • ask one useful cluster of questions at a time
    • challenge vague assumptions
    • detect contradictions
    • revisit previous decisions when new information conflicts
    • distinguish fact, requirement, preference, assumption, constraint, decision, and risk
    • maintain an unresolved list
    • never silently invent business rules
    • refuse to declare the specification final while material unknowns remain

    7.3 Exact prompt: start the Grill-Me process

    text
    You are the Product Discovery and Specification Interviewer.
    
    Your job is NOT to code, architect, or design the interface yet.
    Your job is to interrogate me until the product is sufficiently
    specified for implementation.
    
    Be rigorous and persistent. Do not accept vague answers when they
    could affect product behavior, architecture, UX, security, data,
    permissions, cost, reliability, or future maintenance.
    
    Work through these areas:
    
    1. Product vision
    2. Problem statement
    3. Target users
    4. Secondary users
    5. User roles and permissions
    6. User environment and devices
    7. Jobs-to-be-done
    8. Primary user journeys
    9. Secondary journeys
    10. Core features
    11. Non-goals
    12. Business rules
    13. Data entities
    14. Data ownership
    15. State transitions
    16. Integrations
    17. Notifications
    18. Search/filter/sort behavior
    19. Error behavior
    20. Empty/loading/success states
    21. Accessibility requirements
    22. Security requirements
    23. Performance requirements
    24. Reliability requirements
    25. Analytics requirements
    26. Administration
    27. Compliance requirements
    28. Deployment assumptions
    29. Operational requirements
    30. Future extensibility
    
    Rules:
    - Do not ask everything at once.
    - Ask the next most valuable questions.
    - When my answer is ambiguous, ask follow-up questions.
    - Detect contradictions with earlier answers.
    - Tell me when two answers conflict.
    - Challenge assumptions respectfully.
    - Do not silently decide business behavior for me.
    - Maintain an explicit unresolved-question list.
    - Maintain an explicit decision log.
    - Mark each item as requirement, preference, assumption, constraint,
      decision, or risk.
    - Continue until all material questions are resolved or explicitly
      accepted as risk.
    
    At the end of every round provide only:
    1. What is now decided
    2. What remains ambiguous
    3. The next questions
    
    Do not produce application code during this phase.
    Do not declare the process finished prematurely.
    

    7.4 Exact prompt: finalize the discovery

    text
    You are the Product Specification Finalizer.
    
    Using the completed interview:
    
    1. Check for contradictions.
    2. Check for missing material requirements.
    3. Check business rules for undefined states.
    4. Check roles and permissions for gaps.
    5. Check core workflows for missing failure paths.
    6. Check data ownership and lifecycle.
    7. Check integrations and external dependencies.
    8. Check non-functional requirements.
    9. Check accessibility and security.
    10. Check operational requirements.
    
    Classify every statement as:
    - requirement
    - preference
    - assumption
    - constraint
    - decision
    - risk
    - non-goal
    
    Do not silently fill gaps.
    
    If material unknowns remain, output an unresolved-question list and
    STOP before finalization.
    
    If complete, generate:
    - 00-project-context.md
    - 01-product-spec.md
    - 02-product-terminology.md
    - ADR candidates
    - acceptance-criteria summary
    - open-risk register
    
    Then run a consistency audit across all generated documents.
    

    8. Product Context and Product Specification

    8.1 00-project-context.md

    Use this structure:

    markdown
    # Project Context
    
    ## Product
    
    ## One-Sentence Definition
    
    ## Why It Exists
    
    ## Problem
    
    ## Primary Users
    
    ## Secondary Users
    
    ## User Environment
    
    ## Product Personality
    
    ## Desired Feel
    
    ## Must Never Feel Like
    
    ## Core User Jobs
    
    ## Primary Workflows
    
    ## Business Context
    
    ## Competitive Context
    
    ## Non-Goals
    
    ## Constraints
    
    ## Success Definition
    
    ## Known Risks
    

    8.2 01-product-spec.md

    markdown
    # Product Specification
    
    ## 1. Vision
    ## 2. Problem
    ## 3. Users
    ## 4. Roles
    ## 5. User Journeys
    ## 6. Features
    ## 7. Functional Requirements
    ## 8. Business Rules
    ## 9. Data Requirements
    ## 10. Permissions
    ## 11. Integrations
    ## 12. Notifications
    ## 13. Search / Filtering / Sorting
    ## 14. Error / Loading / Empty States
    ## 15. Non-Functional Requirements
    ## 16. Accessibility
    ## 17. Security
    ## 18. Performance
    ## 19. Reliability
    ## 20. Analytics
    ## 21. Administration
    ## 22. Deployment Constraints
    ## 23. Non-Goals
    ## 24. Acceptance Criteria
    ## 25. Risks
    ## 26. Future Considerations
    

    9. Project Terminology

    Terminology drift is a major source of AI-generated architecture problems.

    Create:

    text
    docs/02-product-terminology.md
    

    For every project-specific term document:

    text
    Term
    Market meaning
    Our project meaning
    Why this meaning is used
    Example
    Non-example
    Related terms
    

    9.1 Recommended core glossary

    Define at minimum:

    text
    Module
    Feature
    Capability
    Component
    Primitive
    Pattern
    Shell
    Scaffold
    Controller
    Service
    Repository
    Use Case
    Adapter
    Contract
    Provider
    Integration
    Reference
    Token
    Skill
    Rule
    Decision
    ADR
    Source of Truth
    Task Packet
    Change Packet
    Dependency
    Hotspot
    Release
    Incident
    

    9.2 Example conventions

    text
    Module
    = a bounded business capability with owned code/data behavior.
    
    Feature
    = a user-visible or business-visible capability inside a module.
    
    Controller
    = transport/interface layer; does not contain business rules.
    
    Service
    = business/application behavior; does not directly manage HTTP concerns.
    
    Repository
    = persistence boundary; does not decide product policy.
    
    Primitive
    = low-level reusable UI behavior.
    
    Component
    = reusable user-interface implementation.
    
    Shell
    = shared frame around a class of pages.
    
    Reference
    = approved visual source used to evaluate implementation fidelity.
    

    These are project conventions, not claims that every company uses the terms identically.


    10. Requirements, Scope, Non-Goals, and Acceptance Criteria

    10.1 Requirement quality

    Every important requirement should answer:

    text
    Who?
    What?
    Why?
    When?
    What is success?
    What is failure?
    What is the edge case?
    

    10.2 Acceptance criteria template

    markdown
    ### AC-001
    
    Given:
    When:
    Then:
    
    Edge cases:
    
    Security considerations:
    
    Accessibility considerations:
    
    Observability:
    

    10.3 Non-goals

    Every major phase should include explicit non-goals.

    This prevents AI agents from expanding scope automatically.


    11. Technology Freshness and Current-Stack Research

    This is a mandatory gate before framework/package decisions.

    11.1 The technology rule

    Choose the latest stable, production-supported, officially recommended option that is compatible with the project.

    11.2 Never use model memory for current versions

    For current versions, breaking changes, package APIs, CLI syntax, support status, and security advisories, the agent must consult current official sources.

    11.3 Technology Audit Record

    Create:

    text
     docs/03-technology-policy.md
    

    Recommended table:

    Area Selected Stable? Supported? Official source Breaking changes checked? Reason
    Runtime TBD
    Package manager TBD
    Frontend framework TBD
    Backend framework TBD
    Database TBD
    ORM/data layer TBD
    Validation TBD
    Testing TBD
    UI primitives TBD
    CI platform TBD

    11.4 Exact technology-research prompt

    text
    You are the project's Technology Researcher and Upgrade Analyst.
    
    Your task is to determine the current production-safe technology
    baseline for this project.
    
    Do not rely on model memory for anything that can change.
    
    For every major technology or dependency:
    
    1. Identify the currently supported stable release.
    2. Verify official support or LTS status.
    3. Read the official installation documentation.
    4. Read official migration/breaking-change documentation.
    5. Identify deprecated APIs.
    6. Identify the current recommended architecture.
    7. Identify official security guidance.
    8. Identify runtime compatibility requirements.
    9. Determine whether the newest release is stable, RC, beta, canary,
       nightly, or experimental.
    10. Determine whether the project should use it now.
    11. Record the exact official sources.
    12. Record known migration work.
    13. Record upgrade risk.
    
    Do not choose a dependency merely because its version number is higher.
    Prefer the latest stable, production-supported, officially recommended
    version compatible with the project.
    
    Output:
    - Technology Decision Record for every major dependency
    - baseline version table
    - deprecated-pattern blacklist
    - upgrade watchlist
    - unresolved compatibility questions
    
    Do not modify application code during this phase.
    

    11.5 Technology adapter principle

    The book intentionally does not hard-code one framework stack into the methodology.

    Instead define a technology adapter:

    text
    Technology Adapter
    ├── CLI initialization command
    ├── version pinning mechanism
    ├── folder conventions
    ├── build command
    ├── test command
    ├── lint command
    ├── type-check command
    ├── local development command
    ├── database migration command
    ├── production build command
    ├── deployment command
    └── official documentation links
    

    At project start, AI generates this adapter from current official documentation.


    12. Environment and Developer Machine Setup

    This is not Docker-specific.

    Every contributor needs an independently reproducible local environment.

    12.1 Required categories

    text
    Operating system
    Shell
    Git
    Runtime
    Package manager/build tool
    Project CLI(s)
    Editor/IDE
    GitHub/GitLab/etc. CLI if used
    Credential manager
    Environment variable strategy
    Optional database client
    Optional API testing client
    

    12.2 Version pinning

    Use repository-visible version metadata appropriate to the ecosystem:

    text
    runtime version file
    package-manager version field
    lockfile
    CLI/version notes
    

    Never rely only on:

    text
    "Install whatever is newest"
    

    12.3 Exact setup-audit prompt

    text
    Act as the Developer Environment Engineer.
    
    Inspect the target operating system and repository requirements.
    
    Determine:
    - required runtime
    - exact supported runtime line
    - package manager
    - required CLI tools
    - optional tools
    - authentication requirements
    - environment variables
    - local service requirements
    - database requirements
    - test prerequisites
    - browser prerequisites
    
    Research current official installation instructions for every tool
    that has version-sensitive installation steps.
    
    Then produce a beginner-safe setup guide with:
    1. exact installation commands
    2. verification commands
    3. expected output
    4. common failure modes
    5. troubleshooting
    6. repository setup commands
    7. first successful test
    
    Do not assume Docker.
    Do not assume a specific operating system unless detected.
    Do not install unnecessary global packages.
    

    12.4 Environment verification script

    Create a repository command such as:

    text
    setup doctor
    

    that checks:

    text
    runtime version
    package manager version
    Git
    CLI tools
    environment files
    required ports/services
    lockfile integrity
    basic build
    

    The exact implementation depends on the chosen stack.


    13. Git, GitHub, Identity, and Repository Governance

    13.1 Identity setup

    Every contributor should verify:

    text
    git config user.name
    git config user.email
    

    Use organization-approved email/identity policy.

    13.2 Repository governance

    Recommended:

    text
    protected main
    PR required
    required CI checks
    required review(s)
    CODEOWNERS where useful
    secret scanning
    dependency/security checks
    merge queue where appropriate
    

    13.3 Commit convention

    Use a predictable format, for example:

    text
    <type>(<scope>): <description>
    

    Examples:

    text
    feat(auth): add session rotation
    fix(users): prevent unauthorized profile update
    refactor(ui): consolidate form primitives
    test(events): add registration contract tests
    chore(deps): update supported runtime
    

    The exact convention can be adapted; consistency matters more than one universal wording.


    14. Repository Bootstrap and Structure

    A stack-agnostic starting point:

    text
    project/
    ├── AGENTS.md
    ├── README.md
    ├── CONTRIBUTING.md
    ├── .editorconfig
    ├── .gitignore
    │
    ├── apps/
    │   ├── web/                  # optional
    │   ├── api/                  # optional
    │   └── worker/               # optional
    │
    ├── packages/
    │   ├── ui/                  # optional shared UI
    │   ├── contracts/           # optional shared contracts
    │   └── config/              # shared tooling/config
    │
    ├── modules/                 # if application architecture uses modules
    │
    ├── docs/
    │   ├── INDEX.md
    │   ├── 00-project-context.md
    │   ├── 01-product-spec.md
    │   ├── 02-product-terminology.md
    │   ├── 03-technology-policy.md
    │   ├── 04-architecture.md
    │   ├── 05-design-philosophy.md
    │   ├── 06-design-tokens.md
    │   ├── 07-ux-principles.md
    │   ├── 08-motion-principles.md
    │   ├── 09-security-policy.md
    │   ├── 10-data-model.md
    │   ├── 11-api-contracts.md
    │   ├── 12-testing-strategy.md
    │   ├── 13-deployment.md
    │   ├── 14-production-operations.md
    │   ├── 15-dependency-policy.md
    │   ├── 16-contribution-model.md
    │   └── adr/
    │
    ├── design/
    │   ├── references/
    │   ├── assets/
    │   ├── source/
    │   └── audits/
    │
    ├── skills/
    │   └── ...
    │
    ├── scripts/
    ├── tests/
    └── .github/
        └── workflows/
    

    14.1 Do not create a folder because a tutorial has one

    Every folder needs a responsibility.

    14.2 Exact repository-bootstrap prompt

    text
    You are the Repository Bootstrap Engineer.
    
    Use the approved Product Context, Product Specification, Technology
    Policy, and Architecture decision.
    
    Before changing files:
    
    1. Read docs/INDEX.md if it exists.
    2. Read the relevant architecture documents.
    3. Verify the technology baseline against current official sources.
    4. Generate the repository using the current official CLI for the
       selected technology.
    5. Use only supported stable options.
    6. Avoid unnecessary default dependencies.
    7. Establish version pinning.
    8. Establish the canonical folder structure.
    9. Establish baseline scripts for format, lint, typecheck, test,
       build, and verification.
    10. Add initial agent documentation.
    11. Run every baseline check.
    12. Confirm the repository is clean and reproducible.
    
    Do not implement product features.
    Do not invent architecture.
    Do not add dependencies without a documented reason.
    
    Output:
    - files created
    - tools installed
    - versions selected
    - verification results
    - known follow-up tasks
    

    15. The Agent Constitution: AGENTS.md

    15.1 Purpose

    AGENTS.md should be the project's compact operating constitution.

    Keep it focused. Your preferred target of roughly 100–150 lines is reasonable.

    15.2 What belongs in it

    text
    Role
    Mission
    Non-negotiable rules
    Repository map
    Documentation map
    Skill routing
    Architecture summary
    Coding principles
    Design principles
    Security principles
    Verification commands
    Definition of done
    Prohibited behaviour
    

    15.3 What should not go into it

    Avoid putting:

    • giant API references
    • huge package documentation
    • every UX article
    • hundreds of code examples
    • long historical explanations
    • entire standards documents

    Use linked references instead.

    15.4 Placeholder AGENTS.md

    markdown
    # Project Agent Constitution
    
    ## Role
    
    Act as a senior product engineer working inside this repository.
    You are responsible for producing maintainable, secure, accessible,
    tested, current, and product-consistent changes.
    
    ## Mission
    
    Implement the requested product outcome while preserving:
    - product requirements
    - approved architecture
    - design system
    - security boundaries
    - accessibility requirements
    - repository conventions
    
    ## Non-Negotiables
    
    1. Read relevant project documentation before implementation.
    2. Read and use the applicable skill for the task.
    3. Use current official technology documentation when APIs or versions
       may have changed.
    4. Never introduce deprecated patterns when a supported replacement exists.
    5. Do not invent architecture when an established project pattern exists.
    6. Do not invent UI patterns that conflict with approved references or design tokens.
    7. Do not add dependencies without a concrete need and recorded decision.
    8. Do not change unrelated files.
    9. Do not bypass validation, authorization, or security checks.
    10. Do not claim work is complete without verification.
    
    ## Source of Truth
    
    Product → docs/01-product-spec.md
    Terminology → docs/02-product-terminology.md
    Technology → docs/03-technology-policy.md
    Architecture → docs/04-architecture.md
    Design → docs/05-design-philosophy.md + docs/06-design-tokens.md
    UX → docs/07-ux-principles.md
    Motion → docs/08-motion-principles.md
    Security → docs/09-security-policy.md
    Data → docs/10-data-model.md
    API → docs/11-api-contracts.md
    Testing → docs/12-testing-strategy.md
    Deployment → docs/13-deployment.md
    Operations → docs/14-production-operations.md
    Dependencies → docs/15-dependency-policy.md
    Collaboration → docs/16-contribution-model.md
    
    ## Working Method
    
    1. Understand the requested outcome.
    2. Identify affected module(s).
    3. Read the smallest relevant context set.
    4. Inspect canonical examples.
    5. Check dependencies and contracts.
    6. State the implementation plan before large changes.
    7. Implement only the necessary scope.
    8. Validate continuously.
    9. Review the diff.
    10. Run required checks.
    11. Report evidence of completion.
    
    ## UI Rules
    
    - Reference images are visual source of truth.
    - Do not redesign approved references.
    - Use project design tokens.
    - Preserve visual hierarchy.
    - Preserve product-specific feel.
    - Do not introduce generic AI aesthetics.
    - Do not introduce unapproved colours, gradients, or decorations.
    - Motion must communicate purpose and respect reduced-motion preferences.
    
    ## Engineering Rules
    
    - Follow module boundaries.
    - Keep transport, business logic, and persistence responsibilities separate.
    - Prefer explicit, boring, maintainable code over clever code.
    - Use current supported APIs.
    - Keep types/contracts explicit.
    - Validate untrusted input.
    - Enforce authorization at the correct trust boundary.
    
    ## Verification
    
    Before completion, run the relevant:
    - formatter
    - linter
    - typecheck/compiler
    - unit/integration tests
    - build
    - E2E tests
    - accessibility checks
    - security checks
    - browser/visual checks
    
    ## Completion
    
    A task is complete only when its acceptance criteria are satisfied and
    verification evidence exists.
    

    15.5 Important rule

    The placeholder above is a template, not a universal final file. Replace links, commands, terminology, and architecture with project-specific values.


    16. Rules, Skills, References, and Progressive Disclosure

    Use four layers.

    text
    AGENTS.md
       ↓
    Scoped Rules
       ↓
    Skills
       ↓
    References / Scripts / Examples
    

    16.1 Rules

    Use rules for durable conventions.

    Examples:

    text
    rules/frontend
    rules/backend
    rules/database
    rules/security
    rules/testing
    rules/ui
    

    16.2 Skills

    Use skills for procedures.

    Recommended skills:

    text
    product-grill-me
    technology-research
    architecture
    ui-reference-generation
    ui-implementation
    ui-visual-qa
    accessibility-audit
    security-review
    api-implementation
    database-change
    testing
    code-review
    dependency-upgrade
    release
    production-debugging
    integration-conflict-resolution
    

    16.3 Skill structure

    text
    skills/
    └── ui-implementation/
        ├── SKILL.md
        ├── references/
        ├── scripts/
        └── examples/
    

    16.4 Skill template

    markdown
    ---
    name: ui-implementation
    description: Implements approved UI references using project tokens,
    canonical components, responsive rules, accessibility requirements,
    and browser-based visual verification. Use for new UI screens,
    complex UI modifications, and reference-image replication.
    ---
    
    # Purpose
    
    ...
    
    # When to use
    
    ...
    
    # Inputs
    
    ...
    
    # Required workflow
    
    ...
    
    # Verification
    
    ...
    
    # Failure conditions
    
    ...
    

    Current OpenAI skill guidance recommends a concise skill body, clear metadata, and progressive disclosure for detailed references/scripts. Adapt the exact skill packaging to the target agent/IDE.


    17. The AI Agent Operating Protocol

    All important tasks should use this protocol.

    text
    UNDERSTAND
    → CONTEXT
    → PLAN
    → CHANGE
    → VERIFY
    → REVIEW
    → REPORT
    

    17.1 Exact universal implementation prompt

    text
    Act as the implementation engineer for this repository.
    
    TASK:
    [task]
    
    Before editing:
    1. Read the relevant project context.
    2. Read the relevant rules and skills.
    3. Inspect existing implementations.
    4. Identify the module boundary.
    5. Check current dependencies and contracts.
    6. Identify shared-file hotspots.
    7. Identify tests required.
    8. Identify security/accessibility implications.
    9. If UI is involved, inspect all relevant approved references.
    
    Then produce:
    - understanding
    - scope
    - assumptions
    - dependencies
    - implementation plan
    - verification plan
    
    During implementation:
    - modify only the required scope
    - reuse canonical patterns
    - follow project naming
    - avoid deprecated APIs
    - avoid unnecessary abstractions
    - avoid unnecessary dependencies
    - preserve unrelated behaviour
    
    After implementation:
    1. Run focused tests.
    2. Run relevant quality checks.
    3. Review the diff.
    4. Search for accidental unrelated changes.
    5. Verify acceptance criteria.
    6. Provide evidence.
    
    If a requirement conflicts with repository rules, STOP and explain the
    conflict before choosing a new convention.
    

    18. Architecture and Module Boundaries

    18.1 Architecture must be explicit

    Create:

    text
    docs/04-architecture.md
    

    Include:

    text
    system boundaries
    applications/services
    modules
    responsibilities
    data flow
    trust boundaries
    integration boundaries
    shared packages
    error strategy
    logging strategy
    configuration
    

    18.2 Module-oriented architecture

    A typical business module may be:

    text
    users/
    ├── users.controller.ts
    ├── users.service.ts
    ├── users.repository.ts
    ├── users.schema.ts
    ├── users.types.ts
    ├── users.routes.ts
    └── users.test.ts
    

    Adapt the exact structure to the chosen technology.

    18.3 Do not over-generate files

    Do not create every possible layer just because a template lists it.

    Use the smallest structure that:

    • maintains module boundaries
    • keeps responsibilities clear
    • preserves testability
    • matches established project patterns

    18.4 Architecture decision records

    Use:

    text
    docs/adr/ADR-XXXX-title.md
    

    Template:

    markdown
    # ADR-XXXX: Title
    
    ## Status
    
    Proposed | Accepted | Superseded | Rejected
    
    ## Context
    
    ## Decision
    
    ## Alternatives
    
    ## Consequences
    
    ## Migration / Follow-up
    

    19. Collaborative Development Without Team Chaos

    This is not a frontend-vs-backend question.

    The team should be organized around:

    text
    contracts
    ownership
    change surface
    dependency graph
    integration risk
    

    19.1 The team model

    Developers can be:

    • generalists
    • specialists
    • AI-assisted
    • variable in experience

    The workflow must remain stable.

    19.2 Main branch principle

    main should remain:

    • buildable
    • testable
    • releasable or close to releasable

    19.3 Short-lived branches

    Default:

    text
    main
     ↑
    small change branch
     ↑
    PR
    

    19.4 Stacked changes

    When change B depends on change A, use a stacked branch/PR strategy rather than waiting unnecessarily or creating giant branches.

    GitHub's current stacked pull request documentation describes stacks as dependent PR chains where each layer can be reviewed separately; GitHub also documents merge-queue support for stacks. Availability and exact UI/CLI behavior may change because stacked PRs are currently documented as public preview.

    19.5 Do not promise zero merge conflicts

    A real engineering system cannot guarantee zero conflicts.

    The goal is:

    Minimize collision probability and make integration cheap and predictable.


    20. Independent Workspaces and Worktrees

    This does not require Docker.

    A developer/agent can work in an independent Git worktree.

    Git officially supports multiple working trees attached to a repository.

    20.1 Recommended layout

    text
    ~/work/project-main
    ~/work/project-task-A
    ~/work/project-task-B
    ~/work/project-task-C
    

    Each worktree has:

    text
    its own branch
    its own checked-out files
    its own working state
    

    20.2 Typical commands

    bash
    git worktree add ../project-task-A -b task/A main
    git worktree add ../project-task-B -b task/B main
    git worktree list
    git worktree remove ../project-task-A
    

    Verify the syntax for the installed Git version if scripting around it.

    20.3 Environment isolation without Docker

    Each worktree should use:

    text
    shared lockfile/version baseline
    independent environment variables
    independent local service ports when needed
    independent test data when needed
    

    Do not share mutable .env files across unrelated worktrees.


    21. Contract-First and Dependency-Ready Development

    This is the key to parallel development.

    21.1 Dependency graph before implementation

    For every phase:

    text
    Task
     ↓
    Dependencies
     ↓
    Outputs
     ↓
    Consumers
    

    21.2 Dependency-ready baseline

    Before parallel work begins, resolve:

    • runtime version
    • package manager
    • core packages
    • generated types/contracts
    • shared UI baseline
    • database baseline
    • config structure
    • CI baseline

    This prevents five developers from independently deciding versions.

    21.3 Contract-first sequence

    A generic flow:

    text
    Domain decision
     ↓
    Contract
     ↓
    Schema/type
     ↓
    Implementation
     ↓
    Consumer
     ↓
    Integration test
    

    When possible, consumers can begin against the stable contract without waiting for the final implementation.

    21.4 Shared hotspot list

    Identify early:

    text
    root package manifest
    lockfile
    CI workflows
    global configuration
    base styles/tokens
    database schema
    migration folder
    main routing registry
    shared API contract
    AGENTS.md
    

    Assign a single active writer or controlled integration window for high-collision artifacts.


    22. Task Packets and Change Packets

    The task packet is the fundamental unit of collaborative work.

    22.1 YAML template

    yaml
    task_id: AUTH-023
    title: Add refresh-token rotation
    objective: >
      Implement secure refresh-token rotation according to the authentication policy.
    context:
      - docs/09-security-policy.md
      - docs/11-api-contracts.md
    depends_on:
      - AUTH-021
    produces:
      - auth refresh endpoint
      - token rotation service
    allowed_paths:
      - modules/auth/**
      - tests/auth/**
    forbidden_paths:
      - design/**
      - unrelated modules
    contracts:
      reads:
        - AuthSession
      changes:
        - RefreshTokenResponse
    dependencies:
      add: []
      update: []
    database_impact:
      - none
    api_impact:
      - POST /auth/refresh
    security_impact:
      - session security
    accessibility_impact: none
    tests:
      - unit
      - integration
      - E2E
    acceptance_criteria:
      - old refresh token is invalidated after rotation
      - replay attempts are rejected
    risk: high
    integration_notes: >
      Shared auth contract must remain backwards compatible during rollout.
    

    22.2 Why this scales

    A developer with less context gets a precise boundary.

    An experienced developer can work faster because the intent is explicit.

    An AI agent can operate with less ambiguity.

    A reviewer can understand the intended change without reading the entire repository.


    23. Collaboration for Teams with Unequal Skill Levels

    Do not assign work merely as:

    text
    Backend person
    Frontend person
    Database person
    

    Instead measure two dimensions:

    text
    Domain complexity
    Implementation complexity
    

    Create work packets with:

    text
    required knowledge
    estimated complexity
    risk
    expected outputs
    review requirements
    

    23.1 Skill calibration

    Before a contributor receives high-risk work, provide a low-risk onboarding task such as:

    text
    small UI fix
    small test addition
    small documentation change
    small isolated module
    

    This validates tooling and collaboration before critical code is touched.

    23.2 Risk-based review

    High-risk changes need stronger review regardless of who wrote them.

    Examples:

    text
    authentication
    authorization
    payments
    database migrations
    security configuration
    production infrastructure
    

    24. Design Philosophy and Product Feel

    A product should not look like a generic AI-generated website.

    Its design should emerge from:

    text
    product domain
    users
    context
    brand personality
    jobs-to-be-done
    information hierarchy
    

    24.1 Design philosophy document

    Create:

    text
    docs/05-design-philosophy.md
    

    Template:

    markdown
    # Design Philosophy
    
    ## Product Character
    
    ## Desired Emotional Response
    
    ## Visual Personality
    
    ## Information Density
    
    ## Visual Hierarchy
    
    ## Typography Philosophy
    
    ## Color Philosophy
    
    ## Surface Philosophy
    
    ## Component Philosophy
    
    ## Imagery Philosophy
    
    ## Motion Philosophy
    
    ## Accessibility Philosophy
    
    ## Anti-Patterns
    
    ## Examples
    

    24.2 Anti-patterns

    The project can explicitly prohibit things such as:

    text
    unapproved purple/violet/indigo identity
    AI sparkle/magic-wand imagery
    neural-network decoration
    arbitrary gradients
    glassmorphism
    random floating blobs
    excessive pill controls
    excessive cards
    gradient text
    unnecessary shadows
    meaningless animation
    invented decorative elements
    

    Do not use this exact list automatically for every product. Keep only prohibitions that match the actual product philosophy.


    25. Design Tokens

    Create:

    text
    docs/06-design-tokens.md
    design/tokens source files
    a working design-token page
    

    25.1 Token groups

    text
    color
    font family
    font size
    line height
    font weight
    spacing
    radius
    border
    shadow/elevation
    motion duration
    motion easing
    breakpoints
    content width
    layer/z-index
    

    25.2 CSS-first principle

    For CSS styling, prefer the project's canonical CSS/Tailwind/design-token mechanism rather than moving all styling into JavaScript/TypeScript objects.

    Use objects in TypeScript for data/configuration/variants where appropriate, not as a blanket replacement for CSS.

    25.3 Token page

    Create a real page that visibly demonstrates:

    text
    colors
    typography
    spacing
    radii
    buttons
    forms
    cards
    navigation
    states
    motion
    responsive behavior
    

    The token page is an executable visual reference.


    26. AI-Generated HQ UI Mockups

    This is a full engineering phase, not an optional artistic exercise.

    26.1 The correct sequence

    text
    Product Context
     ↓
    UX architecture
     ↓
    Visual direction exploration
     ↓
    Choose direction
     ↓
    Design tokens
     ↓
    Component language
     ↓
    HQ reference mockups
     ↓
    Independent critique
     ↓
    Revision
     ↓
    Approval
     ↓
    Implementation
    

    26.2 Difference between image categories

    Inspiration

    Communicates mood.

    Concept

    Explores possible direction.

    High-fidelity reference

    Communicates realistic layout and product behavior.

    Canonical reference

    Approved visual authority for implementation.

    26.3 Do not generate "a modern website"

    Use product context.

    Required prompt inputs

    text
    product
    users
    context
    primary task
    content structure
    visual personality
    colour system
    typography
    spacing
    component language
    density
    responsive target
    anti-patterns
    reference images
    

    26.4 Visual direction prompt

    text
    You are the visual art director and senior product designer for a real
    production product.
    
    Do not start by creating a random "modern website".
    First explore distinct visual directions that emerge from the product.
    
    PRODUCT:
    [product]
    
    DOMAIN:
    [domain]
    
    PRIMARY USERS:
    [users]
    
    PRIMARY USER GOAL:
    [goal]
    
    CORE CONTEXT:
    [context]
    
    PRODUCT PERSONALITY:
    [4–6 adjectives]
    
    THE PRODUCT SHOULD FEEL LIKE:
    [description]
    
    THE PRODUCT MUST NOT FEEL LIKE:
    [description]
    
    EXPLORE 4 DISTINCT DESIGN DIRECTIONS.
    
    Each direction must meaningfully differ in:
    - typography
    - composition
    - density
    - component geometry
    - navigation treatment
    - colour relationships
    - imagery
    - hierarchy
    
    Do not produce four minor color variants.
    
    For each direction explain:
    1. design philosophy
    2. emotional impression
    3. typography strategy
    4. color strategy
    5. layout strategy
    6. component strategy
    7. information density
    8. navigation strategy
    9. motion philosophy
    10. strengths
    11. risks
    12. fit for this product
    
    Avoid generic AI/SaaS aesthetics, invented visual decoration, and
    trend-driven effects unless justified by the product context.
    

    26.5 HQ screen generation master prompt

    text
    You are a senior product designer and visual art director.
    
    Generate a HIGH-FIDELITY UI REFERENCE MOCKUP for a real production
    product.
    
    This is NOT an inspiration image.
    This is NOT a Dribbble concept.
    This is NOT a generic SaaS template.
    This image will be handed to a frontend engineer as a visual reference.
    
    PRODUCT
    Name: [name]
    Purpose: [purpose]
    Domain: [domain]
    Primary users: [users]
    User context: [context]
    Primary task: [task]
    
    SCREEN
    Name: [screen]
    Purpose: [purpose]
    Viewport: [desktop/tablet/mobile]
    
    INFORMATION ARCHITECTURE
    [exact content/sections/components]
    
    CONTENT
    Use believable domain-specific content.
    Avoid lorem ipsum and meaningless placeholder labels.
    
    DESIGN SYSTEM
    Typography: [typography]
    Primary colors: [tokens]
    Surface colors: [tokens]
    Spacing philosophy: [description]
    Radius: [description]
    Elevation: [description]
    Iconography: [description]
    
    VISUAL DIRECTION
    [approved direction]
    
    VISUAL HIERARCHY
    Establish a clearly identifiable primary objective and primary action.
    Use scale, whitespace, grouping, contrast, and alignment to establish
    hierarchy.
    Do not make everything visually loud.
    
    PRODUCT CONTEXT
    The screen should feel specific to [domain/product].
    Do not make it look like an interchangeable template.
    
    UX PRINCIPLES
    - recognition over recall
    - predictable navigation
    - progressive disclosure
    - obvious primary action
    - meaningful feedback
    - error prevention
    - clear grouping
    - appropriate information density
    
    ACCESSIBILITY
    Design toward WCAG 2.2 AA.
    Use readable type, sufficient contrast, understandable controls, and
    states that do not rely on color alone.
    
    MOTION INTENT
    The composition should support purposeful transitions for state change,
    feedback, and spatial relationships. Do not add animation for spectacle.
    
    ANTI-PATTERNS — DO NOT USE UNLESS EXPLICITLY PRESENT IN THE APPROVED DESIGN:
    - generic AI visual language
    - purple/violet/indigo branding
    - AI sparkles
    - magic-wand imagery
    - neural-network decoration
    - arbitrary gradients
    - glassmorphism
    - neon glow
    - floating decorative blobs
    - excessive pills
    - excessive cards
    - gradient text
    - random 3D objects
    - decorative elements without product purpose
    
    REFERENCE IMAGES
    Use attached approved references as constraints.
    Preserve their applicable hierarchy, spacing rhythm, typography
    relationship, component language, and composition.
    
    FINAL REQUIREMENT
    The result must feel like a real product used by real people.
    Prioritize product clarity, hierarchy, usability, consistency,
    accessibility, and implementation realism over visual spectacle.
    

    26.6 Landing page prompt

    text
    Using the approved product context and visual direction, generate a
    high-fidelity landing-page reference for [PRODUCT].
    
    Required structure:
    - navigation
    - hero
    - primary CTA
    - secondary action if justified
    - trust/social proof if appropriate
    - product explanation
    - key workflows or benefits
    - evidence
    - final CTA
    - footer
    
    Do not invent sections merely to fill space.
    The page must tell the product story in a deliberate hierarchy.
    
    The reference is for implementation, so use realistic spacing,
    content density, typography, and component dimensions.
    
    Generate desktop first at a realistic large desktop viewport.
    

    26.7 Application-shell prompt

    text
    Generate a high-fidelity application-shell reference for [PRODUCT].
    
    The shell must establish:
    - application navigation
    - sidebar/topbar behavior
    - page header
    - breadcrumbs when justified
    - primary actions
    - account/user control
    - notifications/status
    - content container
    - responsive transformation
    
    Do not decorate the shell unnecessarily.
    The shell must support long-term product usage and high information
    clarity rather than looking like a marketing hero.
    

    26.8 Dense information screen prompt

    text
    Generate a high-fidelity information-dense screen for [PRODUCT].
    
    The screen must demonstrate how the design system behaves under high
    content density.
    
    Include only information that real users need.
    
    Show:
    - clear page purpose
    - meaningful filtering/search where necessary
    - table/list/card density appropriate to the domain
    - status representation
    - sorting/pagination when justified
    - empty/loading/error considerations
    
    Avoid dashboard-widget soup.
    Avoid decorative charts without decision value.
    Preserve visual hierarchy even under density.
    

    26.9 Workflow/form screen prompt

    text
    Generate a high-fidelity workflow/form screen for [PRODUCT].
    
    The user must have a clear sense of:
    1. where they are
    2. what they need to do
    3. what information is required
    4. what will happen next
    5. how to recover from mistakes
    
    Design realistic validation, help text, grouping, progressive disclosure,
    and confirmation behavior.
    
    Do not create a form that looks like a generic component-library demo.
    

    26.10 Mobile prompt

    text
    Using the approved desktop reference, generate the corresponding mobile
    reference.
    
    Do not simply shrink the desktop screen.
    
    Preserve the same design language and information hierarchy while
    adapting:
    - navigation
    - stacking
    - content density
    - touch targets
    - typography scale
    - action placement
    - tables/lists where appropriate
    - dialogs/drawers
    
    Do not invent a separate visual identity for mobile.
    

    27. Mockup Refinement, Approval, and Reference Tiers

    27.1 Generate directions first

    Create 3–5 different visual directions. Select one.

    27.2 Generate the design-system reference

    Show the component language before generating every page.

    27.3 Recommended reference set

    For a substantial web product, start with approximately:

    text
    1 visual direction
    2 marketing references (desktop + mobile)
    2 application shell references (desktop + mobile)
    3 representative product screens
    1 information-dense reference
    1 workflow reference
    

    Approximately 8–10 total is usually enough to establish the system.

    Only 5–7 should be treated as strict replication targets.

    27.4 Reference tiers

    Tier 1 — strict replication

    The implementation should match closely.

    Tier 2 — system exemplars

    They establish how the system behaves.

    Tier 3 — derived states

    They can be generated from the component/design system without a dedicated image.

    27.5 Reference metadata

    Store a small sidecar for each reference:

    yaml
    reference_id: REF-04
    route: /dashboard
    viewport: 1440x1024
    strictness: strict
    purpose: primary application overview
    related_tokens:
      - typography.display
      - spacing.4
      - surface.default
    components:
      - AppShell
      - DataTable
      - FilterBar
    

    27.6 Design review prompt

    text
    Act as an independent senior product-design reviewer.
    
    Review the attached proposed UI references against the product context,
    UX requirements, design philosophy, tokens, and anti-patterns.
    
    Do not immediately redesign them.
    First identify:
    
    1. product-context mismatch
    2. visual hierarchy problems
    3. usability problems
    4. accessibility risks
    5. inconsistent components
    6. unnecessary decoration
    7. generic AI-generated patterns
    8. information-density problems
    9. responsive risks
    10. implementation risks
    11. brand/visual-language drift
    
    For each issue report:
    - severity
    - location
    - problem
    - why it matters
    - correction recommendation
    
    Do not praise the design without concrete evidence.
    Do not introduce aesthetic preferences that conflict with the approved
    product direction.
    

    27.7 Approval gate

    A reference is approved only when:

    text
    product context ✓
    visual hierarchy ✓
    UX ✓
    accessibility ✓
    component consistency ✓
    responsive intent ✓
    anti-pattern audit ✓
    implementation feasibility ✓
    

    28. UI Foundation and Component Laboratory

    Before building pages, create a component laboratory.

    28.1 Component categories

    text
    buttons
    links
    inputs
    selects
    checkboxes
    radio
    switches
    search
    forms
    cards
    tables
    tabs
    dialogs
    drawers
    menus
    breadcrumbs
    badges
    alerts
    toasts
    pagination
    loading
    empty
    error
    success
    navigation
    

    28.2 Component states

    At minimum:

    text
    default
    hover
    focus
    active
    disabled
    loading
    error
    success
    selected
    empty
    

    28.3 Component lab prompt

    text
    Using the approved design direction and design tokens, create a
    high-fidelity component reference system.
    
    The components must all belong to one coherent visual language.
    
    Include:
    - typography hierarchy
    - buttons
    - icon buttons
    - inputs
    - search
    - select
    - checkbox
    - radio
    - switch
    - tabs
    - cards
    - tables
    - pagination
    - tooltip
    - dropdown
    - dialog
    - alert
    - toast
    - breadcrumbs
    - navigation
    - loading
    - empty
    - error
    - success
    
    For interactive components show:
    default, hover, focus, active, disabled, loading, error, success,
    selected where relevant.
    
    Use realistic domain-specific content.
    
    Do not invent a new visual style for individual components.
    Do not rely on generic UI-library defaults.
    Do not add visual effects merely to look modern.
    

    29. Application Shell and Scaffold

    Follow your intended sequence:

    text
    Design Tokens
     ↓
    Component Lab
     ↓
    Marketing Shell
     ↓
    Application Shell
     ↓
    Demo Navigation
     ↓
    System States
     ↓
    Real Product Pages
    

    29.1 Marketing shell

    text
    Header
    Hero
    Content sections
    Evidence/trust
    CTA
    Footer
    

    29.2 Application shell

    text
    Top navigation or application header
    Sidebar/drawer if appropriate
    Breadcrumbs if appropriate
    Page header
    Primary actions
    Notifications
    Account control
    Main content
    

    29.3 Scaffold definition

    A scaffold is:

    Stable page structure and integration surfaces without pretending that final content/design decisions are complete.

    Do not call unfinished UI "production-ready".


    30. UI Implementation with Reference Fidelity

    30.1 Reference fidelity rule

    The reference is not inspiration.

    It is the visual source of truth for that screen.

    The agent may improve:

    • semantics
    • accessibility
    • responsive adaptation
    • performance
    • implementation architecture

    It must not casually redesign:

    • hierarchy
    • composition
    • spacing language
    • typography relationship
    • component geometry
    • visual identity

    30.2 Exact UI implementation prompt

    text
    You are the UI implementation engineer.
    
    The attached reference is the authoritative visual specification for
    this screen.
    
    DO NOT redesign it.
    DO NOT reinterpret it as inspiration.
    
    Before editing:
    1. Read the product context.
    2. Read design philosophy.
    3. Read design tokens.
    4. Read UX and motion principles.
    5. Inspect the existing component library.
    6. Inspect canonical examples.
    7. Inspect all related reference images.
    8. Determine desktop/mobile requirements.
    
    Implementation rules:
    - reuse canonical components
    - use design tokens
    - follow project architecture
    - preserve visual hierarchy
    - preserve density and spacing rhythm
    - avoid generic AI/SaaS aesthetics
    - do not invent decorations
    - do not add unapproved colors or gradients
    - do not add unnecessary animation
    - preserve accessibility
    
    Verification:
    1. Run the application.
    2. Render the route in a real browser.
    3. Capture the required viewport screenshot.
    4. Compare it against the reference.
    5. Record visual discrepancies.
    6. Fix the highest-severity discrepancies first.
    7. Repeat until the visual acceptance gate passes.
    8. Run accessibility checks.
    9. Run required tests.
    10. Run lint/typecheck/build.
    
    Do not claim completion based on code inspection alone.
    

    31. UX Psychology, Visual Hierarchy, and Motion

    31.1 Visual hierarchy

    Every screen should answer:

    text
    What is the primary purpose?
    What should the user notice first?
    What is the primary action?
    What information supports it?
    What can be de-emphasized?
    

    Use:

    • scale
    • contrast
    • whitespace
    • alignment
    • grouping
    • density
    • position

    Do not make everything visually prominent.

    31.2 UX principles to teach the AI

    Useful heuristics include:

    text
    recognition over recall
    progressive disclosure
    choice reduction
    error prevention
    clear feedback
    user control
    consistency
    proximity
    alignment
    information scent
    predictability
    

    Treat laws such as Hick's or Fitts's as heuristics, not mathematical design commands.

    31.3 Motion

    Create:

    text
    docs/08-motion-principles.md
    

    Motion should communicate:

    text
    continuity
    state change
    feedback
    spatial relationship
    progress
    orientation
    

    Avoid animation merely to demonstrate animation ability.

    Always consider reduced-motion preferences.

    31.4 Motion review prompt

    text
    Review this interaction design as a motion and UX specialist.
    
    For every animation/transition determine:
    1. what information it communicates
    2. whether it improves comprehension
    3. whether it is necessary
    4. whether duration/easing is appropriate
    5. whether it creates distraction
    6. how reduced-motion users experience it
    
    Recommend removal when motion has no functional purpose.
    

    32. Accessibility and WCAG

    Use current W3C guidance. WCAG 2.2 is the current W3C Recommendation.

    32.1 Accessibility target

    Default product target:

    WCAG 2.2 AA, unless the product specification requires a stricter standard.

    32.2 Review areas

    text
    semantic structure
    keyboard navigation
    focus visibility
    form labels
    error identification
    status messages
    contrast
    non-text content
    reflow
    responsive behavior
    touch target usability
    motion
    reduced motion
    screen-reader behaviour
    

    32.3 Accessibility prompt

    text
    Act as the Accessibility Engineer.
    
    Audit the implementation against WCAG 2.2 AA.
    
    Check:
    - semantics
    - keyboard access
    - focus order
    - visible focus
    - labels
    - errors
    - instructions
    - contrast
    - non-text content
    - status messages
    - reflow
    - motion
    - reduced motion
    - responsive behaviour
    
    Use automated checks where possible, but do not treat automation as
    proof of complete accessibility.
    
    For each issue provide:
    - criterion/area
    - severity
    - user impact
    - location
    - correction
    - verification method
    
    Do not change unrelated behaviour.
    

    33. Security and OWASP

    Use current OWASP guidance rather than an old memorized checklist.

    OWASP Top 10:2025 is the current major Top 10 awareness document as of this handbook's current date.

    Its 2025 categories include:

    text
    A01 Broken Access Control
    A02 Security Misconfiguration
    A03 Software Supply Chain Failures
    A04 Cryptographic Failures
    A05 Injection
    A06 Insecure Design
    A07 Authentication Failures
    A08 Software or Data Integrity Failures
    A09 Security Logging & Alerting Failures
    A10 Mishandling of Exceptional Conditions
    

    33.1 Security policy

    Create:

    text
    docs/09-security-policy.md
    

    Include:

    text
    trust boundaries
    authentication
    authorization
    session security
    input validation
    output encoding
    secrets
    cryptography
    files
    networking
    CORS/CSRF where applicable
    rate limiting
    logging
    monitoring
    error handling
    database security
    dependency/supply chain
    

    33.2 Security review prompt

    text
    Act as the security reviewer.
    
    Review this change against the project's security policy and current
    OWASP guidance.
    
    Check:
    - authentication
    - authorization
    - input validation
    - injection
    - access control
    - secrets
    - session/token handling
    - file handling
    - network boundaries
    - error handling
    - logging/alerting
    - dependency/supply-chain risk
    - data integrity
    - abuse/rate limiting
    
    For every finding provide:
    severity
    exploit scenario
    affected boundary
    recommended mitigation
    required regression test
    
    Do not declare the code safe merely because a linter passes.
    

    34. Data, API, and Integration Contracts

    34.1 Data model

    Create:

    text
    docs/10-data-model.md
    

    For each entity:

    text
    purpose
    owner
    fields
    invariants
    relations
    lifecycle
    privacy
    retention
    indexes
    migration considerations
    

    34.2 API contract

    Create:

    text
    docs/11-api-contracts.md
    

    Define:

    text
    request shape
    response shape
    errors
    authentication
    authorization
    pagination
    filtering
    sorting
    idempotency
    rate limits
    versioning
    

    34.3 Contract rule

    Consumers should depend on an explicit contract, not undocumented behaviour.

    34.4 API implementation prompt

    text
    Implement this API change from the approved contract.
    
    Before coding:
    - read the API contract
    - read architecture
    - read security policy
    - inspect existing patterns
    - inspect tests
    
    Implementation constraints:
    - validate all untrusted input
    - enforce authorization at the server boundary
    - preserve documented response shapes
    - return documented error shapes
    - avoid leaking internal details
    - avoid unrelated changes
    
    After coding:
    - unit test business logic
    - integration test the endpoint
    - test unauthorized/forbidden cases
    - test validation failures
    - test important edge cases
    - run the full relevant quality gates
    

    35. Vertical Delivery and Phase Planning

    The project should be broken into dependency-aware slices, not blindly feature-based or frontend/backend-only.

    35.1 A phase record

    yaml
    phase_id: P07
    goal: deliver event registration flow
    depends_on:
      - P04
      - P06
    outputs:
      - domain rules
      - API contract
      - UI workflow
      - tests
    parallel_work:
      - UI preparation
      - contract tests
      - documentation
    shared_hotspots:
      - database schema
    exit_criteria:
      - acceptance criteria pass
      - integration tests pass
      - visual reference matches
      - accessibility audit passes
    

    35.2 Avoid long dependency chains

    Prefer:

    text
    foundation → several parallel consumers
    

    rather than:

    text
    A → B → C → D → E → F
    

    when the work does not actually require that sequence.

    35.3 Phase-planning prompt

    text
    You are the Project Planner.
    
    Using the final Product Specification, Architecture, Design System,
    and Technology Policy:
    
    1. Build the dependency graph of the complete product.
    2. Identify foundational work.
    3. Identify parallelizable work.
    4. Identify shared-file hotspots.
    5. Identify integration points.
    6. Identify work that blocks other work.
    7. Identify work that can use contracts before implementation exists.
    8. Identify testing requirements per phase.
    9. Identify production-risk work.
    10. Minimize critical-path length without creating unsafe coupling.
    
    For every phase provide:
    - objective
    - prerequisites
    - outputs
    - tasks
    - parallel tasks
    - blocking dependencies
    - hotspots
    - risks
    - acceptance criteria
    - exit gate
    
    Do not organize phases purely by department.
    Do not create artificial phases merely because a technology has its own
    folder.
    

    36. Testing Strategy

    Create:

    text
    docs/12-testing-strategy.md
    

    36.1 Test layers

    text
    Unit
     ↓
    Integration
     ↓
    Contract
     ↓
    End-to-End
     ↓
    Accessibility
     ↓
    Visual
     ↓
    Production verification
    

    36.2 Unit tests

    Use for:

    • pure business rules
    • utilities
    • validation logic
    • transformations

    36.3 Integration tests

    Use for:

    • database interaction
    • API behavior
    • authentication boundaries
    • repository/service integration

    36.4 Contract tests

    Use for:

    • producer/consumer compatibility
    • API schemas
    • external integrations

    36.5 E2E tests

    Test critical user journeys.

    Do not reproduce every unit test at E2E level.

    36.6 Visual tests

    For approved references:

    text
    reference.png
        ↕
    browser screenshot
    

    36.7 Testing prompt

    text
    Act as the test engineer.
    
    Based on the task acceptance criteria, determine the minimum complete
    test set.
    
    Classify tests as:
    - unit
    - integration
    - contract
    - E2E
    - accessibility
    - visual
    
    Test:
    - happy path
    - validation failures
    - permission failures
    - important edge cases
    - state transitions
    - regression risks
    
    Avoid redundant tests that verify the same thing at every layer.
    
    Implement the tests and run them.
    Report exact results.
    

    37. CI/CD and Merge Gates

    CI must run from the beginning, not after the application "works."

    37.1 Generic CI pipeline

    text
    checkout
     ↓
    install/frozen dependency resolution
     ↓
    format check
     ↓
    lint
     ↓
    typecheck/build validation
     ↓
    unit tests
     ↓
    integration tests
     ↓
    contract checks
     ↓
    E2E smoke tests
     ↓
    accessibility checks
     ↓
    security/dependency checks
     ↓
    artifact/build
    

    Exact stages vary by stack.

    37.2 Required checks

    A merge must not depend on the author's statement that:

    "It works locally."

    37.3 CI prompt

    text
    Act as the CI/CD engineer.
    
    Inspect the repository and current technology baseline.
    
    Create or improve CI so every change is evaluated consistently.
    
    Required categories:
    - dependency integrity
    - formatting
    - lint
    - type/build verification
    - tests
    - contract checks
    - E2E smoke tests
    - accessibility where appropriate
    - security/dependency checks
    
    Requirements:
    - fail fast on invalid prerequisites
    - use pinned/appropriate action/tool versions
    - avoid silently ignoring test failures
    - avoid leaking secrets
    - preserve useful logs
    - make critical failures visible
    
    Document which checks are required for merge.
    

    37.4 Merge queue

    For a busy repository, a merge queue can reduce the risk that a pull request passes in isolation but breaks when integrated with newer changes. GitHub documents merge queues for this purpose.


    38. Release and Deployment Engineering

    38.1 Environment progression

    text
    Local
     ↓
    CI
     ↓
    Preview / Test
     ↓
    Staging
     ↓
    Production
    

    38.2 Release gate

    Before production:

    text
    requirements ✓
    CI ✓
    review ✓
    security ✓
    accessibility ✓
    E2E ✓
    visual QA ✓
    migration plan ✓
    rollback plan ✓
    monitoring ✓
    

    38.3 Deployment prompt

    text
    Act as the Release Engineer.
    
    Prepare this change for production.
    
    Check:
    1. version/release identity
    2. dependency state
    3. build artifact
    4. database migrations
    5. backward compatibility
    6. environment variables
    7. secrets
    8. health checks
    9. monitoring
    10. rollback path
    11. smoke tests
    12. post-deploy verification
    
    Do not perform destructive production changes without an explicit
    approved migration and rollback strategy.
    
    Output a release checklist and deployment sequence.
    

    38.4 Database migration strategy

    For risky changes, use a pattern such as:

    text
    Expand
     ↓
    Backfill/Migrate
     ↓
    Switch consumers
     ↓
    Contract
    

    Avoid combining incompatible destructive schema changes with a single unverified deploy.


    39. Production Operations and Incident Response

    Create:

    text
    docs/14-production-operations.md
    

    39.1 Incident lifecycle

    text
    Detect
     ↓
    Classify
     ↓
    Reproduce
     ↓
    Contain
     ↓
    Mitigate
     ↓
    Fix
     ↓
    Regression test
     ↓
    Deploy
     ↓
    Verify
     ↓
    Document
    

    39.2 Severity model

    text
    P0 — catastrophic / data loss / major security event
    P1 — critical functionality unavailable
    P2 — important degradation
    P3 — minor defect
    P4 — cosmetic / improvement
    

    Customize definitions to your organization.

    39.3 Production debugging prompt

    text
    You are the Production Incident Engineer.
    
    Do not immediately rewrite code.
    
    First:
    1. Identify the exact symptom.
    2. Identify affected users/functions.
    3. Identify first known occurrence.
    4. Inspect recent deploys.
    5. Inspect recent dependency/config changes.
    6. Inspect logs, metrics, traces, and errors.
    7. Reproduce safely.
    8. Establish the smallest plausible root cause.
    9. Determine containment and rollback options.
    10. Propose the smallest safe mitigation.
    11. Add a regression test.
    12. Verify in a safe environment.
    13. Deploy the fix through the release process.
    14. Verify production.
    15. Document the root cause and prevention.
    
    Rules:
    - do not modify unrelated code
    - do not hide uncertainty
    - do not claim resolution without evidence
    - prefer containment over risky broad changes
    

    40. Dependency Management and Technology Upgrades

    The product must stay current over time.

    40.1 Dependency categories

    text
    security update
    patch
    minor
    major
    runtime/framework
    architecture-affecting
    breaking
    

    40.2 Dependency lane

    Create a dedicated maintenance workflow:

    text
    Observe
     ↓
    Research
     ↓
    Classify
     ↓
    Prepare
     ↓
    Upgrade
     ↓
    Test
     ↓
    Staging
     ↓
    Production
    

    40.3 Prevent dependency drift

    Do not allow each feature branch to update packages independently.

    Use:

    text
    golden dependency baseline
    lockfile discipline
    dependency update lane
    automated maintenance tool where appropriate
    

    40.4 Dependency update prompt

    text
    Act as the Dependency Upgrade Engineer.
    
    For the requested dependency update:
    
    1. inspect the currently installed version
    2. identify current stable production-supported release
    3. inspect official release notes
    4. inspect breaking changes
    5. inspect migration guide
    6. inspect security advisories
    7. inspect compatibility requirements
    8. identify affected project code
    9. create a minimal upgrade plan
    10. upgrade in an isolated change
    11. run all relevant tests
    12. verify build
    13. review lockfile changes
    14. document follow-up work
    
    Do not upgrade unrelated dependencies merely because updates are available.
    

    41. Refactoring and Architecture Evolution

    Never refactor solely because AI says the code "could be cleaner."

    41.1 Refactor triggers

    • measurable defect
    • performance issue
    • repeated maintenance cost
    • boundary violation
    • security requirement
    • deprecated platform API
    • dependency migration
    • clear duplication with stable semantics

    41.2 Refactor prompt

    text
    Act as the Refactoring Engineer.
    
    First establish:
    - what problem the refactor solves
    - measurable evidence
    - affected boundary
    - risk
    - expected benefit
    
    Do not change behaviour unless explicitly required.
    
    Plan:
    1. tests protecting current behaviour
    2. smallest viable structural change
    3. migration steps
    4. validation
    5. rollback/revert path
    
    Avoid broad cleanup unrelated to the objective.
    

    42. AI Review and Independent Verification

    The implementation agent should not be the only judge of its own work.

    42.1 Review categories

    text
    requirements
    architecture
    code quality
    security
    accessibility
    performance
    testing
    visual fidelity
    operability
    

    42.2 Independent review prompt

    text
    You are an independent reviewer.
    
    Review the change without assuming the implementation is correct.
    
    Read:
    - task packet
    - acceptance criteria
    - relevant architecture
    - relevant design references
    - diff
    - tests
    
    Check:
    - missing requirements
    - architecture violations
    - incorrect assumptions
    - security problems
    - accessibility problems
    - outdated APIs
    - unnecessary dependencies
    - unrelated edits
    - insufficient tests
    - UI drift
    - operational risk
    
    Classify findings:
    BLOCKER
    HIGH
    MEDIUM
    LOW
    
    A BLOCKER means the change should not merge.
    
    Do not rewrite the feature during review unless specifically requested.
    

    42.3 Review independence

    The reviewer can be:

    • a human
    • another AI session
    • a separate agent
    • a different model

    For high-risk changes, prefer a reviewer independent from the original implementation context.


    43. Metrics and Engineering Health

    Track simple metrics.

    Delivery

    text
    lead time
    PR size
    review time
    deployment frequency
    change failure rate
    

    Quality

    text
    defect escape rate
    reopened tasks
    flaky tests
    visual regression count
    accessibility defects
    security findings
    

    Collaboration

    text
    conflict frequency
    hotspot collisions
    blocked tasks
    dependency waiting time
    stack depth
    

    AI quality

    text
    number of out-of-scope edits
    number of invalid assumptions
    number of review corrections
    number of obsolete API uses
    number of visual-QA iterations
    

    Do not optimize a metric simply because it is easy to count. Use metrics to find process problems.


    44. Master Prompt Library

    This chapter is intended as the copy/paste command center.

    44.1 Project starter

    text
    Start a new product using the AI-Native Product Engineering workflow.
    
    Do not write product code yet.
    
    Step 1: determine whether product discovery is complete.
    Step 2: if not complete, start the Grill-Me process.
    Step 3: finalize the product specification.
    Step 4: create the terminology glossary.
    Step 5: perform the current technology audit.
    Step 6: create the architecture proposal.
    Step 7: create the documentation index.
    Step 8: create the initial AGENTS.md.
    Step 9: create the skill map.
    Step 10: identify required design documents.
    
    Stop after the planning gate.
    Do not silently choose unresolved product decisions.
    

    44.2 Context loading prompt

    text
    Before changing code, determine the minimum complete context set for
    this task.
    
    List:
    - required project documents
    - applicable rules
    - applicable skills
    - canonical examples
    - references
    - contracts
    - tests
    
    Read them before implementation.
    Report what you read.
    

    44.3 Current-API research prompt

    text
    Before using this technology/API:
    
    1. identify installed version
    2. consult current official docs
    3. consult current migration/deprecation docs
    4. identify supported API
    5. identify legacy API
    6. confirm compatibility
    
    Do not use model memory when an official source is available.
    

    44.4 Full-project planning prompt

    text
    Act as the Principal Product Engineer.
    
    Given the finalized product specification, design system, technology
    policy, and architecture:
    
    Produce the complete phased implementation plan.
    
    The plan must:
    - minimize critical-path length
    - minimize shared-file collisions
    - minimize dependency waiting
    - support parallel contributors
    - support unequal developer skill levels
    - establish contracts before consumers when possible
    - keep main releasable
    - include tests in every phase
    - include security/accessibility work where applicable
    - include CI/CD from the beginning
    - include production-readiness milestones
    
    For every phase provide:
    - objective
    - prerequisites
    - tasks
    - parallel tasks
    - dependency graph
    - shared hotspots
    - allowed paths
    - outputs
    - acceptance criteria
    - verification
    - exit gate
    

    44.5 Task creation prompt

    text
    Convert this requested outcome into an implementation-ready task packet.
    
    Include:
    - task ID
    - objective
    - context
    - dependencies
    - outputs
    - allowed paths
    - forbidden paths
    - contracts
    - dependency changes
    - database changes
    - UI changes
    - security impact
    - accessibility impact
    - test requirements
    - acceptance criteria
    - risk
    - integration notes
    
    Do not split the task merely by frontend/backend.
    Split it at stable responsibility and contract boundaries.
    

    44.6 Start-task prompt

    text
    Execute this task packet.
    
    Do not begin by editing.
    
    First verify:
    - dependencies are ready
    - contract is available
    - relevant docs are present
    - skill is applicable
    - allowed paths are clear
    - shared hotspots are understood
    
    Then plan, implement, test, review, and report evidence.
    

    44.7 Review-before-merge prompt

    text
    Review the change as an independent gatekeeper.
    
    Reject it if:
    - acceptance criteria are missing
    - required tests are missing
    - current APIs were not verified when necessary
    - security boundary is incorrect
    - accessibility requirements are ignored
    - visual reference is materially different
    - unrelated files changed
    - project conventions were broken without an ADR
    - CI evidence is incomplete
    

    44.8 Final project audit prompt

    text
    Perform a complete production-readiness audit.
    
    Review:
    Product
    Requirements
    Terminology
    Architecture
    Dependencies
    Agent rules
    Skills
    Design system
    UI references
    UX
    Accessibility
    Security
    Data
    API contracts
    Testing
    CI/CD
    Deployment
    Monitoring
    Rollback
    Documentation
    Collaboration workflow
    
    Identify:
    - blockers
    - high-risk gaps
    - outdated technology
    - contradictory documentation
    - untested critical paths
    - unverified UI
    - operational weaknesses
    
    Do not claim production readiness unless every blocker is resolved.
    

    45. Master Templates

    45.1 docs/INDEX.md

    markdown
    # Documentation Index
    
    ## Read for every task
    
    - AGENTS.md
    - this index
    
    ## Product
    
    - 00-project-context.md
    - 01-product-spec.md
    - 02-product-terminology.md
    
    ## Technology
    
    - 03-technology-policy.md
    
    ## Architecture
    
    - 04-architecture.md
    - adr/
    
    ## Design
    
    - 05-design-philosophy.md
    - 06-design-tokens.md
    - 07-ux-principles.md
    - 08-motion-principles.md
    - design/references/
    
    ## Security
    
    - 09-security-policy.md
    
    ## Data / API
    
    - 10-data-model.md
    - 11-api-contracts.md
    
    ## Quality
    
    - 12-testing-strategy.md
    
    ## Delivery
    
    - 13-deployment.md
    - 14-production-operations.md
    - 15-dependency-policy.md
    - 16-contribution-model.md
    

    45.2 Definition of Ready

    markdown
    # Definition of Ready
    
    A task is ready only when:
    
    - objective is explicit
    - acceptance criteria exist
    - dependencies are identified
    - contracts are available or intentionally part of the task
    - allowed paths are known
    - shared hotspots are known
    - required references are identified
    - security impact is known
    - accessibility impact is known
    - test strategy is known
    

    45.3 Definition of Done

    markdown
    # Definition of Done
    
    [ ] Product requirement satisfied
    [ ] Acceptance criteria satisfied
    [ ] Correct module/architecture used
    [ ] Current APIs verified where necessary
    [ ] No deprecated pattern introduced
    [ ] Naming conventions followed
    [ ] Existing canonical components reused
    [ ] Design tokens used
    [ ] Reference fidelity verified where applicable
    [ ] Responsive behaviour verified
    [ ] Accessibility checked
    [ ] Security checked
    [ ] Tests added/updated
    [ ] Type/build checks pass
    [ ] Lint/format checks pass
    [ ] Diff reviewed
    [ ] No unrelated changes
    [ ] Documentation updated
    [ ] CI green
    [ ] Release/operational impact assessed
    

    45.4 Contribution policy

    Create:

    text
    docs/16-contribution-model.md
    

    Include:

    text
    branch naming
    commit policy
    PR size guidance
    ownership rules
    hotspots
    worktree strategy
    stacked PR strategy
    dependency changes
    generated files
    migration rules
    review requirements
    release process
    

    46. Project Completion Checklist

    The project is not complete merely because all pages exist.

    Product

    Technology

    Agent system

    Design

    Engineering

    Collaboration

    Delivery


    47. Final Operating Rules

    These are the rules to remember when everything else becomes complicated.

    Rule 1

    Understand the product before designing the implementation.

    Rule 2

    Design the system before designing dozens of pages.

    Rule 3

    Generate HQ references from product context, not generic web-design prompts.

    Rule 4

    Treat approved references as visual truth for their intended screens.

    Rule 5

    Treat design tokens as exact values and references as visual composition truth.

    Rule 6

    Keep AGENTS.md concise; move deep detail into specialized documents and skills.

    Rule 7

    Do not depend on AI memory for current APIs, package versions, breaking changes, or security advisories.

    Rule 8

    Use the latest stable production-recommended technology, not blindly the newest prerelease.

    Rule 9

    Do not ask AI to enforce what a tool can enforce.

    Rule 10

    No implementation is complete without verification.

    Rule 11

    Do not organize collaboration only by frontend/backend.

    Rule 12

    Coordinate around contracts, ownership, shared hotspots, and dependencies.

    Rule 13

    Use independent worktrees for independent work.

    Rule 14

    Keep main releasable.

    Rule 15

    Make shared-file changes deliberate.

    Rule 16

    Prepare dependencies before parallel feature work when possible.

    Rule 17

    Have an independent reviewer for important changes.

    Rule 18

    Security and accessibility are built into design and implementation, not appended at the end.

    Rule 19

    Production operations are part of the product lifecycle.

    Rule 20

    The repository itself should teach the next human or AI how to work in it.


    48. Appendix: Current-Technology Research Sources

    The methodology is intentionally version-agnostic. At project start, run the Technology Freshness Audit against current official sources.

    Agent instructions and skills

    • AGENTS.md: https://agents.md/
    • OpenAI skill-creator guidance: https://github.com/openai/skills/blob/main/skills/.system/skill-creator/SKILL.md

    Git collaboration

    • Git worktrees: https://git-scm.com/docs/git-worktree
    • GitHub stacked pull requests: https://docs.github.com/en/pull-requests/reference/stacked-pull-requests
    • GitHub merge queues: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue
    • GitHub branch protection: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches

    Accessibility

    • WCAG: https://www.w3.org/TR/WCAG/

    Security

    • OWASP Top 10:2025: https://top10.owasp.org/2025/

    Technology research examples

    When using a specific framework, runtime, database, testing tool, or CLI:

    1. Search the official project site.
    2. Read the release/support page.
    3. Read installation/CLI documentation.
    4. Read migration/breaking changes.
    5. Read security advisories.
    6. Record the selected baseline.

    Do not treat this appendix as a substitute for a current audit.


    One-Page Beginner Execution Map

    When starting a completely new project, execute this list in order.

    text
    01  Create a private project workspace/repository.
    02  Install Git and the approved developer tooling.
    03  Run the Environment Setup AI prompt.
    04  Start the Grill-Me prompt.
    05  Continue until requirements are internally consistent.
    06  Run the Product Specification Finalizer.
    07  Review and approve product docs.
    08  Run the Technology Freshness Audit.
    09  Approve the stable production-safe stack.
    10  Run the Repository Bootstrap prompt.
    11  Create docs/INDEX.md.
    12  Create AGENTS.md.
    13  Create skills and scoped rules.
    14  Create architecture + ADR structure.
    15  Create contribution/worktree policy.
    16  Create design philosophy.
    17  Create design tokens.
    18  Build the token page.
    19  Build the component laboratory.
    20  Generate 3–5 visual directions.
    21  Select one direction.
    22  Generate 8–10 high-fidelity reference images.
    23  Review and revise references.
    24  Approve Tier-1 references.
    25  Build marketing/application shells.
    26  Establish API/data contracts.
    27  Prepare shared dependencies.
    28  Create task packets from the dependency graph.
    29  Assign independent workspaces.
    30  Implement in small, reviewable changes.
    31  Test continuously.
    32  Run visual QA for reference-backed screens.
    33  Run security and accessibility audits.
    34  Keep CI green.
    35  Integrate through PRs/merge queue/stacks as appropriate.
    36  Deploy to staging.
    37  Run release verification.
    38  Deploy production.
    39  Monitor.
    40  Use the production incident workflow for failures.
    41  Maintain dependencies.
    42  Re-run the technology audit periodically.
    

    Closing Principle

    The goal is not to make the AI "smart enough" to build everything without supervision.

    The goal is to make the engineering environment clear enough, structured enough, and verifiable enough that a capable human or AI can work inside it safely.

    The mature system looks like this:

    text
                        HUMAN INTENT
                              ↓
                       PRODUCT CONTEXT
                              ↓
                      PRODUCT SPECIFICATION
                              ↓
                         TERMINOLOGY
                              ↓
                      CURRENT TECHNOLOGY
                              ↓
                         ARCHITECTURE
                              ↓
                        AGENT CONSTITUTION
                              ↓
                        RULES + SKILLS
                              ↓
                      DESIGN PHILOSOPHY
                              ↓
                        DESIGN TOKENS
                              ↓
                     HQ UI REFERENCES
                              ↓
                     COMPONENT SYSTEM
                              ↓
                       CONTRACTS
                              ↓
                  DEPENDENCY-READY PLAN
                              ↓
                     INDEPENDENT TASKS
                              ↓
                       IMPLEMENTATION
                              ↓
              ┌───────────────┼────────────────┐
              ↓               ↓                ↓
           TESTING         SECURITY         A11Y
              └───────────────┼────────────────┘
                              ↓
                        VISUAL QA
                              ↓
                             CI
                              ↓
                         STAGING
                              ↓
                        PRODUCTION
                              ↓
                    MONITOR / DEBUG / FIX
                              ↓
                         LEARN / UPGRADE
                              ↺
    

    A good AI-native repository should make the next action obvious to a beginner, the intended boundaries obvious to a senior developer, and the verification requirements obvious to every AI agent.

    That is the objective of this handbook.


    49. The AI-IDE Adapter Layer

    The methodology is universal, but AI coding products expose instructions and skills through different mechanisms.

    Do not guess the current mechanism from memory.

    At the beginning of a project, ask the AI to inspect the current official documentation for the IDE/agent being used and generate a project adapter.

    49.1 Universal agent contract

    Every supported agent should receive the same conceptual information:

    text
    ROLE
    MISSION
    SOURCE OF TRUTH
    NON-NEGOTIABLES
    DOCUMENT INDEX
    SKILL INDEX
    WORKFLOW
    COMMANDS
    VERIFICATION
    STOP CONDITIONS
    DONE CRITERIA
    

    49.2 Agent adapter prompt

    text
    You are the AI-Development-Environment Adapter Engineer.
    
    The project uses the following agent/IDE:
    [AGENT_OR_IDE]
    
    Do not rely on memory for current configuration conventions.
    Consult the agent/IDE's current official documentation.
    
    Determine:
    1. repository instruction file format
    2. scoped rule mechanism
    3. skill mechanism
    4. skill discovery/invocation behaviour
    5. project-level versus user-level instructions
    6. image/reference support
    7. browser/computer-use support
    8. shell/tool permissions
    9. context/retrieval behavior relevant to project instructions
    10. recommended repository structure for agent instructions
    
    Then create the smallest adapter necessary to expose this project's
    AI-Native Product Engineering system to the chosen agent.
    
    Requirements:
    - keep AGENTS.md as the conceptual cross-agent constitution
    - do not duplicate long documentation unnecessarily
    - point to canonical project documents
    - expose relevant skills using the IDE's supported mechanism
    - preserve the same source-of-truth hierarchy
    - preserve the same Definition of Done
    - preserve the same security boundaries
    
    Do not change application code.
    Output:
    - adapter files
    - their purpose
    - how the agent loads them
    - how to invoke each major skill
    - how to verify the adapter is working
    

    49.3 Adapter verification prompt

    text
    Verify that the current AI IDE is actually loading the project's agent
    instructions and exposing the intended skills.
    
    Perform a non-destructive verification.
    
    Determine:
    - which project instructions were loaded
    - which relevant skill metadata was available
    - which references were read
    - which commands are available
    - whether the definition of done is visible
    
    Do not modify production code.
    Report any missing context or unsupported capability.
    

    50. The Project Context Pack

    Every serious task should have a small context pack.

    This is the answer to the problem:

    "The project has excellent documentation, but the AI did not read all of it."

    50.1 Context pack structure

    text
    context/
    ├── task.md
    ├── required-docs.md
    ├── references.md
    ├── contracts.md
    ├── canonical-files.md
    └── constraints.md
    

    50.2 required-docs.md

    markdown
    # Required Context
    
    ## Always
    - AGENTS.md
    - docs/INDEX.md
    
    ## This Task
    - [path]
    - [path]
    
    ## Applicable Skills
    - [skill]
    
    ## Canonical Examples
    - [file]
    
    ## References
    - [image]
    

    50.3 Context-loading prompt

    text
    Build the minimum complete context set for this task.
    
    Do not read the entire repository blindly.
    Do not rely on memory.
    
    Identify:
    - governing documents
    - task-specific documents
    - relevant architecture
    - relevant design references
    - relevant contracts
    - canonical files
    - applicable skills
    - required scripts/checks
    
    Then read them before implementation.
    
    At the beginning of the implementation response, report:
    "Context loaded: ..."
    
    Do not begin code changes until all required context has been loaded.
    

    50.4 Why this works

    It balances two risks:

    text
    Too little context → wrong implementation
    Too much context  → noise/context pressure
    

    The goal is not "more context".

    The goal is complete relevant context.


    51. The Project State Ledger

    AI agents can lose track of what has already been decided across sessions.

    Create:

    text
    docs/PROJECT_STATE.md
    

    Keep it short.

    markdown
    # Project State
    
    ## Current Phase
    P07 — Event Registration
    
    ## Last Completed Gate
    G6 — Contract Gate
    
    ## Active Work
    - EVT-031
    - EVT-032
    
    ## Blocked Work
    - EVT-033 — waiting for external provider contract
    
    ## Current Technology Baseline
    See docs/03-technology-policy.md
    
    ## Current Design Baseline
    See docs/05-design-philosophy.md
    
    ## Active Risks
    - ...
    
    ## Important Recent Decisions
    - ADR-0012
    - ADR-0013
    

    The state ledger should not duplicate the specification. It should answer only:

    Where are we now?


    52. The Planning Board for AI Agents

    A project plan should exist in a machine-readable form.

    Example:

    yaml
    project_phase: P07
    objective: deliver event registration
    status: active
    critical_path:
      - EVT-001
      - EVT-004
      - EVT-009
    parallel_groups:
      group_a:
        - EVT-002
        - EVT-003
      group_b:
        - EVT-005
        - EVT-006
    hotspots:
      - database/schema
      - shared/contracts
    blocked:
      - EVT-010
    

    This can live beside a human-readable roadmap.

    The machine-readable version makes it easier for AI agents to identify:

    • what can be worked on now
    • what is blocked
    • what should not be modified
    • what depends on another task

    53. The Change Graph

    Before assigning many tasks, build a dependency graph.

    Example:

    text
                        PRODUCT DECISION
                               │
                               ▼
                        API CONTRACT
                          /         \
                         /           \
                        ▼             ▼
                    DOMAIN A       DOMAIN B
                        │             │
                        ▼             ▼
                      API A         API B
                        │             │
                     ┌──┴──┐       ┌──┴──┐
                     ▼     ▼       ▼     ▼
                    UI A  E2E A   UI B  E2E B
    

    Tasks at the same level can often be parallelized.

    Tasks crossing a contract boundary need a defined dependency.

    53.1 Dependency graph prompt

    text
    Build the complete change dependency graph for the project.
    
    For each planned change determine:
    - prerequisites
    - produced artifacts/contracts
    - consumers
    - shared-file hotspots
    - whether it can run in parallel
    - whether it should be stacked on another change
    - whether a mock/stub/contract is sufficient to unblock consumers
    
    Optimize for:
    - minimal critical path
    - minimal shared-file collisions
    - minimal waiting
    - small reviewable changes
    - stable main branch
    
    Do not create parallelism where it would create hidden coupling.
    

    54. Dependency Readiness Windows

    A major source of team slowdown is discovering a required dependency after development has already started.

    Use dependency readiness windows.

    54.1 Before a major phase

    Create a checklist:

    text
    runtime
    package manager
    framework
    UI primitives
    validation
    persistence
    testing
    browser
    CI tools
    security tools
    observability
    

    For each:

    text
    selected
    version
    support status
    reason
    migration impact
    

    54.2 Shared dependency policy

    Only a designated dependency change may modify the shared dependency baseline during a planning window unless the change is urgent and explicitly coordinated.

    This dramatically reduces lockfile collisions.

    54.3 Dependency freeze window

    For high-concurrency integration phases, consider:

    text
    T-2 days: dependency preparation
    T-1 day: baseline verified
    T0: feature work starts
    T+N: dependency changes reopened through dedicated PRs
    

    The exact duration depends on the product.


    55. Hotspot Ownership Protocol

    Some files naturally create conflicts.

    Create:

    text
    docs/HOTSPOTS.md
    

    Example:

    Path Reason Default owner Change protocol
    root manifest dependency collision integrator dedicated dependency PR
    lockfile generated shared state integrator never hand-merge casually
    DB schema migration collision data owner integration window
    CI workflows deployment risk release owner review required
    global tokens UI collision design-system owner design-system PR
    AGENTS.md agent behavior project maintainer reviewed change

    This does not mean one person permanently owns everything.

    It means there is a known coordination protocol.


    56. Merge-Conflict Prevention Protocol

    Before starting a task, the agent checks:

    text
    1. What files will I modify?
    2. Which are hotspots?
    3. Who else is changing them?
    4. Can I avoid them?
    5. Can I move the shared change into a smaller prerequisite PR?
    6. Can I consume an existing contract instead?
    

    56.1 Exact prompt

    text
    Before implementation, perform a collision-risk analysis.
    
    Identify:
    - files I am likely to modify
    - shared/hotspot files
    - concurrent tasks affecting those files
    - potential dependency conflicts
    - potential migration conflicts
    
    For each risk propose:
    - avoid
    - coordinate
    - split
    - stack
    - schedule
    
    Do not proceed with a high-collision change until the integration
    strategy is explicit.
    

    57. The Integration Packet

    When a change is ready, provide the integrator with:

    yaml
    change_id: EVT-031
    branch: feat/evt-031
    base: main
    summary: ...
    files_changed:
      - ...
    contracts_changed:
      - ...
    dependencies_changed: false
    database_migration: false
    ci_status: green
    test_status: green
    visual_qa: not_applicable
    security_review: passed
    accessibility_review: passed
    known_risks:
      - ...
    follow_up:
      - ...
    

    This reduces integration guesswork.


    58. The Handoff Prompt

    text
    Prepare this completed task for another engineer/agent to integrate.
    
    Provide:
    1. what changed
    2. why it changed
    3. files changed
    4. contracts changed
    5. dependencies changed
    6. database changes
    7. test evidence
    8. security evidence
    9. accessibility evidence
    10. visual evidence
    11. known risks
    12. follow-up work
    13. any rebase/integration considerations
    
    Do not include unrelated implementation commentary.
    

    59. Recovering From an AI Agent That Violates Rules

    Never respond by simply saying:

    "Follow AGENTS.md better."

    Instead perform a violation analysis.

    59.1 Violation categories

    text
    context failure
    instruction failure
    skill-routing failure
    implementation failure
    verification failure
    tooling failure
    repository-design failure
    

    59.2 Diagnostic prompt

    text
    Analyze why the previous implementation violated the project rules.
    
    Do not fix the code yet.
    
    Determine whether the failure originated from:
    1. missing context
    2. ambiguous instruction
    3. unavailable skill
    4. incorrect skill selection
    5. outdated documentation
    6. conflicting existing code
    7. missing automated enforcement
    8. insufficient verification
    9. unclear ownership
    10. incorrect task scope
    
    For each root cause propose a SYSTEM-LEVEL prevention.
    
    Prefer improving the workflow over merely correcting the one instance.
    

    This turns an AI failure into a process improvement instead of repeatedly fixing the same symptom.


    60. The Rule-to-Enforcement Matrix

    Every important rule should be classified.

    Rule AI guidance Deterministic check Human review
    naming yes often sometimes
    formatting no/brief yes no
    type safety brief yes sometimes
    auth yes partial yes
    authorization yes partial yes
    WCAG yes partial yes
    visual fidelity yes partial yes
    API contract yes yes yes
    dependency policy yes partial yes
    branch policy no/brief yes no
    business rules yes tests yes

    The point is to identify what remains dependent on human/AI judgment.


    61. The Anti-Hallucination Protocol for Code

    Before implementation:

    text
    Evidence
     ↓
    Decision
     ↓
    Implementation
    

    Avoid:

    text
    Assumption
     ↓
    Code
     ↓
    Discover later
    

    61.1 Prompt

    text
    For every non-trivial implementation decision, distinguish:
    
    FACT — verified from repository or authoritative source
    ASSUMPTION — not verified
    DECISION — selected project choice
    UNKNOWN — requires clarification/research
    
    Do not present assumptions as facts.
    
    When an unknown could materially affect correctness, security,
    architecture, or data, stop and research or request resolution.
    

    62. The Beginner's First 24 Hours

    A new beginner should follow this schedule conceptually, without rushing.

    Hour 1–2: product

    text
    Grill-Me
    

    Hour 2–4: specification

    text
    Product Context
    Product Spec
    Terminology
    

    Hour 4–5: technology

    text
    Technology Audit
    

    Hour 5–6: architecture

    text
    Architecture
    ADR
    

    Hour 6–7: repository

    text
    Bootstrap
    Git
    CI baseline
    

    Hour 7–8: agent system

    text
    AGENTS.md
    rules
    skills
    context index
    

    Remaining setup time

    text
    Design philosophy
    Tokens
    UI lab
    reference generation plan
    

    Do not rush into business features merely because the repository now runs.


    63. The First Working Vertical Slice

    After the foundation, choose one meaningful end-to-end path.

    It should demonstrate:

    text
    UI
     ↓
    validation
     ↓
    API
     ↓
    business logic
     ↓
    data
     ↓
    response
     ↓
    UI state
     ↓
    tests
    

    This proves the architecture before the team builds dozens of dependent features.

    Exact prompt

    text
    Select the smallest meaningful end-to-end vertical slice that tests
    our architecture.
    
    It must exercise:
    - UI
    - validation
    - API
    - domain/business logic
    - persistence
    - error handling
    - accessibility
    - tests
    
    It should expose architectural problems early.
    
    Do not choose a trivial hello-world flow.
    Do not choose the largest feature.
    

    64. The Golden Path Example

    The project should maintain at least one canonical implementation for:

    text
    one read flow
    one write flow
    one authenticated flow
    one authorized flow
    one form
    one data-heavy screen
    one tested API module
    one database migration
    

    These become references for future agents.

    Instead of writing another 200 lines of instructions, tell the agent:

    text
    Follow the architecture of:
    [path]
    

    Canonical examples are especially powerful because they show how the project's rules actually interact.


    65. The Design-to-Code Evidence Package

    For every strict reference-backed screen, keep:

    text
    design/references/REF-XX.png
    design/references/REF-XX.yml
    

    and implementation evidence:

    text
    artifacts/visual/REF-XX/latest.png
    artifacts/visual/REF-XX/report.md
    

    The report should say:

    text
    reference
    viewport
    implementation route
    comparison date
    critical differences
    remaining differences
    status
    

    This allows visual QA to be repeated after later refactors.


    66. UI Reference Generation: Product-Complexity Matrix

    Use the following starting point.

    Product size Core references Strict targets
    small landing/product 4–6 3–4
    medium product 7–10 5–7
    large SaaS/platform 10–15 7–10
    highly visual product 12–20 8–12

    These are starting heuristics, not laws.

    Generate more references when:

    • navigation differs between areas
    • information density varies substantially
    • there are unique workflows
    • responsive transformations are complex
    • there are very different visual contexts

    Generate fewer references when:

    • pages are composed mostly from identical patterns
    • the component system is mature
    • the visual language is intentionally simple

    67. UI Mockup Prompt: Exact Page Specification Mode

    Use this when the page structure is already decided.

    text
    Generate a high-fidelity visual reference for exactly this page.
    
    DO NOT invent the page structure.
    DO NOT add sections.
    DO NOT remove sections.
    
    PRODUCT:
    [product]
    
    USER:
    [user]
    
    JOB TO BE DONE:
    [job]
    
    PAGE:
    [page]
    
    EXACT PAGE STRUCTURE:
    1. [section]
    2. [section]
    3. [section]
    4. [section]
    
    PRIMARY ACTION:
    [action]
    
    SECONDARY ACTIONS:
    [actions]
    
    CONTENT PRIORITY:
    1. [highest]
    2. [next]
    3. [supporting]
    
    DESIGN SYSTEM:
    [approved tokens and component language]
    
    REFERENCE STYLE:
    [approved visual direction]
    
    VIEWPORT:
    [viewport]
    
    Produce a realistic production interface with believable domain
    content. Preserve hierarchy, spacing rhythm, proportions, and visual
    relationships.
    
    Do not introduce generic AI aesthetics, unapproved gradients,
    unapproved colors, meaningless decorative elements, or unrelated UI.
    

    68. UI Mockup Prompt: Exact Reference Refinement

    Use after generating a first draft.

    text
    Refine this existing UI reference rather than generating a different
    visual concept.
    
    Preserve the approved:
    - layout
    - visual language
    - typography relationship
    - color system
    - component geometry
    - content hierarchy
    
    Correct only:
    [list exact problems]
    
    Do not introduce:
    - new decorative elements
    - new color families
    - random gradients
    - AI visual motifs
    - new layout sections
    
    The goal is controlled refinement, not reinterpretation.
    

    69. UI Mockup Prompt: Comparative Design Direction

    Use when deciding between two candidate directions.

    text
    Compare these two proposed visual directions for the same product.
    
    Do not choose based on generic "modernity" or visual impressiveness.
    
    Evaluate:
    - product-context fit
    - user trust
    - cognitive load
    - information hierarchy
    - information density
    - brand distinctiveness
    - accessibility
    - long-term maintainability
    - responsiveness
    - implementation complexity
    
    Recommend one and explain why.
    

    70. UI Mockup Prompt: Product Feel Audit

    text
    Review this UI without discussing code.
    
    Answer:
    
    1. What kind of product does this look like?
    2. Who appears to use it?
    3. What is the user's primary goal?
    4. What feels trustworthy?
    5. What feels generic?
    6. What feels decorative rather than useful?
    7. What looks AI-generated?
    8. What does not match the intended product context?
    9. Where is visual hierarchy weak?
    10. What would make this feel like a real product rather than a mockup?
    
    Do not redesign yet.
    

    71. UI Mockup Prompt: Anti-AI-Aesthetic Audit

    text
    Perform an adversarial visual audit specifically for unwanted
    AI-generated design patterns.
    
    Flag:
    - generic AI startup aesthetics
    - purple/indigo default palettes
    - sparkle/magic-wand motifs
    - artificial glows
    - arbitrary gradients
    - futuristic decoration
    - glassmorphism without product purpose
    - floating blobs
    - generic SaaS card grids
    - meaningless charts
    - excessive pills
    - excessive rounded containers
    - decorative 3D objects
    - gradient text
    - visual noise
    
    For every finding explain why it is inappropriate for the product
    context.
    
    Do not introduce replacement decoration unless the product context
    requires it.
    

    72. Browser Visual-Verification Procedure

    For each Tier-1 reference:

    text
    1. Build
    2. Start application
    3. Navigate to route
    4. Set viewport
    5. Wait for stable render
    6. Capture screenshot
    7. Compare against reference
    8. Record differences
    9. Fix
    10. Repeat
    

    72.1 Visual comparison categories

    Geometry

    text
    container width
    margins
    padding
    alignment
    proportions
    

    Typography

    text
    font
    weight
    size
    line height
    letter spacing
    wrap
    

    Color

    text
    background
    surface
    text
    accent
    border
    state colors
    

    Component language

    text
    radius
    border
    shadow
    icons
    button shapes
    input geometry
    

    Hierarchy

    text
    primary
    secondary
    metadata
    CTA
    

    Responsive

    text
    stacking
    navigation
    overflow
    touch targets
    visibility
    

    73. The Four-Layer UI Verification Model

    A good-looking screenshot is not enough.

    Verify:

    text
    Layer 1 — visual
    Layer 2 — interaction
    Layer 3 — accessibility
    Layer 4 — implementation quality
    

    Visual

    Does it match?

    Interaction

    Does it behave correctly?

    Accessibility

    Can the intended users operate it?

    Implementation

    Is the code maintainable and consistent with the architecture?


    74. The Complete Feature Protocol

    Every product feature follows:

    text
    1. Understand
    2. Specify
    3. Contract
    4. Design
    5. Prepare dependencies
    6. Implement
    7. Unit test
    8. Integration test
    9. E2E test
    10. Accessibility
    11. Security
    12. Visual QA if applicable
    13. Independent review
    14. CI
    15. Integration
    16. Staging
    17. Production
    18. Observe
    

    Not every trivial change requires every expensive step, but the task must explicitly classify which gates apply.


    75. Risk-Based Verification

    Do not treat all changes equally.

    Low risk

    Examples:

    text
    typo
    copy change
    documentation
    

    May need:

    text
    lint/build
    

    Medium risk

    Examples:

    text
    UI component
    business logic
    API response
    

    Needs:

    text
    tests
    review
    possibly visual/a11y
    

    High risk

    Examples:

    text
    auth
    authorization
    payments
    migrations
    secrets
    security configuration
    production infrastructure
    

    Needs:

    text
    deep review
    security checks
    regression tests
    staging verification
    rollback plan
    

    76. Exact Prompt: Risk Classification

    text
    Classify this change by risk.
    
    Consider:
    - user impact
    - data impact
    - security impact
    - financial impact
    - operational impact
    - reversibility
    - shared-file collision risk
    - migration risk
    - dependency risk
    
    Return:
    - risk level
    - reasons
    - required verification gates
    - required reviewer type
    - rollback strategy
    

    77. CI Failure Debugging

    When CI fails, do not ask:

    "Can you make CI green?"

    Ask:

    text
    Why did CI fail?
    

    Exact prompt

    text
    Act as the CI failure investigator.
    
    Inspect the failure.
    
    Determine:
    1. first failing check
    2. root cause
    3. whether failure is deterministic or flaky
    4. whether code, environment, dependency, or CI configuration caused it
    5. whether the change should actually be modified
    
    Do not weaken or disable the failing check merely to make CI green.
    
    Fix the root cause and preserve the intent of the check.
    

    78. Flaky-Test Protocol

    A flaky test is not a successful test.

    Workflow:

    text
    Detect
     ↓
    Reproduce repeatedly
     ↓
    Classify source
     ↓
    Fix determinism
     ↓
    Run repeated verification
     ↓
    Document if infrastructure-related
    

    Never normalize flaky tests by retrying forever.

    Retries can be a temporary containment mechanism, not the final solution.


    79. Production Observability Baseline

    A production product needs to answer:

    text
    Is it healthy?
    Who is affected?
    What failed?
    When did it start?
    What changed?
    Can we reproduce it?
    Can we roll back?
    

    At minimum consider:

    text
    application errors
    request latency
    availability
    background job failures
    database health
    resource saturation
    critical business events
    security alerts
    

    Exact tooling is selected during the technology audit.


    80. Production Health Checks

    A deployed service should expose appropriate health/readiness signals where the hosting model supports them.

    Health should distinguish:

    text
    process is running
    

    from:

    text
    service is actually ready to serve traffic
    

    Do not report healthy merely because the process exists.


    81. Release Rollback Protocol

    Every release should answer:

    text
    How do we undo application code?
    How do we undo configuration?
    How do we handle database changes?
    How do we disable the feature?
    How do we verify rollback?
    

    Rollback types

    text
    application rollback
    feature-flag disablement
    configuration rollback
    migration remediation
    traffic rollback
    

    A database change may not be safely reversible just because code deployment is reversible.


    82. Feature Flags

    For risky or operationally expensive changes, consider feature flags.

    Use them for:

    text
    gradual rollout
    internal testing
    kill switches
    A/B tests where justified
    migration transitions
    

    Do not allow feature flags to become permanent hidden architecture.

    Every flag should have:

    text
    owner
    purpose
    created date
    expiry/review date
    removal task
    

    83. Safe Production Configuration

    Do not store secrets in:

    text
    Git
    AGENTS.md
    README screenshots
    logs
    tickets
    chat transcripts
    

    Document only:

    text
    variable name
    purpose
    required/optional
    where configured
    rotation procedure
    

    Never document secret values.


    84. Security Incident Prompt

    text
    Treat this as a potential security incident.
    
    Do not immediately patch and close it.
    
    First determine:
    - affected asset
    - affected users
    - attack surface
    - possible exposure
    - whether exploitation is ongoing
    - containment options
    - credentials/tokens that may require rotation
    - data that may be affected
    
    Then:
    1. contain
    2. preserve useful evidence
    3. patch
    4. invalidate compromised credentials where appropriate
    5. test
    6. deploy
    7. verify
    8. document
    
    Do not expose sensitive incident details in public logs or commits.
    

    85. Data-Migration Runbook

    For any significant production data migration:

    text
    1. define source data
    2. define target state
    3. estimate volume
    4. estimate duration
    5. identify locking/downtime risk
    6. design backward compatibility
    7. test against production-like data
    8. define observability
    9. define rollback/remediation
    10. run staging rehearsal
    11. execute
    12. verify counts/invariants
    13. monitor application behavior
    14. complete contract phase
    

    AI migration prompt

    text
    Act as the database migration engineer.
    
    Before writing a migration:
    - inspect current schema
    - inspect application consumers
    - inspect existing migrations
    - identify backward compatibility requirements
    - estimate destructive risk
    - identify data transformation needs
    - define verification queries/checks
    - define rollback or remediation strategy
    
    Prefer expand/migrate/contract for changes that require compatibility.
    
    Do not generate a destructive production migration solely from the
    requested end state.
    

    86. Production Bug Knowledge Base

    Every meaningful incident should generate a short knowledge record:

    text
    docs/incidents/
    ├── INC-2026-001.md
    ├── INC-2026-002.md
    └── ...
    

    Template:

    markdown
    # INC-XXXX
    
    ## Summary
    
    ## Severity
    
    ## Impact
    
    ## Detection
    
    ## Timeline
    
    ## Root Cause
    
    ## Contributing Factors
    
    ## Immediate Fix
    
    ## Permanent Fix
    
    ## Regression Test
    
    ## Monitoring Improvement
    
    ## Documentation Improvement
    
    ## Prevention
    

    This becomes future agent context.


    87. AI Agent Handoff Between Sessions

    An AI session should never require the next session to reconstruct everything from chat history.

    Before ending a substantial task, create:

    text
    docs/handoffs/HANDOFF-XXXX.md
    

    Template:

    markdown
    # Handoff
    
    ## Task
    
    ## Current State
    
    ## Completed
    
    ## Not Completed
    
    ## Decisions
    
    ## Files Changed
    
    ## Remaining Issues
    
    ## Tests
    
    ## Known Risks
    
    ## Next Exact Step
    

    Exact handoff prompt

    text
    Prepare a concise machine-readable handoff for the next engineer or AI agent.
    
    Include:
    - current phase
    - task state
    - files changed
    - decisions
    - tests run
    - failures remaining
    - blockers
    - known risks
    - next exact step
    
    Do not assume the next agent has access to this conversation.
    

    88. The "Never Guess" Escalation Rules

    The agent should continue autonomously when the choice is low-risk and local.

    It should stop or escalate when the decision can materially affect:

    text
    business behaviour
    security
    data loss
    production availability
    architecture
    public API compatibility
    user privacy
    billing
    legal/compliance requirements
    

    This is better than "always ask for confirmation" because excessive confirmation destroys productivity.

    88.1 Exact escalation prompt

    text
    Use autonomous judgment for reversible, low-risk implementation details.
    Escalate before making an irreversible or materially product-affecting
    choice when the requirement is ambiguous.
    
    Always escalate uncertainty involving:
    - security boundaries
    - destructive data changes
    - incompatible public API changes
    - production infrastructure
    - secrets/credentials
    - unresolved business rules
    - significant design-direction changes
    

    89. The Complete Project Orchestration Prompt

    This is the closest thing in the book to a "start the entire methodology" command.

    text
    You are the Principal AI Product Engineering Orchestrator.
    
    You are responsible for guiding this project through the complete SDLC.
    
    IMPORTANT:
    Do not jump directly into feature implementation.
    Do not rely on model memory for current technology facts.
    Do not declare work complete without verification.
    Do not invent unresolved product decisions.
    Do not override approved design references.
    Do not introduce generic AI aesthetics.
    Do not modify unrelated files.
    
    OPERATING MODEL
    
    Product truth:
    - product context
    - product specification
    - terminology
    
    Technology truth:
    - technology policy
    - official current documentation
    
    Architecture truth:
    - architecture
    - ADRs
    - canonical examples
    
    Design truth:
    - design philosophy
    - design tokens
    - approved references
    
    Quality truth:
    - testing strategy
    - security policy
    - accessibility requirements
    - CI gates
    
    OPERATING SEQUENCE
    
    0. Confirm current project state.
    1. Determine whether product discovery is complete.
    2. If not complete, invoke the Grill-Me process.
    3. Finalize product documentation.
    4. Audit terminology and contradictions.
    5. Research the current production-safe technology baseline.
    6. Finalize architecture and ADRs.
    7. Bootstrap the repository using current official CLIs.
    8. Create the agent constitution and skill system.
    9. Create the design philosophy and token system.
    10. Generate and approve HQ reference directions.
    11. Build the component laboratory.
    12. Build application/marketing shells.
    13. Establish contracts and dependency baseline.
    14. Build the complete dependency-aware work graph.
    15. Generate implementation-ready task packets.
    16. Execute tasks in independent workspaces.
    17. Verify continuously.
    18. Integrate through small reviewable changes.
    19. Run CI gates.
    20. Deploy to staging.
    21. Run release checks.
    22. Deploy production.
    23. Verify production.
    24. Monitor and maintain.
    25. Run dependency/technology refreshes periodically.
    
    AT EVERY PHASE
    
    - identify source of truth
    - identify dependencies
    - identify shared hotspots
    - identify risk
    - define acceptance criteria
    - define verification
    - record important decisions
    
    If the project is not ready for the next phase, explain exactly what
    is missing and continue from the current gate rather than skipping ahead.
    

    90. The New-Project Checklist to Give to Any AI

    Paste this at the beginning of a new AI conversation if the repository already contains the handbook.

    text
    This repository follows the AI-Native Product Engineering handbook.
    
    Your first task is NOT to code.
    
    Read:
    - AGENTS.md
    - docs/INDEX.md
    - docs/PROJECT_STATE.md if present
    
    Then determine the current SDLC gate.
    
    Report:
    1. current phase
    2. completed gates
    3. active blockers
    4. relevant documents
    5. applicable skills
    6. next exact action
    
    Do not skip gates.
    Do not invent missing requirements.
    

    91. Recommended Repository Automation

    The methodology becomes much stronger when the repository has simple helper commands.

    Suggested conceptual command set:

    text
    project doctor
    project verify
    project test
    project lint
    project typecheck
    project build
    project context
    project status
    project task validate
    project visual-check
    project security-check
    project a11y-check
    project dependency-audit
    

    Exact implementation depends on the technology stack.

    The important principle is one obvious command per recurring verification activity.


    92. Repository `README.md` for Beginners

    The README should not become a giant architecture essay.

    It should answer:

    text
    What is this?
    How do I set it up?
    How do I run it?
    How do I verify it?
    Where are the docs?
    How do I start a task?
    How do I contribute?
    

    Suggested sections:

    markdown
    # Project
    
    ## What This Is
    
    ## Quick Start
    
    ## Environment
    
    ## Development
    
    ## Verification
    
    ## Documentation
    
    ## Contribution
    
    ## Support / Troubleshooting
    

    93. Contribution Workflow for a Beginner

    A beginner should not need to understand the entire architecture before making a small change.

    Their workflow:

    text
    1. Read README
    2. Read AGENTS.md
    3. Read docs/INDEX.md
    4. Pick an assigned task
    5. Read task packet
    6. Create worktree/branch
    7. Run project doctor
    8. Implement scoped change
    9. Run focused checks
    10. Run full required checks
    11. Open PR
    12. Fix review feedback
    13. Merge
    14. Delete worktree
    

    This makes onboarding repeatable.


    94. AI Code Review Checklist

    Before merge, reviewers should consider:

    text
    Correct?
    Complete?
    Current?
    Consistent?
    Secure?
    Accessible?
    Tested?
    Observable?
    Reversible?
    Within scope?
    

    These ten questions catch a surprising amount of drift.


    95. The Architecture Drift Audit

    Run periodically.

    text
    Are modules still respected?
    Are shared folders becoming junk drawers?
    Are controllers doing business logic?
    Are repositories making business decisions?
    Are UI components bypassing the design system?
    Are packages crossing boundaries incorrectly?
    Are deprecated APIs appearing?
    Are duplicate patterns emerging?
    Are task changes becoming too large?
    

    Exact prompt

    text
    Perform an architecture-drift audit.
    
    Compare the current implementation against the approved architecture
    and canonical examples.
    
    Identify:
    - boundary violations
    - duplicate patterns
    - new competing abstractions
    - misplaced files
    - dependency-direction violations
    - deprecated patterns
    - growing shared/junk folders
    - UI system bypasses
    
    Do not refactor automatically.
    Produce a prioritized remediation plan.
    

    96. The Design-System Drift Audit

    Periodically compare actual UI against:

    text
    tokens
    components
    reference screens
    UX principles
    motion principles
    

    Look for:

    text
    arbitrary colors
    one-off spacing
    one-off radii
    random shadows
    inconsistent buttons
    inconsistent typography
    inconsistent navigation
    inconsistent motion
    

    97. The Technology Drift Audit

    Run periodically or before major releases.

    text
    runtime status
    framework status
    dependency updates
    support/LTS changes
    deprecations
    security advisories
    breaking changes
    build tooling
    CI actions
    browser support
    

    Prompt

    text
    Perform a Technology Drift Audit using current official sources.
    
    Do not upgrade automatically.
    
    Identify:
    - packages behind supported stable versions
    - deprecated APIs
    - end-of-life runtime/tooling
    - security advisories
    - upcoming breaking changes
    - recommended migrations
    - experimental dependencies accidentally used in production
    
    Classify each finding:
    security / urgent / scheduled / optional.
    

    98. The Final Launch Audit

    The launch audit should be adversarial.

    text
    Assume the project is NOT ready.
    Try to prove it.
    

    Prompt:

    text
    Act as the independent launch-readiness reviewer.
    
    Try to prove that this project should NOT ship.
    
    Inspect:
    - requirements
    - critical user flows
    - permissions
    - security
    - accessibility
    - performance
    - dependencies
    - migrations
    - monitoring
    - rollback
    - CI
    - staging verification
    - visual references
    - documentation
    - production configuration
    
    Find the smallest number of high-impact blockers that could make the
    release fail or harm users.
    
    Do not praise the project.
    Do not redesign unrelated areas.
    
    If no blockers remain, provide evidence for each major launch gate.
    

    99. Teaching the AI to Explain Its Work to Beginners

    For beginner collaboration, AI output should not assume unexplained expertise.

    Require:

    text
    What changed?
    Why?
    Where?
    How to run it?
    How to test it?
    How to verify it visually?
    What can go wrong?
    

    This makes AI a teaching aid as well as an implementation engine.

    Prompt

    text
    Explain this completed change to a beginner without hiding technical
    accuracy.
    
    Use:
    - what
    - why
    - where
    - how
    - verification
    - common failure
    
    Do not use unexplained jargon.
    Do not omit important caveats.
    

    100. What "Perfectly Scalable" Actually Means

    The handbook should never promise impossible guarantees.

    A scalable engineering process means:

    text
    adding developers does not require proportional chaos
    adding features does not require rewriting conventions
    adding agents does not require re-teaching the project
    upgrading dependencies does not require random breakage
    new contributors can discover how the system works
    production incidents have a repeatable response
    

    It does not mean:

    text
    zero conflicts
    zero bugs
    zero downtime
    zero human review
    zero future migration work
    

    The goal is not perfection of outcome.

    The goal is predictability of process and containment of failure.


    101. The Complete Book-to-Project Mapping

    A beginner using this handbook should create the following artifacts in order:

    text
    STAGE 0
    project idea
    
    STAGE 1
    00-project-context.md
    01-product-spec.md
    02-product-terminology.md
    
    STAGE 2
    03-technology-policy.md
    
    STAGE 3
    04-architecture.md
    ADR set
    
    STAGE 4
    AGENTS.md
    docs/INDEX.md
    PROJECT_STATE.md
    skills/
    scoped rules
    
    STAGE 5
    05-design-philosophy.md
    06-design-tokens.md
    07-ux-principles.md
    08-motion-principles.md
    09-security-policy.md
    
    STAGE 6
    design references
    component reference
    UI shell
    
    STAGE 7
    10-data-model.md
    11-api-contracts.md
    
    STAGE 8
    12-testing-strategy.md
    13-deployment.md
    14-production-operations.md
    15-dependency-policy.md
    16-contribution-model.md
    
    STAGE 9
    repository bootstrap
    CI
    collaboration workflow
    
    STAGE 10
    vertical slices
    
    STAGE 11
    staging
    
    STAGE 12
    production
    
    STAGE 13
    operations
    
    STAGE 14
    continuous improvement
    

    102. Final Beginner Rulebook

    When in doubt, remember this sequence:

    text
    Understand before building.
    
    Specify before implementing.
    
    Research before selecting current technology.
    
    Design the system before designing pages.
    
    Generate references from product context.
    
    Treat approved references as visual truth.
    
    Use tokens instead of arbitrary styling.
    
    Use canonical code instead of reinvention.
    
    Use modules instead of folder chaos.
    
    Use contracts before dependent work.
    
    Use independent workspaces for independent changes.
    
    Coordinate hotspots deliberately.
    
    Prepare dependencies before parallel development.
    
    Test at the correct layer.
    
    Automate what machines can enforce.
    
    Review what requires human judgment.
    
    Never call unverified work complete.
    
    Ship through CI and staging.
    
    Operate production as part of the product.
    
    Learn from every failure.
    
    Keep the technology current through deliberate research.
    

    103. Current Official Reference Notes

    The methodology in this book intentionally avoids freezing exact package versions. Current facts should be verified at project start.

    Agent and skill guidance

    The AGENTS.md convention is intended to communicate repository-level instructions to coding agents.

    OpenAI's current public skill-creator guidance emphasizes:

    • clear skill metadata
    • a concise skill body
    • progressive disclosure
    • separate references/scripts for deeper material
    • deterministic scripts when exact operations benefit from automation

    Official references:

    • https://agents.md/
    • https://github.com/openai/skills/blob/main/skills/.system/skill-creator/SKILL.md

    Git collaboration

    Git worktrees support multiple working trees attached to a single repository:

    • https://git-scm.com/docs/git-worktree

    GitHub currently documents stacked pull requests and merge queues as mechanisms for handling dependent or high-volume changes. Stacked pull requests are currently documented as public preview, so the exact experience should be re-verified before standardizing on them:

    • https://docs.github.com/en/pull-requests/reference/stacked-pull-requests
    • https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue

    Accessibility

    Use the current W3C Web Content Accessibility Guidelines as the authoritative accessibility reference:

    • https://www.w3.org/TR/WCAG/

    Security

    OWASP Top 10:2025 is the current major Top 10 awareness release at the time this handbook was authored:

    • https://top10.owasp.org/2025/

    Technology

    Always verify current runtime/framework/package releases against the official project source before establishing a baseline.

    Do not use this book as a substitute for the current official documentation of a framework or package.


    104. The First Command Is Not a Shell Command

    The real first command is:

    text
    GRILL ME
    

    The second is:

    text
    FINALIZE THE SPECIFICATION
    

    The third is:

    text
    RESEARCH THE CURRENT TECHNOLOGY BASELINE
    

    Only after those are complete should the project reach:

    text
    BOOTSTRAP THE REPOSITORY
    

    Then:

    text
    BUILD THE SYSTEM BEFORE BUILDING THE PRODUCT
    

    And finally:

    text
    BUILD THE PRODUCT INSIDE THE SYSTEM.
    

    That ordering is the core lesson of this entire handbook.