- Database Migrations: Alembic for schema versioning
- Exception Handling: Centralized error management with custom exceptions
- Model Preloading: AI models loaded at startup to eliminate cold starts
- WebSocket Support: Real-time updates for dashboard and incidents
- Model Versioning: Track model versions and confidence thresholds
- Security Headers: CORS, trusted hosts, and security middleware
- State Management: Zustand for global state management
- WebSocket Integration: Real-time updates with automatic reconnection
- Error Handling: Comprehensive error states and loading indicators
- API Integration: Centralized API client with token management
- GitHub Actions: Complete CI/CD pipeline with testing, security scans, and Docker builds
- Docker Support: Multi-container setup with health checks
- Database Support: PostgreSQL with Redis caching
- Monitoring: Health checks and connection monitoring
# 1. Clone and setup
git clone <your-repo>
cd zerohack
cp .env.example .env
# 2. Configure environment
# Edit .env with your production values:
# - Database credentials
# - Blockchain RPC URLs and contract addresses
# - SMTP settings for notifications
# - JWT secret keys
# 3. Deploy
docker-compose up -d
# 4. Run database migrations
docker-compose exec backend alembic upgrade head
# 5. Verify deployment
curl http://localhost/health# 1. Create namespace
kubectl create namespace zerohack
# 2. Apply secrets
kubectl apply -f k8s/secrets.yaml
# 3. Apply configmaps
kubectl apply -f k8s/configmaps.yaml
# 4. Deploy services
kubectl apply -f k8s/backend-deployment.yaml
kubectl apply -f k8s/frontend-deployment.yaml
kubectl apply -f k8s/nginx-ingress.yaml
# 5. Run migrations
kubectl exec -it deployment/zerohack-backend -- alembic upgrade head# 1. Build and push images
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account>.dkr.ecr.us-east-1.amazonaws.com
docker build -t zerohack/backend ./backend
docker build -t zerohack/frontend ./frontend
docker tag zerohack/backend:latest <account>.dkr.ecr.us-east-1.amazonaws.com/zerohack/backend:latest
docker tag zerohack/frontend:latest <account>.dkr.ecr.us-east-1.amazonaws.com/zerohack/frontend:latest
docker push <account>.dkr.ecr.us-east-1.amazonaws.com/zerohack/backend:latest
docker push <account>.dkr.ecr.us-east-1.amazonaws.com/zerohack/frontend:latest
# 2. Deploy with ECS
aws ecs create-cluster --cluster-name zerohack
aws ecs register-task-definition --cli-input-json file://aws/task-definition.json
aws ecs create-service --cluster zerohack --service-name zerohack-backend --task-definition zerohack-backend# Database
ZEROHACK_DATABASE_URL=postgresql+asyncpg://user:password@host:5432/zerohack
ZEROHACK_REDIS_URL=redis://host:6379
# Security
ZEROHACK_SECRET_KEY=your-super-secret-key-256-bits
ZEROHACK_ACCESS_TOKEN_EXPIRE_MINUTES=60
ZEROHACK_REFRESH_TOKEN_EXPIRE_DAYS=7
# Blockchain
ZEROHACK_BLOCKCHAIN_RPC_URL=https://polygon-mainnet.infura.io/v3/your-key
ZEROHACK_LOGGER_CONTRACT_ADDRESS=0x...
ZEROHACK_RESPONSE_CONTRACT_ADDRESS=0x...
ZEROHACK_DAO_CONTRACT_ADDRESS=0x...
ZEROHACK_SENDER_ACCOUNT_ADDRESS=0x...
ZEROHACK_SENDER_PRIVATE_KEY=0x...
# Email
ZEROHACK_SMTP_SERVER=smtp.gmail.com
ZEROHACK_SMTP_PORT=587
ZEROHACK_SMTP_USERNAME=your-email@gmail.com
ZEROHACK_SMTP_PASSWORD=your-app-password
ZEROHACK_ALERT_EMAIL=admin@yourcompany.com
# AI Model Thresholds
ZEROHACK_CRITICAL_THRESHOLD=0.9
ZEROHACK_HIGH_THRESHOLD=0.7
ZEROHACK_MEDIUM_THRESHOLD=0.5
ZEROHACK_LOW_THRESHOLD=0.3
# URLs
ZEROHACK_BASE_URL=https://zerohack.yourcompany.com
ZEROHACK_API_URL=https://api.zerohack.yourcompany.com-- Create database and user
CREATE DATABASE zerohack;
CREATE USER zerohack_user WITH PASSWORD 'secure_password';
GRANT ALL PRIVILEGES ON DATABASE zerohack TO zerohack_user;
-- Run migrations
alembic upgrade head# nginx.conf
server {
listen 443 ssl http2;
server_name zerohack.yourcompany.com;
ssl_certificate /etc/ssl/certs/zerohack.crt;
ssl_certificate_key /etc/ssl/private/zerohack.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'";
location / {
proxy_pass http://frontend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /api/ {
proxy_pass http://backend:8008;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /ws/ {
proxy_pass http://backend:8008;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}# Application health
curl https://api.zerohack.yourcompany.com/health
# Database connectivity
curl https://api.zerohack.yourcompany.com/health | jq '.services.database'
# AI models status
curl https://api.zerohack.yourcompany.com/health | jq '.services.ai'
# Blockchain connectivity
curl https://api.zerohack.yourcompany.com/health | jq '.services.blockchain'# prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'zerohack-backend'
static_configs:
- targets: ['backend:8008']
metrics_path: '/metrics'
scrape_interval: 5s# backend/utils/logger.py
import structlog
import logging
# Configure structured logging
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
structlog.processors.JSONRenderer()
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)- Environment Variables: All secrets stored in secure vault (AWS Secrets Manager, HashiCorp Vault)
- Database Security: Encrypted at rest, SSL connections, least privilege access
- API Security: Rate limiting, input validation, CORS properly configured
- Authentication: JWT with proper expiration, 2FA enabled
- Blockchain Security: Private keys stored securely, contract addresses verified
- SSL/TLS: Valid certificates, proper cipher suites, HSTS enabled
- Network Security: VPC, security groups, WAF if applicable
- Penetration Testing: Third-party security assessment
- Vulnerability Scanning: Regular dependency updates
- Access Logging: Monitor authentication and authorization events
- Incident Response: Plan for security incidents
- Backup Strategy: Regular database and file backups
- Disaster Recovery: Multi-region deployment if needed
# alertmanager.yml
groups:
- name: zerohack.rules
rules:
- alert: HighErrorRate
expr: rate(http_requests_total{status=~"5.."}[5m]) > 0.1
for: 5m
labels:
severity: critical
annotations:
summary: "High error rate detected"
- alert: DatabaseDown
expr: up{job="zerohack-database"} == 0
for: 1m
labels:
severity: critical
annotations:
summary: "Database is down"
- alert: AIModelDown
expr: zerohack_ai_models_ready == 0
for: 2m
labels:
severity: warning
annotations:
summary: "AI models are not ready"- Service Down: Check health endpoints, restart containers
- Database Issues: Check connection pool, run migrations
- AI Model Issues: Check model loading, restart AI service
- Blockchain Issues: Check RPC connectivity, verify contract addresses
- Security Incident: Isolate affected systems, review logs
# Database connection pooling
DATABASE_URL = "postgresql+asyncpg://user:pass@host:5432/db?pool_size=20&max_overflow=30"
# Redis caching
CACHE_TTL = 3600 # 1 hour
CACHE_PREFIX = "zerohack:"
# Model optimization
MODEL_BATCH_SIZE = 32
MODEL_CACHE_SIZE = 1000// Code splitting
const Dashboard = lazy(() => import('./components/Dashboard'));
const Incidents = lazy(() => import('./components/Incidents'));
// Service worker for caching
// PWA support for offline functionality# Kubernetes resource limits
resources:
requests:
memory: "512Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "500m"
# Horizontal Pod Autoscaling
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: zerohack-backend-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: zerohack-backend
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70- Response Time: < 200ms for API calls
- Availability: 99.9% uptime
- Throughput: 1000+ requests/minute
- AI Inference: < 1 second per analysis
- Zero Security Breaches: No unauthorized access
- Vulnerability Response: < 24 hours for critical issues
- Audit Compliance: 100% audit trail coverage
- Threat Detection: 95%+ accuracy
- False Positive Rate: < 5%
- User Satisfaction: > 4.5/5 rating
- Incident Response Time: < 5 minutes
- Deploy to Staging: Test all features in staging environment
- Load Testing: Simulate production traffic
- Security Audit: Third-party security assessment
- Documentation: Update user guides and API docs
- Training: Train security team on new features
- Go Live: Deploy to production with monitoring
- Continuous Improvement: Regular updates and optimizations
ZeroHack is now production-ready with enterprise-grade security, monitoring, and scalability! 🎉