Skip to main content

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
  • 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

RuleDescription
no-circular-depsPrevents circular dependencies
max-complexityLimits cyclomatic complexity
max-file-lengthLimits file size
naming-conventionEnforces 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

  1. Run analysis regularly - Catch issues early
  2. Define architecture rules - Prevent violations
  3. Review complexity - Refactor hotspots
  4. Monitor trends - Track metrics over time