How vgalvoso/spm works
Project Type and Purpose
• This is a minimal PHP MVC “framework” designed to help you quickly spin up small web applications.
• It provides a front controller (index.php), a lightweight router (routes.php), controllers, views, models, and database connectivity, all without heavy dependencies.
Key Architectural Elements from File Structure
• app/Config/Database.php: database configuration, loaded by a DotEnv library
• app/Libraries: core framework helpers (DotEnv loader, base Model, general Helper functions)
• app/Controller: your HTTP-facing controllers (e.g., Home.php)
• app/Model: your data-access classes (e.g., HomeModel.php)
• app/Views: presentation layer (templates, header/footer sections)
• public/: static assets (CSS, JS) served by the web server
• index.php + autoload.php: front controller and PSR-4 autoloader bootstrap
• routes.php: maps GET/POST/CLI endpoints to controller methods
Main Components & Their Relationships
a. Client & Transport Layer
• Browser or CLI client makes HTTP/CLI requests to the Web Server.
• Web Server (Apache/Nginx) points all traffic to index.php (via .htaccess or vhost).
b. Front Controller & Router
• index.php initializes Composer autoloader, loads DotEnv, reads app/Config/Database.
• routes.php defines endpoints; router dispatches request to the correct controller method.
c. Controllers
• Receive request data (GET/POST/CLI), invoke business logic, call Models, and select Views.
d. Models & Database
• Base Model in app/Libraries/Model.php handles connection, query execution, transactions.
• HomeModel (and others) extend base Model, perform CRUD via getItem(), getItems(), exec() methods.
• Database drivers: MySQL, MSSQL, SQLite.
e. Views & Presentation
• Controllers call view() helper to render header, page body, footer.
• Templates in app/Views produce HTML + embedded PHP variables.
f. Static Assets
• public/css/style.css (and potentially JS/images) are referenced by Views, served directly by the web server.
Architectural Patterns & Principles
• MVC separation: Controllers only coordinate, Models only handle data, Views only present.
• Front Controller pattern: single entry point (index.php).
• Router abstraction: declarative routes in routes.php.
• Dependency injection via DotEnv and config file.
• PSR-4 autoloading (via composer.json) ensures class mapping.