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

# Applications

# Applications API Reference

Deploy, manage, and monitor applications across your infrastructure with the Applications API. Supports Docker, binary/systemd, Kubernetes (Helm via [basic-service](https://github.com/O1ahmad/basic-service)), and dual-mode (Docker + binary) deployments with comprehensive lifecycle management.

## Endpoints Overview

| Method | Endpoint                                               | Description             |
| ------ | ------------------------------------------------------ | ----------------------- |
| GET    | `/api/applications`                                    | List all applications   |
| POST   | `/api/applications/create`                             | Create new application  |
| PUT    | `/api/applications/edit`                               | Edit application        |
| GET    | `/api/applications/{applicationName}`                  | Get application details |
| GET    | `/api/applications/{applicationName}/deployment-modes` | Get deployment modes    |
| POST   | `/api/applications/deploy`                             | Deploy application      |
| POST   | `/api/applications/deployments/rerun`                  | Rerun deployment        |
| POST   | `/api/applications/uninstall`                          | Uninstall application   |

## Application Management

### List All Applications

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
GET /api/applications
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "applications": {
    "Anvil": {
      "name": "Anvil",
      "basic_info": {
        "description": "A fast local Ethereum development node from Foundry",
        "iconUrl": "https://example.com/icons/anvil.png"
      },
      "tags": ["blockchain", "ethereum", "development"],
      "installation": {
        "setup_type": "dual",
        "binary": {
          "url": "https://github.com/foundry-rs/foundry/releases/download/v1.0.0/anvil-linux-amd64",
          "executable": "anvil",
          "versions": ["1.0.0", "1.1.0", "1.2.0"]
        },
        "docker": {
          "image": "ghcr.io/foundry-rs/foundry:latest",
          "versions": ["latest", "1.0.0", "1.1.0"]
        }
      },
      "configuration": {
        "config_files": [
          {
            "filename": "config.yaml",
            "content": "server:\n  port: {port}\n  host: {host}",
            "destinationPath": "/etc/anvil/config.yaml"
          }
        ],
        "environment_variables": [
          {
            "key": "ANVIL_IP_ADDR",
            "value": "{anvil_host}"
          }
        ]
      }
    }
  }
}
```

### Create Application

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /api/applications/create
```

**Request Body (JSON):**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "name": "Anvil",
  "basic_info": {
    "description": "A fast local Ethereum development node from Foundry"
  },
  "installation": {
    "setup_type": "dual",
    "binary": {
      "url": "https://github.com/foundry-rs/foundry/releases/download/v1.0.0/anvil-linux-amd64",
      "executable": "anvil"
    },
    "docker": {
      "image": "ghcr.io/foundry-rs/foundry:latest"
    }
  }
}
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": true,
  "message": "Application created successfully"
}
```

### Get Application Details

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
GET /api/applications/{applicationName}
```

**Parameters:**

* `applicationName` (path): Name of the application

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": true,
  "application": {
    "name": "Anvil",
    "basic_info": {
      "description": "A fast local Ethereum development node from Foundry"
    },
    "installation": {
      "setup_type": "dual",
      "binary": {
        "url": "https://github.com/foundry-rs/foundry/releases/download/v1.0.0/anvil-linux-amd64",
        "executable": "anvil",
        "versions": ["1.0.0", "1.1.0", "1.2.0"]
      },
      "docker": {
        "image": "ghcr.io/foundry-rs/foundry:latest",
        "versions": ["latest", "1.0.0", "1.1.0"]
      }
    }
  }
}
```

## Deployment Management

### Get Deployment Modes

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
GET /api/applications/{applicationName}/deployment-modes
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "isDualMode": true,
  "availableModes": ["docker", "binary"],
  "defaultMode": "binary",
  "versions": {
    "docker": ["latest", "1.0.0", "1.1.0"],
    "binary": ["1.0.0", "1.1.0", "1.2.0"],
    "kubernetes": []
  }
}
```

For Kubernetes-only applications (`setup_type: kubernetes`), `availableModes` is `["kubernetes"]` and the backend generates Helm values for the basic-service role (`setup_mode: k8s`).

