Architecture Analysis
Learn how to use ArchiCore to understand and improve your codebase architecture.
Overview
ArchiCore analyzes your code structure to identify:
- Module dependencies
- Circular dependencies
- Layer violations
- Code complexity hotspots
- Architecture patterns
Visualization
Dependency Graph
The main dashboard shows an interactive dependency graph:
- Nodes represent files or modules
- Edges represent imports/dependencies
- Colors indicate module types or health
- Size reflects file complexity
Navigation
- Zoom with mouse wheel
- Pan by dragging
- Click nodes to see details
- Double-click to focus on a module
Architecture Rules
Define rules to enforce architectural boundaries.
Creating Rules
// .archicore/rules.json
{
"rules": [
{
"id": "layer-separation",
"name": "Layer Separation",
"type": "import",
"severity": "error",
"config": {
"forbidden": [
{
"from": "controllers/*",
"to": "repositories/*",
"message": "Controllers should not access repositories directly"
}
]
}
}
]
}
Built-in Rules
| Rule | Description |
|---|---|
no-circular-deps | Prevents circular dependencies |
max-complexity | Limits cyclomatic complexity |
max-file-length | Limits file size |
naming-convention | Enforces naming standards |
Validating Rules
> /rules validate
Validating architecture rules...
✓ no-circular-deps: PASSED
✗ layer-separation: FAILED (2 violations)
- src/controllers/user.ts:5 imports src/repositories/user.ts
- src/controllers/product.ts:3 imports src/repositories/product.ts
Bounded Contexts
Define logical boundaries in your application:
// .archicore/architecture.json
{
"boundedContexts": [
{
"name": "Authentication",
"description": "User authentication and sessions",
"paths": ["src/auth/*", "src/middleware/auth*"]
},
{
"name": "Products",
"description": "Product catalog management",
"paths": ["src/products/*", "src/inventory/*"]
}
]
}
Metrics
Complexity Metrics
- Cyclomatic Complexity - Number of independent paths
- Cognitive Complexity - How hard code is to understand
- Maintainability Index - Overall maintainability score
Identifying Hotspots
> /metrics --sort complexity
Code Complexity Hotspots:
1. src/services/order.ts:processOrder()
Complexity: 25 | Lines: 180 | Maintainability: 45
2. src/utils/parser.ts:parseInput()
Complexity: 18 | Lines: 120 | Maintainability: 52
3. src/api/handlers.ts:handleRequest()
Complexity: 15 | Lines: 95 | Maintainability: 58
Refactoring Suggestions
ArchiCore can suggest refactoring opportunities:
> /refactoring src/services/order.ts
Refactoring Suggestions for src/services/order.ts:
1. Extract Method
processOrder() is too complex (25)
Suggestion: Extract validation logic to validateOrder()
2. Split File
File has 180 lines with multiple responsibilities
Suggestion: Split into OrderProcessor and OrderValidator
3. Reduce Dependencies
File imports 12 modules
Suggestion: Consider facade pattern to reduce coupling
Best Practices
- Run analysis regularly - Catch issues early
- Define architecture rules - Prevent violations
- Review complexity - Refactor hotspots
- Monitor trends - Track metrics over time