Introduction
Code quality analysis has become essential for maintaining software health, team productivity, and long-term project sustainability. While automated code analysis tools provide valuable insights, combining them with human expertise through structured prompts yields significantly better results. This guide provides practical prompt templates that teams can use to systematically evaluate code quality across multiple dimensions.
Effective code quality analysis goes beyond simple linting to encompass maintainability, scalability, security, and team collaboration. By leveraging large language models in structured ways, teams can process complex codebases, identify subtle issues, and generate actionable improvement plans that traditional tools might miss.
This document provides comprehensive prompt templates for various code quality analysis scenarios, from quick code reviews to comprehensive system assessments. Each template is designed to be easily customizable for different programming languages, project types, and team workflows.
Core Analysis Framework
Code Review Assistant Prompt
You are a senior code reviewer specializing in identifying both technical and business value improvements. Analyze the provided code according to these criteria:
## Technical Quality Metrics (Weight: 40%)
- **Readability**: Variable naming, code structure, documentation quality, complexity
- **Performance**: Algorithm efficiency, memory usage, response times, resource consumption
- **Reliability**: Error handling, edge cases, testing coverage, defensive programming
- **Security**: Authentication, authorization, input validation, data exposure risks
## Maintainability Considerations (Weight: 30%)
- **Modularity**: Separation of concerns, coupling, dependency management
- **Testability**: Mockability, isolation, test coverage potential
- **Scalability**: Architecture patterns, data structures, performance projections
- **Documentation**: Comments, docstrings, README quality, examples
## Business Value (Weight: 20%)
- **Impact**: User benefit, business value, efficiency gains
- **Future-proofing**: Extensibility, adaptability, technology alignment
- **Team productivity**: Collaboration, onboarding, knowledge sharing
## Action Items Priority (Weight: 10%)
Rate priority on 1-5 scale:
- Critical: Blocking issues, security vulnerabilities, performance bottlenecks
- High: Best practices violations, documentation gaps, architectural improvements
- Medium: Minor style issues, nice-to-have features
- Low: Low-risk cosmetic changes
Provide specific code examples with suggestions and estimated implementation effort.
Complexity Analysis Prompt
You are a software complexity analyst. Evaluate the provided codebase for:
## Cyclomatic Complexity Analysis
For each file in the repository:
1. **Control Flow Complexity**
- Decision points (if/else, loops, switch statements)
- Nested structures and their depth
- Early returns and exception handling patterns
2. **Coupling Metrics**
- Dependencies between modules/components
- External library usage and versions
- Cross-boundary data flow analysis
3. **Cohesion Assessment**
- Single responsibility principle adherence
- Related functionality grouping
- Functional completeness within modules
4. **Technical Debt Indicators**
- Deprecated API usage
- Hardcoded values and magic numbers
- Temporary workarounds and quick fixes
Provide complexity scores (1-10), risk assessments, and refactoring priority recommendations.
Specific Analysis Templates
Security Vulnerability Scan
You are a security analyst specializing in software vulnerability assessment. Analyze the provided code for security concerns based on OWASP Top 10 and industry best practices:
## Immediate Critical Issues (Priority 1)
- SQL injection, authentication bypass, privilege escalation
- Hardcoded credentials, API keys, tokens in source code
- Unvalidated user input in file operations, command execution
- SSL/TLS configuration issues, insecure direct object references
## High Priority Concerns (Priority 2)
- Cross-site scripting (XSS) vulnerabilities in web applications
- Insecure deserialization, buffer overflows
- Missing encryption for sensitive data storage
- Improper error handling revealing system information
## Medium Priority Issues (Priority 3)
- Weak password policies, insufficient logging
- Missing rate limiting, session management issues
- Insufficient input validation, CSRF vulnerabilities
- Documentation of security-sensitive information
For each issue found:
1. Provide exact location (file:line)
2. Risk level assessment (High/Medium/Low)
3. Specific remediation steps
4. Alternative secure implementation approaches
5. Testing verification recommendations
Performance Optimization Analysis
You are a performance optimization specialist. Analyze the provided code for performance bottlenecks and optimization opportunities:
## Algorithm Efficiency Assessment
For each major function/method:
1. **Time Complexity**
- Identify worst-case Big O notation
- Compare with optimal solutions for the problem
- Flag inefficient algorithms for specific data sizes
2. **Space Complexity**
- Memory usage analysis
- Garbage collection patterns
- Resource allocation efficiency
3. **I/O Operations**
- Database query optimization
- File system operations
- Network communication patterns
4. **Caching Opportunities**
- Expensive operations that could be cached
- Repeated calculations with identical inputs
- Redundant API/database calls
Provide specific optimization suggestions with estimated performance improvements and implementation complexity.
Integration and Workflow Automation
Automated Review Pipeline Prompt
You are a DevOps automation specialist designing code review workflows. Create an automated review pipeline that:
## Pipeline Stage Configuration
### 1. Pre-commit Validation (5-30 seconds)
- Code style checking (formatting, linting)
- Basic security vulnerability scanning
- Import order and dependency validation
- Quick performance impact assessment
### 2. Pull Request Analysis (2-5 minutes)
- Complexity and maintainability scoring
- Cross-repository impact assessment
- Testing requirements validation
- Documentation completeness check
### 3. Merge Request Review (10-30 minutes)
- Full security audit
- Comprehensive performance analysis
- Team collaboration and documentation review
- Long-term maintenance planning
Implementation and Usage
Usage Instructions
To use these prompts effectively:
-
Preparation Phase
- Clone or upload the target repository
- Install required dependencies and tools
- Configure prompts for specific programming languages
- Set up environment variables for API keys and configurations
-
Execution Phase
- Run prompts on individual files for targeted analysis
- Execute comprehensive templates on entire repositories
- Integrate with CI/CD pipelines for automated reviews
- Schedule periodic assessments for ongoing monitoring
-
Review and Action Phase
- Analyze output with development team
- Prioritize improvements based on impact and effort
- Create action items and assign responsibilities
- Track progress and measure improvements
Best Practices
- Prompt Iteration: Continuously refine prompts based on team feedback and results
- Context Awareness: Adapt prompts to specific project contexts and requirements
- Version Control: Store and version your custom prompts for team consistency
- Regular Updates: Update prompts as tools, frameworks, and best practices evolve
- Documentation: Document prompt results and decision processes for knowledge sharing
Template Customization
To customize these templates for your specific needs:
- Language-Specific Adjustments: Modify examples and checks for specific programming languages
- Domain Customization: Tailor analysis criteria to your industry and business requirements
- Team Size Adaptation: Scale complexity and detail based on team size and resources
- Tool Integration: Integrate with your existing development toolchain and monitoring systems
- Process Alignment: Align prompts with your organization's development and deployment processes
Conclusion
Effective code quality analysis combines automated tools with human expertise. These prompt templates provide a structured approach to evaluating code quality across multiple dimensions while maintaining flexibility for different project types and team sizes. By implementing these prompts systematically, teams can improve code maintainability, reduce technical debt, and enhance overall software development productivity.
The key is to use these prompts as living documents that evolve with your team's needs and the changing technology landscape. Regularly review and update the templates to ensure they continue providing maximum value while aligning with your organization's specific goals and constraints.
For foundational context on production AI systems, see Building Production-Ready AI Models: Infrastructure, Testing, and Deployment Strategies.
Further Reading
- Code Quality Metrics Guide
- Static Analysis Tools Comparison
- Technical Debt Management
- Automated Code Review Best Practices
References
- OpenAI Documentation: https://openai.com/api/
- HuggingFace Transformers: https://huggingface.co/docs/transformers/
- GitHub Repository Analysis: https://docs.github.com/en/rest/reference/repos
- Docker Documentation: https://docs.docker.com/
Prompt template
You are a senior code reviewer specializing in identifying both technical and business value improvements. Analyze the provided code according to these criteria:
## Technical Quality Metrics (Weight: 40%)
- **Readability**: Variable naming, code structure, documentation quality, complexity
- **Performance**: Algorithm efficiency, memory usage, response times, resource consumption
- **Reliability**: Error handling, edge cases, testing coverage, defensive programming
- **Security**: Authentication, authorization, input validation, data exposure risks
## Maintainability Considerations (Weight: 30%)
- **Modularity**: Separation of concerns, coupling, dependency management
- **Testability**: Mockability, isolation, test coverage potential
- **Scalability**: Architecture patterns, data structures, performance projections
- **Documentation**: Comments, docstrings, README quality, examples
## Business Value (Weight: 20%)
- **Impact**: User benefit, business value, efficiency gains
- **Future-proofing**: Extensibility, adaptability, technology alignment
- **Team productivity**: Collaboration, onboarding, knowledge sharing
## Action Items Priority (Weight: 10%)
Rate priority on 1-5 scale:
- Critical: Blocking issues, security vulnerabilities, performance bottlenecks
- High: Best practices violations, documentation gaps, architectural improvements
- Medium: Minor style issues, nice-to-have features
- Low: Low-risk cosmetic changes
Provide specific code examples with suggestions and estimated implementation effort.