-
-
Notifications
You must be signed in to change notification settings - Fork 2
DEPLOYMENT ARCHITECTURE
This guide explains how nself deploys services across different environments and the distinction between staging and production deployments.
nself organizes services into five distinct categories:
These are the foundational services required for any nself deployment:
| Service | Purpose | Subdomain |
|---|---|---|
| PostgreSQL | Primary database | Internal only |
| Hasura | GraphQL API engine | api.domain.com |
| Auth | Authentication service (nhost-compatible) | auth.domain.com |
| Nginx | Reverse proxy & SSL termination | Main entry point |
Enable these based on your application needs:
| Service | Enable Flag | Subdomain | Purpose |
|---|---|---|---|
| nself-admin | NSELF_ADMIN_ENABLED=true |
admin.domain.com |
Web management UI |
| MinIO | MINIO_ENABLED=true |
minio.domain.com |
S3-compatible storage |
| Redis | REDIS_ENABLED=true |
Internal | Cache & sessions |
| Functions | FUNCTIONS_ENABLED=true |
functions.domain.com |
Serverless runtime |
| MLflow | MLFLOW_ENABLED=true |
mlflow.domain.com |
ML experiment tracking |
| Mailpit | MAILPIT_ENABLED=true |
mail.domain.com |
Dev email testing |
| Meilisearch | MEILISEARCH_ENABLED=true |
search.domain.com |
Full-text search |
When MONITORING_ENABLED=true, all 10 services are deployed:
| Service | Purpose |
|---|---|
| Prometheus | Metrics collection |
| Grafana | Dashboards & visualization |
| Loki | Log aggregation |
| Promtail | Log shipping (required for Loki) |
| Tempo | Distributed tracing |
| Alertmanager | Alert routing |
| cAdvisor | Container metrics |
| Node Exporter | System metrics |
| Postgres Exporter | Database metrics |
| Redis Exporter | Redis metrics |
Completely independent backend applications with custom business logic:
# In .env
CS_1=order-api:express-js:8001 # Order processing API
CS_2=webhooks:nestjs:8002 # Webhook handler service
CS_3=payments:fastapi-py:8003 # Payment processing
CS_4=ml-inference:fastapi-py:8004 # ML model servingCustom services are separate applications that:
- Have their own codebase and logic
- May or may not connect to the database
- Run as independent Docker containers
- Can integrate with Hasura via Actions/Event Triggers
Examples:
- Order processing API
- Payment processing service
- Email notification worker
- ML inference endpoint
- Third-party integration handlers (webhooks, callbacks)
Different from Custom Services! Remote Schemas are multiple Hasura GraphQL endpoints for different apps/tenants, all accessing the same database with different exposed schemas:
Same nself instance, same PostgreSQL, different GraphQL APIs:
api.app1.com → Hasura endpoint exposing App1 tables/permissions
api.app2.com → Hasura endpoint exposing App2 tables/permissions
Use case: One nself deployment serving multiple applications:
-
www.app1.comusesapi.app1.com(sees users, products, orders) -
www.app2.comusesapi.app2.com(sees different tables/fields)
Configuration in .env:
# Remote Schemas (multiple Hasura endpoints)
REMOTE_SCHEMA_1_NAME=app1
REMOTE_SCHEMA_1_DOMAIN=api.app1.com
REMOTE_SCHEMA_2_NAME=app2
REMOTE_SCHEMA_2_DOMAIN=api.app2.comFrontend applications configured for Nginx routing:
# In .env
FRONTEND_APP_1_NAME=web
FRONTEND_APP_1_PORT=3000
FRONTEND_APP_1_ROUTE=app
FRONTEND_APP_2_NAME=admin
FRONTEND_APP_2_PORT=3001
FRONTEND_APP_2_ROUTE=dashboardKey Point: These are NOT Docker containers - they run outside Docker and Nginx routes to them.
🔑 KEY DIFFERENCE: Frontend apps are included in staging (complete testing environment) but excluded in production (deployed separately to Vercel/CDN).
┌─────────────────────────────────────────────────────────────────┐
│ LOCAL DEVELOPMENT │
│ nself init → nself build → nself start │
│ All services run in Docker on localhost │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ STAGING │
│ nself deploy staging │
│ │
│ ✅ Deploys: Core + Optional + Monitoring + Custom + Frontends │
│ │
│ Frontend apps served by Nginx on subdomains: │
│ app.staging.example.com → Frontend App 1 │
│ dashboard.staging.example.com → Frontend App 2 │
│ │
│ Complete replica for testing everything together │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ PRODUCTION │
│ nself deploy production │
│ │
│ ✅ Deploys: Core + Optional + Monitoring + Custom │
│ ❌ Frontend apps EXCLUDED by default (deploy separately) │
│ │
│ Frontend apps deployed to specialized platforms: │
│ ├── Vercel (Next.js, React) - Auto-scaling, edge cache │
│ ├── Cloudflare Pages (static) - Global CDN │
│ ├── Mobile apps (App Store, Play Store) │
│ └── Any CDN/hosting platform │
│ │
│ API endpoints exposed: │
│ api.example.com → Hasura GraphQL │
│ auth.example.com → Authentication │
│ │
│ 💡 Override: Use --include-frontends to deploy frontends │
└─────────────────────────────────────────────────────────────────┘
⚠️ IMPORTANT: The key difference is frontend app deployment behavior!
| Aspect | Staging | Production |
|---|---|---|
| Frontend Apps | ✅ INCLUDED (Nginx serves) | ❌ EXCLUDED (Vercel/CDN) |
| Hasura Console | ✅ Enabled | ❌ Disabled |
| Debug Mode | ❌ Off | ❌ Off |
| Log Level | info |
warning |
| Mailpit | ✅ Available | ❌ Use real email |
| Monitoring | ✅ Required | |
| Purpose | Testing & QA | Live users |
💡 TL;DR: Staging = test everything together. Production = backend on VPS, frontends on specialized platforms.
Staging: You want a complete replica to test everything together - frontend, backend, APIs, integrations. Nginx serves all frontend apps on staging subdomains. This ensures your staging environment matches the full user experience.
Production: Frontend apps have different scaling needs and are typically deployed on specialized platforms:
- Vercel/Netlify: Automatic scaling, edge caching, preview deployments, serverless functions
- Cloudflare Pages: Global CDN with 200+ edge locations, instant cache invalidation
- Mobile Apps: App Store / Google Play (can't run on your VPS anyway)
Why separate?
- ✅ Better performance (global CDN vs single VPS)
- ✅ Lower costs (frontend hosting is often free)
- ✅ Easier deployment (Git push vs Docker rebuild)
- ✅ Better DX (preview deployments, instant rollbacks)
Your VPS focuses on what it does best: running the backend services, APIs, and databases.
# Initialize staging
nself staging init staging.example.com --email admin@example.com
# Configure server
# Edit .environments/staging/server.json
# Generate secrets
nself staging secrets generate
# Deploy everything
nself staging deploy
# What gets deployed:
# ✓ Core Services (PostgreSQL, Hasura, Auth, Nginx)
# ✓ Optional Services (based on *_ENABLED)
# ✓ Monitoring Bundle (if enabled)
# ✓ Custom Services (CS_1, CS_2, ...)
# ✓ Frontend Apps (FRONTEND_APP_1, FRONTEND_APP_2, ...)# Initialize production
nself prod init example.com --email admin@example.com
# Configure server
# Edit .environments/prod/server.json
# Generate secrets
nself prod secrets generate
# Security audit
nself prod check
# Deploy backend only
nself deploy prod
# What gets deployed:
# ✓ Core Services (PostgreSQL, Hasura, Auth, Nginx)
# ✓ Optional Services (based on *_ENABLED)
# ✓ Monitoring Bundle (if enabled)
# ✓ Custom Services (CS_1, CS_2, ...)
# ○ Frontend Apps (excluded - deploy to Vercel/CDN)# Force include frontends in production (unusual)
nself deploy prod --include-frontends
# Exclude frontends in staging (e.g., testing backend only)
nself staging deploy --exclude-frontendsnself can serve multiple applications from one deployment using Remote Schemas - different Hasura GraphQL endpoints with different exposed schemas, all hitting the same database:
┌─────────────────────────────────────────────────────────────┐
│ nself Deployment │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ api.app1.com │ │ api.app2.com │ │ api.main │ │
│ │ (Remote 1) │ │ (Remote 2) │ │ (Default) │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └───────────────────┼───────────────────┘ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ PostgreSQL │ │
│ │ (Same Database)│ │
│ └─────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Use case: SaaS platform serving multiple white-label apps from one backend.
Custom Services (CS_N) are separate backend applications that can integrate with Hasura:
Your Custom Service handles business logic called from GraphQL:
# Custom service for complex operations
CS_1=order-service:nestjs:8001In Hasura Console → Actions:
- Handler URL:
http://order-service:8001/validate-and-process - Expose as:
processOrdermutation - Hasura handles auth, your service handles logic
Your Custom Service reacts to database changes:
# Worker service for async processing
CS_2=notification-worker:express-js:8002In Hasura Console → Events:
- Webhook URL:
http://notification-worker:8002/on-order-created - Trigger on:
INSERTintoorderstable - Your service sends emails, updates analytics, etc.
Custom Services can also be completely independent:
# Telemetry API (no Hasura integration)
CS_3=telemetry:express-js:8003
# ML inference (no Hasura integration)
CS_4=ml-api:fastapi-py:8004These run alongside nself but handle their own routing and logic.
my-project/
├── .environments/
│ ├── staging/
│ │ ├── .env # Staging config
│ │ ├── .env.secrets # Staging secrets
│ │ └── server.json # Staging VPS SSH config
│ └── prod/
│ ├── .env # Production config
│ ├── .env.secrets # Production secrets
│ └── server.json # Production VPS SSH config
├── .env.dev # Local development config
├── docker-compose.yml # Generated by nself build
├── nginx/ # Generated nginx configs
├── services/ # Generated custom services
│ ├── payment_api/ # CS_1
│ ├── event_worker/ # CS_2
│ └── ml_inference/ # CS_3
└── frontend/ # Your frontend apps (not in Docker)
├── web/ # Next.js app → Vercel in prod
└── mobile/ # React Native → App stores
- Staging mirrors production config - Same services, same structure
- Test everything in staging - Including frontend integrations
- Production is backend-focused - Let specialized platforms handle frontends
- Use Hasura for API - Custom services extend, don't replace it
- Monitor everything - Enable monitoring bundle in staging and production
- Secure secrets - Different secrets per environment, never commit them
- nself env - Environment management
- nself staging - Staging commands
- nself prod - Production commands
- nself deploy - Deployment commands
- Custom Services - CS_N configuration
ɳSelf CLI v1.0.9. MIT licensed. Docs CC BY 4.0.
GitHub · Issues · Discussions · nself.org · nself.org/docs
Getting Started
Commands
- Commands, Overview
- Lifecycle: cmd-init · cmd-build · cmd-start · cmd-stop · cmd-restart · cmd-dev
- Monitoring: cmd-status · cmd-logs · cmd-health · cmd-urls · cmd-doctor · cmd-monitor · cmd-alerts · cmd-sentry · cmd-watchdog
- Data: cmd-db · cmd-backup · cmd-dr · cmd-queue · cmd-webhooks
- Config: cmd-config · cmd-service · cmd-env · cmd-promote
- Networking: cmd-ssl · cmd-trust · cmd-dns-setup
- Security: cmd-access · cmd-security · cmd-secrets
- Tenancy: cmd-tenant · cmd-billing
- Plugins: cmd-plugin · cmd-license · cmd-dogfood (extracted, CLI-R11) · cmd-k8s (extracted, CLI-R11) · cmd-encryption (extracted, CLI-R11) · cmd-waf (extracted, CLI-R11) · cmd-federation (extracted, CLI-R11) · cmd-mail (extracted, CLI-R11) · cmd-dlq (extracted, CLI-R11)
- AI: cmd-ai · cmd-claw · cmd-model
- Templates: cmd-template
- Utilities: cmd-exec · cmd-clean · cmd-reset · cmd-update · cmd-upgrade · cmd-version · cmd-admin · cmd-migrate · cmd-migrate-firebase · cmd-migrate-supabase · cmd-completion
Features
- Features, Overview
- Feature-Auth
- Feature-Storage
- Feature-Search
- Feature-Functions
- Feature-Email
- Feature-Monitoring
- Feature-Plugins
- Feature-nClaw, AI Assistant
- Feature-nChat, Messaging
- Feature-nTV, Media Player
- Feature-nFamily, Family Social
- Feature-nCloud, Managed Hosting
- Feature-Memory-Rooms, Knowledge Organization
- Feature-Agent-Dashboard, Agent Metrics
- Feature-Image-Generation, AI Image Generation
Configuration
- Configuration, Overview
- Config-Env-Vars
- Config-Postgres
- Config-Hasura
- Config-Auth
- Config-Nginx
- Config-Optional-Services
- Config-Custom-Services
- Config-System
Plugins (87 + 10 monitoring)
Free (25)
- plugin-backup
- plugin-content-acquisition
- plugin-content-progress
- plugin-cron
- plugin-donorbox
- plugin-feature-flags
- plugin-github
- plugin-github-runner
- plugin-invitations
- plugin-jobs
- plugin-link-preview
- plugin-mdns
- plugin-mlflow
- plugin-monitoring
- plugin-notifications
- plugin-notify
- plugin-paypal
- plugin-search
- plugin-shopify
- plugin-stripe
- plugin-subtitle-manager
- plugin-tokens
- plugin-torrent-manager
- plugin-vpn
- plugin-webhooks
Pro (62)
- plugin-access-controls
- plugin-activity-feed
- plugin-admin-api
- plugin-nself-ai-gateway
- plugin-nself-ai-mcp
- plugin-nself-ai-mcp
- plugin-analytics
- plugin-auth
- plugin-backup-pro
- plugin-bots
- plugin-browser
- plugin-calendar
- plugin-cdn
- plugin-chat
- plugin-claw
- plugin-claw-budget
- plugin-claw-news
- plugin-claw-web
- plugin-cloudflare
- plugin-cms
- plugin-compliance
- plugin-cron-pro
- plugin-ddns
- plugin-devices
- plugin-documents
- plugin-donorbox-pro
- plugin-entitlements
- plugin-epg
- plugin-file-processing
- plugin-game-metadata
- plugin-geocoding
- plugin-geolocation
- plugin-google
- plugin-home
- plugin-idme
- plugin-knowledge-base
- plugin-linkedin
- plugin-livekit
- plugin-media-processing
- plugin-meetings
- plugin-moderation
- plugin-mux
- plugin-notify-pro
- plugin-object-storage
- plugin-observability
- plugin-paypal-pro
- plugin-photos
- plugin-podcast
- plugin-post
- plugin-realtime
- plugin-recording
- plugin-retro-gaming
- plugin-rom-discovery
- plugin-shopify-pro
- plugin-social
- plugin-sports
- plugin-stream-gateway
- plugin-streaming
- plugin-stripe-pro
- plugin-support
- plugin-tmdb
- plugin-voice
- plugin-web3
- plugin-workflows
Planned (26)
plugin-auditplugin-blogplugin-checkoutplugin-commerceplugin-drmplugin-exportplugin-flowplugin-importplugin-ldapplugin-mailgunplugin-mediaplugin-oauth-providersplugin-pagesplugin-postmarkplugin-rate-limitplugin-reportsplugin-samlplugin-schedulerplugin-sendgridplugin-ssoplugin-subscriptionplugin-thumbplugin-transcoderplugin-twilioplugin-wafplugin-watermark
Guides
- Guide-Production-Deployment
- Guide-SSL-Setup
- Guide-Multi-Tenancy
- Guide-Security-Hardening
- Guide-Monitoring-Setup
- Guide-Backup-Restore
- Guide-Custom-Services
- Guide-Migration-from-v1
Architecture
Reference
- API-Reference
- error-codes, Error Codes
Licensing
Security
Brand
Operations
- operations/release-cascade, Release Cascade
- operations/self-healing, Self-Healing Schema
- operations/redis-tuning, Redis Pool Tuning
- operations/meilisearch-warmup, MeiliSearch Warm-Up
- operations/jwt-rotation, JWT Key Rotation
- operations/windows-wsl2-setup, Windows / WSL2 Setup
- operations/gemini-oauth-reauth, Gemini OAuth Reauth
Contributing
Admin
- USER-ACTION-QUEUE, Pending Admin Actions
All commands (52)
- A: cmd-access · cmd-account · cmd-admin
- B: cmd-backup · cmd-build · cmd-bundle
- C: cmd-ci · cmd-clean · cmd-completion · cmd-config
- D: cmd-db · cmd-deploy · cmd-dev · cmd-doctor
- E: cmd-env · cmd-exec
- F: cmd-functions
- G: cmd-generate
- H: cmd-health · cmd-help-topics
- I: cmd-init · cmd-install
- L: cmd-license · cmd-login · cmd-logout · cmd-logs
- M: cmd-man · cmd-mcp · cmd-migrate
- O: cmd-oauth · cmd-ops
- P: cmd-plugin · cmd-promote
- R: cmd-remove · cmd-reset · cmd-restart · cmd-runner
- S: cmd-secrets · cmd-security · cmd-self-heal · cmd-server · cmd-service · cmd-start · cmd-status · cmd-stop
- T: cmd-telemetry · cmd-template · cmd-trust
- U: cmd-update · cmd-urls
- V: cmd-verify-sbom · cmd-version