How esteban389/qsul-backend works
Main Components
• HTTP/API Layer: Represented by the controllers (found in app/Http/Controllers) and routes files (routes/api.php, routes/web.php, etc.). This layer handles incoming requests for tasks such as user authentication, survey submission, and university management.
• Request Validation and DTOs: The HTTP Requests (app/Http/Requests) coupled with DTOs (app/DTOs) ensure that data is structured and validated before being processed by the underlying services.
• Business Logic / Service Layer: The services in app/Http/Services (such as SurveyService, EmployeeService, FileService, etc.) encapsulate the core business logic. This layer interacts with the models and coordinates tasks.
• Data Persistence Layer: The models (found in app/Models) represent the database entities. The migrations and seeders (in database/) define the structures of tables like users, surveys, campuses, employees, etc.
• Event and Notification Handling: The events (app/Events), listeners (app/Listeners), and notifications (app/Notifications) support asynchronous processing and messaging (e.g., notifying users on survey completion or password resets).
• Middleware and Policies: The middleware (app/Http/Middleware) and policy files (app/Policies) handle security, validation, and authorization concerns.
• Supporting Libraries: Components in app/Lib provide auxiliary functionality (for example, generating unique IDs using NanoId).
Relationships and Interactions
• Web Clients make HTTP requests that are routed via the routes files to the appropriate controllers.
• Controllers invoke Request objects for validation and then use DTOs to structure and pass data into the Service layer.
• The Service layer executes business rules by interacting with the Models (which encapsulate ORM-based data persistence).
• Business operations might fire Events, which have corresponding Listeners that process notifications (e.g., dispatching a PasswordResetNotification or SurveyAnsweredNotification).
• Policies and Middleware protect routes and actions, ensuring that only authorized and valid requests go through.
• The system leverages Laravel’s artisan commands (such as php artisan migrate, queue:work, storage:link) to initialize, manage and run background tasks, emphasizing server-side orchestration.
Architectural Patterns and Design Principles
• Separation of Concerns: Clearly delineate the responsibilities among Controllers, Services, Models, and Validators/DTOs.
• MVC (Model-View-Controller): Although this is an API-focused application, the structure still reflects the separation between the data (Models), processing (Services/Controllers), and presentation (Routes/Views).
• Event-Driven Architecture: Employing events and listeners for asynchronous, decoupled operations.
• Service Layer / SOLID Principles: Isolating business logic in service classes to keep controllers thin and focused on I/O handling.
• Use of Contracts and Policies promotes clean authentication and authorization practices.
Relevant Technologies and Tools
• PHP and Laravel as the core framework.
• Composer for dependency management.
• Artisan for CLI commands to manage database migrations, queue workers, etc.
• Database connections configured in config/database.php (likely a SQL-based DB).
• Notification system (mail, or built-in Laravel notifications) for user alerts.
• Use of external libraries (ex: NanoId in app/Lib) for supporting functionality.