Skip to content

Configuration ​

Bonsai Backend is configured through environment variables. Copy the .env.example file to .env and adjust the values for your deployment.

Environment Variables ​

Server ​

VariableDefaultDescription
PORT3000HTTP server port
CORS_ORIGIN*Allowed CORS origin(s). Set to a specific domain in production
NODE_ENV—Set to production for production deployments
WS_MAX_PAYLOAD_BYTES10485760Maximum WebSocket message payload size in bytes (default: 10 MB)

Database ​

VariableDefaultDescription
DB_CONNECTION_STRING—PostgreSQL connection string (e.g., postgresql://user:pass@host:5432/db)
DB_POOL_SIZE10Maximum number of database connections in the pool
DB_SSLfalseSet to true to enable SSL connections to the database

Authentication ​

VariableDefaultDescription
JWT_SECRET—Required. Secret key used to sign and verify JWT tokens

Logging ​

VariableDefaultDescription
LOG_LEVELinfoLog level: trace, debug, info, warn, error, fatal

Build Info ​

VariableDefaultDescription
GIT_COMMIT—Git commit hash, exposed via the version endpoint

Docker Configuration ​

When running with Docker, configure environment variables in docker-compose.yml or pass them via -e flags:

bash
docker run -d \
  -e DB_CONNECTION_STRING=postgresql://user:pass@db:5432/bonsai \
  -e JWT_SECRET=your-secret-key \
  -e PORT=3000 \
  -p 3000:3000 \
  bonsai-backend

Migrations run automatically on container startup before the application starts.

Initial Setup ​

After starting the server for the first time, you need to create the initial super operator account. Use the setup endpoint:

bash
curl -X POST http://localhost:3000/api/setup/initial-operator \
  -H "Content-Type: application/json" \
  -d '{
    "id": "operator",
    "name": "Super Operator",
    "password": "your-secure-password"
  }'

This endpoint is only available when no operator accounts exist. It creates a super operator with full system access.

Swagger UI ​

API documentation is available at /api-docs once the server is running. It provides an interactive interface for exploring all REST API endpoints.

WebSocket Endpoint ​

The WebSocket server listens at /ws on the same port as the HTTP server. Clients connect here for real-time conversational sessions.

Released under the Apache-2.0 License.