0

Prompt: Codebase Analysis & Architecture Review

Categorize and quantify tech debt: CRITICAL (address in Auth[AuthMiddleware] Auth --> Routes Routes --> ProductService[ProductService ⚠️ GOD CLASS] Routes --> OrderService[OrderService] ProductService --> DB[(PostgreSQL)] ProductService --> Redis[(Redis Cache)] ProductService --> S3[AWS S3] Orde

Prompt · برومبتawsgemini

Works with

claude-code (compatible), claude (compatible), codex (compatible), chatgpt (compatible), gemini-cli (compatible), cursor (compatible), copilot (compatible), opencode (compatible), amp (compatible), roo (compatible), kiro (compatible), goose (compatible), junie (compatible), trae (compatible), cline (compatible), continue (compatible), antigravity (compatible), windsurf (compatible), augment (compatible), qwen-code (compatible), aider (compatible)

Content

Prompt: Codebase Analysis & Architecture Review

Purpose: Perform an exhaustive codebase analysis covering architecture quality, code health, technical debt, security posture, and scalability assessment — producing an actionable improvement roadmap.

Best For: Architecture reviews, M&A technical due diligence, onboarding to new codebases, tech debt assessment

Model Recommendation: Gemini 1.5 Pro (1M context window), Antigravity, Claude Opus 4

Usage Instructions:

  1. Use Gemini 1.5 Pro for large codebases (supports up to 1M tokens ≈ ~750,000 lines of code).
  2. Upload your repo as a zip or paste the output of git ls-files | xargs cat with file separators.
  3. Alternatively, use Antigravity's code-review-graph MCP tool for large repos.

---

THE PROMPT

You are a Principal Engineer conducting a thorough technical architecture review. Analyze the provided codebase systematically and produce a comprehensive technical assessment report.

**ANALYSIS DIMENSIONS:**

### 1. Architecture Overview
- Identify the architectural pattern(s) in use (monolith, microservices, serverless, event-driven, layered, hexagonal, etc.)
- Draw the system architecture as a Mermaid diagram showing:
  - Major components and their relationships
  - Data flow between components
  - External dependencies (databases, APIs, queues)
  - Entry points (APIs, workers, scheduled jobs)
- Identify architectural anti-patterns (big ball of mud, circular dependencies, god objects)

### 2. Code Quality Assessment

**Complexity Analysis:**
- Identify the 10 most complex functions/classes (by cyclomatic complexity)
- Flag functions over 50 lines (should be decomposed)
- Identify deeply nested code (>4 levels = problem)

**SOLID Principles Audit:**
- Single Responsibility: Classes/functions doing too many things
- Open/Closed: Code that requires modification to extend (should be extensible)
- Liskov Substitution: Incorrect inheritance hierarchies
- Interface Segregation: Fat interfaces
- Dependency Inversion: Hard-coded dependencies vs dependency injection

**DRY (Don't Repeat Yourself):**
- Identify duplicated code blocks (copy-paste programming)
- Find similar functions that should be abstracted

**Code Smells Inventory:**
- Long parameter lists (>5 parameters)
- Magic numbers/strings (should be constants)
- Commented-out code
- Dead code (never executed paths)
- TODO/FIXME comments (count and categorize)
- Inappropriate intimacy (class A deeply coupled to class B internals)

### 3. Technical Debt Report

Categorize and quantify tech debt:

CRITICAL (address in <1 month): [ ] [Component]: [Issue] - Risk: [what breaks if unaddressed] - Effort: [X days]

HIGH (address in 1-3 months): [ ] ...

MEDIUM (next quarter): [ ] ...

LOW (backlog): [ ] ...

TOTAL ESTIMATED DEBT: X developer-months


### 4. Security Assessment
- Hardcoded secrets / credentials in code
- Unvalidated user inputs (injection risks)
- Insecure dependencies (flag outdated packages with known CVEs)
- Missing authentication/authorization checks
- Data exposure (PII in logs, verbose error messages)
- Cryptographic weaknesses

### 5. Performance Red Flags
- N+1 query patterns in database code
- Missing pagination (loading all records)
- Synchronous blocking I/O in async contexts
- Missing caching for expensive computations
- Memory leaks (unclosed connections, event listener accumulation)
- Inefficient algorithms (O(n²) where O(n log n) is possible)

### 6. Testing Coverage Analysis
- Estimate test coverage percentage
- Identify untested critical paths
- Assess test quality (are they testing behavior or just hitting lines?)
- Missing test categories (unit, integration, E2E, contract)

### 7. Dependency Analysis
- List all external dependencies with versions
- Flag outdated dependencies
- Identify license conflicts
- Highlight single points of failure (unmaintained libraries)

### 8. Documentation Quality
- Missing README sections
- Undocumented APIs
- Outdated documentation vs actual implementation
- Missing architecture decision records (ADRs)

**REPORT FORMAT:**

Codebase Analysis Report: [Project Name]

Date: [Today] Analyzed by: Gemini 1.5 Pro Codebase Size: [X files, Y lines of code] Languages: [list]

Health Score: X/100

| Dimension | Score | Grade | |------------------------|-------|-------| | Architecture | X/20 | A/B/C/D/F | | Code Quality | X/20 | ... | | Security | X/20 | ... | | Performance | X/20 | ... | | Maintainability | X/20 | ... |

Critical Issues (Fix Immediately)

[Numbered list]

Architecture Diagram

[Mermaid diagram]

90-Day Improvement Roadmap

Month 1: Foundation

  • [List of changes with estimated effort]

Month 2: Core Improvements

...

Month 3: Polish

...

Estimated ROI of Improvements

[What business outcomes improve with these changes]


**CODEBASE TO ANALYZE:**
[Paste code or describe how to access it]

**Context (helps with analysis):**
- Application type: [Web API / Frontend / Data pipeline / CLI tool / etc.]
- Team size: [X developers]
- Age of codebase: [X years]
- Main language(s): [Python / TypeScript / Java / etc.]
- Known problem areas: [any specific concerns]
- Business context: [what this system does at a high level]

---

Example Output Excerpt:

# Codebase Analysis Report: InventoryAPI

## Health Score: 62/100
| Dimension       | Score | Grade |
|-----------------|-------|-------|
| Architecture    | 13/20 | C+    |
| Code Quality    | 11/20 | D+    |
| Security        | 14/20 | B-    |
| Performance     | 12/20 | C+    |
| Maintainability | 12/20 | C+    |

## Critical Issues

### CRIT-001: SQL Injection in Search Endpoint (routes/products.py:124)
The search query is directly concatenated into SQL string. An attacker can extract the entire database.

### CRIT-002: God Class — ProductService (1,847 lines)
ProductService handles: inventory, pricing, search, recommendations, export, import, and notifications. Should be 6 separate services.

### CRIT-003: N+1 Query in Order Listing (services/orders.py:89)
For each order, a separate query fetches the user. With 1000 orders/page, this is 1001 queries → 8 second response time.

## Architecture Diagram

graph TD API[FastAPI :8000] --> Auth[AuthMiddleware] Auth --> Routes Routes --> ProductService[ProductService<br/>⚠️ GOD CLASS] Routes --> OrderService[OrderService] ProductService --> DB[(PostgreSQL)] ProductService --> Redis[(Redis Cache)] ProductService --> S3[AWS S3] OrderService --> DB OrderService --> Stripe[Stripe API] OrderService --> Email[SendGrid]

Source and license

Source
Enterprise AI Prompts
Original
m0shaban/enterprise-ai-prompts/prompts/gemini-antigravity/codebase-analysis.md
License
MIT