How jennymph/tt-web-backend works
1. What this repository is
- TT-Web is a Laravel-based REST backend for managing the “proceso de protocolos” at ESCOM.
- The architecture is server-side focused: HTTP APIs, database persistence, email delivery, and a small set of Blade views for mail/templates and public pages.
2. Top-level application boundary
- The application follows the standard Laravel split: routes receive requests, app/Http/Controllers orchestrate logic, app/Models map to the database, and database/migrations define the schema.
- The main runtime boundary is the Laravel HTTP kernel plus middleware stack, with an additional CLI boundary through artisan and console kernel.
3. Primary business areas
- The codebase centers on a few domain objects:
- User for authentication and account management
- Student
- Staff
- Protocol
- DatesAndTerms
- Consulta for contact/help inquiries
- These suggest the backend coordinates users and academic protocol records, with time/term configuration as a separate concern.
4. HTTP/API layer
- Controllers in app/Http/Controllers are the main entry points:
- AuthController
- UsersController
- StudentController
- StaffController
- ProtocolController
- DatesAndTermsController
- VerifyMail
- Routes are split between routes/web.php and routes/api.php, so the app likely serves both browser-facing pages and API endpoints.
5. Authentication and session/token handling
- Auth is reinforced by Laravel middleware and config, including Authenticate, RedirectIfAuthenticated, UpdateTokenExpiry, and ValidateSignature.
- config/sanctum.php and personal_access_tokens migration indicate Laravel Sanctum is used for API authentication/token access.
- config/session.php and the standard Laravel auth scaffolding suggest some routes may still rely on session-based behavior for web flows.
6. Persistence and database model
- Database structure is defined entirely through migrations, including users, students, staff, protocols, consultas, and dates/terms.
- There is a migration to enable PostgreSQL extensions, which strongly suggests PostgreSQL is the primary database.
- Eloquent models mirror the tables and are the main persistence abstraction; no separate repository layer is present.
7. Protocol document/file handling
- app/Services/FileService.php is a dedicated service boundary for file operations.
- This likely supports protocol-related attachments, PDF handling, or uploads stored via Laravel’s filesystem abstraction (config/filesystems.php).
- The migration change_pdf_type_in_protocols implies protocol records store PDF-related data or references.
8. Email and communication flow
- Mail classes in app/Mail show a distinct outbound communication subsystem:
- BienvenidoVerifMail
- EnvioCorreoMailabre
- MensajeDeContacto
- RecuperarContrasena
- Corresponding Blade templates in resources/views support email content and likely public contact/recovery pages.
- This mail flow is important for account verification, password recovery, and contact messages.
9. Middleware and request processing
- The custom middleware UpdateTokenExpiry is notable because it suggests token lifecycle management beyond default Laravel behavior.
- Standard Laravel middleware handles CSRF, cookie encryption, proxy trust, host trust, maintenance mode, and auth gating.
- This indicates a conventional request pipeline with one custom extension around token freshness.
10. Presentation layer
- resources/views contains a small set of Blade templates (welcome, contacto, Recuperar, BienvenidoVerifMail, etc.), so the UI footprint is limited and mostly supportive.
- resources/js and resources/css exist with Vite configuration, but this appears secondary to the backend API role.
- The UI layer likely serves account/contact/recovery screens rather than a large SPA.
11. Operational and framework infrastructure
- The app uses standard Laravel providers, logging, cache, queue, broadcasting, and CORS configuration.
- config/queue.php and mail configuration imply asynchronous-capable infrastructure, even if the current codebase may primarily use synchronous execution.
- public/index.php is the web entry point, while artisan is the CLI/admin entry point.
12. Testing and documentation artifacts
- There is a basic PHPUnit setup under tests, currently with scaffold tests.
- umlDiagrams/ contains Visual Paradigm files, indicating the project has existing design documentation outside the codebase.
- These artifacts suggest the repository is maintained with explicit modeling/documentation in mind, even if implementation tests are minimal.
13. Overall data flow
- A typical request enters through Laravel routing, passes middleware/auth checks, reaches a controller, then reads/writes Eloquent models backed by PostgreSQL migrations.
- If needed, the controller delegates file work to FileService or email work to a Mailable class.
- Responses are returned as API payloads or Blade-rendered pages depending on the route group.
14. Architecture summary for a diagram
- The clearest diagram would show four layers: HTTP/API + Middleware, Controllers, Domain/Persistence Models, and Infrastructure services (database, mail, filesystem, auth tokens).
- The key external systems are PostgreSQL, email delivery, and Laravel Sanctum token auth.
- The app is not a generic frontend-heavy system; it is primarily a backend workflow service for managing protocol-related academic records and communications.
Main entry points: 2025_02_29_061853_create_protocols_table.php Migrations · Kernel.php HTTP Kernel · api.php API Routes · UsersController.php Users
Components 34
Entry & Runtime
Framework entry points and runtime kernels
- Entry · Web bootstrap entry point
src/public/index.php - Artisan · Command-line application entry point
src/artisan - Console Kernel · Console command scheduling and bootstrapping
src/app/Console/Kernel.php
HTTP Layer
Routes, controllers, and request middleware
- HTTP Kernel · Main HTTP middleware pipeline
src/app/Http/Kernel.php - Web Routes · Browser-facing route definitions
src/routes/web.php - API Routes · API route definitions
src/routes/api.php - Auth · Login, verification, and auth flows
src/app/Http/Controllers/AuthController.php - Users · User account and profile operations
src/app/Http/Controllers/UsersController.php - Students · Student management endpoints
src/app/Http/Controllers/StudentController.php - Staff · Staff management endpoints
src/app/Http/Controllers/StaffController.php - Protocols · Protocol workflow endpoints
src/app/Http/Controllers/ProtocolController.php - Dates & Terms · Academic dates and term configuration
src/app/Http/Controllers/DatesAndTermsController.php - Verify Mail · Mail verification endpoint
src/app/Http/Controllers/VerifyMail.php - Auth Guard · Authentication gate for protected routes
src/app/Http/Middleware/Authenticate.php - Redirect Auth · Redirects authenticated users away from guest routes
src/app/Http/Middleware/RedirectIfAuthenticated.php - Token Expiry · Refreshes API token lifecycle
src/app/Http/Middleware/UpdateTokenExpiry.php - Signed URL · Validates signed requests
src/app/Http/Middleware/ValidateSignature.php
Domain & Data
Core business entities and schema
- User · Authentication and account entity
src/app/Models/User.php - Student · Student record entity
src/app/Models/Student.php - Staff · Staff record entity
src/app/Models/Staff.php - Protocol · Protocol record entity
src/app/Models/Protocol.php - Dates & Terms · Dates and academic term entity
src/app/Models/DatesAndTerms.php - Consulta · Contact and help inquiry entity
src/app/Models/Consulta.php - Migrations · Database schema and change history
src/database/migrations/2025_02_29_061853_create_protocols_table.php - PostgreSQL · Primary relational persistence store
Infrastructure
Mail, files, and external integrations
- File Service · Protocol file and upload handling
src/app/Services/FileService.php - Welcome Mail · Account verification email
src/app/Mail/BienvenidoVerifMail.php - Contact Mail · Inbound contact message email
src/app/Mail/MensajeDeContacto.php - Password Mail · Password recovery email
src/app/Mail/RecuperarContrasena.php - Open Mail · Outgoing mail helper/template flow
src/app/Mail/EnvioCorreoMailabre.php - Sanctum · API token authentication
src/config/sanctum.php - Filesystem · File storage backend for protocol assets
src/config/filesystems.php - Mail Delivery · Outbound email transport and rendering
src/config/mail.php
Views
Blade templates and public-facing pages
- Blade Views · Public pages and email templates
src/resources/views/welcome.blade.php
Connections 41
- Entry → HTTP Kernel: boots · Web requests enter the Laravel HTTP pipeline
- Artisan → Console Kernel: boots · CLI commands enter the console runtime
- HTTP Kernel → Auth Guard: pipeline · HTTP requests pass through middleware
- HTTP Kernel → Redirect Auth: pipeline · Guest/auth redirects are applied in the request path
- HTTP Kernel → Token Expiry: pipeline · Token freshness is maintained for authenticated API access
- HTTP Kernel → Signed URL: pipeline · Signed URLs are validated during request handling
- Web Routes → Auth: dispatches · Web routes map into controller actions
- Web Routes → Users: dispatches · Web routes map into controller actions
- Web Routes → Verify Mail: dispatches · Web routes map into controller actions
- API Routes → Students: dispatches · API routes map into controller actions
- API Routes → Staff: dispatches · API routes map into controller actions
- API Routes → Protocols: dispatches · API routes map into controller actions
- API Routes → Dates & Terms: dispatches · API routes map into controller actions
- Auth → User: uses · Authentication and account logic operates on users
- Users → User: uses · User management reads and updates user records
- Students → Student: uses · Student endpoints operate on student records
- Staff → Staff: uses · Staff endpoints operate on staff records
- Protocols → Protocol: uses · Protocol workflow persists protocol records
- Protocols → File Service: delegates · Protocol documents and uploads are handled separately
- Dates & Terms → Dates & Terms: uses · Dates and term settings are persisted through Eloquent
- Verify Mail → Welcome Mail: sends · Verification flow triggers email delivery
- Protocols → Contact Mail: sends · Protocol-related contact or notification mail may be sent
- Users → Password Mail: sends · Account recovery uses password reset email
- Users → Open Mail: sends · General email sending flow
- User → Migrations: backed by · Users table is defined in migrations
- Student → Migrations: backed by · Students table is defined in migrations
- Staff → Migrations: backed by · Staff table is defined in migrations
- Protocol → Migrations: backed by · Protocols schema evolves through migrations
- Dates & Terms → Migrations: backed by · Dates and terms schema evolves through migrations
- Consulta → Migrations: backed by · Consulta records are schema-managed
- Migrations → PostgreSQL: targets · Schema is applied to PostgreSQL
- Auth → Sanctum: auth · API access is token-protected through Sanctum
- Token Expiry → Sanctum: refreshes · Token expiry is managed around Sanctum tokens
- File Service → Filesystem: stores in · Uploads and protocol files use Laravel storage
- Welcome Mail → Mail Delivery: delivered via · Verification email is sent through mail infrastructure
- Contact Mail → Mail Delivery: delivered via · Contact mail is sent through mail infrastructure
- Password Mail → Mail Delivery: delivered via · Recovery mail is sent through mail infrastructure
- Open Mail → Mail Delivery: delivered via · General mail flow uses mail infrastructure
- Blade Views → Welcome Mail: renders · Blade templates support email content
- Blade Views → Password Mail: renders · Blade templates support recovery pages and mail content
- Blade Views → Contact Mail: renders · Blade templates support public contact pages and mail content