What It Includes
Front controller, AltoRouter integration, core request and response services, authentication helpers, upload and mail utilities, plus a CLI scaffolder.
architecture-MVC-libraries is a lightweight PHP MVC foundation for APIs and server-rendered applications. It combines explicit controller dispatch, lazy database access, centralized JSON responses, and a simple code generator into a maintainable starting point for real-world projects.
Front controller, AltoRouter integration, core request and response services, authentication helpers, upload and mail utilities, plus a CLI scaffolder.
Explicit flow, predictable routing, lightweight abstractions, and practical extensibility over heavy framework ceremony.
Use it for APIs, admin tools, prototypes that need structure, or small applications where a full framework would feel excessive.
Install dependencies, create your environment file, then run the built-in PHP server.
composer install
composer dump-autoload
cp .env.example .env
php -S localhost:8000 -t publicDB_HOST, DB_NAME, DB_USER, DB_PASSJWT_SECRETCORS_ALLOWED_ORIGINSAPP_ENV and APP_DEBUGconfig/ Environment and application configuration
controllers/ Base controller and application controllers
core/ Request, response, auth, config, and bootstrapping services
models/ Data access classes and domain models
public/ HTTP entry point
router/ AltoRouter wrapper and controller dispatcher
routes/ Route declarations grouped by HTTP verb
tests/ Lightweight test runner and architecture checks
utils/ Reusable helpers: security, uploads, and mail
views/ PHP templates for server-rendered pages
automat CLI generator for models and controllerspublic/index.php loads Composer, environment variables, core services, the router, and the route files.
Router\Router delegates matching to AltoRouter and resolves the request to either a closure or a controller target.
The controller instance is built through Core\Core::makeController(), which injects shared request and response objects.
Controllers orchestrate input, call models, and return either rendered views or JSON responses using a consistent API.
Routes are grouped by HTTP verb and should prefer direct controller targets over inline closures.
Router\Router::get('/api', [Controllers\ApiController::class, 'index']);
Router\Router::post('/api/articles', [Controllers\ArticleController::class, 'apiStore']);
Router\Router::put('/api/articles/[i:id]', [Controllers\ArticleController::class, 'apiUpdate']);
Router\Router::delete('/api/articles/[i:id]', [Controllers\ArticleController::class, 'apiDestroy']);Core\RequestEncapsulates body reading, JSON decoding, headers, request method, URI, and uploaded files.
Core\ResponseStandardizes JSON output, status handling, and response termination.
Core\AuthServiceValidates bearer tokens, enforces HS256, checks signatures, and verifies time-based claims.
Core\AppConfigReads environment variables and exposes helpers for debug mode, environment, and allowed CORS origins.
Models\DataModelProvides lazy PDO access so the application does not connect to the database during bootstrap.
Controllers\ControllerOffers base rendering, redirect, request, response, and JSON helper behavior for all controllers.
JWT_SECRET.CORS_ALLOWED_ORIGINS in production.APP_DEBUG=false outside development.A lightweight test runner is included for fast architecture-level checks.
php tests/run.phpThe current suite covers JSON request decoding, JWT behavior, and router-to-controller dispatch.
automat scaffolds models and controllers aligned with the current architecture.
php automat list
php automat create:model Article
php automat create:controller ArticleControllerfindAll, findById, create, update, deleteindex, show, create, store, edit, update, destroyapiIndex, apiShow, apiStore, apiUpdate, apiDestroyUse the architecture reference for a deeper contributor-oriented description of runtime flow, service responsibilities, conventions, and future extension points.