Expert Coding & Architecture Prompts
GPT-5.2's expanded context window (128k+) allows for "whole-repo" reasoning. Stop pasting small snippets. Use these prompts to architect systems, refactor legacy codebases, and generate test-driven features with production-ready error handling.

Context-Aware System Re-architecture
### ROLE Act as a Senior Staff Software Architect specialized in Cloud-Native Distributed Systems. ### CONTEXT We have a monolithic application [SYSTEM_NAME] written in [LANGUAGE/FRAMEWORK]. - **Current Pain Points**: Slow deployment cycles, single point of failure in the [MODULE_NAME], and inability to scale [SPECIFIC_FUNCTION] independently. - **Goal**: Migrate to a [TARGET_ARCHITECTURE, e.g., Event-Driven Microservices] on AWS/GCP. ### TASK Analyze the provided Architecture Document/Code Structure. 1. **Decomposition Strategy**: Propose 3 distinct microservices based on Domain-Driven Design (DDD) Bounded Contexts. 2. **Trade-off Analysis**: For each proposed service, list the Pros/Cons of extracting it versus keeping it in the monolith. 3. **Migration Plan**: Outline a "Strangler Fig" pattern approach to migrate without downtime. ### OUTPUT FORMAT - **Executive Summary**: High-level architectural vision. - **Service Boundaries Table**: Service Name | Responsibility | Shared Data | API Contract. - **Risk Assessment**: Potential consistency issues (CAP theorem considerations). ### INPUT [INSERT ARCHITECTURE DESCRIPTION OR LINK TO GIST]
Why it works with GPT-5.2
This prompt leverages the 'Principal Architect' persona to force the model into high-level strategic thinking rather than low-level coding. It explicitly asks for trade-offs and migration patterns (Strangler Fig), which are hallmarks of senior engineering decisions.
Expected Output
A strategic migration document including a breakdown of new microservices, a comparative analysis of extraction risks, and a step-by-step low-risk implementation plan.
Advanced Variation
Change TASK to 'Design a Disaster Recovery Strategy' focusing on RTO/RPO objectives.
The Senior Architech Refactor
### ROLE Act as a Principal Software Engineer (Language: TypeScript/Rust expert). ### CONTEXT I am providing a legacy file [INSERT FILE CONTENT OR GITHUB LINK] that uses outdated patterns (e.g., callback hell, global state mutation). ### TASK Refactor this code into a modern, functional style. ### REQUIREMENTS 1. **Preserve Logic**: The external API and return values must remain identical. 2. **Modern Patterns**: Use Async/Await, discriminative unions for state, and dependency injection where applicable. 3. **Performance**: Identify and optimize any O(n^2) loops or unnecessary re-renders. 4. **Safety**: Add runtime validation (Zod/Pydantic) for all external inputs. ### OUTPUT FORMAT - **Analysis**: Brief bullet points on what was deprecated and why. - **Refactored Code**: The full, compile-ready code block. - **Unit Tests**: 3 edge-case tests (Jest/Vitest) proving the refactor is strictly equivalent.
Why it works with GPT-5.2
Most coding prompts fail because they don't specify *safety* or *equivalence*. This prompt forces the AI to act as a Principal Engineer who cares about runtime safety (Zod) and regression testing, leveraging GPT-5.2's ability to hold the entire file's logic in memory.
Expected Output
A brief analysis of the 'smells' in the old code, followed by a clean, typed, and validated version of the code, plus unit tests.
Advanced Variation
### VARIATION: API Contract Generation Change TASK to "Generate a Swagger/OpenAPI 3.0 definition for this code's implicit API". Add Requirement: "Identify potential security vulnerabilities (OWASP Top 10) in the current logic".
Full-Stack Feature Implementation (TDD)
### OBJECTIVE Implement the following User Story using a TDD (Test Driven Development) approach. ### STACK - Frontend: React (Next.js 15), Tailwind - Backend: Node.js (Hono), PostgreSQL (Prisma) - State: Zustand ### USER STORY "As a user, I want to upload a CSV file, validate its rows against a schema, and see a progress bar during the batch import process." ### INSTRUCTIONS 1. **Plan**: Outline the API endpoint signature and the Database Schema change. 2. **Test First**: Write the backend integration test (failing state). 3. **Implementation**: - Write the Prisma schema update. - Write the Backend Service logic (handle streaming/pagination for large files). - Write the Frontend Component (optimistic UI updates). ### CONSTRAINTS - Handle error cases (invalid CSV format, network timeout). - Use proper HTTP status codes. - Do not use 'any' types.
Why it works with GPT-5.2
This prompt leverages GPT-5.2's 'System 2' thinking to plan across the stack *before* writing code. By enforcing TDD, it ensures the generated code is testable and robust, rather than just 'looking correct'.
Expected Output
A structured response containing Schema.prisma changes, a .test.ts file, the backend route handler, and the React component interaction logic.
Advanced Variation
### VARIATION: Microservices Communication Change Stack to "Go (gRPC) and Python (FastAPI)". Task: "Design the Protobuf message definition and the error handling strategy for service-to-service communication."
Engineering FAQ
Does GPT-5.2 actually write secure code?
It is significantly better than GPT-4, but you must explicitly request "security best practices" and "runtime validation" (as seen in our prompts) to ensure it doesn't hallucinate insecure shortcuts.
How do I handle multiple files?
With the 128k+ context window, you can paste 10-20 files wrapped in XML tags (e.g., <file name="utils.ts">...</file>). GPT-5.2 understands file boundaries better when explicitly tagged.