Skip to main content

Sparki Command Reference - Quick Lookup

Quick Access: Use this document to quickly find the exact command you need.

⚑ Essential Commands (Run These First)

Initial Setup

# Complete setup in order (do this once)
cd /Users/alexarno/materi/domain
make setup                                  # Create workspace structure
make assemble ENV=development              # Initialize services
docker-compose -f docker-compose.unified.yml up -d postgres redis

Start Services

# Start all services (requires postgres/redis running)
make start

# Verify they're running
make health

# Expected output:
# Service Health Status:
# β”œβ”€ API (8080):     βœ… Healthy
# β”œβ”€ Relay (8081):   βœ… Healthy
# β”œβ”€ Shield (8000):  βœ… Healthy
# └─ Overall:        βœ… All services operational

πŸ§ͺ Testing Commands

Run Tests

# All tests (comprehensive)
./tests/sparki-test-orchestrator.sh all development          # ~120 min

# Specific test suites
./tests/sparki-test-orchestrator.sh unit development         # ~5 min (fast)
./tests/sparki-test-orchestrator.sh integration development  # ~10 min
./tests/sparki-test-orchestrator.sh quality development      # ~20 min (linting + security)

# Single service tests
cd .workspace/api && make test                  # Go unit tests
cd .workspace/relay && make test                # Rust tests
cd .workspace/shield && python manage.py test   # Django tests

View Test Results

# Human-readable report
cat test-reports/orchestrator.log

# Machine-readable (JSON)
cat test-reports/test-report-*.json | jq .

# Quick summary
ls -lh test-reports/
tail -50 test-reports/orchestrator.log

πŸ“Š Metrics & Monitoring

View Metrics

# API metrics (port 9090)
curl http://localhost:9090/metrics

# Relay metrics (port 9092)
curl http://localhost:9092/metrics

# Shield metrics (port 9091)
curl http://localhost:9091/metrics

# Specific metric queries
curl -s http://localhost:9090/metrics | grep http_requests_total
curl -s http://localhost:9090/metrics | grep database_connections
curl -s http://localhost:9092/metrics | grep websocket_connections
curl -s http://localhost:9091/metrics | grep jwt_validations

Health Endpoints

# Check individual service health
curl http://localhost:8080/health  # API
curl http://localhost:8081/health  # Relay (or /ready)
curl http://localhost:8000/health  # Shield

# Readiness checks
curl http://localhost:8080/ready   # API readiness
curl http://localhost:8081/ready   # Relay readiness
curl http://localhost:8000/ready   # Shield readiness

πŸ“ Logs & Debugging

View Logs

# All service logs
make logs

# Specific service logs
make logs-api                       # API logs
make logs-relay                     # Relay logs
make logs-shield                    # Shield logs

# Real-time tail
make logs-api | tail -f             # Follow API logs
make logs-relay | tail -f           # Follow Relay logs

# Search logs
make logs-api | grep -i error
make logs | grep -i exception

Rebuild & Restart

# Stop and start services
make restart

# Rebuild from scratch
make clean
make build
make start

# Rebuild specific service
cd .workspace/api && make rebuild
cd .workspace/relay && make rebuild
cd .workspace/shield && make rebuild

πŸ—„οΈ Database Commands

Database Operations

# Run migrations
make migrate                        # Apply all migrations
make migrate ENV=production        # Migrations for production

# Check migration status
make migrate-status

# Database shell (PostgreSQL)
make db-shell                       # Connect to database
# Then run SQL: SELECT * FROM users; etc.

# Backup database
make db-backup                      # Create backup

# Reset database (DESTRUCTIVE)
make db-reset                       # Drop and recreate all tables
make db-reset ENV=development      # Reset dev database

# Create new migration
cd .workspace/api && make migration NAME=add_user_table
cd .workspace/shield && python manage.py makemigrations

πŸ” Redis Commands

Redis Operations

# Connect to Redis
make redis-shell                    # Open Redis CLI

# From Redis CLI:
XLEN materi:events:documents                           # Count events
XREAD COUNT 10 STREAMS materi:events:documents 0       # Read first 10 events
XREAD STREAMS materi:events:documents $ BLOCK 5000     # Wait for new events

