Skip to content

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

StackPilot

Deploy to TryDirect

Self-hosted AI website support assistant β€” a fully functional RAG-based chat widget that learns from your data, deployable with a single command.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     WEBSITE (any site)                      β”‚
β”‚  <script src="stackpilot.try.direct/widget.js"></script>    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  STACKPILOT API (FastAPI)                   β”‚
β”‚  β€’ Widget endpoint  β€’ Admin dashboard  β€’ RAG pipeline       β”‚
β””β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β–Ό          β–Ό          β–Ό          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Postgresβ”‚ β”‚ Redis  β”‚ β”‚Ollama  β”‚ β”‚    n8n     β”‚
β”‚+pgvec  β”‚ β”‚        β”‚ β”‚        β”‚ β”‚            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Deploy

stacker install stackpilot
stacker deploy --target cloud --key htz-0

Features

  • Embeddable chat widget β€” one <script> tag adds AI support to any website
  • RAG-powered answers β€” semantic search over your knowledge base using pgvector
  • Website crawler β€” automatically ingests your site content into the knowledge base
  • Self-hosted AI β€” runs Ollama locally, no OpenAI/Anthropic API keys needed
  • Conversation learning β€” stores chat history, tracks feedback, improves over time
  • Workflow automation β€” escalates low-confidence answers via n8n webhooks
  • Admin dashboard β€” manage knowledge base, view conversations, pull models
  • Production-ready β€” Nginx Proxy Manager with auto-SSL, health checks, status panel

Tech Stack

Service Image Purpose
app Custom Python (FastAPI) API, RAG pipeline, admin dashboard, widget
stackpilot-db pgvector/pgvector:0.8.0-pg16 Knowledge base vectors + conversation history
stackpilot-redis redis:7-alpine Caching, rate limiting, session store
stackpilot-ollama ollama/ollama:latest Self-hosted LLM inference + embeddings
stackpilot-n8n n8nio/n8n:latest Workflow automation, escalation, notifications
nginx-proxy-manager jc21/nginx-proxy-manager:latest Reverse proxy with auto-SSL

Prerequisites

  • A server with Docker and Docker Compose installed
  • At least 2GB RAM + 2GB swap (8GB+ recommended for running larger LLMs)
  • (Optional) A domain pointed at your server for SSL

Quick server setup (installs Docker, creates swap):

./scripts/setup-server.sh YOUR_SERVER_IP

Installation

Option 1: Deploy with Stacker (recommended)

git clone https://github.com/trydirect/awesome-selfhosted-stacker.git
cd awesome-selfhosted-stacker/stacker-projects/stackpilot

# Generate secrets
cp .env.example .env
./scripts/generate-secrets.sh

# Deploy to your server
stacker deploy

Option 2: Manual Docker Compose deploy

git clone https://github.com/trydirect/awesome-selfhosted-stacker.git
cd awesome-selfhosted-stacker/stacker-projects/stackpilot

# Copy compose file and build
cp .stacker/docker-compose.yml .
docker compose up -d --build

First Run Checklist

  1. Open the admin dashboard

    http://YOUR_SERVER_IP:8080/api/admin/dashboard
    
  2. Sign in with the ADMIN_PASSWORD from your .env file

  3. Pull AI models β€” go to the Ollama tab and pull:

    • llama3.1 β€” the LLM for generating responses
    • nomic-embed-text β€” the embedding model for semantic search
  4. Build your knowledge base β€” go to the Websites tab and crawl your website:

    https://your-website.com
    

    Or add documents manually via the Knowledge Base tab.

  5. Embed the widget on your website:

    <script src="http://YOUR_SERVER_IP:8080/api/widget/widget.js"></script>
  6. (Optional) Set up SSL β€” configure Nginx Proxy Manager at port 81 to route your domain to the app.


Configuration

All configuration is via environment variables in .env:

Variable Default Description
SECRET_KEY auto-generated Session signing key
DB_PASSWORD auto-generated PostgreSQL password
ADMIN_PASSWORD auto-generated Dashboard login password
N8N_PASSWORD auto-generated n8n basic auth password
OLLAMA_MODEL llama3.1 LLM model for generating responses
OLLAMA_EMBED_MODEL nomic-embed-text Embedding model for vector search
DEPLOY_HOST β€” Server IP for Stacker deployment
BASE_PATH β€” Local project path for Stacker

API Reference

Widget API

Method Endpoint Description
POST /api/widget/chat Send a message, get an AI response
GET /api/widget/widget.js Embeddable chat widget JavaScript
POST /api/widget/feedback Submit feedback on a conversation
POST /api/widget/resolve Mark a conversation as resolved

Admin API

