Skip to content

Lightweight PHP MVC framework built by Mouad Oumous while learning Laravel internals. Demonstrates routing, controllers, models, views, middleware, database handling with PDO, sessions, validation, and basic Active Record patterns. Ideal for learning, experimentation, and understanding MVC concepts.

Notifications You must be signed in to change notification settings

droidevs/PHP-MVC-Framework

Repository files navigation

PHP MVC Framework (Educational Project by Mouad Oumous)

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.


🧠 Motivation

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.


✨ Features

  • 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

📘 Use Cases

  • 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

⚠️ Note: This framework is not intended for production use. It’s an educational tool meant for learning, experimentation, and exploration.


🧩 Requirements

  • PHP 8.0 or newer
  • PDO extension enabled (e.g. pdo_mysql or pdo_sqlite)
  • Composer (for autoloading)
  • Apache/Nginx or PHP built-in server

⚙️ Installation

  1. Clone the repository:

    git clone https://github.com/mouadoumous/php-mvc-framework.git
    cd php-mvc-framework
  2. Install dependencies and generate autoloader:

    composer install
  3. Configure your environment:

    • Update database settings in config/ or .env
    • Point your webserver to the public/ directory
  4. Run the local development server:

    php -S localhost:8000 -t public
  5. Visit in your browser:

    http://localhost:8000
    

📁 Directory Structure

/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

🚦 Routing & Controllers

Example:

$app->router->get('/users/{id}', [UserController::class, 'profile']);

Controllers extend a base Controller class and use dependency-injected Request and Response objects.


🧱 Models & Database Layer

  • Each model extends a DbModel base 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 & Layouts

  • 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']);

🔐 Middleware & Sessions

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!');

🧪 Validation

The framework includes a basic validation system for form inputs:

$this->addRule('email', [self::RULE_REQUIRED, self::RULE_EMAIL]);

⚠️ Limitations

  • 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

🧑‍💻 Contributing

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

📜 License

MIT License Copyright (c) 2025 Mouad Oumous


❤️ Credits

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

About

Lightweight PHP MVC framework built by Mouad Oumous while learning Laravel internals. Demonstrates routing, controllers, models, views, middleware, database handling with PDO, sessions, validation, and basic Active Record patterns. Ideal for learning, experimentation, and understanding MVC concepts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published