How erik-egam/backend-sistema-academico works
Project type and purpose
• Project Type: Monolithic backend API
• Technology Stack: Python, FastAPI, MySQL (via a config module), JWT for auth
• Purpose: Provide role-based REST endpoints to manage users, programs, courses, semesters, enrollments and grades in an academic environment.
High-level architectural layers
• Presentation/API Layer (FastAPI routes)
• Business Logic/Service Layer (model “functions” modules)
• Data Access Layer (config.py + direct MySQL calls)
• Persistence Layer (MySQL database)
Main components
a. FastAPI Application (main.py)
b. Route Modules (“routes/”):
• usuarios.py (authentication, JWT issuance)
• admin.py (admin CRUD and assignments)
• estudiantes.py (student operations)
• profesores.py (professor operations)
c. Model Modules (“models/”):
• Entity Models (Pydantic schemas in Asignatura.py, Semestre.py, Programa.py, Notas.py, Usuario.py)
• Service Modules (Admin_functions.py, estudiantes_functions.py, profesor_functions.py)
• config.py (database connection factory)
d. External System: MySQL database (seeded via inserts_pruebas.txt)
Relationships & data flow
• Client → HTTP request to FastAPI → routed by main.py
• Route handler invokes service function in models/*.py
• Service function uses config.get_connection() → executes SQL against MySQL
• Raw DB result → Pydantic model validations/serializations → JSON response
• Authentication routes generate/validate JWT → used as bearer token in subsequent calls
Architectural patterns & principles
• Layered/Clean Architecture: separation of concerns between controllers (routes), business logic (service functions), and data access (config + raw SQL)
• Role-Based Access Control: enforced in route decorators or inside handler logic (e.g., JWT scopes, user role checks)
• Modular Design: one file per domain function (e.g., Admin_functions.py) and one route per actor
• Dependency Injection (FastAPI’s Depends) for auth and DB connections
Technologies & frameworks
• FastAPI for HTTP server, routing, dependency injection, OpenAPI docs
• Pydantic for data validation and serialization
• mysql-connector/python (or equivalent) for direct DB connections
• PyJWT (via FastAPI dependency) for token creation & validation
• CORS middleware (configured in main.py)