Back to N8n Workflows

šŸ¤– AI Automation Stack

ai-stack/README.md

latest10.3 KB
Original Source

šŸ¤– AI Automation Stack

Turnkey Local AI Automation: n8n + Agent Zero + ComfyUI

A single-command deployable stack for AI-powered workflow automation with image generation capabilities.


šŸ“š Documentation

šŸ‘‰ START HERE: Documentation Index - Choose the right guide for you!


šŸŽÆ What's Included

ServicePurposePortURL
n8nWorkflow automation engine (the conductor)5678http://localhost:5678
Agent ZeroAI agent runtime & planning UI50080http://localhost:50080
ComfyUIAI image/video generation8188http://localhost:8188

šŸš€ Quick Start

Prerequisites

One-Command Launch

Windows (PowerShell):

powershell
.\start.ps1

Linux/macOS:

bash
chmod +x start.sh
./start.sh

That's it! The script will:

  1. āœ… Check Docker is installed and running
  2. āœ… Detect GPU availability
  3. āœ… Create all necessary directories
  4. āœ… Pull the latest images
  5. āœ… Start all services
  6. āœ… Display access URLs

šŸ“ Directory Structure

ai-stack/
ā”œā”€ā”€ docker-compose.yml      # Main stack configuration
ā”œā”€ā”€ .env                    # Environment variables
ā”œā”€ā”€ start.ps1               # Windows startup script
ā”œā”€ā”€ start.sh                # Linux/macOS startup script
ā”œā”€ā”€ README.md               # This file
│
ā”œā”€ā”€ data/                   # Persistent data (auto-created)
│   ā”œā”€ā”€ n8n/                # n8n workflows & credentials
│   └── agent-zero/         # Agent Zero data
│
ā”œā”€ā”€ shared/                 # Shared between all services
│   ā”œā”€ā”€ comfyui/
│   │   ā”œā”€ā”€ models/         # AI models (checkpoints, LoRAs, etc.)
│   │   │   ā”œā”€ā”€ checkpoints/
│   │   │   ā”œā”€ā”€ loras/
│   │   │   ā”œā”€ā”€ vae/
│   │   │   ā”œā”€ā”€ controlnet/
│   │   │   └── embeddings/
│   │   ā”œā”€ā”€ output/         # Generated images
│   │   ā”œā”€ā”€ input/          # Input images
│   │   └── custom_nodes/   # ComfyUI extensions
│   └── workflows/          # Shared workflow files
│
└── workflows/              # Pre-built n8n workflows
    ā”œā”€ā”€ comfyui-image-generation.json
    └── comfyui-simple-test.json

šŸ”§ Commands

Windows (PowerShell)

powershell
.\start.ps1              # Start the stack
.\start.ps1 -Stop        # Stop the stack
.\start.ps1 -Logs        # View logs
.\start.ps1 -Status      # Check status
.\start.ps1 -NoPull      # Start without pulling images
.\start.ps1 -CPU         # Force CPU mode (no GPU)

Linux/macOS

bash
./start.sh               # Start the stack
./start.sh --stop        # Stop the stack
./start.sh --logs        # View logs
./start.sh --status      # Check status
./start.sh --no-pull     # Start without pulling images
./start.sh --cpu         # Force CPU mode (no GPU)

Docker Compose (Direct)

bash
docker compose up -d     # Start
docker compose down      # Stop
docker compose logs -f   # View logs
docker compose ps        # Status

šŸŽØ Adding Models to ComfyUI

Place your models in the appropriate directories:

Model TypeDirectory
Stable Diffusion checkpointsshared/comfyui/models/checkpoints/
LoRA modelsshared/comfyui/models/loras/
VAE modelsshared/comfyui/models/vae/
ControlNet modelsshared/comfyui/models/controlnet/
Upscale modelsshared/comfyui/models/upscale_models/
Embeddingsshared/comfyui/models/embeddings/

Download SD 1.5 and place it in shared/comfyui/models/checkpoints/.


šŸ“Š Pre-built Workflows

1. ComfyUI Image Generation Pipeline

