The Autonome backend is a Hono API server that runs on a VPS with persistent connections to PostgreSQL. This guide covers Docker-based deployment for production environments.
Architecture
The backend consists of:
Hono HTTP Server : Handles oRPC endpoints and SSE streams
Schedulers : Background jobs for trading, price tracking, portfolio snapshots
PostgreSQL : Primary data store
AI Integrations : Anthropic, OpenRouter, NIM, Mistral APIs
Prerequisites
VPS with Docker and Docker Compose installed
PostgreSQL 15+ (can be containerized)
Domain or subdomain for API (e.g., api.autonome.app)
SSL certificate (use Caddy or nginx for HTTPS)
Docker Deployment
Dockerfile
The project includes Dockerfile for the backend:
# Stage 1: Builder
FROM oven/bun:latest AS builder
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun run build:api
# Stage 2: Production Runner
FROM oven/bun:latest AS runner
WORKDIR /app
# Create non-root user
RUN groupadd --system --gid 1001 nodejs && \
useradd --system --uid 1001 --gid nodejs bunjs
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY --from=builder --chown=bunjs:nodejs /app/api/dist ./api/dist
COPY --from=builder --chown=bunjs:nodejs /app/drizzle ./drizzle
COPY --from=builder --chown=bunjs:nodejs /app/drizzle.config.ts ./drizzle.config.ts
COPY --from=builder --chown=bunjs:nodejs /app/scripts ./scripts
COPY --from=builder --chown=bunjs:nodejs /app/src/db ./src/db
COPY --from=builder --chown=bunjs:nodejs /app/src/core/shared ./src/core/shared
COPY --from=builder --chown=bunjs:nodejs /app/src/env.ts ./src/env.ts
COPY --from=builder --chown=bunjs:nodejs /app/tsconfig.json ./tsconfig.json
RUN mkdir -p /app/logs && chown bunjs:nodejs /app/logs
USER bunjs
ENV PORT=8081
EXPOSE 8081
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD bun -e "if ((await fetch('http://localhost:8081/health')).status !== 200) process.exit(1)"
CMD [ "bun" , "api/dist/index.js" ]
docker-compose.yml
The full stack configuration:
services :
# Backend API Server
api :
image : smoggyowo/autonome-api:latest
container_name : autonome-api
restart : always
ports :
- "8081:8081"
env_file :
- .env
environment :
- DATABASE_URL=postgresql://autonome:autonome_secret@db:5432/autonome
- PORT=8081
depends_on :
db :
condition : service_healthy
seed :
condition : service_completed_successfully
# Migration Runner
migrate :
image : smoggyowo/autonome-api:latest
container_name : autonome-migrate
restart : "no"
env_file :
- .env
environment :
- DATABASE_URL=postgresql://autonome:autonome_secret@db:5432/autonome
depends_on :
db :
condition : service_healthy
command : [ "bun" , "run" , "db:push" ]
# Database Seeder
seed :
image : smoggyowo/autonome-api:latest
container_name : autonome-seed
restart : "no"
env_file :
- .env
environment :
- DATABASE_URL=postgresql://autonome:autonome_secret@db:5432/autonome
depends_on :
migrate :
condition : service_completed_successfully
command : [ "bun" , "run" , "db:seed" ]
# PostgreSQL Database
db :
image : postgres:16-alpine
container_name : autonome-db
restart : always
environment :
POSTGRES_USER : autonome
POSTGRES_PASSWORD : autonome_secret
POSTGRES_DB : autonome
volumes :
- postgres_data:/var/lib/postgresql/data
healthcheck :
test : [ "CMD-SHELL" , "pg_isready -U autonome -d autonome" ]
interval : 10s
timeout : 5s
retries : 5
volumes :
postgres_data :
Deployment Steps
Prepare VPS
Install Docker and Docker Compose: # Ubuntu/Debian
sudo apt update
sudo apt install -y docker.io docker-compose
sudo systemctl enable docker
sudo systemctl start docker
Clone Repository
git clone https://github.com/yourusername/autonome.git
cd autonome
Configure Environment
Create .env file: cp .env.example .env
nano .env # Edit with your values
See Environment Variables section below.
Build Docker Image
docker build -t autonome-api -f Dockerfile .
Or pull from registry: docker pull smoggyowo/autonome-api:latest
Start Services
This will:
Start PostgreSQL and wait for health check
Run migrations (db:push)
Seed database with initial models
Start API server
Verify Deployment
Check API health: curl http://localhost:8081/health
Expected response: {
"status" : "healthy" ,
"timestamp" : "2026-03-07T12:00:00.000Z" ,
"schedulers" : {
"priceTracker" : true ,
"tradeExecutor" : true ,
"portfolioSnapshot" : true
}
}
Environment Variables
Create a .env file with the following configuration:
Core Configuration
# Server
PORT = 8081
SERVER_URL = https://api.autonome.app
# Database
DATABASE_URL = postgresql://autonome:strong_password@db:5432/autonome
# CORS (comma-separated frontend URLs)
CORS_ORIGINS = https://autonome.vercel.app,https://app.autonome.com
# Trading Mode
TRADING_MODE = simulated # or "live" for production trading
AI Provider Keys
# Primary AI providers (at least one required)
NIM_API_KEY = your_nim_key
OPENROUTER_API_KEY = your_openrouter_key
MISTRAL_API_KEY = your_mistral_key
# Multiple keys for rate limit distribution
NIM_API_KEY1 = additional_key_1
NIM_API_KEY2 = additional_key_2
OPENROUTER_API_KEY1 = additional_openrouter_key
AIHUBMIX_API_KEY = your_aihubmix_key
AIHUBMIX_API_KEY1 = additional_aihubmix_key
Lighter Trading API
LIGHTER_API_KEY_INDEX = 2
LIGHTER_BASE_URL = https://mainnet.zklighter.elliot.ai
Simulator Options
SIM_INITIAL_CAPITAL = 10000
SIM_QUOTE_CURRENCY = USDT
SIM_REFRESH_INTERVAL_MS = 10000
Optional Services
# Technical analysis API
TAAPI_API_KEY = your_taapi_key
Security : Never commit .env files to Git. Use .env.example as a template and keep real credentials secure.
Manual Deployment (Without Docker)
If you prefer not to use Docker:
Install Dependencies
bun install --frozen-lockfile
Build API
This creates api/dist/index.js
Start Server
Or use a process manager: # Using PM2
pm2 start api/dist/index.js --name autonome-api
# Using systemd
sudo systemctl enable autonome-api
sudo systemctl start autonome-api
HTTPS Setup with Caddy
For production, use Caddy as a reverse proxy:
api.autonome.app {
reverse_proxy localhost:8081
# Enable compression
encode gzip
# SSE requires long timeouts
request_timeout 0
# Health check
handle /health {
reverse_proxy localhost:8081
}
}
Install and start Caddy:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
sudo systemctl enable caddy
sudo systemctl start caddy
Monitoring
Health Checks
The API exposes health endpoints:
# Basic health
curl https://api.autonome.app/health
# Detailed scheduler health
curl https://api.autonome.app/health/schedulers
Docker Logs
# View API logs
docker logs -f autonome-api
# View database logs
docker logs -f autonome-db
# View migration logs
docker logs autonome-migrate
Process Management
Monitor container status:
# Check running containers
docker-compose ps
# Restart API
docker-compose restart api
# View resource usage
docker stats autonome-api
Troubleshooting
Database Connection Fails
Problem : ECONNREFUSED or timeout errors
Solutions :
Verify DATABASE_URL format: postgresql://user:pass@host:port/dbname
Check PostgreSQL is running: docker-compose ps db
Test connection: docker exec -it autonome-db psql -U autonome -d autonome
Review firewall rules if using external database
Schedulers Not Starting
Problem : Health check shows schedulers as false
Solutions :
Check API logs: docker logs autonome-api
Verify environment variables are set correctly
Ensure trading mode is configured (TRADING_MODE=simulated)
Check for port conflicts
CORS Errors
Problem : Frontend can’t connect to API
Solutions :
Add frontend domain to CORS_ORIGINS
Restart API after changing environment variables
Verify frontend is using correct VITE_API_URL
Check browser console for specific CORS error messages
Updates and Maintenance
Update to Latest Version
# Pull latest code
git pull origin main
# Rebuild and restart
docker-compose down
docker-compose build
docker-compose up -d
Database Backups
# Backup
docker exec autonome-db pg_dump -U autonome autonome > backup.sql
# Restore
cat backup.sql | docker exec -i autonome-db psql -U autonome autonome
View Application Logs
# Live tail
docker-compose logs -f api
# Last 100 lines
docker-compose logs --tail=100 api
# Specific time range
docker-compose logs --since= "2026-03-07T12:00:00" api
Next Steps
Database Setup Learn about PostgreSQL configuration and migrations
Frontend Deployment Deploy the TanStack Start frontend