---
title: "Xec Recipes Cookbook"
description: "Practical recipes and real-world examples for common Xec use cases"
---

# Xec Recipes Cookbook

Welcome to the Xec Recipes Cookbook - a collection of adaptable recipes for common automation tasks using Xec's universal command execution system.

## 📚 Recipe Categories

### 🚀 [Deployment](/docs/recipes/deployment/node-app-deploy)

Deployment strategies and explicit acceptance checks

- **[Node.js Application Deployment](/docs/recipes/deployment/node-app-deploy)** - Deploy Node.js applications with a reviewed transition
- **[Static Site Deployment](/docs/recipes/deployment/static-site-deploy)** - Deploy to CDNs, S3, Nginx, and more
- **[Docker Container Deployment](/docs/recipes/deployment/docker-deploy)** - Container orchestration and management
- **[Kubernetes Deployment](/docs/recipes/deployment/k8s-deploy)** - Deploy to Kubernetes clusters with Helm

### 🔧 [Maintenance](/docs/recipes/maintenance/backup-restore)

System maintenance and operational excellence

- **[Log Aggregation](/docs/recipes/maintenance/log-aggregation)** - Inspect sources and verify centralized delivery
- **[Backup and Restore](/docs/recipes/maintenance/backup-restore)** - Comprehensive backup strategies
- **[Health Checks](/docs/recipes/maintenance/health-checks)** - Service monitoring and alerting
- **[Certificate Renewal](/docs/recipes/maintenance/certificate-renewal)** - SSL/TLS certificate management

### 💻 [Development](/docs/recipes/development/database-setup)

Development workflows and environment setup

- **[Database Setup](/docs/recipes/development/database-setup)** - Local database configuration
- **[API Mocking](/docs/recipes/development/api-mocking)** - Mock servers for development
- **[Test Data Generation](/docs/recipes/development/test-data)** - Generate deterministic test fixtures
- **[Hot Reload Workflows](/docs/recipes/development/hot-reload)** - Live development with hot reload

### 🔌 [Integration](/docs/recipes/integration/github-actions)

Third-party service and tool integrations

- **[GitHub Actions](/docs/recipes/integration/github-actions)** - CI/CD with GitHub Actions
- **[GitLab CI](/docs/recipes/integration/gitlab-ci)** - GitLab CI/CD pipelines
- **[Jenkins](/docs/recipes/integration/jenkins)** - Jenkins automation
- **[AWS Services](/docs/recipes/integration/aws-integration)** - AWS service integration

## 🎯 How to Use This Cookbook

### Recipe Structure

Each recipe follows a consistent structure:

1. **Problem** - The challenge being addressed
2. **Solution** - How Xec solves it
3. **Quick Example** - Minimal working example
4. **Complete Recipe** - Full implementation with all details
5. **Usage Examples** - Common usage patterns
6. **Best Practices** - Recommended approaches
7. **Troubleshooting** - Common issues and solutions
8. **Related Topics** - Links to related recipes

### Code Verification

JavaScript and TypeScript examples are checked against Xec's public types. Commands that use remote services, databases or cloud providers also require the named tools, credentials and application-owned scripts. Type checking does not establish a production deployment or restore guarantee: run each recipe's acceptance checks in the intended environment.

### Getting Started

1. **Choose a recipe** that matches your use case
2. **Copy the configuration** to your `.xec/config.yaml`
3. **Adapt the scripts** to your specific needs
4. **Run the commands** as shown in the usage examples

## 🔍 Finding the Right Recipe

### By Use Case

**Deploying Applications:**

- Web applications → [Node.js Deployment](/docs/recipes/deployment/node-app-deploy)
- Static websites → [Static Site Deployment](/docs/recipes/deployment/static-site-deploy)
- Containerized apps → [Docker Deployment](/docs/recipes/deployment/docker-deploy)
- Microservices → [Kubernetes Deployment](/docs/recipes/deployment/k8s-deploy)

**Managing Infrastructure:**

- Log management → [Log Aggregation](/docs/recipes/maintenance/log-aggregation)
- Data protection → [Backup and Restore](/docs/recipes/maintenance/backup-restore)
- Monitoring → [Health Checks](/docs/recipes/maintenance/health-checks)
- SSL certificates → [Certificate Renewal](/docs/recipes/maintenance/certificate-renewal)

**Development Workflows:**

- Local development → [Hot Reload](/docs/recipes/development/hot-reload)
- Database setup → [Database Setup](/docs/recipes/development/database-setup)
- API development → [API Mocking](/docs/recipes/development/api-mocking)
- Testing → [Test Data Generation](/docs/recipes/development/test-data)

**CI/CD Automation:**

