Loading...
Loading...
Provides comprehensive code review covering 6 focused aspects - architecture & design, code quality, security & dependencies, performance & scalability, testing coverage, and documentation & API design. Use this skill for deep analysis with actionable feedback after significant code changes.
npx skill4agent add duck4nh/antigravity-kit code-review# Read project documentation for conventions and architecture
for doc in AGENTS.md CLAUDE.md README.md CONTRIBUTING.md ARCHITECTURE.md; do
[ -f "$doc" ] && echo "=== $doc ===" && head -50 "$doc"
done
# Detect architectural patterns from directory structure
find . -type d -name "controllers" -o -name "services" -o -name "models" -o -name "views" | head -5
# Identify testing framework and conventions
ls -la *test* *spec* __tests__ 2>/dev/null | head -10
# Check for configuration files that indicate patterns
ls -la .eslintrc* .prettierrc* tsconfig.json jest.config.* vitest.config.* 2>/dev/null
# Recent commit patterns for understanding team conventions
git log --oneline -10 2>/dev/null# Detect error handling patterns
grep -r "Result<\|Either<\|Option<" --include="*.ts" --include="*.tsx" . | head -5
# Check for dependency injection patterns
grep -r "@Injectable\|@Inject\|Container\|Provider" --include="*.ts" . | head -5
# Identify state management patterns
grep -r "Redux\|MobX\|Zustand\|Context\.Provider" --include="*.tsx" . | head -5
# Testing conventions
grep -r "describe(\|it(\|test(\|expect(" --include="*.test.*" --include="*.spec.*" . | head -5**Issue**: Function `processUserData` is 200 lines long
**Root Cause Analysis**:
This function violates Single Responsibility Principle by handling:
1. Input validation (lines 10-50)
2. Data transformation (lines 51-120)
3. Business logic (lines 121-170)
4. Database persistence (lines 171-200)
**Solution**:
```typescript
// Extract into focused classes
class UserDataValidator {
validate(data: unknown): ValidationResult { /* lines 10-50 */ }
}
class UserDataTransformer {
transform(validated: ValidatedData): UserModel { /* lines 51-120 */ }
}
class UserBusinessLogic {
applyRules(user: UserModel): ProcessedUser { /* lines 121-170 */ }
}
class UserRepository {
save(user: ProcessedUser): Promise<void> { /* lines 171-200 */ }
}
// Orchestrate in service
class UserService {
async processUserData(data: unknown) {
const validated = this.validator.validate(data);
const transformed = this.transformer.transform(validated);
const processed = this.logic.applyRules(transformed);
return this.repository.save(processed);
}
}
## 4. Cross-File Intelligence
### Comprehensive Analysis Commands
```bash
# For any file being reviewed, check related files
REVIEWED_FILE="src/components/UserForm.tsx"
# Find its test file
find . -name "*UserForm*.test.*" -o -name "*UserForm*.spec.*"
# Find where it's imported
grep -r "from.*UserForm\|import.*UserForm" --include="*.ts" --include="*.tsx" .
# If it's an interface, find implementations
grep -r "implements.*UserForm\|extends.*UserForm" --include="*.ts" .
# If it's a config, find usage
grep -r "config\|settings\|options" --include="*.ts" . | grep -i userform
# Check for related documentation
find . -name "*.md" -exec grep -l "UserForm" {} \;# Check if similar code exists elsewhere (potential duplication)
PATTERN="validateEmail"
echo "Similar patterns found in:"
grep -r "$PATTERN" --include="*.ts" --include="*.js" . | cut -d: -f1 | uniq -c | sort -rn
# Identify frequently changed files (high churn = needs refactoring)
git log --format=format: --name-only -n 100 2>/dev/null | sort | uniq -c | sort -rn | head -10
# Check deprecation patterns
grep -r "@deprecated\|DEPRECATED\|TODO.*deprecat" --include="*.ts" .shared/validatorsutils/date.ts# Identify hot paths (frequently called code)
grep -r "function.*\|const.*=.*=>" --include="*.ts" . | xargs -I {} grep -c "{}" . | sort -rn
# Find user-facing code
grep -r "onClick\|onSubmit\|handler\|api\|route" --include="*.ts" --include="*.tsx" .
# Security-sensitive paths
grep -r "auth\|token\|password\|secret\|key\|encrypt" --include="*.ts" .**Issue**: Memory leak in resize listener (line 45)
**Current Code**:
```typescript
componentDidMount() {
window.addEventListener('resize', this.handleResize);
}componentDidMount() {
window.addEventListener('resize', this.handleResize);
}
componentWillUnmount() {
window.removeEventListener('resize', this.handleResize);
}useEffect(() => {
const handleResize = () => { /* logic */ };
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);// Create in hooks/useWindowResize.ts
export function useWindowResize(handler: () => void) {
useEffect(() => {
window.addEventListener('resize', handler);
return () => window.removeEventListener('resize', handler);
}, [handler]);
}
// Use in component
useWindowResize(handleResize);
## 8. Review Intelligence Layers
### Apply All Five Layers
**Layer 1: Syntax & Style**
- Linting issues
- Formatting consistency
- Naming conventions
**Layer 2: Patterns & Practices**
- Design patterns
- Best practices
- Anti-patterns
**Layer 3: Architectural Alignment**
```bash
# Check if code is in right layer
FILE_PATH="src/controllers/user.ts"
# Controllers shouldn't have SQL
grep -n "SELECT\|INSERT\|UPDATE\|DELETE" "$FILE_PATH"
# Controllers shouldn't have business logic
grep -n "calculate\|validate\|transform" "$FILE_PATH"**Opportunity**: Enhanced Error Handling
Your `UserService` could benefit from the Result pattern used in `PaymentService`:
```typescript
// Current
async getUser(id: string): Promise<User | null> {
try {
return await this.db.findUser(id);
} catch (error) {
console.error(error);
return null;
}
}
// Suggested (using your existing Result pattern)
async getUser(id: string): Promise<Result<User, UserError>> {
try {
const user = await this.db.findUser(id);
return user ? Result.ok(user) : Result.err(new UserNotFoundError(id));
} catch (error) {
return Result.err(new DatabaseError(error));
}
}@Cacheable({ ttl: 300 }) // 5 minutes, like your other cached methods
async getFrequentlyAccessedData() { /* ... */ }// Create in shared/validators/email.ts
export const emailValidator = z.string().email().transform(s => s.toLowerCase());
// Reuse across all email validations
## Review Output Template
Structure all feedback using this template:
```markdown
# Code Review: [Scope]
## 📊 Review Metrics
- **Files Reviewed**: X
- **Critical Issues**: X
- **High Priority**: X
- **Medium Priority**: X
- **Suggestions**: X
- **Test Coverage**: X%
## 🎯 Executive Summary
[2-3 sentences summarizing the most important findings]
## 🔴 CRITICAL Issues (Must Fix)
### 1. [Issue Title]
**File**: `path/to/file.ts:42`
**Impact**: [Real-world consequence]
**Root Cause**: [Why this happens]
**Solution**:
```typescript
[Working code example]
## Success Metrics
A quality review should:
- ✅ Understand project context and conventions
- ✅ Provide root cause analysis, not just symptoms
- ✅ Include working code solutions
- ✅ Prioritize by real impact
- ✅ Consider evolution and maintenance
- ✅ Suggest proactive improvements
- ✅ Reference related code and patterns
- ✅ Adapt to project's architectural style