This guide provides comprehensive instructions for deploying AgriCredit to production environments.
- Prerequisites
- Environment Setup
- Database Deployment
- Smart Contract Deployment
- Backend Deployment
- Frontend Deployment
- Monitoring Setup
- Security Configuration
- Post-Deployment Verification
- Node.js: 20.x or later
- Python: 3.11 or later
- Docker: 24.x or later
- Git: 2.x or later
- Supabase: For database hosting
- Vercel: For frontend hosting
- Railway/Heroku: For backend hosting
- Infura/Alchemy: For blockchain RPC
- PolygonScan: For contract verification
Required environment variables:
# Database
DATABASE_URL=postgresql://...
# Blockchain
POLYGON_RPC_URL=https://polygon-rpc.com
PRIVATE_KEY=your_deployer_private_key
# External APIs
OPENWEATHER_API_KEY=...
INFURA_PROJECT_ID=...
# Cloud Services
VERCEL_TOKEN=...
RAILWAY_TOKEN=...git clone https://github.com/your-org/agricredit.git
cd agricredit# Root dependencies
npm ci
# Frontend
cd src && npm ci && cd ..
# Backend
cd backend && pip install -r requirements.txt && cd ..Create .env files in respective directories:
# .env (root)
NODE_ENV=production
VERCEL_ENV=production
# backend/.env
DATABASE_URL=...
REDIS_URL=...
SECRET_KEY=...
# src/.env.local
NEXT_PUBLIC_API_URL=...
NEXT_PUBLIC_CONTRACT_ADDRESS=...-
Create Supabase Project
# Via CLI (if available) or dashboard supabase projects create agricredit-prod -
Deploy Schema
# Connect to Supabase SQL Editor # Execute contents of final_database_schema.sql
-
Configure Authentication
- Enable email confirmations
- Set up OAuth providers if needed
- Configure JWT secrets
-
Set Up Storage
- Create buckets for IPFS fallbacks
- Configure CORS policies
cd backend
python test_db_connection.pyUpdate hardhat.config.js:
networks: {
polygon: {
url: process.env.POLYGON_RPC_URL,
accounts: [process.env.PRIVATE_KEY]
}
}npx hardhat run scripts/deploy.js --network polygonnpx hardhat verify --network polygon CONTRACT_ADDRESS "Constructor Args"Update contract addresses in src/lib/contracts.ts
# Install Railway CLI
npm install -g @railway/cli
# Login and create project
railway login
railway init agricredit-backend
# Deploy
railway up# Build image
docker build -t agricredit-backend ./backend
# Run container
docker run -p 8000:8000 agricredit-backendSet production environment variables in your hosting platform:
DATABASE_URL=...
REDIS_URL=...
SECRET_KEY=...
CORS_ORIGINS=https://your-frontend-domain.com# Install Vercel CLI
npm install -g vercel
# Deploy
cd src
vercel --prodEnsure vercel.json is configured:
{
"buildCommand": "npm run build",
"outputDirectory": "out",
"framework": "nextjs"
}Set in Vercel dashboard:
NEXT_PUBLIC_API_URLNEXT_PUBLIC_CONTRACT_ADDRESSNEXT_PUBLIC_INFURA_ID
cd monitoring
docker-compose up -dUpdate prometheus.yml with your service endpoints:
scrape_configs:
- job_name: 'agricredit-backend'
static_configs:
- targets: ['your-backend-url:8000']Configure alert rules in alert_rules.yml:
groups:
- name: agricredit
rules:
- alert: HighErrorRate
expr: rate(http_requests_total{status=~"5.."}[5m]) > 0.1
for: 5m
labels:
severity: criticalImport pre-configured dashboards for:
- Application metrics
- Database performance
- Blockchain interactions
- AI model performance
- Enable HTTPS on all services
- Configure SSL certificates
- Set up certificate auto-renewal
# Allow only necessary ports
ufw allow 80
ufw allow 443
ufw allow 22
ufw --force enable- Implement rate limiting
- Enable CORS properly
- Set up API authentication
- Configure API gateways
- Enable RLS policies
- Set up database backups
- Configure connection pooling
- Monitor for security vulnerabilities
# Frontend
curl -f https://your-frontend-domain.com
# Backend
curl -f https://your-backend-domain.com/health
# Database
curl -f https://your-supabase-project.supabase.co/rest/v1/# Run integration tests
npm run test:e2e
# Test smart contracts
npx hardhat test --network polygon# Load testing
npm run test:load
# Monitor response times
# Check monitoring dashboards# Run security scans
npm run audit
# Check contract vulnerabilities
npx hardhat run scripts/security-audit.js-
Database Connection Failed
- Verify DATABASE_URL
- Check Supabase project status
- Ensure IP allowlist
-
Contract Deployment Failed
- Verify RPC URL and private key
- Check gas prices
- Ensure sufficient funds
-
Frontend Build Failed
- Check Node.js version
- Verify environment variables
- Clear build cache
-
Backend Startup Failed
- Check Python dependencies
- Verify environment variables
- Check database connectivity
- Check Vercel deployment logs
- Monitor Railway/Heroku logs
- Review Supabase logs
- Check monitoring dashboards
-
Update Dependencies
npm audit fix pip install --upgrade -r requirements.txt
-
Database Backups
- Automated via Supabase
- Verify backup integrity monthly
-
Security Updates
- Monitor vulnerability alerts
- Apply patches promptly
-
Performance Monitoring
- Review metrics weekly
- Optimize slow queries
- Horizontal Scaling: Add more backend instances
- Database Scaling: Upgrade Supabase plan
- CDN: Use Vercel's global edge network
- Caching: Implement Redis clusters
For deployment issues:
- Check documentation
- Review GitHub issues
- Contact DevOps team
- Check monitoring alerts
Last updated: December 2025 Version: 1.0.0