File: workflows/comfyui-image-generation.json

A complete webhook-triggered image generation pipeline:

  1. Import the workflow into n8n
  2. Activate the workflow
  3. Send a POST request:
bash
curl -X POST http://localhost:5678/webhook/generate-image \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "a cyberpunk city at night, neon lights, rain, highly detailed",
    "negative_prompt": "blurry, low quality",
    "steps": 20,
    "cfg": 7,
    "width": 512,
    "height": 512
  }'

2. ComfyUI Simple Test

File: workflows/comfyui-simple-test.json

A simple connectivity test:

  1. Import and activate in n8n
  2. Visit: http://localhost:5678/webhook/comfyui-status
  3. Should return ComfyUI system stats

šŸ”— Integration Architecture

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│                         n8n (Conductor)                         │
│                      http://localhost:5678                      │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
                      │                       │
                      ā–¼                       ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│       Agent Zero            │ │           ComfyUI               │
│   http://localhost:50080    │ │     http://localhost:8188       │
│                             │ │                                 │
│  • AI planning/reasoning    │ │  • POST /prompt (queue job)     │
│  • Tool use decisions       │ │  • GET /history/{id} (results)  │
│  • Prompt optimization      │ │  • GET /view (retrieve images)  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
                      │                       │
                      ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
                                  ā–¼
                    ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
                    │    Shared Volume        │
                    │      ./shared/          │
                    │                         │
                    │  • ComfyUI outputs      │
                    │  • Shared workflows     │
                    │  • Cross-service data   │
                    ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Typical Workflow Loop

  1. Trigger: n8n receives webhook/schedule/event
  2. Plan (optional): n8n calls Agent Zero for decision-making
  3. Generate: n8n submits workflow to ComfyUI POST /prompt
  4. Poll: n8n checks GET /history/{prompt_id} until complete
  5. Deliver: n8n retrieves output and sends to destination

🌐 ComfyUI API Reference

Queue a Generation

bash
POST http://comfyui:8188/prompt
Content-Type: application/json

{
  "prompt": { /* ComfyUI workflow JSON */ }
}

Response:

json
{
  "prompt_id": "abc123-def456-..."
}

Check Status

bash
GET http://comfyui:8188/history/{prompt_id}

Get Queue Status

bash
GET http://comfyui:8188/queue

Retrieve Generated Image

bash
GET http://comfyui:8188/view?filename={name}&subfolder=&type=output

System Stats

bash
GET http://comfyui:8188/system_stats

āš™ļø Configuration

Environment Variables (.env)

bash
# Timezone
TZ=America/Los_Angeles

# n8n Basic Auth (optional)
N8N_BASIC_AUTH_ACTIVE=false
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=changeme

# API Keys for Agent Zero (optional)
OPENAI_API_KEY=sk-your-key-here
ANTHROPIC_API_KEY=sk-ant-your-key-here

Custom Webhook URL

If running behind a reverse proxy:

bash
WEBHOOK_URL=https://your-domain.com

šŸ”’ Security Notes

  • By default, all services are only accessible on localhost
  • For production deployment, add a reverse proxy (Traefik/Caddy/nginx)
  • Enable n8n basic auth for any non-local deployment
  • Keep API keys in .env file (not committed to git)

šŸ› Troubleshooting

ComfyUI can't see GPU

  1. Ensure NVIDIA drivers are installed
  2. Install NVIDIA Container Toolkit
  3. Restart Docker Desktop
  4. Run docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi to test

Services won't start

bash
# Check logs
docker compose logs -f

# Restart specific service
docker compose restart n8n

# Full reset
docker compose down -v
docker compose up -d

n8n can't connect to ComfyUI

  • Use http://comfyui:8188 (Docker internal network), not localhost
  • Ensure ComfyUI container is healthy: docker compose ps

Port conflicts

Edit docker-compose.yml to change port mappings:

yaml
ports:
  - "NEW_PORT:INTERNAL_PORT"

šŸ“š Resources


šŸ“„ License

MIT License - Use freely for personal and commercial projects.