Revisão de Código
Cenários reais para revisar e melhorar código.
Revisão de PR
Objetivo: Revisar mudanças antes de fazer o merge.
Comando:
Review the changes in src/modules/auth/O que acontece:
- Analisa todos os arquivos alterados
- Verifica conformidade com a spec
- Verifica qualidade de código
- Verifica padrões de arquitetura
- Emite um veredicto
Resultado:
Review: src/modules/auth/
Spec Compliance: PASS
✓ Login functionality works
✓ Token refresh implemented
✓ Logout clears state
Code Quality: PASS
✓ No TypeScript errors
✓ Tests pass
✓ No console.logs
Architecture: WARN
⚠ auth-service.ts:15 — Try/catch should be at boundary, not in service
⚠ useAuth.ts:42 — Missing error handling for refresh failure
Verdict: APPROVED WITH NOTES
Fix the 2 warnings before deploying to production.Verificação de Arquitetura
Objetivo: Verificar se o código segue os padrões de arquitetura.
Comando:
Check architecture of the orders moduleO que acontece:
- Lê o ARCHITECTURE.md
- Verifica a estrutura de pastas
- Verifica a separação de camadas
- Valida as importações
Resultado:
Architecture Check: orders module
Structure: PASS
✓ types/ contains only type definitions
✓ services/ contains only HTTP calls
✓ adapters/ contains only transformations
Layer Separation: PASS
✓ Components don't import services directly
✓ Services don't contain business logic
✓ No circular dependencies
Violations: 1 found
✗ OrderList.tsx imports ordersService directly
Should use useOrders hook instead
Overall: 95% compliantRefatorar Código
Objetivo: Limpar código bagunçado ou duplicado.
Comando:
Refactor src/utils/helpers.ts — it has too many responsibilitiesO que acontece:
- Analisa o arquivo
- Identifica code smells
- Sugere um plano de refatoração
- Aplica as mudanças
Resultado:
Analysis: helpers.ts (450 lines)
Issues Found:
- 15 unrelated functions in one file
- 3 functions duplicated with slight variations
- 2 functions over 50 lines
Refactoring Plan:
1. Extract date functions → utils/date.ts
2. Extract format functions → utils/format.ts
3. Extract validation → utils/validation.ts
4. Merge duplicates
5. Split long functions
After:
utils/
├── date.ts (45 lines)
├── format.ts (60 lines)
├── validation.ts (80 lines)
└── index.ts (re-exports)Revisão de Segurança
Objetivo: Verificar problemas de segurança.
Comando:
Review the checkout flow for security issuesO que acontece:
- Verifica o OWASP top 10
- Revisa autenticação e autorização
- Verifica o tratamento de dados
- Revisa a segurança da API
Resultado:
Security Review: Checkout Flow
CRITICAL (fix immediately):
✗ checkout-service.ts:25 — Credit card number logged
✗ payment-form.tsx:18 — Card data in component state
HIGH:
✗ No rate limiting on payment attempts
✗ Missing CSRF token on form submission
MEDIUM:
⚠ PCI compliance: Card data should never touch your servers
Use Stripe.js or similar to tokenize client-side
Recommendations:
1. Remove all card logging
2. Use payment provider's hosted fields
3. Add rate limiting (3 attempts per minute)
4. Add CSRF protectionRevisão de Performance
Objetivo: Encontrar gargalos de performance.
Comando:
Review the dashboard for performance issuesO que acontece:
- Analisa renders de componentes
- Verifica o data fetching
- Revisa o impacto no bundle
- Identifica otimizações
Resultado:
Performance Review: Dashboard
Render Issues:
⚠ MetricsCard re-renders 12x on data load
Fix: Wrap with memo, stabilize props
⚠ ChartWidget creates new function on every render
Fix: Use useCallback for event handlers
Data Fetching:
⚠ 8 separate API calls on mount
Fix: Combine into single dashboard endpoint or use parallel queries
⚠ No staleTime set — refetches on every focus
Fix: Add staleTime: 5 * 60 * 1000 (5 min)
Bundle:
⚠ chart.js adds 180KB
Fix: Dynamic import, load only when needed
Estimated Impact:
- Initial load: 2.4s → 1.1s (-54%)
- Time to interactive: 3.8s → 2.2s (-42%)Dicas Rápidas
Delimite o Escopo da Revisão
# Revisar tudo (lento, custoso)
Review the entire codebase
# Revisar área específica (rápido, focado)
Review src/modules/payments/
# Revisar apenas mudanças recentes
Review the files I changed todayFaça Perguntas Específicas
# Genérico (menos útil)
Review this code
# Específico (mais útil)
Review this code for:
- SQL injection vulnerabilities
- Missing error handling
- N+1 query problemsDê Seguimento
Após a revisão:
Fix the security issues found in the reviewCenários Relacionados
- Construindo Features — Construir código para revisar
- Depurar Problemas — Quando a revisão encontra bugs
- Segurança — Auditoria de segurança aprofundada