# Advanced System Analyzer - API Documentation

## Base URL
```
http://localhost:5001/api/
```

## Authentication
Currently, no authentication is required for local access.

## Endpoints

### System Analysis

#### POST /api/system/analyze
Start comprehensive system analysis.

**Response:**
```json
{
  "status": "started",
  "message": "Analysis started successfully"
}
```

#### GET /api/system/health
Get quick system health check.

**Response:**
```json
{
  "system_info": {
    "hostname": "example-host",
    "os_name": "Linux",
    "os_version": "5.4.0",
    "architecture": "x86_64",
    "uptime": "2 days, 3:45:30"
  },
  "cpu_info": {
    "name": "Intel(R) Core(TM) i7-8700K",
    "usage_percent": 45.2,
    "cores": 6,
    "threads": 12,
    "frequency": 3700.0
  },
  "memory_info": {
    "total": 16777216000,
    "used": 8388608000,
    "available": 8388608000,
    "usage_percent": 50.0
  },
  "disk_info": [
    {
      "device": "/dev/sda1",
      "mountpoint": "/",
      "total": 250000000000,
      "used": 100000000000,
      "free": 150000000000,
      "usage_percent": 40.0
    }
  ],
  "health_analysis": {
    "overall_health": "Good",
    "issues": [],
    "recommendations": []
  }
}
```

#### GET /api/system/results
Get latest analysis results.

#### GET /api/system/status
Get current analysis status.

**Response:**
```json
{
  "is_running": false,
  "has_results": true,
  "last_update": "2025-06-21T22:00:00"
}
```

### System Maintenance

#### POST /api/system/cleanup
Perform system cleanup.

**Response:**
```json
{
  "timestamp": "2025-06-21T22:00:00",
  "operations": [
    "Cleaned /tmp: 150.25 MB",
    "Cleared apt package cache"
  ],
  "space_freed": 157286400,
  "errors": []
}
```

### Process Management

#### GET /api/system/processes
Get top processes by resource usage.

**Response:**
```json
{
  "processes": [
    {
      "pid": 1234,
      "name": "python",
      "cpu_percent": 15.2,
      "memory_percent": 8.5,
      "memory_rss": 104857600
    }
  ],
  "timestamp": "2025-06-21T22:00:00"
}
```

### Network Information

#### GET /api/system/network
Get network interface information.

**Response:**
```json
{
  "network": [
    {
      "interface": "eth0",
      "ip_address": "192.168.1.100",
      "mac_address": "00:11:22:33:44:55",
      "bytes_sent": 1048576,
      "bytes_recv": 2097152
    }
  ],
  "timestamp": "2025-06-21T22:00:00"
}
```

## WebSocket Events

### Connection
```javascript
const socket = io('http://localhost:5001');
```

### Events

#### analysis_complete
Emitted when system analysis is completed.

```javascript
socket.on('analysis_complete', function(data) {
  if (data.status === 'success') {
    console.log('Analysis results:', data.results);
  } else {
    console.error('Analysis failed:', data.error);
  }
});
```

#### status_update
Emitted when analysis status changes.

```javascript
socket.on('status_update', function(data) {
  console.log('Status:', data.is_running, data.has_results);
});
```

## Error Handling

All endpoints return appropriate HTTP status codes:

- `200` - Success
- `400` - Bad Request
- `404` - Not Found
- `500` - Internal Server Error

Error responses include an error message:

```json
{
  "error": "Description of the error"
}
```

## Rate Limiting

Currently, no rate limiting is implemented. Use responsibly.

## Support

For API support, contact:
- Phone: +31 61 380 3782
- Email: support@tel1.nl
- Website: www.tel1.nl
