Architecture Overview
The backend provides:- User authentication (registration, login, profile management)
- Forum response management (forums 1-6 with dynamic endpoints)
- Exam submission and retrieval (examen1, examen2)
- Teacher dashboard with student records
- Feedback system for activities
- Image upload handling for specific forums
Prerequisites
Before deploying, ensure you have:- Python 3.8 or higher
- PostgreSQL database (see Database Deployment)
- Access to a cloud platform (Render, Railway, Heroku, or VPS)
Dependencies
The backend requires the following Python packages:requirements.txt
python-multipart is required for handling file uploads in forum 5, which includes image submissions.Server Configuration
Main Application Setup
The FastAPI application is configured inback/main.py:
back/main.py
CORS Settings
For production, restrict CORS to your frontend domain:Database Connection
The backend connects to PostgreSQL using thepsycopg2 driver:
back/main.py
Environment Variable Configuration
Refactor the connection to use environment variables:.env file for local development:
.env
Running the Server
Development Mode
For local development, run the server with auto-reload:http://127.0.0.1:8000.
Production Mode
For production deployment, the server configuration frommain.py is:
back/main.py
Deployment Platforms
Render Deployment
Configure environment variables
In the Render dashboard, add all database environment variables under the Environment tab.
Railway Deployment
Docker Deployment
API Endpoints
The backend provides the following endpoint categories:User Management
POST /registrar- User registrationPOST /login- User authenticationPOST /actualizar_perfil- Update user profileGET /conseguir_usuario/{email}- Get user details
Dynamic Forum Endpoints (1, 2, 4, 6)
POST /guardar_foro{foro_id}- Submit forum responsesGET /respuestas_foro{foro_id}- Get all forum responsesGET /verificar_foro{foro_id}/{email}- Check user participation
Special Forums
POST /guardar_en_foro_3- Forum 3 with complex table structurePOST /guardar_foro5/{email}- Forum 5 with image uploadsGET /respuestas_en_foro_3- Get Forum 3 responsesGET /respuestas_en_foro_5- Get Forum 5 responses with base64 images
Exams
POST /guardar_examen1- Submit exam 1POST /guardar_examen2- Submit exam 2GET /respuestas_examen1- Get exam 1 submissionsGET /respuestas_examen2- Get exam 2 submissionsGET /verificar_examen1/{email}- Check exam 1 participationGET /verificar_examen2/{email}- Check exam 2 participation
Teacher Dashboard
GET /lista_estudiantes- Get all students (excluding admin)GET /expediente_completo/{email}- Get complete student recordGET /expediente_completo_alumno/{email}- Get student’s own recordPOST /guardar_feedback- Submit teacher feedbackGET /obtener_feedback/{email}- Get feedback for student
Production Considerations
Security hardening
- Remove hardcoded credentials
- Restrict CORS origins
- Implement rate limiting
- Add API authentication/authorization
- Hash passwords (currently stored in plaintext)
Performance optimization
- Use connection pooling for database
- Implement caching for frequently accessed data
- Add database indexes on email fields
- Use async database drivers (asyncpg)
Monitoring and logging
- Implement structured logging
- Add error tracking (Sentry, Rollbar)
- Monitor database connection health
- Track API response times
Health Check Endpoint
Add a health check endpoint for monitoring:Troubleshooting
Database Connection Errors
If you see connection errors:- Verify database credentials
- Check if the database allows connections from your deployment IP
- Ensure SSL mode is correctly configured
- Test connection using
psqlcommand-line tool
CORS Issues
If the frontend can’t connect:- Verify frontend domain is in
allow_origins - Check browser console for CORS error details
- Ensure both HTTP and HTTPS variants are allowed if needed
Port Binding Issues
If the server won’t start:- Check if port 8000 is already in use
- Use
PORTenvironment variable for cloud platforms - Verify firewall rules allow incoming connections
The backend is currently deployed on Render at
https://proyecto-ingenieria-software-6ccv.onrender.com according to the frontend source code.