This document describes the master automation architecture that orchestrates UI, Database, API, and SDK builds and deployments across the GXQ Studio platform.
The master.sh script provides a comprehensive, production-ready orchestration of the entire system build and validation pipeline. It ensures all components are validated, built, and ready for deployment.
scripts/master.sh# Run full master orchestration
npm run master
# Or directly
bash scripts/master.shThe master script executes an 11-step pipeline:
- Validates all required environment variables using
scripts/env-check.sh - Verifies environment template sync with
scripts/env-sync-check.sh - Ensures no secrets are committed to
.env.example - Exit on failure: Yes (critical step)
Required Variables:
SOLANA_RPC_URL- Solana RPC endpointWALLET_PRIVATE_KEY- Base58 wallet private keyJWT_SECRET- JWT signing secretADMIN_USERNAME- Admin panel usernameADMIN_PASSWORD- Admin panel password
- Runs
npm cifor backend dependencies - Runs
npm cifor webapp dependencies - Uses
--prefer-offlinefor faster installation - Exit on failure: Yes
- Type-checks backend with
npm run type-check - Type-checks webapp with
npm run type-check:webapp - Uses strict TypeScript mode
- Exit on failure: Yes
- Lints backend with ESLint (
npm run lint) - Lints webapp with ESLint (
npm run lint:webapp) - Reports issues but continues (non-blocking)
- Exit on failure: No (warnings logged)
- Runs
scripts/auto-fix.shto fix common issues - Formats code and applies safe fixes
- Exit on failure: No (warnings logged)
- Compiles TypeScript to JavaScript
- Output directory:
dist/ - Verifies critical artifacts exist:
dist/src/index.js(main entry)dist/src/server.js(server entry)
- Exit on failure: Yes
- Builds Next.js webapp for production
- Output directory:
webapp/.next/ - Optimizes for performance
- Exit on failure: Yes
- Checks for
db/schema.sql - Runs migrations if database is configured
- Uses
scripts/db-migrate.sh - Exit on failure: No (database is optional)
Database Configuration:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=gxq_studio
DB_USER=postgres
DB_PASSWORD=your_password- Validates
api/health.tsexists - Verifies health endpoints in
src/server.ts - Exit on failure: No (informational)
- Runs
scripts/validate-build.sh - Verifies all build artifacts exist
- Checks configuration files
- Exit on failure: Yes
- Stages changes with
git add . - Creates commit with timestamp
- Creates git tag (e.g.,
v2025.12.28-1430) - Pushes to origin with tags
- Exit on failure: No (warnings logged)
Validates required environment variables are present.
npm run env-checkValidates:
- Required variables are set
- Optional variables are documented
- Provides guidance on missing variables
Ensures .env.example is synchronized with production requirements.
npm run env-syncValidates:
- All required variables are documented in
.env.example - No real secrets are present in
.env.example - Placeholders are used appropriately
Runs database migrations and seed data.
npm run db-migrateFeatures:
- Tests database connection
- Runs
db/schema.sql - Optionally runs
db/seed.sql - Gracefully handles missing database configuration
Requirements:
- PostgreSQL client tools (
psql) - Database environment variables configured
Validates all build artifacts are present and correct.
npm run validate-buildChecks:
- Backend build artifacts (
dist/) - Webapp build artifacts (
webapp/.next/) - Configuration files
- Core scripts
- Database schemas
Comprehensive system health monitoring.
npm run healthChecks:
- Backend service availability
- Webapp service availability
- Database connectivity
- Solana RPC endpoint health
- Environment variable configuration
- System resources (memory, disk)
Comprehensive pipeline with the following jobs:
- install - Install dependencies (Node 18, 20)
- lint - ESLint validation
- typecheck - TypeScript type checking
- unit-tests-backend - Backend test suite
- unit-tests-webapp - Webapp test suite
- coverage-merge - Merge and upload coverage
- security-scan - npm audit and security checks
- build - Build backend and webapp
- health-check - Validate health checks and environment ✨ NEW
- ci-summary - Generate summary and report
Key Features:
- Runs on pull requests and push to main/develop
- Matrix strategy for multiple Node versions
- Artifact caching for faster builds
- Continue-on-error for non-critical steps
- Comprehensive reporting
Enables native GitHub auto-merge when conditions are met:
Requirements:
- PR has
auto-mergelabel - PR is not in draft state
- At least 1 approval from non-bot user
- No changes requested
- All required CI checks pass (enforced by GitHub)
How it works:
- Validates PR meets gating requirements
- Enables GitHub native auto-merge
- GitHub automatically merges when all status checks pass
- Respects branch protection rules
Respects Branch Protection: The workflow uses GitHub's native auto-merge API, which automatically respects all branch protection rules configured in the repository settings, including:
- Required status checks
- Required reviews
- Required signatures
- Restrictions on who can push
How to Use:
- Create your PR as normal
- Add the
auto-mergelabel to the PR - Get at least 1 approval from a team member
- The workflow will automatically enable GitHub's auto-merge
- When all CI checks pass, GitHub will automatically merge the PR
- A comment will be added to confirm auto-merge is enabled
Troubleshooting:
- If the workflow fails with "Missing 'auto-merge' label", add the label via GitHub UI
- If it fails with "Not enough approvals", request and receive a review approval
- If it fails with "Changes requested", address the review comments first
- If it fails with "PR is draft", mark the PR as ready for review
# Full validation suite
npm run validate
# Individual steps (matching CI)
npm run lint
npm run type-check
npm run test
npm run build
npm run healthThe .env.example file serves as the canonical documentation for all environment variables.
Sections:
- Deployment Platform
- Solana Configuration (Required)
- Server Configuration
- Admin Panel (Required)
- Trading Configuration
- Jito MEV Protection
- Jupiter V6 Configuration
- Priority Fee Configuration
- Dev Fee Configuration
- Profit Distribution
- Flash Loan Providers
- Jupiter Aggregator
- QuickNode Configuration (Optional)
- Oracle Intelligence (Optional)
- Database Configuration (Optional)
- Farcaster Integration (Optional)
- GXQ Ecosystem (Optional)
- Webapp Configuration
- Application Settings
- Production System Configuration
Security Requirements:
- All values must be placeholders
- No real secrets committed
- Clear documentation for each variable
- Examples of expected format
When adding new environment variables:
- Add to your local
.envfile - Add to
.env.examplewith placeholder value - Document the variable's purpose
- Run
npm run env-syncto validate - Update this documentation if needed
Location: db/schema.sql
Features:
- PostgreSQL 12+ compatible
- UUID primary keys
- Comprehensive wallet analysis tables
- Farcaster profile integration
- Trade history tracking
- Airdrop eligibility scoring
Automatic (via master.sh):
npm run master # Runs migrations if DB configuredManual:
npm run db-migrateProduction Deployment:
# Set environment variables
export DB_HOST=your-db-host
export DB_USER=your-db-user
export DB_PASSWORD=your-db-password
export DB_NAME=gxq_studio
# Run migrations
npm run db-migrateThe system provides a unified API through src/server.ts:
Health Endpoints:
GET /health- System health statusGET /api/health- API health check
Admin Endpoints:
POST /api/admin/start- Start arbitrage scanningPOST /api/admin/stop- Stop scanningPOST /api/admin/pause- Pause scanningGET /api/admin/status- Get current status
Monitoring:
GET /api/monitor- Real-time metricsGET /metrics- Prometheus metrics
The project is not published as an SDK, but provides:
- Type declarations in
src/types.ts - Service interfaces for flash loans, DEX, providers
- Reusable utilities in
src/utils/
For SDK publishing (future):
- Add
typesfield topackage.json - Configure
tsconfig.jsonwithdeclaration: true - Add
prepublishOnlyscript - Configure npm registry
-
Vercel (Webapp)
- Root Directory:
webapp - Build Command:
npm run build - Output:
.next/
- Root Directory:
-
Railway (Backend)
- Build Command:
npm run build:backend - Start Command:
npm run start:server - Port: 3000
- Build Command:
-
Docker
- Multi-stage builds
- Separate containers for backend/webapp
- Docker Compose orchestration
-
VPS/Self-Hosted
- PM2 process management
- Systemd service configuration
- Nginx reverse proxy
Before deploying to any platform:
- ✅ Run
npm run mastersuccessfully - ✅ Ensure all CI checks pass
- ✅ Verify environment variables are configured
- ✅ Test health endpoints locally
- ✅ Review security audit logs
- ✅ Backup database (if applicable)
- ✅ Tag release with semantic version
Issue: Environment validation fails
# Solution: Check required variables
npm run env-check
# Copy example and fill in values
cp .env.example .env
nano .envIssue: Build artifacts missing
# Solution: Clean and rebuild
rm -rf dist webapp/.next
npm run buildIssue: Database migration fails
# Solution: Check database connectivity
psql -h $DB_HOST -U $DB_USER -d $DB_NAME -c "SELECT 1"
# Verify credentials
npm run env-checkIssue: Health check fails in CI
# Solution: Run health check locally
npm run health
# Check for missing dependencies
npm ci
cd webapp && npm ci && cd ..Enable verbose logging:
# Set debug mode
export DEBUG=true
export LOG_LEVEL=debug
# Run master script
npm run master- Run
npm run masterto validate everything - Check
git statusto review changes - Ensure no secrets in committed files
- Run
npm run env-syncto validate templates
Recommended settings:
- Require pull request reviews (1+)
- Require status checks to pass:
- lint
- typecheck
- unit-tests-backend
- build
- health-check
- Require branches to be up to date
- Include administrators in restrictions
- Create PR with comprehensive description
- Add
auto-mergelabel - Request review from team member
- Wait for approval
- Auto-merge enables automatically
- PR merges when CI passes
- Never commit secrets to version control
- Use environment variables for all sensitive data
- Rotate secrets regularly (JWT_SECRET, passwords)
- Use strong passwords (12+ characters)
- Enable 2FA on all service accounts
.env- Local development (gitignored).env.example- Template (committed).env.local- Alternative local (gitignored).env.production- Never commit this!
- All deployments logged with timestamps
- Git tags for version tracking
- CI/CD logs retained for 7 days
- Database migrations tracked in schema
The system provides multiple health check levels:
- Basic: Service is running
- Database: Database connectivity
- RPC: Solana RPC availability
- Full: All components operational
Prometheus-compatible metrics at /metrics:
- Request rates
- Response times
- Error rates
- Trade execution metrics
- Arbitrage opportunities found
Structured logging via Winston:
- Development: Console with colors
- Production: JSON to stdout
- Levels: error, warn, info, debug
- Correlation IDs for request tracing
When adding new automation:
- Update
scripts/master.shif needed - Add corresponding npm script to
package.json - Document in this file
- Add to CI workflow if required
- Update
.env.examplewith new variables - Test locally before committing
- v1.0.0 - Initial master automation
- v1.1.0 - Added database migration support
- v1.2.0 - Added environment sync validation
- v1.3.0 - Added health check to CI pipeline
- v1.4.0 - Enhanced auto-merge with branch protection
Last Updated: 2025-12-28 Maintained By: GXQ Studio Team