**Example Kubernetes installation block:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "installation": {
    "setup_type": "kubernetes",
    "kubernetes": {
      "image": "nginx:1.25",
      "versions": ["1.25.0"],
      "helm_namespace": "default",
      "cluster_name": "my-eks-cluster"
    }
  }
}
```

Ensure the target node has `kubectl` access (`KUBECONFIG` / `KUBE_CONTEXT` as required by basic-service).

### Deploy Application

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /api/applications/deploy
```

**Request Body (JSON):**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "applicationName": "Anvil",
  "nodeName": "test-anvil-01",
  "version": "1.0.0",
  "deploymentMode": "binary",
  "variables": {
    "anvil_port": 8545,
    "accounts": 10
  },
  "deploymentId": "deploy-20240115-103000"
}
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": true,
  "deploymentId": "deploy-20240115-103000",
  "message": "Deployment started"
}
```

### Rerun Deployment

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /api/applications/deployments/rerun
```

**Request Body (JSON):**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "deploymentId": "deploy-20240115-103000",
  "newDeploymentId": "deploy-20240116-140000",
  "applicationName": "Anvil",
  "nodeName": "test-anvil-01"
}
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": true,
  "message": "Deployment rerun started",
  "deploymentId": "deploy-20240116-140000",
  "node": "test-anvil-01",
  "playbookPath": "/playbooks/anvil/deploy.yml",
  "originalDeploymentId": "deploy-20240115-103000"
}
```

### Uninstall Application

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /api/applications/uninstall
```

**Request Body (JSON):**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "applicationName": "Anvil",
  "nodeName": "test-anvil-01",
  "deploymentMode": "binary"
}
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": true,
  "message": "Application uninstalled successfully"
}
```

## Deployment History & Monitoring

### Get Deployment History

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
GET /api/applications/{applicationName}/deployments
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
[
  {
    "deployment_id": "deploy-20240115-103000",
    "applicationName": "Anvil",
    "nodeName": "test-anvil-01",
    "version": "1.0.0",
    "deploymentMode": "binary",
    "status": "completed",
    "startTime": "2024-01-15T10:30:00Z",
    "endTime": "2024-01-15T10:35:00Z",
    "variables": {
      "anvil_port": 8545,
      "accounts": 10
    },
    "logs": [
      {
        "timestamp": "2024-01-15T10:30:00Z",
        "type": "info",
        "message": "Starting deployment"
      },
      {
        "timestamp": "2024-01-15T10:35:00Z",
        "type": "status",
        "message": "Deployment completed successfully"
      }
    ]
  }
]
```

## Advanced Features

### Fetch Versions (Auto-detection)

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /api/applications/fetch-versions
```

**Request Body (JSON):**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "url": "https://api.github.com/repos/foundry-rs/foundry/releases",
  "key": "[].tag_name"
}
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "versions": ["v1.0.0", "v1.1.0", "v1.2.0"]
}
```

### Update Deployment Mode

```bash theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
PATCH /api/applications/{applicationName}/nodes/{nodeName}/deployment-mode
```

**Request Body (JSON):**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "deploymentMode": "binary"
}
```

**Response:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": true,
  "message": "Deployment mode updated from docker to binary",
  "data": {
    "applicationName": "Anvil",
    "nodeName": "test-anvil-01",
    "oldMode": "docker",
    "newMode": "binary"
  }
}
```

## Error Responses

Common error responses for Applications API:

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": false,
  "error": "Application not found",
  "details": {
    "applicationName": "non-existent-app"
  }
}
```

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": false,
  "error": "Deployment failed",
  "details": {
    "deploymentId": "deploy-20240115-103000",
    "nodeName": "test-anvil-01",
    "output": "SSH connection failed"
  }
}
```

## Best Practices

### Deployment Strategies

* Use dual-mode applications when possible for flexibility
* Test deployments in staging before production
* Implement proper rollback procedures
* Monitor deployment health and performance

### Configuration Management

* Use environment-specific variables
* Implement proper secret management
* Version control configuration files
* Test configuration changes in isolation

### Monitoring & Observability

* Set up comprehensive logging
* Implement health checks and monitoring
* Monitor resource usage and performance
* Set up alerting for critical issues

For detailed schema definitions, refer to the OpenAPI specification published alongside the backend service.
