Self-Hosting Guide
Deploy Autonomy on your own infrastructure for complete data sovereignty.
Why Self-Host?
Self-hosting Autonomy gives you:
- Complete data sovereignty — Your signals never leave your infrastructure
- Full control — Customize, modify, and extend as needed
- Privacy — No third-party access to your documented reality
- No platform dependencies — You're not subject to terms of service changes
System Requirements
Minimum
- • 1 CPU core
- • 1GB RAM
- • 10GB storage
- • Node.js 18+
- • PostgreSQL 14+ or MySQL 8+
Recommended
- • 2+ CPU cores
- • 4GB+ RAM
- • 50GB+ storage (for media files)
- • Node.js 20+
- • PostgreSQL 16+ (for PostGIS/pgvector)
Installation Steps
Step 1: Clone Repository
git clone https://github.com/rswfire/autonomy.git cd builtwithautonomy.com
Step 2: Install Dependencies
npm install
Step 3: Set Up Database
Create a PostgreSQL or MySQL database:
# PostgreSQL createdb autonomy # MySQL mysql -u root -p -e "CREATE DATABASE autonomy;"
Step 4: Configure Environment
Create .env file:
# Database (choose one) DATABASE_URL="postgresql://user:password@localhost:5432/autonomy" # DATABASE_URL="mysql://user:password@localhost:3306/autonomy" # JWT Secret (generate random string) JWT_SECRET="your-secure-random-secret-key-here" # Environment NODE_ENV="production" # Port (optional, defaults to 3000) PORT=3000
Security: Generate a strong JWT_SECRET using:
openssl rand -base64 32Step 5: Generate Schema & Run Migrations
npm run db:generate-schema npx prisma generate npx prisma migrate deploy
Step 6: Create Owner Account
npm run create:owner
Follow the prompts to set up your admin account. This also creates your default private realm.
Step 7: Build & Start
npm run build npm start
Application will be available at http://localhost:3000
Process Management
Using systemd (Linux)
Create ~/.config/systemd/user/autonomy.service:
[Unit] Description=Autonomy - Cognitive Infrastructure After=network.target [Service] Type=simple WorkingDirectory=/path/to/builtwithautonomy.com Environment="NODE_ENV=production" Environment="PORT=3000" ExecStart=/usr/bin/npm start Restart=always RestartSec=10 [Install] WantedBy=default.target
Enable and start:
systemctl --user daemon-reload systemctl --user enable autonomy systemctl --user start autonomy systemctl --user status autonomy
Using PM2 (Cross-platform)
npm install -g pm2 pm2 start npm --name autonomy -- start pm2 save pm2 startup
Reverse Proxy (HTTPS)
Nginx Configuration
Create /etc/nginx/sites-available/autonomy:
server {
listen 80;
server_name yourdomain.com;
# Redirect to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}Enable site:
sudo ln -s /etc/nginx/sites-available/autonomy /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx
SSL Certificate (Let's Encrypt)
sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d yourdomain.com
Automated Deployment Script
Create scripts/deploy.sh for easy updates:
#!/bin/bash
set -euo pipefail
DOMAIN="yourdomain.com"
APP_DIR="/path/to/builtwithautonomy.com"
BRANCH="main"
echo "🚀 Deploying $DOMAIN"
cd "$APP_DIR"
# Show current version
echo "📝 Current commit: $(git rev-parse --short HEAD)"
# Fetch and reset
echo "⬇️ Fetching latest changes..."
git fetch origin "$BRANCH"
git reset --hard "origin/$BRANCH"
# Show new version
echo "📝 New commit: $(git rev-parse --short HEAD)"
# Clean build
echo "🧹 Cleaning old build..."
rm -rf node_modules .next
# Install dependencies
echo "📦 Installing dependencies..."
npm ci
# Generate Prisma client
echo "🔄 Generating Prisma client..."
npx prisma generate
# Build
echo "🔨 Building application..."
npm run build
# Verify build
if [ ! -d ".next" ]; then
echo "❌ Build failed: .next directory missing"
exit 1
fi
echo "✅ Build successful"
# Restart service
echo "🔄 Restarting service..."
systemctl --user restart autonomy
# Wait for service to start
sleep 2
# Check service status
if systemctl --user is-active --quiet autonomy; then
echo "✅ Service restarted successfully"
echo "🌐 Live at: https://$DOMAIN"
else
echo "❌ Service failed to start"
echo "📋 Check logs: journalctl --user -u autonomy -n 50"
exit 1
fiMake executable and run:
chmod +x scripts/deploy.sh ./scripts/deploy.sh
Backup Strategy
Database Backups
Set up automated daily backups:
# PostgreSQL pg_dump autonomy > backup_$(date +%Y%m%d).sql # MySQL mysqldump autonomy > backup_$(date +%Y%m%d).sql
Add to cron for daily backups at 2 AM:
0 2 * * * pg_dump autonomy > /backups/autonomy_$(date +%Y%m%d).sql
Monitoring & Logs
View Logs (systemd)
# Last 50 lines journalctl --user -u autonomy -n 50 # Follow logs journalctl --user -u autonomy -f
View Logs (PM2)
# View logs pm2 logs autonomy # Monitor pm2 monit
Troubleshooting
Port already in use
Change PORT in .env file or stop conflicting service
lsof -i :3000Database connection failed
Verify DATABASE_URL is correct and database is running
Build errors after update
Clean install:
rm -rf node_modules .next && npm install && npm run buildPrisma client not found
Regenerate:
npx prisma generate