Skip to main content
This guide covers deploying the Tesis Rutas platform to production, including both the FastAPI backend and React frontend.

Deployment Architecture

Tesis Rutas consists of two separate applications:

Backend

FastAPI application that needs a Python-compatible hosting service

Frontend

React + Vite application that can be deployed to static hosting

Prerequisites

Before deploying, ensure you have:
1

Configuration ready

All environment variables configured (see Configuration guide)
2

External services active

  • MongoDB Atlas cluster running
  • Cloudinary account configured
  • JWT secret key generated
3

Code tested locally

Application runs successfully in development

Backend Deployment

The FastAPI backend can be deployed to various platforms that support Python applications.

Deployment Options

Railway provides easy deployment for Python applications.
1

Install Railway CLI

npm install -g @railway/cli
2

Login to Railway

railway login
3

Initialize project

From your project root:
railway init
4

Add environment variables

In the Railway dashboard, add all required environment variables:
  • MONGO_URI
  • MONGO_DB
  • CLOUDINARY_CLOUD_NAME
  • CLOUDINARY_API_KEY
  • CLOUDINARY_API_SECRET
  • JWT_SECRET_KEY
  • JWT_ALGORITHM
  • JWT_EXPIRE_MINUTES
5

Deploy

railway up
Railway will automatically detect your Python application and deploy it.
Railway provides a free tier with 500 hours/month, perfect for small projects.

Verify Backend Deployment

After deployment, test your backend:
curl https://your-backend-url.com/
You should receive:
{"message": "API de Turismo Digital UCE funcionando correctamente 🚀"}

Frontend Deployment

The React frontend is a static site that can be deployed to various hosting platforms.

Update API Base URL

Before building, update the API endpoint in your frontend configuration to point to your deployed backend:
// frontend/src/config/api.js (or similar)
const API_BASE_URL = 'https://your-backend-url.com';

Deployment Options

Post-Deployment Configuration

After deploying both frontend and backend:
1

Update CORS settings

Update the allowed origins in src/infrastructure/api/main.py:
origins = [
    "http://localhost:5173",                    # Local dev
    "https://tesis-rutas.vercel.app",          # Production frontend
    "https://www.your-custom-domain.com",      # Custom domain (if any)
]
Redeploy the backend after making this change.
2

Test the full application

  1. Visit your frontend URL
  2. Test user authentication
  3. Test route creation and destination management
  4. Verify image uploads work correctly
3

Set up custom domain (optional)

Configure custom domains:
  • Frontend: Follow your hosting provider’s custom domain guide
  • Backend: Most platforms provide custom domain settings in their dashboard

Environment-Specific Settings

# src/config/settings.py
class Settings(BaseSettings):
    app_name: str = "FARM Turismo API"
    debug: bool = False  # ← Disable debug in production
    # ... other settings
Always set debug: bool = False in production to prevent exposing sensitive error information.

Monitoring and Maintenance

Health Checks

Monitor your deployment health:
# Backend health check
curl https://your-backend-url.com/

# Frontend availability
curl https://your-frontend-url.com/

Common Issues

Problem: Frontend can’t connect to backend due to CORS policySolution:
  • Verify your frontend URL is added to the origins list in src/infrastructure/api/main.py
  • Ensure you redeploy the backend after updating CORS settings
  • Check that the frontend is using HTTPS (not HTTP) if the backend uses HTTPS
Problem: Application can’t find configuration in productionSolution:
  • Verify all environment variables are set in your hosting platform’s dashboard
  • Check for typos in variable names (they are case-sensitive)
  • Restart your application after adding environment variables
Problem: Can’t connect to MongoDB Atlas from productionSolution:
  • Whitelist your hosting provider’s IP addresses in MongoDB Atlas
  • Or allow access from anywhere (0.0.0.0/0) for testing
  • Verify the MongoDB URI is correct and includes credentials
Problem: Frontend or backend build fails during deploymentSolution:
  • Check build logs for specific errors
  • Ensure all dependencies are listed in requirements.txt or package.json
  • Verify Python/Node.js versions match your local environment

Scaling Considerations

As your application grows:

Database indexing

Add indexes to MongoDB collections for better query performance

CDN for media

Cloudinary automatically provides CDN for images

Caching

Implement Redis for session/data caching

Load balancing

Use multiple backend instances with a load balancer

Rollback Strategy

If a deployment fails:
1

Identify the issue

Check logs in your hosting platform’s dashboard
2

Revert to previous version

Most platforms support instant rollback to previous deployments
3

Fix locally

Reproduce and fix the issue in your local environment
4

Redeploy

Deploy the fixed version

Next Steps

Monitor logs

Set up logging and monitoring for your production application

Backup strategy

Implement regular MongoDB backups using Atlas automated backups

CI/CD

Set up automated deployments with GitHub Actions or similar

Performance testing

Use tools like Lighthouse to test frontend performance

Build docs developers (and LLMs) love