Architecture Principles
The system is designed around three core principles:- Separation of Concerns - MVC pattern separates business logic, data access, and presentation
- Custom Routing - Lightweight router without framework overhead
- Database Abstraction - PDO-based database layer for secure, prepared statements
Directory Structure
The
public/ directory is the only web-accessible folder. All application code is kept outside the web root for security.Request Flow
The application follows a front controller pattern with the following request lifecycle:Request Lifecycle Steps
- Entry Point - All requests are routed to
public/index.php - Router Initialization - Router instance is created and route definitions are loaded
- Route Matching - Router matches the request URI and HTTP method to registered routes
- Controller Dispatch - Matched controller and action method are invoked
- Business Logic - Controller interacts with models to retrieve/manipulate data
- View Rendering - Controller loads the appropriate view template
- Response - HTML is returned to the client
Front Controller
Thepublic/index.php file serves as the single entry point for all HTTP requests:
public/index.php
The front controller pattern ensures that all requests go through a single point, allowing for centralized request handling, security checks, and initialization logic.
Core Components
The application’s core functionality is provided by two main classes:- Router
- Database
Router (
app/core/Router.php)Custom routing system that maps HTTP requests to controller actions. Features:- HTTP method matching (GET, POST)
- Clean URL support
- Base path normalization for subdirectory installations
- Controller/action dispatching
- 404 error handling
MVC Components
Controllers
Controllers handle HTTP requests and coordinate between models and views:AuthController- Authentication (login/logout)DashboardController- Dashboard viewsReservationController- Reservation managementMaterialController- Material API endpoints
Models
Models encapsulate database operations and business logic:User- User authentication and managementReservation- Reservation CRUD operationsRoom- Room data managementMaterial- Material managementReservationSlot- Time slot management
Views
Views are PHP templates that render HTML responses:Helper Classes
The application includes helper classes for common functionality:- Session - Session management and flash messages
- Auth - Authentication guards and role checks
Security Features
The application implements several security best practices:
- Prepared statements prevent SQL injection
- Password hashing with
password_verify() - Session management with secure regeneration
- Authentication guards on protected routes
- CSRF protection (recommended for future enhancement)
Next Steps
Explore the detailed documentation for each architectural component:- MVC Pattern - Detailed MVC implementation
- Routing System - Custom router deep dive
- Database Layer - PDO connection and models