Method Endpoint Description
GET /api/admin/stats Dashboard statistics
GET /api/admin/dashboard Admin dashboard HTML
POST /api/admin/login Authenticate
POST /api/admin/logout Sign out
GET /api/admin/documents List knowledge base documents
POST /api/admin/documents Add a document
DELETE /api/admin/documents/{id} Remove a document
GET /api/admin/websites List crawled websites
POST /api/admin/websites Register a website
POST /api/admin/websites/crawl Start crawling a website
DELETE /api/admin/websites/{id} Remove a website
GET /api/admin/conversations List conversations
GET /api/admin/ollama/status Check Ollama health + installed models
POST /api/admin/ollama/pull Pull a new model

Webhook API

Method Endpoint Description
POST /api/webhooks/n8n n8n callback for escalation events
POST /api/webhooks/ingest External content ingestion endpoint

How It Works

Data Flow

1. Visitor asks a question on your website
   ↓
2. widget.js sends message to /api/widget/chat
   ↓
3. Query is embedded using nomic-embed-text via Ollama
   ↓
4. pgvector performs cosine similarity search (top-K results)
   ↓
5. Retrieved documents are injected into the prompt as context
   ↓
6. llama3.1 generates a response using the context
   ↓
7. Response is returned to the visitor in real-time
   ↓
8. Conversation is stored for analytics and learning
   ↓
9. If confidence < 0.3 β†’ escalation via n8n webhook

Knowledge Base Pipeline

Website URL β†’ Crawler β†’ Text extraction β†’ Chunking (500 tokens)
  β†’ Embedding (nomic-embed-text) β†’ pgvector storage

Documents are automatically chunked into 500-token pieces with 100-token overlap for context continuity.


Deployment Targets

Local

deploy:
  target: local

Remote Server (SSH)

deploy:
  target: server
  server:
    host: ${DEPLOY_HOST}
    user: root
    ssh_key: ${BASE_PATH}/stacker-project-test

Cloud (Hetzner)

deploy:
  target: cloud
  cloud:
    provider: hetzner
    region: fsn1
    size: cpx32
    public_ports:
      - "80"
      - "443"
      - "8080"
      - "5678"

Services & Ports

Service External Port Internal Port Purpose
StackPilot App 8080 8000 API + Dashboard + Widget
Nginx Proxy Manager 80, 443, 81 80, 443, 81 Reverse proxy + SSL + admin
n8n 5678 5678 Workflow automation
Ollama 11434 11434 LLM inference
PostgreSQL internal 5432 Database
Redis internal 6379 Cache

Troubleshooting

App keeps restarting

Check logs:

docker logs stackpilot-app-1 --tail 50

Common issues:

  • Database connection error β€” PostgreSQL may still be starting. The app retries automatically for 60 seconds.
  • invalid DSN β€” Ensure DATABASE_URL uses postgresql:// (not postgresql+asyncpg://).

Widget not loading

  • Ensure the <script> tag points to the correct URL
  • Check browser console for CORS errors
  • Verify the app is running: curl http://YOUR_IP:8080/health

Ollama not responding

docker exec stackpilot-stackpilot-ollama-1 ollama list

If no models are listed, pull them via the dashboard or:

docker exec stackpilot-stackpilot-ollama-1 ollama pull llama3.1
docker exec stackpilot-stackpilot-ollama-1 ollama pull nomic-embed-text

NPM shows 502 Bad Gateway

Ensure the proxy host forward hostname is set to app (not stackpilot-app).


Project Structure

stackpilot/
β”œβ”€β”€ stacker.yml                 # Stacker deployment config
β”œβ”€β”€ .env.example                # Environment template
β”œβ”€β”€ Dockerfile                  # Python backend build
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ generate-secrets.sh     # Secret generation
β”‚   β”œβ”€β”€ download-model.sh       # Pre-pull Ollama models
β”‚   └── seed-knowledge.sh       # Crawl a URL into KB
└── app/
    β”œβ”€β”€ main.py                 # FastAPI entry point
    β”œβ”€β”€ config.py               # Settings from env vars
    β”œβ”€β”€ database.py             # asyncpg + pgvector setup
    β”œβ”€β”€ models.py               # Pydantic schemas
    β”œβ”€β”€ knowledge.py            # KB CRUD, crawling, chunking
    β”œβ”€β”€ rag.py                  # RAG pipeline, Ollama, n8n
    β”œβ”€β”€ routes/
    β”‚   β”œβ”€β”€ widget.py           # Chat API + widget.js
    β”‚   β”œβ”€β”€ admin.py            # Dashboard, KB management
    β”‚   └── webhooks.py         # n8n + ingestion webhooks
    └── templates/
        └── dashboard.html      # Admin SPA

License

MIT

About

StackPilot - Self-hosted AI website support assistant

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages