Overview
The Tesis Rutas backend is built with FastAPI and follows Clean Architecture principles. It uses MongoDB for data persistence and JWT for authentication.Prerequisites
- Python 3.9+ installed
- MongoDB running (local or Atlas)
- pip or virtualenv for dependency management
Installation
Install dependencies
- fastapi - Modern web framework
- uvicorn - ASGI server
- pymongo - MongoDB driver
- python-jose - JWT authentication
- bcrypt - Password hashing
- cloudinary - Image upload service
- pydantic-settings - Configuration management
Start the server
Clean Architecture Structure
The backend follows Clean Architecture with clear separation of concerns:Architecture Layers
Domain Layer
Contains business entities and rules. No dependencies on external frameworks.
src/domain/entities/destino.py
Application Layer
Implements use cases that orchestrate business logic.
src/application/use_cases/agregar_destino.py
API Endpoints
The API exposes the following routers:Destinos (Destinations)
src/infrastructure/api/routers/destinos_router.py
Rutas (Routes)
Auth (Authentication)
Testing Endpoints
- FastAPI Docs
- curl
- Python
Navigate to http://localhost:8000/docs for interactive API documentation (Swagger UI).Features:
- Try endpoints directly from the browser
- See request/response schemas
- Test authentication flows
Running with Hot Reload
The--reload flag enables auto-restart on code changes:
--reload- Auto-reload on file changes--host 0.0.0.0- Listen on all network interfaces--port 8000- Custom port (default: 8000)--log-level debug- Verbose logging
Troubleshooting
ModuleNotFoundError: No module named 'src'
ModuleNotFoundError: No module named 'src'
Ensure youβre running uvicorn from the project root directory, not from inside
src/.MongoDB connection timeout
MongoDB connection timeout
Check if MongoDB is running:Verify
MONGO_URI in local_config.json is correct.CORS errors from frontend
CORS errors from frontend
Ensure
http://localhost:5173 is in the origins list in main.py:JWT token errors
JWT token errors
Generate a secure secret key:Add it to
local_config.json as JWT_SECRET_KEY.Next Steps
Database Setup
Configure MongoDB and understand the schema
Frontend Setup
Set up the React frontend