# View all streams
COMMAND DOCS XLEN
INFO streams

# Clear cache
FLUSHDB                             # Clear entire database (DESTRUCTIVE)
FLUSHALL                            # Clear everything (DESTRUCTIVE)

Event Monitoring

# Subscribe to real-time events
make redis-shell
XREAD STREAMS materi:events:collaboration $ BLOCK 0

# Monitor specific event stream
XLEN materi:events:collaboration    # Count collaboration events
XLEN materi:events:documents        # Count document events
XLEN materi:events:users            # Count user events
XLEN materi:events:workspaces       # Count workspace events

πŸ” Authentication & Tokens

JWT Token Management

# Generate test token (Shield service)
cd .workspace/shield && python manage.py shell
>>> from apps.auth.utils import generate_jwt_token
>>> token = generate_jwt_token(user_id="test-user")
>>> print(token)

# Or use script if available
cd .workspace/shield && python scripts/generate_token.py

# Validate token with API
curl -H "Authorization: Bearer <token>" http://localhost:8080/api/v1/documents

# Set JWT secret (if not already set)
export JWT_SECRET=$(openssl rand -base64 32)
echo $JWT_SECRET  # Copy this for future use

πŸ› οΈ Service Management

Service Operations

# Build services
make build                          # Build all services
make build-manuscript              # Build schema definitions
make build-core                    # Build API, Relay, Shield
make rebuild                       # Clean and rebuild

# Start/stop individual services
make start                         # Start all services
make stop                          # Stop all services
make restart                       # Restart all services

# Shell access to service
make shell SERVICE=api            # Access API container
make shell SERVICE=relay          # Access Relay container
make shell SERVICE=shield         # Access Shield container

Service Ports & Endpoints

ServicePortPurposeHealth Check
API8080HTTP REST APIcurl localhost:8080/health
Relay8081WebSocketcurl localhost:8081/health
Shield8000Auth/Userscurl localhost:8000/health
API Metrics9090Prometheuscurl localhost:9090/metrics
Shield Metrics9091Prometheuscurl localhost:9091/metrics
Relay Metrics9092Prometheuscurl localhost:9092/metrics
PostgreSQL5432Databasemake db-shell
Redis6379Events/Cachemake redis-shell

πŸš€ CI/CD & Deployment

Testing Pipeline

# Local CI simulation
make ci                             # Run full CI pipeline locally

# GitHub Actions (if set up)
git push origin main                # Triggers CI/CD in GitHub

# View workflow status
# Navigate to: github.com/yourorg/materi/actions
# Or: .github/workflows/sparki-domain-test.yml

Deployment

# Prepare for deployment
make validate                       # Validate all configurations
make security-scan                  # Run security checks

# Deploy locally (staging equivalent)
make start                          # Start all services
make health                         # Verify health
./tests/sparki-test-orchestrator.sh all  # Run all tests

# Production deployment (via GitHub Actions)
# 1. Push to main branch
# 2. Wait for CI pipeline to pass
# 3. Manual approval for production
# 4. Services deployed to production

πŸ“‹ Validation & Quality

Code Quality

# Run all quality checks
make qa                             # Lint + test + security + rust checks

# Linting only
make lint                           # Run all linters

# Format code
make format                         # Format all code

# Security scanning
make security-scan                  # All security checks

# Service-specific quality
cd .workspace/api && make lint
cd .workspace/relay && make fmt && make lint
cd .workspace/shield && flake8 .

Protocol Validation

