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:
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):
3. Apply to actual DB:
4. Rollback (if needed):
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