> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zenable.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Legacy Code Assessment

> Automated deep-dive analysis maps dependencies, identifies risks, and creates implementation roadmaps

## Overview

Understanding and modernizing legacy systems requires months of manual analysis. Zenable provides automated deep-dive analysis that maps dependencies, identifies risks, and creates implementation roadmaps - giving you complete understanding of tech debt in hours, not months.

## Out-of-the-Box Analysis

Zenable automatically detects these legacy code issues:

<Card title="Standard Legacy Code Checks" icon="magnifying-glass">
  * **Code Smells** - Deep nesting, long methods, duplicate code
  * **Outdated Patterns** - Deprecated APIs, obsolete libraries
  * **Security Vulnerabilities** - SQL injection, hardcoded secrets, weak crypto
  * **Technical Debt** - Missing tests, poor documentation, cyclomatic complexity
  * **Dead Code** - Unused functions, unreachable code
  * **Performance Issues** - N+1 queries, inefficient algorithms
</Card>

## Custom Organization Requirements

Apply your specific modernization criteria:

> "All legacy code must be migrated to our new microservices architecture, use our internal authentication service, follow our naming conventions, and include telemetry with our monitoring stack."

## In Action

```bash theme={null}
# Run a comprehensive assessment, including custom requirements
zenable check '**/*'
```

## Custom Modernization Examples

### Example: Microservices Migration

**Your Policy:** "All monolithic components must be refactored into domain-bounded microservices"

```python expandable theme={null}
# ❌ Legacy monolith
class UserService:
    def create_user(self, data):
        user = self.validate_user(data)
        self.send_email(user.email)  # Mixing concerns
        self.update_inventory(user)  # Unrelated domain
        self.log_analytics(user)     # Another concern
        return user

# ✅ Zenable suggests microservices refactor
class UserService:
    def create_user(self, data):
        user = self.validate_user(data)
        event_bus.publish("user.created", user)
        return user

# Separate services handle their domains
# EmailService, InventoryService, AnalyticsService
```

### Example: Internal Standards Migration

**Your Policy:** "Replace all direct database calls with our DataAccess layer"

```javascript theme={null}
// ❌ Legacy direct DB access
function getUser(id) {
    const result = db.query(`SELECT * FROM users WHERE id = ${id}`);
    return result[0];
}

// ✅ Zenable enforces your data layer
function getUser(id) {
    return DataAccess.users.findById(id, {
        cache: true,
        metrics: true,
        audit: true
    });
}
```

### Example: Tech Stack Modernization

**Your Policy:** "Migrate from jQuery to React, replace callback patterns with async/await"

```javascript expandable theme={null}
// ❌ Legacy jQuery code
$(document).ready(function() {
    $.ajax({
        url: '/api/data',
        success: function(data) {
            $('#result').html(data);
        }
    });
});

// ✅ Zenable suggests modern React
import { useState, useEffect } from 'react';

function DataComponent() {
    const [data, setData] = useState(null);

    useEffect(() => {
        const fetchData = async () => {
            const response = await fetch('/api/data');
            setData(await response.json());
        };
        fetchData();
    }, []);

    return <div>{data}</div>;
}
```

### Example: Observability Requirements

**Your Policy:** "All legacy code must add distributed tracing and structured logging"

```python expandable theme={null}
# ❌ Legacy without observability
def process_payment(amount):
    result = payment_gateway.charge(amount)
    return result

# ✅ Zenable adds your observability
from opentelemetry import trace
from structlog import get_logger

tracer = trace.get_tracer(__name__)
logger = get_logger()

def process_payment(amount):
    with tracer.start_as_current_span("process_payment") as span:
        span.set_attribute("payment.amount", amount)

        logger.info("payment.started", amount=amount)
        result = payment_gateway.charge(amount)

        logger.info("payment.completed",
                   amount=amount,
                   transaction_id=result.id)

        return result
```

## Benefits

* **Complete Tech Debt Understanding** - Know exactly what needs modernization
* **Custom Migration Path** - Enforce your specific architectural standards
* **Risk-Based Prioritization** - Focus on critical issues first
* **Accelerated Modernization** - Move from months to hours of analysis

## Related Use Cases

* [Security Assessment](/use-cases/security-assessment) - Deep security analysis
* [Policy as Code](/use-cases/policy-as-code) - Prevent future technical debt
* [Starting New Projects](/use-cases/starting-new-project) - Build with modern standards