- GitHub → [GitHub Actions](/docs/recipes/integration/github-actions)
- GitLab → [GitLab CI](/docs/recipes/integration/gitlab-ci)
- Jenkins → [Jenkins Integration](/docs/recipes/integration/jenkins)
- AWS → [AWS Integration](/docs/recipes/integration/aws-integration)

### By Technology

**Container Technologies:**

- Docker → [Docker Deployment](/docs/recipes/deployment/docker-deploy)
- Kubernetes → [Kubernetes Deployment](/docs/recipes/deployment/k8s-deploy)
- Docker Compose → See Docker Deployment recipes

**Cloud Platforms:**

- AWS → [AWS Integration](/docs/recipes/integration/aws-integration), [Static Site Deployment](/docs/recipes/deployment/static-site-deploy)
- Google Cloud → See Kubernetes and Docker recipes
- Azure → Adaptable from AWS patterns

**Databases:**

- PostgreSQL → [Backup and Restore](/docs/recipes/maintenance/backup-restore)
- MySQL → [Database Setup](/docs/recipes/development/database-setup)
- MongoDB → [Database Setup](/docs/recipes/development/database-setup)
- Redis → [Database Setup](/docs/recipes/development/database-setup)

## 💡 Common Patterns

### Parallel Execution

```typescript
const hosts = ['web-1.example.com', 'web-2.example.com'];
const results = await $.parallel.map(hosts,
  host => $.ssh({ host, username: 'observer' })`hostname`,
  { maxConcurrency: 2 });
for (const result of results.results) {
  if (result instanceof Error) throw result;
  console.log(result.stdout.trim());
}
```

### Error Handling

```typescript
const result = await $`node --version`.nothrow();
if (!result.ok) throw new Error(`Runtime probe failed: ${result.cause}`);
console.log(result.stdout.trim());
```

### Progress Tracking

```typescript
import { Pipeline } from '@xec-sh/ops';
const result = await Pipeline.create('validate')
  .step('runtime', { run: 'node --version' })
  .step('package-manager', { run: 'npm --version', dependsOn: ['runtime'] })
  .run({}, { onEvent: event => { console.log(event); } });
if (result.status !== 'success') throw new Error(`Validation ${result.status}`);
```

### Connection Reuse

```typescript
const server = $.ssh({ host: 'staging.example.com', username: 'observer' });
await server`hostname`;
await server`uptime`;
```

## 📝 Contributing Recipes

We welcome contributions! To add a new recipe:

1. **Follow the structure** - Use existing recipes as templates
2. **Test your code** - Ensure all examples work
3. **Document thoroughly** - Include all necessary details
4. **Reference implementations** - Link to actual Xec source files
5. **Submit a PR** - Include a description of the use case

## 🔗 Quick Links

- [Xec Core Documentation](/docs/core/execution-engine/overview)
- [Command Reference](/docs/commands/overview)
- [Configuration Guide](/docs/configuration/overview)
- [Core Concepts](/docs/introduction/core-concepts)

## 📊 Recipe Statistics

The cookbook groups recipes into deployment, maintenance, development and integration. The examples use shared Xec execution, configuration and lifecycle APIs; application-specific schemas and service policies remain explicit inputs.

## 🚦 Recipe Maturity

Choose acceptance criteria for the actual target: a successful process exit, healthy container, reachable HTTP endpoint and validated application data are separate guarantees. Adapt and test the selected recipe before enabling automated production changes. Preserve a recovery path appropriate to the data and service being changed.

## 🎓 Learning Path

### Beginner

1. Start with [Hot Reload](/docs/recipes/development/hot-reload) for local development
2. Learn [Static Site Deployment](/docs/recipes/deployment/static-site-deploy)
3. Explore [GitHub Actions](/docs/recipes/integration/github-actions) integration

### Intermediate

1. Master [Node.js Deployment](/docs/recipes/deployment/node-app-deploy)
2. Implement [Log Aggregation](/docs/recipes/maintenance/log-aggregation)
3. Setup [Backup and Restore](/docs/recipes/maintenance/backup-restore)

### Advanced

1. Deploy with [Docker](/docs/recipes/deployment/docker-deploy)
2. Orchestrate with [Kubernetes](/docs/recipes/deployment/k8s-deploy)
3. Build complete CI/CD pipelines

## 🆘 Getting Help

- **Documentation**: Check the detailed documentation for each recipe
- **Examples**: Look at the complete examples in each recipe
- **Troubleshooting**: Each recipe includes a troubleshooting section
- **Support**: Open an issue for recipe-specific problems

***

*This cookbook is continuously updated with new recipes and improvements. All recipes are tested against the current Xec implementation and follow the surgical precision requirement for documentation accuracy.*