A lightweight educational PHP MVC framework built from scratch while learning how Laravel and other modern frameworks work internally. It follows a clean and simple architecture to demonstrate Routing, Controllers, Models, Views, and Middlewares — the core concepts behind Laravel’s MVC pattern.
This project was created by Mouad Oumous during my journey to deeply understand how PHP frameworks like Laravel work under the hood. By building this from scratch, I explored:
- How routing and controllers interact
- How middleware and request/response cycles function
- How models handle database persistence
- How templates and layouts are rendered
The goal isn’t to compete with Laravel — but to learn its philosophy by recreating its minimal core step by step.
- Custom Routing (GET & POST)
- Controllers and Action methods
- View rendering with layouts
- Simple Model & Active Record pattern
- Database migrations and persistence via PDO
- Form handling & Validation
- Session and Flash messages
- Middleware support (for auth, CSRF, etc.)
- Event hooks and lifecycle control
- Fully PSR-4 autoloaded via Composer
- Learn the internals of Laravel and MVC in PHP
- Use as a teaching or demo project
- Extend into a micro-framework
- Build small personal projects or tools
- PHP 8.0 or newer
- PDO extension enabled (e.g.
pdo_mysqlorpdo_sqlite) - Composer (for autoloading)
- Apache/Nginx or PHP built-in server
-
Clone the repository:
git clone https://github.com/mouadoumous/php-mvc-framework.git cd php-mvc-framework -
Install dependencies and generate autoloader:
composer install
-
Configure your environment:
- Update database settings in
config/or.env - Point your webserver to the
public/directory
- Update database settings in
-
Run the local development server:
php -S localhost:8000 -t public
-
Visit in your browser:
http://localhost:8000
/app
/controllers
/models
/views
/config
/core
Application.php
Controller.php
Router.php
Request.php
Response.php
Model.php
View.php
/migrations
/public
index.php
/vendor
composer.json
.env
README.md
Example:
$app->router->get('/users/{id}', [UserController::class, 'profile']);Controllers extend a base Controller class and use dependency-injected Request and Response objects.
- Each model extends a
DbModelbase class - Basic Active Record–like operations:
save(),findOne(), etc. - PDO prepared statements for database safety
Example:
$user = new User();
$user->name = "John";
$user->email = "john@example.com";
$user->save();- Views are simple PHP templates
- Each page extends a global layout
- Data passed from controllers is available in the view
Example:
return $this->render('home', ['name' => 'Mouad']);You can protect routes with middleware such as authentication checks:
$this->registerMiddleware(new AuthMiddleware(['profile']));Sessions and flash messages make handling user state easy:
Application::$app->session->setFlash('success', 'Welcome back!');The framework includes a basic validation system for form inputs:
$this->addRule('email', [self::RULE_REQUIRED, self::RULE_EMAIL]);- Minimal ORM (no query builder or relationships)
- No built-in CSRF or XSS protection
- Basic routing (no regex parameters)
- Not meant for large production applications
- Learning-focused; extend at your own pace
If you find this project interesting or educational:
- Fork it and experiment
- Add your own features (query builder, CSRF protection, etc.)
- Improve documentation
- Share feedback or open pull requests
MIT License Copyright (c) 2025 Mouad Oumous
Inspired by laravel — I used it as a foundation to understand and rebuild core Laravel concepts in a simplified PHP environment.
“The best way to learn a framework is to build one.” — Mouad Oumous