Command-line interface and scripts reference for Optionix.
- Overview
- Setup Scripts
- Runtime Scripts
- Database Management
- Testing Scripts
- Code Quality
- Deployment Scripts
- Monitoring
Optionix provides a comprehensive set of command-line tools for development, testing, deployment, and operations. All scripts are located in the scripts/ directory.
Automated environment setup script that installs all dependencies.
Location: scripts/setup_optionix_env.sh
Usage:
chmod +x scripts/setup_optionix_env.sh
./scripts/setup_optionix_env.shWhat it does:
- Checks for required tools (Python, Node.js, npm)
- Creates Python virtual environment
- Installs backend dependencies
- Installs frontend dependencies
- Sets up blockchain environment
Options:
| Flag | Description | Example |
|---|---|---|
--skip-backend |
Skip backend setup | ./setup_optionix_env.sh --skip-backend |
--skip-frontend |
Skip frontend setup | ./setup_optionix_env.sh --skip-frontend |
--dev |
Install development dependencies | ./setup_optionix_env.sh --dev |
Example Output:
Starting Optionix project setup...
✓ All required tools found.
Setting up Optionix Backend...
✓ Backend dependencies installed.
Setting up Optionix Web Frontend...
✓ Frontend dependencies installed.
Optionix project setup script finished.
Main script to start the entire Optionix platform.
Location: scripts/run_optionix.sh
Usage:
chmod +x scripts/run_optionix.sh
./scripts/run_optionix.shWhat it does:
- Starts backend API server
- Starts frontend development server
- Optionally starts blockchain node
Options:
| Flag | Description | Example |
|---|---|---|
--backend-only |
Start only backend | ./run_optionix.sh --backend-only |
--frontend-only |
Start only frontend | ./run_optionix.sh --frontend-only |
--production |
Production mode | ./run_optionix.sh --production |
--port PORT |
Custom port | ./run_optionix.sh --port 8080 |
Python script to start the backend API server.
Location: code/run_backend.py
Usage:
cd code
python run_backend.pyEnvironment Variables:
| Variable | Default | Description |
|---|---|---|
HOST |
0.0.0.0 | Server host |
PORT |
8000 | Server port |
DEBUG |
False | Debug mode |
RELOAD |
False | Auto-reload on code changes |
Example:
# Development mode with auto-reload
DEBUG=true RELOAD=true python run_backend.py
# Production mode with 4 workers
uvicorn backend.app:app --workers 4 --host 0.0.0.0 --port 8000Comprehensive database management script.
Location: scripts/db_manager.sh
Commands:
| Command | Description | Example |
|---|---|---|
init |
Initialize database | ./db_manager.sh init |
migrate |
Run migrations | ./db_manager.sh migrate |
rollback |
Rollback last migration | ./db_manager.sh rollback |
seed |
Seed database with test data | ./db_manager.sh seed |
backup |
Create database backup | ./db_manager.sh backup |
restore |
Restore from backup | ./db_manager.sh restore backup.sql |
reset |
Reset database (destructive) | ./db_manager.sh reset |
Usage Examples:
# Initialize database
./scripts/db_manager.sh init
# Create new migration
./scripts/db_manager.sh migrate --message "Add user preferences table"
# Backup database
./scripts/db_manager.sh backup
# Output: Database backed up to: backups/optionix_2025-01-01_120000.sql
# Restore database
./scripts/db_manager.sh restore backups/optionix_2025-01-01_120000.sql
# Reset database (WARNING: Destructive)
./scripts/db_manager.sh reset --confirmDirect database migration management using Alembic.
Usage:
cd code/backend
# Create a new migration
alembic revision --autogenerate -m "Description of changes"
# Apply all pending migrations
alembic upgrade head
# Rollback one migration
alembic downgrade -1
# Show migration history
alembic history
# Show current version
alembic current
# Upgrade to specific revision
alembic upgrade <revision_id>
# Downgrade to specific revision
alembic downgrade <revision_id>Run all tests across the project.
Location: scripts/comprehensive_test.sh
Usage:
./scripts/comprehensive_test.shOptions:
| Flag | Description | Example |
|---|---|---|
--backend |
Test only backend | ./comprehensive_test.sh --backend |
--frontend |
Test only frontend | ./comprehensive_test.sh --frontend |
--coverage |
Generate coverage report | ./comprehensive_test.sh --coverage |
--verbose |
Verbose output | ./comprehensive_test.sh --verbose |
Example Output:
Running Optionix Comprehensive Tests...
========================================
Backend Tests:
✓ test_option_pricing.py::test_black_scholes_call PASSED
✓ test_option_pricing.py::test_black_scholes_put PASSED
...
Backend: 154/154 tests passed (100%)
Coverage: 81%
Frontend Tests:
✓ Dashboard.test.tsx PASSED
...
Frontend: 89/89 tests passed (100%)
Overall: 243/243 tests passed ✓
cd code/backend
# Run all tests
pytest
# Run specific test file
pytest tests/test_pricing.py
# Run specific test
pytest tests/test_pricing.py::test_black_scholes_call
# Run with coverage
pytest --cov=backend --cov-report=html
# Run with verbose output
pytest -v
# Run in parallel
pytest -n auto
# Stop on first failure
pytest -x
# Run only failed tests from last run
pytest --lfcd web-frontend
# Run all tests
npm test
# Run in watch mode
npm test -- --watch
# Run with coverage
npm test -- --coverage
# Update snapshots
npm test -- --updateSnapshot
# Run specific test file
npm test -- Dashboard.test.tsxRun all linters and code quality checks.
Location: scripts/lint-all.sh
Usage:
./scripts/lint-all.shOptions:
| Flag | Description | Example |
|---|---|---|
--fix |
Auto-fix issues | ./lint-all.sh --fix |
--backend |
Lint only backend | ./lint-all.sh --backend |
--frontend |
Lint only frontend | ./lint-all.sh --frontend |
Checks Performed:
- Python: flake8, black, isort, mypy, bandit
- JavaScript/TypeScript: ESLint, Prettier
- Security: bandit (Python), npm audit (Node)
- Code complexity analysis
Example Output:
Running Code Quality Checks...
==============================
✓ flake8: No issues found
✓ black: All files formatted correctly
✓ isort: Import order correct
✓ mypy: Type checking passed
✓ ESLint: No errors
✓ Prettier: All files formatted
✓ bandit: No security issues
Overall: All checks passed ✓
Backend:
cd code/backend
# Flake8 (style)
flake8 .
# Black (formatter)
black . --check # Check only
black . # Format
# isort (import sorting)
isort . --check-only # Check only
isort . # Sort
# mypy (type checking)
mypy .
# bandit (security)
bandit -r . -f json -o security_report.jsonFrontend:
cd web-frontend
# ESLint
npm run lint
# Fix lint issues
npm run lint:fix
# Prettier
npm run format:check # Check only
npm run format # Format
# Type check
npm run type-checkBuild production-ready artifacts.
Location: scripts/build_production.sh
Usage:
./scripts/build_production.shWhat it does:
- Builds optimized backend Docker image
- Builds optimized frontend bundle
- Compiles smart contracts
- Creates deployment artifacts
Options:
| Flag | Description | Example |
|---|---|---|
--tag TAG |
Docker image tag | ./build_production.sh --tag v2.0.0 |
--push |
Push to registry | ./build_production.sh --push |
--no-cache |
Build without cache | ./build_production.sh --no-cache |
Example:
# Build with specific tag
./scripts/build_production.sh --tag v2.0.0
# Build and push to Docker registry
./scripts/build_production.sh --tag v2.0.0 --push
# Output:
# Building backend Docker image...
# ✓ Backend image built: optionix-backend:v2.0.0
# Building frontend bundle...
# ✓ Frontend bundle created: web-frontend/build/
# Compiling smart contracts...
# ✓ Contracts compiled: code/blockchain/build/CI/CD pipeline script.
Location: scripts/ci_cd_pipeline.sh
Usage:
./scripts/ci_cd_pipeline.shStages:
- Environment validation
- Dependency installation
- Code quality checks
- Unit tests
- Integration tests
- Build artifacts
- Deploy to staging
Options:
| Flag | Description | Example |
|---|---|---|
--stage STAGE |
Run specific stage | ./ci_cd_pipeline.sh --stage test |
--skip-tests |
Skip test stage | ./ci_cd_pipeline.sh --skip-tests |
--deploy-prod |
Deploy to production | ./ci_cd_pipeline.sh --deploy-prod |
Monitor system performance and health.
Location: scripts/performance_monitor.sh
Usage:
./scripts/performance_monitor.shOptions:
| Flag | Description | Example |
|---|---|---|
--interval SECONDS |
Monitoring interval | ./performance_monitor.sh --interval 5 |
--duration MINUTES |
Monitoring duration | ./performance_monitor.sh --duration 60 |
--output FILE |
Save report to file | ./performance_monitor.sh --output report.txt |
Metrics Monitored:
- CPU usage
- Memory usage
- Disk I/O
- Network traffic
- API response times
- Database connections
- Redis cache hit rate
Example Output:
Optionix Performance Monitor
============================
Timestamp: 2025-01-01 12:00:00
CPU Usage: 35%
Memory Usage: 2.4GB / 8GB (30%)
Disk I/O: Read 15MB/s, Write 5MB/s
Network: In 10Mbps, Out 5Mbps
API Metrics:
Requests/sec: 145
Avg Response Time: 45ms
P95 Response Time: 120ms
P99 Response Time: 250ms
Database:
Active Connections: 12/20
Query Time (avg): 12ms
Redis:
Cache Hit Rate: 94%
Memory: 512MB
Validate environment configuration.
Location: scripts/env_validator.sh
Usage:
./scripts/env_validator.shChecks:
- Required tools installed (Python, Node.js, PostgreSQL, Redis)
- Environment variables configured
- Database connectivity
- API endpoints reachable
- Blockchain node connectivity
Example Output:
Validating Optionix Environment...
===================================
✓ Python 3.11 found
✓ Node.js 18.x found
✓ npm 9.x found
✓ PostgreSQL 14 found
✓ Redis 7 found
✓ Environment variables configured
✓ Database connection successful
✓ Redis connection successful
✗ Blockchain node not reachable (Warning)
Environment validation: 8/9 checks passed
# Remove build artifacts and cache
./scripts/clean_project.sh
# What it removes:
# - Python __pycache__ directories
# - Node modules (with --deep flag)
# - Build directories
# - Coverage reports
# - Log files# Generate API documentation
./scripts/doc_generator.sh
# Options:
# --api Generate API docs only
# --code Generate code docs only
# --all Generate all documentation# Build Docker image
docker build -t optionix-backend -f infrastructure/Dockerfile .
# Run container
docker run -d -p 8000:8000 optionix-backend
# Docker Compose
docker-compose up -d # Start all services
docker-compose down # Stop all services
docker-compose logs -f # View logs
docker-compose ps # View status
docker-compose restart # Restart services# Apply configurations
kubectl apply -f infrastructure/kubernetes/
# Check status
kubectl get pods -n optionix
kubectl get services -n optionix
# View logs
kubectl logs -f deployment/optionix-backend -n optionix
# Scale deployment
kubectl scale deployment/optionix-backend --replicas=5 -n optionix
# Port forward
kubectl port-forward service/optionix-backend 8000:8000 -n optionixcd infrastructure/terraform
# Initialize
terraform init
# Plan changes
terraform plan
# Apply changes
terraform apply
# Destroy infrastructure
terraform destroy
# Output values
terraform outputcd infrastructure/ansible
# Run playbook
ansible-playbook -i inventory/production.ini playbooks/deploy.yml
# Check syntax
ansible-playbook playbooks/deploy.yml --syntax-check
# Dry run
ansible-playbook -i inventory/production.ini playbooks/deploy.yml --check
# Run specific tasks
ansible-playbook -i inventory/production.ini playbooks/deploy.yml --tags "backend"| Command | Arguments | Description | Example |
|---|---|---|---|
setup_optionix_env.sh |
[--skip-backend|--skip-frontend|--dev] |
Setup environment | ./setup_optionix_env.sh |
run_optionix.sh |
[--backend-only|--frontend-only|--production] |
Start platform | ./run_optionix.sh --production |
db_manager.sh |
<init|migrate|backup|restore|reset> |
Manage database | ./db_manager.sh backup |
comprehensive_test.sh |
[--backend|--frontend|--coverage] |
Run tests | ./comprehensive_test.sh --coverage |
lint-all.sh |
[--fix|--backend|--frontend] |
Code quality | ./lint-all.sh --fix |
build_production.sh |
[--tag TAG|--push] |
Build artifacts | ./build_production.sh --tag v2.0 |
performance_monitor.sh |
[--interval N|--duration N] |
Monitor system | ./performance_monitor.sh --interval 5 |
env_validator.sh |
None | Validate environment | ./env_validator.sh |
-
Always activate virtual environment before running Python commands:
source venv/bin/activate -
Run tests before committing:
./scripts/comprehensive_test.sh
-
Check code quality:
./scripts/lint-all.sh --fix
-
Backup database before migrations:
./scripts/db_manager.sh backup alembic upgrade head
-
Monitor logs during deployment:
docker-compose logs -f
See TROUBLESHOOTING.md for common CLI issues and solutions.
- API Reference - REST API documentation
- Configuration - Environment configuration
- Examples - Practical examples