DEMO_SETUP - nself-org/cli GitHub Wiki
The demo setup (nself init --demo) provides a fully-featured Backend-as-a-Service environment with all major components enabled. This configuration showcases the complete capabilities of nself.
# Initialize demo project
nself init --demo
# Build all services
nself build
# Start everything
nself start
# View running services
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"These form the foundation of every nself deployment:
-
PostgreSQL - Primary database
- Latest v16 with all extensions
- pgvector for AI/ML embeddings
- PostGIS for geospatial data
- Full-text search capabilities
-
Hasura - GraphQL API Engine
- Instant GraphQL APIs
- Real-time subscriptions
- Row-level security
- Remote schema stitching
-
Auth - Authentication Service
- JWT-based authentication
- Email/password login
- Social providers ready
- WebAuthn support
-
Nginx - Reverse Proxy
- SSL termination
- Load balancing
- Route management
- Static file serving
Complete observability stack enabled with MONITORING_ENABLED=true:
- Prometheus - Metrics collection and storage
- Grafana - Visualization and dashboards
- Loki - Log aggregation system
- Promtail - Log shipping agent
- Tempo - Distributed tracing
- Alertmanager - Alert routing
- cAdvisor - Container metrics
- Node Exporter - System metrics
- Postgres Exporter - Database metrics
- Redis Exporter - Cache metrics
-
Redis - In-memory data store
- Session management
- Caching layer
- Pub/Sub messaging
- Job queue backend
-
MinIO - S3-compatible storage
- File uploads
- Backup storage
- ML model artifacts
- Static assets
-
Storage API - File management service
- Upload handling
- Image transformations
- Access control
- CDN integration
-
MailPit - Email testing
- Catches all emails
- Web UI for viewing
- API for testing
- No emails sent externally
-
MeiliSearch - Full-text search
- Typo-tolerant search
- Faceted search
- Multi-language support
- Instant results
-
nself Admin - Management UI
- Service monitoring
- Configuration management
- Database administration
- Log viewing
Demo includes four diverse custom services to showcase different architectures:
-
express_api - REST API Service
- Express.js framework
- RESTful endpoints
- JWT authentication
- PostgreSQL integration
- Template:
express-js - Port: 8001
- Route:
https://api.<domain>
-
bullmq_worker - Background Job Processor
- BullMQ queue processing
- Redis-backed jobs
- Retry logic
- Dead letter queue
- Template:
bullmq-js - Port: 8002
- Internal service (no public route)
-
go_grpc - High-Performance gRPC Service
- Go implementation
- Protocol buffers
- Bi-directional streaming
- Service mesh ready
- Template:
grpc - Port: 8003
- Route:
https://grpc.<domain>
-
python_api - ML/Data API
- FastAPI framework
- Async/await support
- OpenAPI documentation
- ML model serving
- Template:
fastapi - Port: 8004
- Route:
https://ml-api.<domain>
The demo .env includes:
# Custom Backend Services
CUSTOM_SERVICES=express-api,bullmq-worker,go-grpc,python-api
CS_1=express_api:express-js:8001
CS_2=bullmq_worker:bullmq-js:8002
CS_3=go_grpc:grpc:8003
CS_4=python_api:fastapi:8004
# Service-specific configuration
CS_1_MEMORY=512M
CS_1_CPU=0.5
CS_1_ROUTE=api
CS_1_HEALTHCHECK=/health
CS_2_MEMORY=256M
CS_2_CPU=0.25
CS_2_QUEUE_NAME=demo-jobs
CS_3_MEMORY=256M
CS_3_CPU=0.5
CS_3_REPLICAS=2
CS_3_ROUTE=grpc
CS_4_MEMORY=512M
CS_4_CPU=0.5
CS_4_ROUTE=ml-apigraph TB
subgraph "External Access"
User[User/Browser]
end
subgraph "Required Services"
Nginx[Nginx :443]
PostgreSQL[(PostgreSQL :5432)]
Hasura[Hasura :8080]
Auth[Auth :4000]
end
subgraph "Custom Services"
API[express_api :8001]
Worker[bullmq_worker :8002]
GRPC[go_grpc :8003]
ML[python_api :8004]
end
subgraph "Optional Services"
Redis[(Redis :6379)]
MinIO[MinIO :9000]
Search[MeiliSearch :7700]
Admin[nself Admin :3021]
end
subgraph "Monitoring"
Prometheus[Prometheus :9090]
Grafana[Grafana :3006]
Loki[Loki :3100]
end
User --> Nginx
Nginx --> Hasura
Nginx --> Auth
Nginx --> API
Nginx --> GRPC
Nginx --> ML
Nginx --> Admin
Nginx --> Grafana
Hasura --> PostgreSQL
Auth --> PostgreSQL
API --> PostgreSQL
API --> Redis
Worker --> Redis
ML --> MinIO
Prometheus --> API
Prometheus --> Worker
Loki --> Promtail[Promtail]
Promtail --> API
Promtail --> Worker
After starting the demo, services are available at:
- GraphQL Playground:
https://api.local.nself.org - Authentication:
https://auth.local.nself.org
- REST API:
https://api.local.nself.org - gRPC Service:
https://grpc.local.nself.org - ML API:
https://ml-api.local.nself.org - API Documentation:
https://ml-api.local.nself.org/docs
- nself Admin:
https://admin.local.nself.org - Grafana:
https://grafana.local.nself.org - Prometheus:
https://prometheus.local.nself.org - Alertmanager:
https://alertmanager.local.nself.org
- Mail UI:
https://mail.local.nself.org - Search UI:
https://search.local.nself.org - MinIO Console:
https://storage-console.local.nself.org
- CPU: 4 cores
- RAM: 8GB
- Disk: 20GB
- Network: Local development
- CPU: ~2-3 cores utilized
- RAM: ~4-6GB active
- Disk: ~5GB after pulling images
- Network: Minimal (local only)
| Service Category | CPU | Memory | Storage |
|---|---|---|---|
| Core (4) | 1.5 cores | 2GB | 2GB |
| Monitoring (10) | 2 cores | 3GB | 5GB |
| Optional (6) | 1 core | 1.5GB | 3GB |
| Custom (4) | 1.5 cores | 1.5GB | 1GB |
| Total | 6 cores | 8GB | 11GB |
# Test Express API
curl https://api.local.nself.org/health
# Test Python ML API
curl https://ml-api.local.nself.org/predict \
-H "Content-Type: application/json" \
-d '{"data": [1, 2, 3, 4, 5]}'
# GraphQL Query via Hasura
curl https://api.local.nself.org/v1/graphql \
-H "Content-Type: application/json" \
-H "x-hasura-admin-secret: demo-admin-secret" \
-d '{"query": "{ users { id email } }"}'// Submit job to BullMQ worker
const Queue = require('bull');
const demoQueue = new Queue('demo-jobs', {
redis: {
host: 'redis',
port: 6379,
password: 'demo-redis-password'
}
});
await demoQueue.add('process-data', {
userId: 123,
action: 'generate-report'
});// Upload to MinIO via Storage API
const formData = new FormData();
formData.append('file', fileInput.files[0]);
fetch('https://storage.local.nself.org/upload', {
method: 'POST',
body: formData,
headers: {
'Authorization': 'Bearer <token>'
}
});The demo includes Grafana dashboards for:
- System Overview - All services at a glance
- Container Metrics - CPU, memory, network per container
- PostgreSQL Performance - Query performance, connections
- Redis Metrics - Hit rate, memory usage
- API Performance - Request rates, latencies
- Custom Service Metrics - Business metrics
All services automatically ship logs to Loki:
# View logs in Grafana
# Navigate to: https://grafana.local.nself.org
# Go to Explore → Select Loki
# Query: {container="express_api"} |= "error"Tempo collects traces from all services:
# Services automatically instrumented
# View traces in Grafana
# Useful for debugging request flowAfter nself build, customize your services:
# Edit Express API
vim services/express_api/src/index.js
# Edit Python API
vim services/python_api/main.py
# Changes persist - won't be overwritten
nself build # Safe to run again# Add to .env
CS_5=websocket_server:socketio-js:8005
CS_6=temporal_worker:temporal-js:8006
# Rebuild
nself build
# Restart
nself restart# Edit docker-compose.yml
# Under service definition:
deploy:
replicas: 3
# Apply changes
nself restart# Check status
nself status
# View logs
nself logs <service-name>
# Common issues:
# - Port conflicts
# - Database connection
# - Missing environment variables# Check resource usage
docker stats
# View Grafana dashboards
# https://grafana.local.nself.org
# Scale down monitoring if needed
MONITORING_ENABLED=false nself restart# Access PostgreSQL
nself db connect
# Check connections
SELECT * FROM pg_stat_activity;
# Reset database
nself db reset-
Development
- Use demo for learning and testing
- Customize services incrementally
- Monitor resource usage
-
Before Production
- Change all passwords
- Disable unnecessary services
- Configure proper domains
- Set up backups
-
Resource Optimization
- Disable monitoring in development
- Use Redis for session storage
- Implement caching strategies
- Optimize database queries
-
Explore Services
- Access each service URL
- Try the API endpoints
- View monitoring dashboards
-
Customize
- Modify custom services
- Add your business logic
- Configure integrations
-
Learn
- Study the generated code
- Understand service communication
- Review monitoring data
-
Build
- Create your own services
- Implement your use case
- Deploy to production