Overview
NutriFit implements a robust asynchronous notification system using Laravel’s queue infrastructure. All email notifications are dispatched to a queue and processed by background workers, ensuring:- ⚡ Fast HTTP responses - Users don’t wait for emails to send
- 🔄 Automatic retries - Failed emails are retried automatically
- 📊 Job tracking - Monitor notification delivery status
- 🎯 Scalability - Handle high email volumes efficiently
Architecture Diagram
Queue Configuration
Queue Driver: Database
Configuration:config/queue.php
- ✅ No additional infrastructure (Redis, Beanstalkd)
- ✅ Transactional safety with database operations
- ✅ Easy monitoring via database queries
- ✅ Perfect for small to medium traffic
Database Tables
jobs
Purpose: Store pending notification jobs| Column | Type | Description |
|---|---|---|
id | bigint | Job ID |
queue | string | Queue name (default) |
payload | longtext | Serialized notification data |
attempts | tinyint | Number of processing attempts |
reserved_at | int | When worker picked up job |
available_at | int | When job becomes available |
created_at | int | Job creation timestamp |
database/migrations/2025_10_28_193455_create_jobs_table.php
failed_jobs
Purpose: Log permanently failed notifications| Column | Type | Description |
|---|---|---|
id | bigint | Failed job ID |
uuid | string | Unique identifier |
connection | text | Queue connection |
queue | text | Queue name |
payload | longtext | Job data |
exception | longtext | Error stack trace |
failed_at | timestamp | Failure timestamp |
Environment Configuration
File:.env
Notification Classes
NutriFit includes 16 notification classes inapp/Notifications/:
User Lifecycle Notifications
1. WelcomeNotification
Trigger: User registrationRecipient: New user
Purpose: Welcome message with platform overview File:
app/Notifications/WelcomeNotification.php
app/Listeners/SendWelcomeNotification.php
2. VerifyEmailNotification
Trigger: Registration or manual verification requestRecipient: User with unverified email
Purpose: Email verification link Custom Override in
app/Models/User.php:
3. PasswordChangedNotification
Trigger: User updates passwordRecipient: User
Purpose: Security notification of password change
4. ResetPasswordNotification
Trigger: User requests password resetRecipient: User
Purpose: Password reset link Custom Override in
app/Models/User.php:
Account Management Notifications
5. UserAccountEnabledNotification
Trigger: Admin activates user accountRecipient: User
Purpose: Inform user their account is now active
6. UserAccountDisabledNotification
Trigger: Admin deactivates user accountRecipient: User
Purpose: Inform user their account is suspended
7. PersonalDataCreatedNotification
Trigger: Admin/Nutritionist creates personal data for userRecipient: User
Purpose: Notify user their profile was completed
Appointment Lifecycle Notifications
8. AppointmentCreatedForPatientNotification
Trigger: New appointment createdRecipient: Patient
Purpose: Confirm appointment details File:
app/Notifications/AppointmentCreatedForPatientNotification.php
PacienteController::storeAppointment()
9. AppointmentCreatedNotification
Trigger: New appointment createdRecipient: Nutritionist
Purpose: Inform nutritionist of new appointment
10. AppointmentConfirmedForPatient
Trigger: Nutritionist confirms appointmentRecipient: Patient
Purpose: Appointment confirmation
11. AppointmentReminderNotification
Trigger: Scheduled task (24 hours before appointment)Recipient: Both patient and nutritionist
Purpose: Reminder notification File:
app/Notifications/AppointmentReminderNotification.php
app/Console/Commands/SendAppointmentReminders.php
routes/console.php or app/Console/Kernel.php
12. AppointmentRescheduledNotification
Trigger: Nutritionist reschedules appointmentRecipient: Patient
Purpose: Notify of new appointment time
13. AppointmentCancelledByPatient
Trigger: Patient cancels appointmentRecipient: Nutritionist
Purpose: Inform nutritionist of cancellation
14. AppointmentCancelledByNutricionista
Trigger: Nutritionist cancels appointmentRecipient: Patient
Purpose: Inform patient of cancellation
Medical Attention Notifications
15. AttentionCompletedNotification
Trigger: Nutritionist completes medical attention recordRecipient: Patient
Purpose: Notify patient that consultation is documented
Contact Form Notification
16. ContactFormNotification
Trigger: User submits contact formRecipient: Admin/System
Purpose: Forward contact inquiry to admin
Notification Dispatch Patterns
1. Direct Dispatch
2. Event Listener Dispatch
Event:Illuminate\Auth\Events\Registered
Listener: app/Listeners/SendWelcomeNotification.php
app/Providers/EventServiceProvider.php
3. Model Observer Dispatch
4. Scheduled Command Dispatch
See AppointmentReminderNotification example above.Queue Worker Management
Starting the Worker
Development:Monitoring
Check Queue Status:Production Worker (Supervisor)
Config:/etc/supervisor/conf.d/nutrifit-worker.conf
Email Template Customization
Default Template Location
Laravel usesvendor/laravel/framework/src/Illuminate/Notifications/resources/views/email.blade.php
Custom Template
Publish:resources/views/vendor/notifications/email.blade.php
Customize:
Testing Notifications
Unit Test
Email Preview (Mailtrap)
Development Setup:- Sign up at mailtrap.io
- Get SMTP credentials
- Update
.env:
Notification Performance
Metrics
| Metric | Value | Optimization |
|---|---|---|
| Avg. Queue Time | < 2 seconds | Worker always running |
| Email Send Time | 3-5 seconds | SMTP connection pooling |
| Retry Attempts | 3 | Configurable per notification |
| Queue Throughput | ~100 jobs/min | Scale with multiple workers |
Optimization Tips
1. Use Queue Priority:Troubleshooting
Issue: Emails not sending
Check:Issue: Worker stops processing
Solution: Use Supervisor (see above) or:Issue: Jobs stuck in queue
Check:Security Considerations
1. Prevent Information Disclosure
2. Rate Limit Notification Sends
3. Validate Recipients
Next Steps
Architecture Overview
Full system architecture
Database Schema
Queue and job tables structure
Creating Notifications
Build custom notification classes
Task Scheduling
Set up appointment reminders