Architecture Philosophy
NutriFit implements a modern, layered architecture based on the MVC (Model-View-Controller) pattern enhanced with the TALL Stack (Tailwind CSS, Alpine.js, Laravel, Livewire). This approach ensures:- Separation of concerns between presentation, business logic, and data
- Reactive UI without heavy JavaScript frameworks
- Scalability through Laravel’s robust ecosystem
- Maintainability with clear architectural boundaries
Architectural Layers
Layer Diagram
1. Presentation Layer
Purpose: Handle user interface and interaction Components:- Livewire Components - Reactive server-side components (
app/Livewire/) - Blade Templates - View rendering (
resources/views/) - Tailwind CSS - Utility-first styling
- Flux UI - Premium component library for consistent UI
/resources/views/, /app/Livewire/
Example:
2. Application Layer
Purpose: Orchestrate business logic and handle HTTP requests Components:- Controllers - Handle HTTP requests (
app/Http/Controllers/)AdminController.php- Admin panel operationsNutricionistaController.php- Nutritionist workflowsPacienteController.php- Patient operationsAttentionController.php- Medical attention management
- Middleware - Request filtering and authorization
- Role-based access control
- Email verification enforcement
- Password change requirement
- Fortify Actions - Authentication workflows (
app/Actions/)RedirectAfterLogin.phpRedirectAfterRegister.phpRedirectAfterEmailVerification.php
routes/web.php):
/administrador/*- Admin panel/nutricionista/*- Nutritionist dashboard/paciente/*- Patient portal
3. Domain Layer
Purpose: Core business logic and domain models Components:Eloquent Models (app/Models/)
User.php- User accounts with role-based methodsAppointment.php- Appointment scheduling and state managementAttention.php- Medical consultationsAttentionData.php- Anthropometric measurements and nutrition calculationsPersonalData.php- Patient personal informationRole.php- User roles (administrador, nutricionista, paciente)
Notifications (app/Notifications/)
16 notification classes handling:
- Welcome emails
- Appointment confirmations
- Reminders (24h before)
- Cancellations
- Password changes
Event Listeners (app/Listeners/)
SendWelcomeNotification.php- Triggered on user registration
4. Persistence Layer
Purpose: Data storage and retrieval Database:- Development: SQLite (embedded)
- Production: MySQL 8.0+
- Active Record pattern
- Relationship management
- Query builder with fluent interface
database/migrations/)
See Database Schema for detailed table structure.
Key Architectural Components
Authentication System
Provider: Laravel Fortify Features:- Email/password authentication
- Email verification (required)
- Two-Factor Authentication (2FA)
- Password reset flow
- OAuth integration (Google)
Role-Based Access Control (RBAC)
Roles:| Role | ID | Access Pattern |
|---|---|---|
| Administrador | 1 | /administrador/* |
| Nutricionista | 2 | /nutricionista/* |
| Paciente | 3 | /paciente/* |
Queue System
Driver: Database-backed queue (jobs table)
Purpose:
- Asynchronous email sending
- Preventing HTTP request delays
- Retry failed jobs automatically
config/queue.php):
Appointment Workflow
The appointment system demonstrates the full stack in action: Implementation Flow:- Presentation: Livewire component displays available slots
- Application:
PacienteController::storeAppointment() - Domain:
Appointment::create()+ validation - Queue:
AppointmentCreatedForPatientNotificationdispatched - Email: Sent asynchronously via SMTP
Configuration Management
Environment Variables (.env):
config/):
app.php- Application settingsdatabase.php- Database connectionsqueue.php- Queue configurationmail.php- Email settingsfortify.php- Authentication features
Development Tools
| Tool | Purpose | Command |
|---|---|---|
| Vite | Asset bundling + HMR | npm run dev |
| Artisan | CLI commands | php artisan serve |
| Pest | Testing framework | composer test |
| Pint | Code styling (PSR-12) | ./vendor/bin/pint |
| Concurrently | Parallel processes | composer run dev |
Performance Considerations
Caching Strategy
Production Optimization:Database Optimization
Eager Loading:- Foreign keys automatically indexed
(nutricionista_id, day_of_week)composite index on schedules- Email uniqueness constraint
Security Architecture
Data Protection
Measures:- Password hashing (bcrypt)
- CSRF protection (built-in)
- SQL injection prevention (Eloquent)
- XSS protection (Blade escaping)
- Data consent tracking (LOPD compliance)
Session Management
Database-backed sessions with:- IP address tracking
- User agent logging
- Activity timestamps
- Remember token for “stay logged in”
Scalability Patterns
Horizontal Scaling Ready
✅ Stateless application - Sessions in database✅ Queue-based tasks - Offloaded to workers
✅ Database connection pooling - MySQL support
✅ CDN-ready assets - Vite manifest for cache busting
Future Enhancements
Next Steps
Database Schema
Explore table structures and relationships
TALL Stack Deep Dive
How Tailwind, Alpine, Laravel, and Livewire work together
Notifications System
Queue-based email notifications architecture
Getting Started
Set up your development environment