Skip to main content

Build and Deployment

API server build:
Build output is generated in the api/dist directory.Web frontend build:
Build output is generated in the web/dist directory.
API server:
Or using PM2:
A server started from the build output (dist/index.js), sonamu start, and sonamu build use NODE_ENV from .env.local or .env when NODE_ENV is unset, and fall back to production otherwise. Set NODE_ENV explicitly to run another environment such as staging.With auth enabled, the server also needs a secret (such as BETTER_AUTH_SECRET) and an auth baseURL (server.auth.baseURL, BETTER_AUTH_URL, or an absolute http(s) server.baseUrl) to start.
Web server:Serve static files with Nginx or Apache:

Environment Variables

Sonamu automatically loads .env.{environment} files based on NODE_ENV.Create .env.production file:
Sonamu reads SONAMU_DB_* environment variables to automatically configure DB connections, so you don’t need to specify connection details directly in sonamu.config.ts. Use database.defaultOptions to override defaults:
Method 1: Environment Variables
Method 2: Secret Management Tools
  • AWS Secrets Manager
  • HashiCorp Vault
  • Azure Key Vault

Database

1. Check migration status:
2. Test on Shadow DB (recommended):Shadow targets are limited to test and fixture; the Shadow DB is a temporary copy of that database, not of production.
3. Apply to actual DB:
4. Rollback (if needed):The target argument is required; NODE_ENV does not supply it. Rollback undoes the latest applied batch.
These commands ask for confirmation in a TTY; add --confirm for non-interactive runs.
PostgreSQL backup:
Automatic backup (Cron):

Monitoring and Logging

Sonamu provides structured logging based on LogTape. Configure it via the logging option in sonamu.config.ts:
Using the logger:
See LogTape Setup for detailed configuration.
Sentry integration:

Performance Optimization

1. Connection Pool settings:
2. Enable caching:
3. Enable compression:
Nginx configuration:

Docker

Create Dockerfile:
docker-compose.yml:
Run:

CI/CD

.github/workflows/deploy.yml:

Security

Let’s Encrypt + Nginx:
Nginx HTTPS configuration:

Best Practices

Security:
  • HTTPS configured
  • Sensitive info managed via environment variables
  • CORS properly configured
  • Rate Limiting set up
  • SQL Injection prevention (using Puri)
  • XSS prevention (input validation)
Performance:
  • Connection Pool optimized
  • Redis caching enabled
  • Static file caching
  • DB indexes optimized
  • N+1 queries eliminated
Monitoring:
  • Health check endpoint
  • Error monitoring (Sentry)
  • Log collection (LogTape)
  • DB backup automation
Deployment:
  • Production environment variables set
  • Migration tested (Shadow DB)
  • CI/CD pipeline
  • Rollback plan