Perform architectural review of uncommitted TypeScript code with quality checks and pragmatic improvement suggestions
Performs architectural review of uncommitted TypeScript code with quality checks and pragmatic improvement suggestions
/plugin marketplace add cliftonc/claude-plugins/plugin install ts-quality@cliftonc-pluginsThis command performs a comprehensive architectural review of uncommitted TypeScript code, combining quality checks with architectural analysis to provide concrete, pragmatic suggestions for improvement.
When invoked, this command:
git diff to find modified/new .ts/.tsx filespnpm typecheck)pnpm lint)pnpm build)/ts-review
Run this command before committing TypeScript changes to ensure both quality and good architectural design.
When this command is invoked, follow these steps:
Step 1: Find changed TypeScript files
# Get list of modified TypeScript files (both staged and unstaged)
{ git diff --name-only; git diff --cached --name-only; } | sort -u | grep -E '\.(ts|tsx)$'
# Also get untracked TypeScript files
git ls-files --others --exclude-standard | grep -E '\.(ts|tsx)$'
If no TypeScript files found:
Step 2: Check total diff size (for planning purposes)
# Count total lines changed (gives us a sense of changeset size)
{ git diff; git diff --cached; } | wc -l
If diff is larger than 1000 lines:
If diff is 1000 lines or less:
Execute quality checks sequentially, stopping at first failure:
pnpm typecheck && pnpm lint && pnpm build
If any check fails:
If all checks pass:
Use the Read tool to analyze all changed TypeScript files from step 1.
For each file in the list:
Build understanding:
Analyze the uncommitted code for:
SOLID Principles:
Common Issues to Flag:
File Organization:
Function/Method Design:
Class Design:
Type Quality:
any being abused? (should use unknown or proper types)Type Organization:
Error Handling:
Edge Cases:
Testability:
Maintainability:
Common Performance Issues:
Note: Only flag performance issues that are clearly problematic, not micro-optimizations.
For each issue found, provide:
src/auth/login.ts:45-67)Format each suggestion as:
### Issue: [Brief Title]
**Location:** `file/path.ts:line-range`
**Problem:**
[Clear description of what's wrong]
**Impact:**
[Why this matters - coupling, maintainability, bugs, performance]
**Suggestion:**
[Concrete steps to improve]
**Example:**
[Optional: before/after code snippet]
Organize suggestions by priority:
๐ด Critical (Fix Now):
๐ก Important (Fix Soon):
๐ข Nice to Have (Consider):
End with a summary:
## Summary
**Files Reviewed:** [count]
**Quality Checks:** โ All passed
**Issues Found:**
- ๐ด Critical: [count]
- ๐ก Important: [count]
- ๐ข Nice to Have: [count]
**Overall Assessment:**
[1-2 sentence summary of code quality]
**Top Priority:**
[Most important thing to address]
If the code is genuinely good:
## Review Complete
**Files Reviewed:** [count]
**Quality Checks:** โ All passed
**Architectural Issues:** None found
**Assessment:**
The uncommitted TypeScript code follows good architectural practices. The code is:
- Well-structured and organized
- Properly typed with good TypeScript usage
- Testable and maintainable
- Following SOLID principles appropriately
No changes recommended. Code is ready to commit.
If quality checks fail before architectural review:
## Quality Checks Failed
**Files Reviewed:** [count]
**Quality Check Status:** โ Failed
The following quality checks must pass before architectural review:
[Error output from failed checks]
Please fix these errors and run `/ts-review` again.
Some files good, some with issues - provide granular feedback per file.
# TypeScript Architectural Review
**Date:** 2025-01-15
**Uncommitted Files:** 3 TypeScript files
## Quality Checks
โ Type checking passed
โ Linting passed
โ Build passed
โ Tests passed (12/12)
---
## Architectural Review
### ๐ด Critical: God Class with Multiple Responsibilities
**Location:** `src/services/UserService.ts:15-250`
**Problem:**
The `UserService` class handles authentication, profile management, email notifications, and database operations. This violates the Single Responsibility Principle.
**Impact:**
- Difficult to test (must mock database, email, auth)
- Changes to email logic risk breaking authentication
- Class has 250 lines and growing
**Suggestion:**
Split into focused services:
1. `AuthService` - handles login/logout/tokens
2. `UserProfileService` - manages user profiles
3. `UserNotificationService` - sends user emails
4. `UserRepository` - database operations
Keep `UserService` as a facade if needed, delegating to specialized services.
**Example:**
```typescript
// Before: One class doing everything
class UserService {
login() { /* auth logic */ }
updateProfile() { /* profile logic */ }
sendEmail() { /* email logic */ }
saveToDb() { /* db logic */ }
}
// After: Focused services
class AuthService {
constructor(private userRepo: UserRepository) {}
login() { /* auth logic */ }
}
class UserProfileService {
constructor(
private userRepo: UserRepository,
private notificationService: UserNotificationService
) {}
updateProfile() { /* profile logic */ }
}
Location: src/api/PaymentProcessor.ts:45-89
Problem: Stripe API calls are made directly throughout the code with hardcoded endpoints and no abstraction layer.
Impact:
Suggestion:
Create a PaymentGateway interface and StripePaymentGateway implementation:
interface PaymentGateway {
processPayment(amount: number, token: string): Promise<PaymentResult>
refund(transactionId: string): Promise<RefundResult>
}
class StripePaymentGateway implements PaymentGateway {
// Stripe-specific implementation
}
// Easy to test with a mock
class MockPaymentGateway implements PaymentGateway {
// Test implementation
}
Location: src/types/api.ts:120-145
Problem: Inline type definition for API response is complex and reused in 3 places with slight variations.
Suggestion: Extract to a named type with generic parameter for variations:
type ApiResponse<T> = {
data: T
status: 'success' | 'error'
metadata: {
timestamp: number
requestId: string
}
}
Files Reviewed: 3 Quality Checks: โ All passed Issues Found:
Overall Assessment: Code quality is good, but the UserService class needs immediate refactoring to improve testability and maintainability.
Top Priority: Split UserService into focused services (AuthService, UserProfileService, etc.)
## Requirements
This command requires:
- **Git repository** - Uses git to identify uncommitted files
- **pnpm** - For running quality checks
- **TypeScript** - Configured in the project
- **Linter, build, test** - Same requirements as typescript-quality skill
## Related
- **typescript-quality skill** - Automatically enforces quality checks when modifying TypeScript files
- Use `/ts-review` for deeper architectural analysis before commits