Skip to main content
This guide covers all configuration steps needed to run Tesis Rutas locally and in production.

Configuration Overview

Tesis Rutas uses environment variables for configuration. The application can read configuration from:
  1. Environment variables (.env file or system variables) - Recommended for production
  2. local_config.json - Optional for local development
The configuration system is defined in src/config/settings.py and uses Pydantic Settings for validation.

Required Environment Variables

MongoDB Configuration

Tesis Rutas uses MongoDB for data storage.
1

Get MongoDB connection string

You can use:
  • MongoDB Atlas (cloud) - Recommended
  • Local MongoDB instance
For MongoDB Atlas:
  1. Create a free account at mongodb.com/cloud/atlas
  2. Create a new cluster
  3. Get your connection string (format: mongodb+srv://username:[email protected]/)
2

Set MongoDB variables

MONGO_URI=mongodb+srv://username:[email protected]/
MONGO_DB=turismo_digital_uce
Never commit local_config.json or .env files to version control. These files contain sensitive credentials.

Cloudinary Configuration

Cloudinary is used for image and media storage.
1

Create Cloudinary account

  1. Sign up at cloudinary.com
  2. Navigate to your Dashboard
  3. Copy your Cloud Name, API Key, and API Secret
2

Set Cloudinary variables

CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
These credentials are configured in src/infrastructure/services/cloudinary_config.py.

JWT Authentication

JWT tokens are used for user authentication and authorization.
1

Generate JWT secret key

Generate a secure random secret key:
python -c "import secrets; print(secrets.token_urlsafe(32))"
2

Set JWT variables

JWT_SECRET_KEY=your_generated_secret_key
JWT_ALGORITHM=HS256
JWT_EXPIRE_MINUTES=60
Use a strong, randomly generated secret key. Never use the default or share it publicly.

Configuration File Locations

# Place in project root directory
tesis-rutas/
├── .env              # ← Backend environment variables
├── requirements.txt
├── src/
└── frontend/

Complete Configuration Example

# MongoDB
MONGO_URI=mongodb+srv://user:[email protected]/
MONGO_DB=turismo_digital_uce

# Cloudinary
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=123456789012345
CLOUDINARY_API_SECRET=your_api_secret

# JWT
JWT_SECRET_KEY=your_secure_random_key_here
JWT_ALGORITHM=HS256
JWT_EXPIRE_MINUTES=60

# Application
DEBUG=false

Frontend Configuration

The frontend needs to know where the backend API is running.
1

Development - Update API base URL

In your frontend code (typically in src/config/api.js or similar), set:
const API_BASE_URL = 'http://localhost:8000';
2

Production - Update CORS origins

Update allowed origins in src/infrastructure/api/main.py:
origins = [
    "http://localhost:5173",              # Local development
    "https://your-frontend.vercel.app",   # Production frontend
]

Verify Configuration

Test your configuration to ensure everything is set up correctly:
1

Test MongoDB connection

python -c "from src.infrastructure.database.mongo_config import get_database; db = get_database(); print('✅ MongoDB connected')"
You should see: ✅ Conectado a MongoDB (turismo_digital_uce) correctamente.
2

Test Cloudinary connection

python -c "from src.infrastructure.services.cloudinary_config import cloudinary; print('✅ Cloudinary configured')"
3

Run the application

Start the backend server:
uvicorn src.infrastructure.api.main:app --reload
Visit http://localhost:8000 - you should see:
{"message": "API de Turismo Digital UCE funcionando correctamente 🚀"}

Troubleshooting

Problem: ServerSelectionTimeoutError when connecting to MongoDBSolutions:
  • Verify your MONGO_URI is correct
  • Check that your IP address is whitelisted in MongoDB Atlas (Network Access)
  • Ensure your database user has proper permissions
  • Check your internet connection
Problem: Application can’t find configuration variablesSolutions:
  • For .env file: Place it in the project root directory
  • For local_config.json: Place it in src/config/ directory
  • Verify file names are exact (case-sensitive)
  • Check that environment variables are properly formatted
Problem: Images fail to upload to CloudinarySolutions:
  • Verify all three Cloudinary credentials are set correctly
  • Check that your API key and secret have no extra spaces
  • Ensure your Cloudinary account is active
Problem: Token validation failsSolutions:
  • Ensure JWT_SECRET_KEY is set and consistent across restarts
  • Verify JWT_ALGORITHM is set to HS256
  • Check that tokens haven’t expired (default: 60 minutes)

Next Steps

Run locally

Start the development server:
# Backend
uvicorn src.infrastructure.api.main:app --reload

# Frontend (in another terminal)
cd frontend && npm run dev

Deploy to production

Learn how to deploy your configured application

Build docs developers (and LLMs) love