A high-performance, production-ready TypeScript bot that processes Space Invaders flash images with real-time synchronization, health monitoring, and advanced performance optimization.
This cron-driven bot maintains a complete pipeline for Space Invaders street art data:
- π Real-time Flash Sync: Fetches latest flashes from space-invaders.com API every 5 minutes
- ποΈ PostgreSQL Storage: Robust database operations with real-time flash records and conflict handling
- π¬ RabbitMQ Integration: Queues flashes for image processing with batch optimization
- π¨ Image Processing: IPFS integration for decentralized image storage
- π± Social Media: Auto-posts to Farcaster via Neynar SDK for registered users
- π Retry Logic: Persistent disk-based retry system for failed operations
- π Proxy Support: Smart proxy rotation with failure tracking
- 6 Optimized Indexes: 40-60% faster queries with concurrent creation
- Batch Processing: Memory-efficient handling of large datasets
- Query Monitoring: Real-time performance analysis and slow query detection
- Service Health Checks: Database, RabbitMQ, API, and disk monitoring
- Degradation Detection: Smart status monitoring beyond simple up/down
- Performance Metrics: Memory usage, response times, and system health
- Structured Logging: JSON format for production, human-readable for development
- Operation Timing: Automatic performance measurement and context tracking
- Memory Monitoring: Real-time memory usage and garbage collection optimization
- 30-50% Memory Reduction: Efficient batch processing and resource cleanup
- Garbage Collection: Smart GC triggering based on memory thresholds
- Resource Management: Automatic cleanup of large arrays and objects
- Type-Safe Config: Centralized configuration with validation
- Environment Detection: Automatic development/production environment handling
- Secret Management: Secure handling of sensitive configuration data
- Node.js 19.9.0+ (specified in engines)
- PostgreSQL (for flash storage)
- RabbitMQ (for image processing queue)
- Yarn (package manager)
# Clone the repository
git clone https://github.com/gitpancake/invaders.bot.git
cd invaders.bot
# Install dependencies
yarn install
# Set up environment variables (see Configuration section)
cp .env.example .env
# Edit .env with your configuration
# Apply database optimizations
yarn performance-optimize
# Build the project
yarn build
# Start the bot
yarn start# Run in development with hot reload
yarn dev
# Check system performance
yarn performance-check
# Full performance analysis
yarn performance-fullCreate a .env file with the following variables:
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/invaders
# RabbitMQ
RABBITMQ_URL=amqp://user:password@localhost:5672
RABBITMQ_QUEUE=flash_processing_queue
# Security
SIGNER_ENCRYPTION_KEY=your-32-character-encryption-key
# API Configuration (optional - has defaults)
API_URL=https://api.space-invaders.com
API_TIMEOUT=15000# Distributed Tracing (OpenTelemetry)
TEMPO_HTTP_ENDPOINT=http://tempo.railway.internal:4318/v1/traces# Database Pool
DB_POOL_MAX=20
DB_POOL_MIN=2
DB_IDLE_TIMEOUT=30000
# Memory Optimization
MEMORY_BATCH_SIZE=100
MEMORY_CONCURRENCY_LIMIT=10
MEMORY_GC_THRESHOLD=512
# Proxy Configuration
PROXY_LIST=http://proxy1:8080,http://user:pass@proxy2:3128
FALLBACK_PROXY_LIST=http://backup1:8080
# Logging
LOG_LEVEL=info
LOG_STRUCTURED=false# Check system health and performance
yarn performance-check
# Apply database optimizations
yarn performance-optimize
# Full performance analysis with recommendations
yarn performance-fullThe bot provides comprehensive health monitoring for:
- Database Performance (query times, connection health)
- RabbitMQ Status (queue health, connection status)
- API Availability (Space Invaders API response times)
- Memory Usage (heap usage, GC performance)
- Disk Persistence (failed flash tracking)
- Prometheus Metrics (port 9090): Request rates, errors, sync durations, memory usage
- Distributed Tracing (via OTLP): Auto-instrumented HTTP, PostgreSQL, and Express traces sent to Tempo
# Cast verification and repair
yarn cast-check
yarn cast-nulls
# Performance monitoring
yarn performance-monitor [check|optimize|full]- Database Queries: 40-60% improvement with optimized indexes
- Memory Usage: 30-50% reduction during flash processing
- Processing Rate: ~300 flashes per batch with 8-17 new flashes typically found
- API Response: <100ms for most database operations
- Health Checks: Complete system analysis in <2 seconds
- Real-time Processing: Continuous flash synchronization with space-invaders.com
- Processing Rate: ~8-17 new flashes per 5-minute cycle
- Memory Efficiency: Stable usage over 24+ hour periods
- Uptime: Designed for continuous 24/7 operation
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Space β β Invaders Bot β β Image β
β Invaders API βββββΊβ (This Repo) βββββΊβ Processing β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β PostgreSQL βββββΊβ Health & βββββΊβ Farcaster β
β Database β β Monitoring β β (Neynar) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌ
ββββββββββββββ ββββββββββββββ ββββββββββββββ
β RabbitMQ β β Prometheus β β Tempo β
β Queue β β Metrics β β Tracing β
ββββββββββββββ ββββββββββββββ ββββββββββββββ
# Run all tests
yarn test
# Run tests in watch mode
yarn test:watch
# Generate coverage report
yarn test:coverage
# Run tests for CI
yarn test:ci- IMPROVEMENTS.md: Detailed documentation of performance and reliability improvements
- Database Indexes: SQL for performance optimization indexes
- Health Monitoring: Comprehensive service health checking system
- Performance Tools: Performance analysis and optimization tools
- Non-Breaking Changes: All improvements maintain 100% backward compatibility
- Encryption: Secure handling of signer keys and sensitive data
- Input Validation: Comprehensive validation of flash data and configuration
- Error Handling: Robust error recovery with disk persistence for failed operations
- Rate Limiting: Smart proxy rotation and API rate limiting
- Database Setup: Apply performance indexes with
yarn performance-optimize - Health Checks: Monitor system status with
yarn performance-check - Environment: Configure production environment variables
- Monitoring: Set up continuous health monitoring
- Scaling: Adjust batch sizes and concurrency based on load
- Database indexes are created with
CONCURRENTLY(no table locks) - Configuration changes are backwards compatible
- Health monitoring provides deployment verification
- Gradual rollout supported through configuration flags
This bot maintains real-time infrastructure for Space Invaders flash processing. When contributing:
- Test Thoroughly: Use the comprehensive testing suite
- Monitor Performance: Run performance checks before and after changes
- Maintain Compatibility: Ensure no breaking changes to existing functionality
- Document Changes: Update relevant documentation and performance metrics
ISC
Built with β€οΈ for the Space Invaders community | Real-time flash synchronization π