# Validate YAML syntax
yamllint /Users/alexarno/materi/domain/sparki/*.sparki.yml
yamllint /Users/alexarno/materi/domain/sparki/protocol-rules.yml

# Validate configuration files
cd /Users/alexarno/materi/domain && make validate

# Run protocol tests
./tests/sparki-test-orchestrator.sh quality development

πŸ”§ Configuration Files

Key Files to Know

# Domain orchestration
cat /Users/alexarno/materi/domain.nest.yml              # Multi-repo setup

# Service definitions
cat /Users/alexarno/materi/domain/sparki/api.sparki.yml         # API config
cat /Users/alexarno/materi/domain/sparki/relay.sparki.yml       # Relay config
cat /Users/alexarno/materi/domain/sparki/shield.sparki.yml      # Shield config

# Protocol rules
cat /Users/alexarno/materi/domain/sparki/protocol-rules.yml     # HTTP, JWT, WebSocket, Redis

# Monitoring
cat /Users/alexarno/materi/domain/monitoring/folio-sparki.yml   # Metrics bridge

# CI/CD
cat /Users/alexarno/materi/domain/.github/workflows/sparki-domain-test.yml
cat /Users/alexarno/materi/domain/.github/workflows/sparki-domain-deploy.yml

Edit Configuration

# Edit with your editor
vim /Users/alexarno/materi/domain/sparki/api.sparki.yml
nano /Users/alexarno/materi/domain/sparki/relay.sparki.yml
code /Users/alexarno/materi/domain/sparki/shield.sparki.yml

# Then validate and restart
make validate
make restart
make health

πŸ†˜ Troubleshooting Quick Fixes

Port Already in Use

# Find what's using the port
lsof -i :8080   # API port
lsof -i :8081   # Relay port
lsof -i :8000   # Shield port

# Kill the process
kill -9 <PID>

# Or change ports in .sparki.yml and restart
make restart

Service Won’t Start

# 1. Check if PostgreSQL/Redis running
docker ps | grep -E "postgres|redis"

# 2. Start if needed
docker-compose -f docker-compose.unified.yml up -d postgres redis

# 3. Check service logs
make logs-api | tail -50
make logs-relay | tail -50
make logs-shield | tail -50

# 4. Restart service
make restart

# 5. Check health
make health

Tests Failing

# 1. Check health first
make health

# 2. Reset database
make db-reset

# 3. Re-assemble
make assemble

# 4. Rebuild
make build

# 5. Run tests
./tests/sparki-test-orchestrator.sh unit development

# 6. View detailed errors
cat test-reports/orchestrator.log | tail -100

Metrics Not Available

# 1. Verify service is running
curl http://localhost:8080/health

# 2. Check metrics endpoint
curl http://localhost:9090/metrics

# 3. If fails, check logs
make logs-api | grep -i "metric\|prometheus"

# 4. Restart service
make restart

# 5. Wait 5 seconds for initialization
sleep 5
curl http://localhost:9090/metrics

DocumentPurposePath
Setup GuideComplete initializationSETUP.md
Sparki READMEService definitionssparki/README.md
Monitoring BridgeObservability setupmonitoring/MONITORING-BRIDGE.md
Protocol RulesAPI contractssparki/protocol-rules.yml
Quick StartGetting startedSPARKI-QUICK-START.md
This DocumentQuick commandsSPARKI-COMMAND-REFERENCE.md

πŸ’‘ Pro Tips

# Alias for frequently used commands
alias mh="make health"              # Check health
alias mt="make test"                # Run tests
alias ml="make logs"                # View logs
alias mr="make restart"             # Restart services
alias mc="make ci"                  # Full CI pipeline

# Add to ~/.bashrc or ~/.zshrc:
echo 'alias mh="make health"' >> ~/.bashrc

# One-liner to check entire system status
make health && echo "βœ… All systems go" && curl -s http://localhost:9090/metrics | grep http_requests_total

🎯 Common Workflows

”I want to start fresh"

cd /Users/alexarno/materi/domain
make clean
make setup
make assemble
docker-compose -f docker-compose.unified.yml up -d postgres redis
make start
make health

"I want to run tests"

cd /Users/alexarno/materi/domain
./tests/sparki-test-orchestrator.sh all development
cat test-reports/orchestrator.log

"I want to monitor my services"

# Terminal 1: Monitor health
watch -n 5 'make health'

# Terminal 2: Monitor logs
make logs | tail -f

# Terminal 3: Monitor metrics
watch -n 5 'curl -s http://localhost:9090/metrics | grep http_requests_total'

"I want to debug a failing service”

make health                         # See which service is down
make logs-<service> | tail -100    # View its logs
make db-shell                      # Check database state
make redis-shell                   # Check Redis state
make restart                       # Restart services

Last Updated: 2025-12-16 Status: Ready to use Questions? Check SETUP.md or SPARKI-QUICK-START.md