Impact Analysis
Understand the ripple effects of code changes before you make them.
What is Impact Analysis?
Impact analysis answers the question: "If I change this file, what else will be affected?"
This helps you:
- Plan changes more carefully
- Identify required tests
- Avoid unexpected breakages
- Estimate effort for changes
Running Impact Analysis
Web Interface
- Select a project
- Click on a file in the visualization
- Click Analyze Impact
CLI
> /analyze src/services/user.ts
API
curl -X POST https://api.archicore.io/api/v1/projects/:id/analyze \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"path": "src/services/user.ts"}'
Understanding Results
Impact Analysis for src/services/user.ts
╭─────────────────────────────────────────╮
│ Direct Dependencies (5) │
├─────────────────────────────────────────┤
│ → src/utils/crypto.ts │
│ → src/db/models/user.ts │
│ → src/config/auth.ts │
│ → src/types/user.ts │
│ → src/utils/validation.ts │
╰─────────────────────────────────────────╯
╭─────────────────────────────────────────╮
│ Dependents - Will Be Affected (8) │
├─────────────────────────────────────────┤
│ ← src/controllers/auth.ts │
│ ← src/controllers/profile.ts │
│ ← src/controllers/admin.ts │
│ ← src/middleware/auth.ts │
│ ← src/services/session.ts │
│ ← src/api/routes/users.ts │
│ ← tests/user.test.ts │
│ ← tests/auth.test.ts │
╰─────────────────────────────────────────╯
Risk Level: MEDIUM
Affected Tests: 2
Impact Levels
| Level | Description | Action |
|---|---|---|
| Low | Few dependents, isolated change | Proceed with standard review |
| Medium | Multiple dependents, moderate risk | Thorough testing recommended |
| High | Many dependents, core module | Extensive testing, consider phased rollout |
| Critical | Affects critical paths | Extra review, feature flags recommended |
Simulating Changes
Preview the impact of a proposed change:
> /simulate
Describe your change: Adding a new parameter to UserService.getUser()
Simulation Results:
Files that need updates:
1. src/controllers/auth.ts:34 - calls getUser()
2. src/controllers/profile.ts:12 - calls getUser()
3. src/services/session.ts:45 - calls getUser()
Tests that need updates:
1. tests/user.test.ts - 5 test cases call getUser()
2. tests/auth.test.ts - 3 test cases call getUser()
Estimated effort: Medium (8 files, 15 call sites)
Best Practices
Before Making Changes
- Run impact analysis on files you plan to modify
- Review the dependency chain - understand the blast radius
- Identify affected tests - ensure they're updated
- Check for circular dependencies - they amplify impact
Reducing Impact
- Use interfaces - Depend on abstractions
- Apply SOLID principles - Single responsibility limits impact
- Decouple modules - Reduce direct dependencies
- Write facade layers - Shield implementation details
Example: Safe Refactoring
// Before: Direct dependency
// Changing User affects all consumers
class UserController {
constructor(private userService: UserService) {}
}
// After: Interface dependency
// Changing UserService implementation doesn't affect consumers
interface IUserService {
getUser(id: string): Promise<User>;
}
class UserController {
constructor(private userService: IUserService) {}
}
Integration with CI/CD
Add impact analysis to your pipeline:
# .gitlab-ci.yml
impact-analysis:
script:
- archicore analyze --changed-files
- if [ $IMPACT_LEVEL == "critical" ]; then
echo "Critical impact detected - requires additional review";
exit 1;
fi