Case Study 02: Raj's Codebase Context — Making AI a Useful Code Reviewer
Chapter: 8 — Context Is Everything: Loading Your AI's Working Memory Persona: Raj (Senior Software Engineer, Meridian Payments) Scenario: Providing architecture context, coding standards, and review criteria that transform generic AI code review into precise, standards-aligned feedback for a production codebase
The Problem
Raj's engineering team at Meridian Payments has 12 developers and a growing backlog of pull requests. Senior engineers — including Raj — spend significant time on code review that could be partly assisted by AI, but early attempts produced disappointing results.
The AI's code review feedback was consistently in one of two categories: 1. Generic best practices: "Consider adding error handling," "This could be more readable," "You should add unit tests." All technically correct. None specific to Meridian's codebase. 2. False flags: The AI would flag as issues things that were intentional architectural decisions. "You should use asynchronous file reads here" — flagging a pattern that was a deliberate startup initialization choice. "Consider using a different ORM" — flagging their Prisma setup when that was a locked architectural decision.
The result: engineers stopped using AI for code review because the signal-to-noise ratio was too low. Every real issue was buried under false positives and generic advice.
Raj's hypothesis: the AI does not know their codebase, their standards, or their intentional decisions. It is reviewing against the general population of Node.js codebases, not against Meridian's specific requirements.
His goal: build a code review context packet that calibrates the AI to their actual standards.
Phase 1: Identifying What the AI Needs to Know
Raj interviews three team members who do the most code review: himself, the lead backend engineer, and the QA lead. He asks each of them: "If you were onboarding a senior engineer from outside our team for their first week of code review, what would you need to explain that they could not learn from general Node.js knowledge?"
The answers cluster into four categories:
1. Architectural patterns that are non-negotiable Things like the repository pattern, the service layer, the centralized error handling middleware. These are established and the team does not want the AI to suggest alternatives.
2. Specific standards that differ from common defaults TypeScript strict mode, the specific error response format, the Zod validation approach, the custom logger. Things where the AI's "best practice" advice might contradict their actual practice.
3. Intentional decisions that look like mistakes to an outside reviewer Synchronous file reads in config loading, the verbose error format, specific naming conventions that differ from standard TypeScript community conventions.
4. What the review should actually focus on Security considerations, data exposure risks, performance impact for the payments critical path, proper use of their transaction handling patterns, idempotency key usage.
This interview process takes 90 minutes. It produces the raw material for the context packet.
Phase 2: Building the Code Review Context Packet
Raj drafts the context packet over an afternoon. He iterates several times, cutting things that are too generic (the AI already knows standard Node.js best practices — no need to tell it) and expanding things that are Meridian-specific (the things the AI would not know).
Draft 1: Too Long, Too Generic
Raj's first draft was 800 words and included things like "use async/await rather than callbacks" and "always handle promise rejections." After reviewing it, he cuts anything the AI would already know about Node.js and TypeScript. The goal is to tell the AI what is different about Meridian — not what is true everywhere.
Draft 2: Too Technical, Not Enough Framing
The second draft was precise but lacked framing about what kind of review was expected. A junior-level review (catch basic mistakes), a senior-level review (assess architecture and patterns), or a security review (focus on exposure risks) require different emphasis. Without framing, the AI would produce a blend of all three, which was unfocused.
Final Draft: The Completed Context Packet
=== MERIDIAN PAYMENTS — CODE REVIEW CONTEXT PACKET ===
CODEBASE OVERVIEW:
Meridian Payments processes real-time payment transactions for enterprise clients.
The codebase is a Node.js (TypeScript strict mode) REST API using Express.js.
Database: PostgreSQL accessed via Prisma ORM. All code lives in a monorepo.
REVIEW POSTURE FOR THIS SESSION:
[Raj fills this in per session: "security review," "standard PR review,"
"architecture review," or "junior dev output — check for patterns"]
---
ARCHITECTURE PATTERNS — DO NOT SUGGEST ALTERNATIVES TO THESE:
These are established, intentional, and team decisions. Flag violations; do not
suggest replacement patterns.
- Repository pattern: All database access goes through /src/repositories/*.
Controllers NEVER call Prisma directly. Flag any direct Prisma usage outside
the repository layer.
- Service layer: Business logic lives in /src/services/*. Repositories handle
data; services handle logic. Flag business logic in controllers or repositories.
- Centralized error handling: All errors should propagate to the global error
middleware in /src/middleware/errorHandler.ts. No try/catch at controller level
that swallows errors; no unhandled promise rejections.
- Request validation: All request validation happens at the controller level using
Zod schemas in /src/validators/*. Flag any endpoint that processes request data
without Zod validation.
---
CODING STANDARDS TO ENFORCE:
- TypeScript strict mode: No 'any' types. No non-null assertion operator (!) unless
there is a comment explaining why it is safe. Flag all violations.
- Return type annotations: All functions must have explicit TypeScript return types.
Flag missing annotations.
- Logger usage: Use our logger utility (/src/utils/logger.ts) not console.log.
console.log is a flag; console.error is a flag.
- Snake_case vs camelCase: Database columns are snake_case, TypeScript is camelCase.
This is handled by Prisma transform config. Do NOT flag this as inconsistency.
- Environment config: All env vars accessed via /src/config/index.ts which uses Zod
for validation on startup. Flag any direct process.env access outside this file.
---
INTENTIONAL DECISIONS — DO NOT FLAG THESE:
These will look like issues to a general code reviewer. They are not.
- Synchronous file reads in /src/config/: This is an intentional startup-time
initialization pattern. Do not recommend converting to async.
- Verbose error response format: Our error responses include debugging details.
This is intentional for our enterprise clients' integration teams. Do not
suggest simplifying the format.
- Prisma client singleton pattern: We instantiate once and export. Do not suggest
connection pooling alternatives — we use PgBouncer at the infrastructure level.
- Migration files contain raw SQL: Our migration files use raw SQL for performance
reasons. Do not suggest ORM-abstracted alternatives.
---
REVIEW PRIORITY ORDER (most important first):
1. Security issues: data exposure, authentication bypass risks, injection
vulnerabilities, improper handling of payment data
2. Pattern violations: any violation of the architectural patterns listed above
3. Error handling gaps: paths where errors could be swallowed or propagate uncaught
4. TypeScript violations: strict mode, return types, any types
5. Performance on critical path: POST /payments and GET /payments/:id are
performance-critical — flag any N+1 queries, unnecessary awaits, or
synchronous blocking in these routes
6. Test coverage: flag if new code paths are not covered by tests
7. Code style and readability: lowest priority — flag only significant issues
---
OUTPUT FORMAT FOR CODE REVIEW:
Organize your review as:
- CRITICAL (security or data integrity issues): [issue], [location], [recommended fix]
- HIGH (pattern violations, error handling gaps): [issue], [location], [recommended fix]
- MEDIUM (TypeScript issues, performance): [issue], [location], [suggested improvement]
- LOW (style, readability): [issue], [location], [optional suggestion]
If you find no issues in a category, state "None found." Do not invent issues to
fill categories.
End with: OVERALL ASSESSMENT: [1-2 sentences on whether this PR is ready to merge,
needs changes, or has blocking issues]
=== END MERIDIAN CODE REVIEW CONTEXT PACKET ===
Phase 3: Testing the Context Packet
Raj tests the packet on three recent pull requests: one that had passed code review (no known issues), one that had a known security bug that was caught in review, and one that contained a deliberate violation of the repository pattern.
Test 1: Clean PR
Prompt: "[Context packet] Please review this pull request. Review posture: standard PR review. [Paste PR diff]"
AI Output (condensed):
CRITICAL: None found.
HIGH: None found.
MEDIUM: Line 47 — function processWebhookEvent is missing explicit return type annotation. Should be : Promise<void>.
LOW: Line 23 — variable name d should be more descriptive given the context. Suggest paymentData or webhookPayload.
OVERALL ASSESSMENT: This PR is ready to merge after addressing the missing return type annotation on line 47. The architecture patterns are correctly followed, validation is present, and error handling propagates correctly to the middleware.
Raj's assessment: "Accurate. No false positives. The return type issue is real. The variable naming suggestion is fair. It found nothing that wasn't there."
Test 2: PR with Known Security Bug
The PR contained a bug where user-supplied data was being used in a Prisma raw query without sanitization — a SQL injection risk that human reviewers had caught.
AI Output (condensed):
CRITICAL: Line 34 — prisma.$queryRaw` is called with user-supplied data from `req.body.filter` without sanitization. This is a SQL injection vulnerability. The `$queryRaw function should use parameterized queries: prisma.$queryRaw\`SELECT * FROM payments WHERE ${Prisma.sql\filter = ${req.body.filter}`}``, or this logic should be moved to the repository layer where Prisma's query builder handles parameterization automatically.
Raj: "Exact issue, exact location, correct fix recommendation. This took 8 seconds."
Test 3: Repository Pattern Violation
AI Output (condensed):
HIGH: Line 12 — Direct Prisma client call in the payment controller (prisma.payment.findMany()). Per the repository pattern, all database access should go through /src/repositories/paymentRepository.ts. This controller should call paymentRepository.findAll() or an equivalent method. This is a flagged pattern violation.
Raj: "Correct. This is exactly the kind of feedback that was missing before — specific to our pattern, not to generic Node.js."
Phase 4: Team Adoption and Process Integration
Raj presents the context packet to the team and proposes a workflow:
- Every PR author can run the context packet + their own PR diff through AI before requesting human review
- AI review is pre-screening, not replacement — all PRs still get human review, but AI surfaces the mechanical issues in advance
- The context packet is stored in the repository's
/docs/ai-review-packet.md— any team member can use it - The packet is reviewed quarterly and updated when architectural decisions change
Three-month results: - Reduction in "pattern violation" comments in human code review: approximately 40% (engineers caught their own pattern violations in AI pre-review) - Reduction in TypeScript annotation issues caught in human review: approximately 60% - False positive rate from AI review: approximately 5% (compared to approximately 70% before the context packet) - Senior engineer time saved on code review per week: approximately 4-6 hours across the team
The most significant improvement was the false positive reduction. When the AI was flagging intentional decisions as problems, engineers lost confidence in the tool entirely. Once the AI knew what was intentional, its signal became trustworthy — and trustworthy tools get used.
The Critical Insight: Context That Prevents False Positives
The section of Raj's context packet that mattered most was arguably "INTENTIONAL DECISIONS — DO NOT FLAG THESE." This section directly addressed the failure mode that had killed team trust in AI code review: false positives that required engineers to explain why an AI was wrong.
Every professional domain has equivalent false-positive risks: - Legal: AI flagging established practices as unusual without knowing the jurisdiction-specific context - Finance: AI recommending standard approaches that conflict with regulatory requirements specific to the company - Marketing: AI suggesting conventional best practices that contradict the brand's deliberate counter-positioning - HR: AI applying general communication guidance that conflicts with specific organizational culture norms
The solution in each case is the same as Raj's: build a context packet section explicitly listing the intentional decisions in your domain — things that are correct for your context even though they might look wrong to a general expert.
This is not just a prompting technique. It is a documentation discipline. Raj's context packet contains institutional knowledge about architectural decisions that might otherwise exist only in senior engineers' heads. When junior engineers join the team, they can read the AI context packet as part of their onboarding — it functions as a technical decision log as much as a prompting tool.
Applying This to Non-Technical Domains
The principles of Raj's code review context packet apply directly to any knowledge-work domain where: - There are domain-specific standards that differ from general best practices - There are intentional decisions that look like mistakes to a general reviewer - The quality of feedback depends on knowing the specific standards, not just the general field - False positives have a real cost (in this case, eroding trust in the AI tool)
A legal team would build a context packet with their jurisdiction, their clients' specific regulatory contexts, their firm's established positions on contested legal questions, and their document style guide.
A financial analysis team would build one with their modeling conventions, their standard assumptions, the regulatory frameworks governing their reports, and their firm's specific risk appetite parameters.
An HR team would build one with their organization's specific culture, their approach to sensitive topics, their legal counsel's standing guidance, and the vocabulary they use (and avoid) for specific populations.
In each case, the packet transforms the AI from a generalist who knows the field to a specialist who knows your organization's approach to the field. That transformation is worth the 90-minute investment.