Architecture
Sistema de Ventas follows Laravel’s MVC (Model-View-Controller) architecture pattern with a clear separation of concerns:Key Components
Routes
Defined in
routes/web.php, routes map URLs to controller methodsControllers
Handle business logic and coordinate between models and views
Models
Eloquent models represent database tables and relationships
Middleware
Filter HTTP requests (authentication, verification, etc.)
Authentication System
Sistema de Ventas uses Laravel’s built-in authentication with custom modifications:Authentication Features
- Laravel UI: Provides authentication scaffolding
- Laravel Sanctum: API token authentication
- Email Verification: Required before accessing protected routes
- Password Reset: Email-based password recovery
- Custom Usuario Model: Uses
usuariotable instead of defaultusers
Authentication Flow
User Registration
Users register via
Auth::routes() which provides:/register- Registration form/login- Login form/logout- Logout endpoint/password/reset- Password reset flow
RESTful Resource Routes
Several controllers use Laravel’s resource routing for standard CRUD operations:ProductoController
routes/web.php:55
| Method | URI | Action | Route Name |
|---|---|---|---|
| GET | /productos | index | productos.index |
| GET | /productos/create | create | productos.create |
| POST | /productos | store | productos.store |
| GET | /productos/{id} | show | productos.show |
| GET | /productos/{id}/edit | edit | productos.edit |
| PUT/PATCH | /productos/{id} | update | productos.update |
| DELETE | /productos/{id} | destroy | productos.destroy |
CategoriaController
routes/web.php:67
UsuarioController
routes/web.php:70
EntradaController
routes/web.php:76
Custom Routes
In addition to resource routes, Sistema de Ventas defines custom routes for specific operations:Profile Management
routes/web.php:41-44
Product Operations
routes/web.php:56-58
Company Management
routes/web.php:48-51
Middleware
Verified Middleware
All protected routes use theverified middleware, which ensures:
- User is authenticated
- User’s email is verified
- Redirects to verification notice if not verified
Web Middleware Group
All routes automatically receive theweb middleware group which provides:
- Session state
- CSRF protection
- Cookie encryption
- Request validation
Database Query Approach
Sistema de Ventas uses a mix of query approaches:Raw SQL Queries
Many controllers useDB::select() for complex queries:
ProductoController.php:18-22
Query Builder
For simpler operations, the query builder is used:ProductoController.php:58-66
Eloquent Models
TheUsuario model extends Authenticatable for authentication:
Usuario.php:8-17
Response Types
View Responses
Most routes return Blade views:Redirect Responses
After form submissions:JSON Responses
For AJAX requests:ProductoController.php:200-217
Validation
Controllers use Laravel’s request validation:ProductoController.php:41-48
File Uploads
The system handles file uploads for:- Product images (
storage/app/public/FOTO-PRODUCTOS/) - User avatars
- Company logos
ProductoController.php:70-77
Error Handling
Controllers use try-catch blocks for error handling:Next Steps
Routes Reference
Complete route listing with details
Controllers
Detailed controller documentation
Database Schema
Database structure and relationships
Models
Eloquent model documentation