2008robocode-crypto/code-generation-system
0
1# Deployment Guide2 3## Quick Deployment Options4 5### Option 1: Replit (Easiest - FREE)6 71. **Create Account**: https://replit.com/signup82. **Create New Project**: Click "Create" → "Import from GitHub"93. **Enter Repository URL**: Paste your GitHub repo URL104. **Deploy**:11 ```bash12 pip install -r requirements.txt13 python web/app.py14 ```155. **Access**: Replit will provide a live URL (e.g., `https://project-name.replit.dev`)16 17### Option 2: Railway (FREE tier available)18 191. **Create Account**: https://railway.app202. **Connect Repository**: Click "Create Project" → "Deploy from GitHub"213. **Select Your Repo**: Choose the AI code generation repo224. **Add Environment Variables** (if using LLM):23 - Key: `ANTHROPIC_API_KEY`24 - Value: Your API key255. **Deploy**: Railway auto-deploys on push266. **Get URL**: Check "Deployments" for live URL27 28### Option 3: Heroku (Paid but easy)29 301. **Create Account**: https://heroku.com312. **Install Heroku CLI**: https://devcenter.heroku.com/articles/heroku-cli323. **Create App**:33 ```bash34 heroku login35 heroku create your-app-name36 ```374. **Deploy**:38 ```bash39 git push heroku main40 ```415. **Get URL**: `https://your-app-name.herokuapp.com`42 43### Option 4: Google Cloud Run (Pay-per-use)44 451. **Setup**:46 ```bash47 gcloud auth login48 gcloud config set project your-project-id49 ```50 512. **Create Dockerfile**:52 ```dockerfile53 FROM python:3.9-slim54 WORKDIR /app55 COPY . .56 RUN pip install -r requirements.txt57 EXPOSE 500058 CMD ["python", "web/app.py"]59 ```60 613. **Deploy**:62 ```bash63 gcloud run deploy code-gen \64 --source . \65 --platform managed \66 --region us-central167 ```68 694. **Get URL**: GCP will provide a live URL70 71---72 73## Local Deployment (for testing)74 75### Prerequisites76- Python 3.8+77- Git78 79### Steps80 811. **Clone Repository**82 ```bash83 git clone https://github.com/your-username/ai-code-gen.git84 cd ai-code-gen85 ```86 872. **Install Dependencies**88 ```bash89 pip install -r requirements.txt90 ```91 923. **Set Environment Variables** (Optional)93 ```bash94 export ANTHROPIC_API_KEY="your-api-key" # For LLM features95 ```96 974. **Run Server**98 ```bash99 python web/app.py100 ```101 1025. **Access**103 ```104 http://localhost:5000105 ```106 107---108 109## Production Deployment (Best Practices)110 111### 1. Use Gunicorn112 113```bash114pip install gunicorn115gunicorn -w 4 -b 0.0.0.0:8000 web.app116```117 118### 2. Use Environment Variables119 120Create `.env` file:121```122ANTHROPIC_API_KEY=your-key123FLASK_ENV=production124```125 126### 3. Add SSL/HTTPS127 128Use a reverse proxy (Nginx, Cloudflare)129 130### 4. Enable Logging131 132```python133# In web/app.py134import logging135logging.basicConfig(level=logging.INFO)136```137 138### 5. Add Rate Limiting139 140```python141from flask_limiter import Limiter142from flask_limiter.util import get_remote_address143 144limiter = Limiter(145 app=app,146 key_func=get_remote_address,147 default_limits=["200 per day", "50 per hour"]148)149```150 151---152 153## Docker Deployment154 155### Dockerfile156 157```dockerfile158FROM python:3.9-slim159 160WORKDIR /app161 162# Copy requirements and install163COPY requirements.txt .164RUN pip install --no-cache-dir -r requirements.txt165 166# Copy application167COPY . .168 169# Expose port170EXPOSE 5000171 172# Run with gunicorn for production173CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "web.app"]174```175 176### Build and Run177 178```bash179# Build image180docker build -t code-gen:latest .181 182# Run container183docker run -p 5000:5000 code-gen:latest184 185# Access186open http://localhost:5000187```188 189### Docker Compose190 191```yaml192version: '3.8'193 194services:195 web:196 build: .197 ports:198 - "5000:5000"199 environment:200 - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}201 restart: unless-stopped202```203 204Run with:205```bash206docker-compose up207```208 209---210 211## Monitoring & Logging212 213### Application Logging214 215```python216import logging217 218logger = logging.getLogger(__name__)219 220@app.route('/api/generate', methods=['POST'])221def generate():222 logger.info("Generation request received")223 try:224 # ... generation code ...225 logger.info("Generation successful")226 except Exception as e:227 logger.error(f"Generation failed: {e}")228 229 return jsonify(...)230```231 232### Health Check233 234The API includes a health endpoint:235```bash236curl https://your-app.com/api/health237```238 239Returns:240```json241{242 "status": "healthy",243 "timestamp": "2026-05-06T07:52:40.123456",244 "total_requests": 42245}246```247 248---249 250## Performance Optimization251 252### 1. Enable Caching253 254```python255from functools import lru_cache256 257@lru_cache(maxsize=128)258def extract_intent(prompt):259 # Intent extraction is cached260 return ...261```262 263### 2. Use Connection Pooling264 265```python266# For database connections (future)267pool = create_engine(268 'postgresql://...',269 poolclass=StaticPool,270 pool_size=20271)272```273 274### 3. Enable Compression275 276```python277from flask_compress import Compress278Compress(app)279```280 281### 4. Use CDN282 283Deploy static files to CDN (Cloudflare, AWS CloudFront)284 285---286 287## Troubleshooting288 289### Port Already in Use290 291```bash292# Windows293netstat -ano | findstr :5000294taskkill /PID <PID> /F295 296# Linux/Mac297lsof -i :5000298kill -9 <PID>299```300 301### Module Not Found302 303```bash304pip install --upgrade pip305pip install -r requirements.txt306```307 308### API Timeout309 310Increase timeout in production:311```python312app.config['REQUEST_TIMEOUT'] = 60 # seconds313```314 315### Memory Issues316 317Use rule-based generation:318```python319pipeline = Pipeline(use_llm=False) # Lower memory usage320```321 322---323 324## Continuous Deployment (CD)325 326### GitHub Actions327 328Create `.github/workflows/deploy.yml`:329 330```yaml331name: Deploy332 333on:334 push:335 branches: [main]336 337jobs:338 deploy:339 runs-on: ubuntu-latest340 steps:341 - uses: actions/checkout@v2342 - uses: actions/setup-python@v2343 with:344 python-version: 3.9345 - run: pip install -r requirements.txt346 - run: pytest # If tests exist347 - uses: AkhileshNS/heroku-deploy@v3.12.12348 with:349 heroku_api_key: ${{secrets.HEROKU_API_KEY}}350 heroku_app_name: "your-app-name"351 heroku_email: "your-email@example.com"352```353 354### Push to Deploy355 356```bash357git push origin main358# Automatically deploys!359```360 361---362 363## Monitoring Checklist364 365- [ ] Health endpoint working366- [ ] Error logging enabled367- [ ] Performance monitored368- [ ] API rate limits set369- [ ] SSL/HTTPS enabled (production)370- [ ] Environment variables secured371- [ ] Backups configured372- [ ] Alerts setup373 374---375 376## Cost Estimates377 378| Platform | Free Tier | Paid Tier |379|----------|-----------|-----------|380| Replit | ✅ Yes | $7/mo |381| Railway | ✅ Yes (10 GB) | $5/mo+ |382| Heroku | ✅ (limited) | $7-50/mo |383| Google Cloud Run | ✅ ($11 free) | $0.00002/req |384| Vercel | ✅ (serverless) | $20/mo |385 386**Recommendation**: Start with Replit (free, easiest)387 388---389 390## Live URL Examples391 392After deployment, you'll have URLs like:393- Replit: `https://ai-code-gen.replit.dev`394- Railway: `https://ai-code-gen-production.up.railway.app`395- Heroku: `https://ai-code-gen.herokuapp.com`396- Cloud Run: `https://code-gen-xyz.run.app`397 398---399 400## Testing Live Deployment401 402```bash403# Test health404curl https://your-app-url/api/health405 406# Test generation407curl -X POST https://your-app-url/api/generate \408 -H "Content-Type: application/json" \409 -d '{"prompt":"Build a todo app"}'410 411# Test example412curl https://your-app-url/api/example413```414 415---416 417## Support418 419For deployment issues:4201. Check platform-specific documentation4212. Review application logs4223. Test locally first4234. Use health endpoint for diagnostics424 425---426 427*Choose your deployment platform and go live! 🚀*428 