๐ง GXQ Smart Brain Operator
March 1, 2026 ยท View on GitHub
Overview
The GXQ Smart Brain Operator is a comprehensive orchestration system designed to enforce production-readiness, automate deployments, and maintain operational excellence for the GXQ Studio Solana arbitrage platform.
This system provides:
- Automated validation of code, builds, and environment
- One-command orchestration for production-ready releases
- Deployment automation for multiple platforms (Vercel, Railway, Docker)
- Health monitoring and performance reporting
- CI/CD integration with GitHub Actions
Philosophy
The Smart Brain Operator follows these principles:
- Fail-Fast: Detect and abort at the first sign of trouble
- Idempotent: Safe to run multiple times without side effects
- Transparent: Clear output and logging at every step
- Automated: Minimize manual intervention and human error
- Production-Ready: Every successful run guarantees deployability
Architecture
Core Scripts
All orchestration scripts are located in scripts/ and follow consistent patterns:
scripts/
โโโ master.sh # Main orchestrator
โโโ validate-build.sh # Build validation
โโโ auto-fix.sh # Automated code repair
โโโ env-check.sh # Environment validation
โโโ gxq-selfheal.sh # System regeneration
โโโ deploy-vercel.sh # Vercel deployment
โโโ deploy-railway.sh # Railway deployment
โโโ deploy-docker.sh # Docker deployment
โโโ health-check.sh # Health monitoring
โโโ monitor-logs.sh # Log aggregation
โโโ performance-report.sh # Performance metrics
Script Dependencies
master.sh
โโโ env-check.sh (validates environment)
โโโ npm ci (installs dependencies)
โโโ npm run type-check (TypeScript validation)
โโโ npm run lint (code linting)
โโโ auto-fix.sh (automated repairs)
โโโ npm run build:backend (backend build)
โโโ npm run build:webapp (webapp build)
โโโ validate-build.sh (artifact validation)
โโโ git operations (commit, tag, push)
Quick Start
Prerequisites
- Node.js 20.x or higher
- npm package manager
- Git for version control
- Bash shell (Linux, macOS, WSL on Windows)
Initial Setup
-
Clone the repository
git clone https://github.com/SMSDAO/TradeOS.git cd TradeOS -
Set up environment variables
cp .env.example .env # Edit .env and fill in required variables npm run env-check -
Run the master orchestrator
npm run master
Core Commands
Master Orchestration
Purpose: Complete validation, build, and deployment preparation
npm run master
What it does:
- Validates all environment variables
- Clean-installs all dependencies (backend + webapp)
- Runs TypeScript type-checking
- Runs code linting
- Executes auto-fix for common issues
- Builds backend and webapp
- Validates build artifacts
- Commits changes with timestamp
- Creates version tag
- Pushes to origin with tags
When to use:
- Before deploying to production
- After major changes
- To ensure system is in deployable state
Environment Validation
npm run env-check
Validates:
- Required:
SOLANA_RPC_URL,WALLET_PRIVATE_KEY,JWT_SECRET,ADMIN_USERNAME,ADMIN_PASSWORD - Optional:
GEMINI_API_KEY,NEYNAR_API_KEY,QUICKNODE_RPC_URL,DB_HOST, etc.
Output: Color-coded status (โ OK, โ MISSING, โ ๏ธ OPTIONAL)
Build Validation
npm run validate-build
Checks:
- Backend artifacts:
dist/src/index.js,dist/src/server.js,dist/src/index-railway.js - Webapp artifacts:
webapp/.next/ - Config files:
package.json,tsconfig.json,next.config.ts - Core scripts:
scripts/master.sh,scripts/validate-build.sh - Database schemas:
db/directory
System Self-Heal
npm run selfheal
Actions:
- Verifies repository structure
- Cleans build artifacts (
dist/,webapp/.next/) - Removes nested
node_modules - Reinstalls dependencies
- Runs full master orchestration
When to use:
- After Git conflicts or merge issues
- When builds are failing mysteriously
- To reset to a clean state
Deployment
Vercel (Webapp)
npm run deploy:vercel
Requirements:
VERCEL_TOKENenvironment variable- Vercel CLI (auto-installed if missing)
Steps:
- Checks for VERCEL_TOKEN
- Runs pre-deployment validation
- Deploys to Vercel production
- Displays deployment URL
- Updates
.env.productionif exists
Railway (Backend)
npm run deploy:railway
Requirements:
- Railway CLI installed:
npm install -g @railway/cli railway.jsonconfiguration file
Steps:
- Validates Railway CLI installation
- Checks
railway.jsonconfiguration - Builds backend
- Deploys to Railway
- Monitors deployment status
- Runs health check on deployed service
Docker
npm run deploy:docker
Steps:
- Validates Docker installation
- Checks
Dockerfileanddocker-compose.yml - Builds Docker image:
gxq-studio:latest - Tests container locally
- Optionally pushes to registry if
DOCKER_REGISTRYis set
Monitoring
Health Check
npm run health
Monitors:
- Backend service (local and production)
- Webapp service (local and production)
- Database connection (if
DB_HOSTset) - Solana RPC endpoint
- Critical environment variables
- System resources (memory, disk)
Output: ASCII art dashboard with component-by-component status
Log Monitoring
npm run logs [backend|webapp|all] [ERROR|WARN|INFO|DEBUG|all]
Examples:
npm run logs all # Monitor all logs
npm run logs backend # Backend logs only
npm run logs webapp ERROR # Webapp errors only
Features:
- Real-time log tailing
- Color-coded by log level (ERROR=red, WARN=yellow, INFO=cyan, DEBUG=blue)
- Log level filtering
- Multi-source aggregation
Performance Report
npm run perf
Generates:
- Build times (backend + webapp)
- Bundle sizes (
dist/andwebapp/.next/) - Dependency counts
- TypeScript compilation time
- Test coverage percentage
- Memory usage
Output:
- Markdown report:
reports/performance-YYYY-MM-DD.md - JSON metrics:
reports/metrics.json
CI/CD Integration
GitHub Actions Workflows
The system includes four CI/CD workflows:
1. gxq-master-ci.yml
Triggers: Push to master or main branch
Jobs:
- validate-environment - Mock env validation
- install-dependencies - Clean install with caching
- lint-and-typecheck - ESLint + TypeScript checks
- build-backend - Backend compilation
- build-webapp - Webapp build
- validate-build - Artifact validation
- security-scan - npm audit
- master-ci-summary - Overall status
2. gxq-pr-check.yml
Triggers: Pull requests to master/main
Features:
- Full validation pipeline
- Artifact size reporting
- Automated PR comments with results
- Security scanning
3. gxq-deploy-production.yml
Triggers:
- Manual workflow dispatch
- Push to tags matching
v*
Jobs:
- prepare-deployment - Build all artifacts
- deploy-vercel - Deploy webapp to Vercel
- deploy-railway - Deploy backend to Railway
- post-deployment-health - Health checks
- notify-deployment - Slack/Discord notifications (optional)
4. gxq-scheduled-health.yml
Triggers: Every 6 hours (cron: 0 */6 * * *)
Features:
- Automated health checks for all services
- Creates GitHub issue if services are down
- Auto-closes issues when services recover
- Health report in workflow summary
Environment Variables
Required Variables
These must be set for the system to function:
| Variable | Description | Example |
|---|---|---|
SOLANA_RPC_URL | Solana RPC endpoint | https://api.mainnet-beta.solana.com |
WALLET_PRIVATE_KEY | Base58 encoded wallet key | 5J7W8... |
JWT_SECRET | Secret for JWT signing | your-secret-key |
ADMIN_USERNAME | Admin authentication | admin |
ADMIN_PASSWORD | Admin password | secure-password |
Optional Variables
Enhance functionality but not required:
| Variable | Description |
|---|---|
GEMINI_API_KEY | For AI features |
NEYNAR_API_KEY | Farcaster integration |
QUICKNODE_RPC_URL | Enhanced RPC features |
DB_HOST | Database host |
DB_PORT | Database port |
DB_USER | Database user |
DB_PASSWORD | Database password |
DB_NAME | Database name |
Deployment Variables
| Variable | Description |
|---|---|
VERCEL_TOKEN | Vercel API token |
VERCEL_ORG_ID | Vercel organization ID |
VERCEL_PROJECT_ID | Vercel project ID |
RAILWAY_TOKEN | Railway API token |
DOCKER_REGISTRY | Docker registry URL |
Troubleshooting
Common Issues
Issue: Environment validation fails
Solution:
cp .env.example .env
# Edit .env and fill in required variables
npm run env-check
Issue: Build fails with TypeScript errors
Solution:
npm run type-check # See errors
npm run auto-fix # Attempt fixes
npm run type-check # Verify fixes
Issue: Linting errors
Solution:
npm run lint # See errors
npm run auto-fix # Attempt fixes
npm run lint # Verify fixes
Issue: Master orchestration gets stuck
Solution:
npm run selfheal # Full system reset
Issue: Deployment fails
Solution:
# For Vercel
echo $VERCEL_TOKEN # Check token is set
npm run deploy:vercel # Retry
# For Railway
railway login # Authenticate
npm run deploy:railway # Retry
Issue: Health checks fail
Solution:
npm run health # Check status
# Review output and fix failed components
GitHub Codespaces Integration
The Smart Brain Operator works seamlessly in GitHub Codespaces:
-
Open in Codespaces
- Click "Code" โ "Codespaces" โ "Create codespace"
-
Setup environment
npm run env-check # Validate env vars npm run master # Run full orchestration -
Deploy from Codespaces
export VERCEL_TOKEN=your_token npm run deploy:vercel
Best Practices
Before Deployment
- Always run
npm run masterfirst - Fix any issues reported
- Commit and push changes
- Run
npm run healthto verify current state - Then deploy with
npm run deploy:vercelornpm run deploy:railway
During Development
- Run
npm run env-checkafter changing environment - Run
npm run validate-buildafter builds - Use
npm run auto-fixfor quick repairs - Monitor with
npm run logsduring testing
Maintenance
- Run
npm run healthdaily - Review
npm run perfreports weekly - Use
npm run selfhealif issues arise - Keep dependencies updated
Integration Examples
Pre-commit Hook
Add to .git/hooks/pre-commit:
#!/bin/bash
npm run validate-build || exit 1
CI/CD Pipeline
# Add to your workflow
- name: Run Smart Brain Validation
run: npm run master
Monitoring Cron Job
# Add to crontab
0 */6 * * * cd /path/to/repo && npm run health
Support
- Documentation: See
docs/CI_CD_GUIDE.mdanddocs/DEPLOYMENT.md - Issues: Report at https://github.com/SMSDAO/TradeOS/issues
- Health Checks: Automated issues created by scheduled health workflow
Version History
- v1.0.0 (2025-01-01) - Initial Smart Brain Operator implementation
- Core orchestration scripts
- Deployment automation
- Health monitoring
- CI/CD workflows
- Performance reporting
This is a living document. Updates are made as the system evolves.