ayouberrak / ayoub-framework
Lightweight PHP MVC Framework
Requires
- php: ^8.2
- eftec/bladeone: ^4.19
- filp/whoops: ^2.18
- vlucas/phpdotenv: ^5.6
README
A lightweight, robust, and modern PHP MVC framework designed for speed and simplicity. Built with a "Nadi" (Premium) philosophy.
✨ Features
- MVC Architecture: Clean separation of Models, Views, and Controllers.
- Custom CLI (
ayoub): Powerful command-line interface for scaffolding. - Dynamic Routing: Supports static routes and dynamic parameters (e.g.,
/user/{id}). - Database Agnostic: Native PDO support for MySQL and PostgreSQL.
- Pretty Error Handling: Integrated
Whoopsfor beautiful debugging. - Modern UI: Includes premium, glassmorphism-styled default views.
📦 Installation
-
Create a new project via Composer:
composer create-project ayouberrak/ayoub-framework my-app cd my-app -
Configure Environment: Copy the example env file and configure your database.
cp .env.example .env
Edit
.envto setDB_CONNECTION,DB_HOST,DB_DATABASE, etc. -
Run the Server:
php ayoub run
🛠️ CLI Commands (php ayoub)
The framework comes with a powerful CLI tool named ayoub to speed up your development.
🚀 Server Commands
Start Development Server
Start the built-in PHP development server.
php ayoub run
Starts server on http://localhost:8000
Custom Port:
php ayoub run 3000
Starts server on http://localhost:3000
📝 Scaffolding Commands
Make Controller
Generate a new controller class.
php ayoub make:controller UserController
Creates: app/Controllers/UserController.php
Example:
php ayoub make:controller ProductController
Make Model
Generate a new database model.
php ayoub make:model Product
Creates: app/Models/Product.php
Example:
php ayoub make:model User
Make Service
Generate a business logic service.
php ayoub make:service PaymentService
Creates: app/Services/PaymentService.php
Example:
php ayoub make:service AuthService
Make Repository
Generate a data repository.
php ayoub make:repository OrderRepository
Creates: app/Repositories/OrderRepository.php
Example:
php ayoub make:repository UserRepository
💡 Tip: Suffixes are optional!
php ayoub make:controller Userwill automatically generateUserController.
🛣️ Route Commands
Make Route
Generate a new route and append it to routes/web.php.
php ayoub make:route <method> <uri> <controller@action>
Examples:
# GET route php ayoub make:route get /users UserController@index # POST route php ayoub make:route post /users/create UserController@store # Dynamic route php ayoub make:route get /users/{id} UserController@show # DELETE route php ayoub make:route delete /users/{id} UserController@destroy
List All Routes
Display all registered routes in your application.
php ayoub route:list
Output Example:
Registered Routes:
METHOD URI ACTION
------------------------------------------------------------
GET / Closure
GET /users UserController@index
POST /users UserController@store
GET /users/{id} UserController@show
📋 All Commands Summary
| Command | Description | Example |
|---|---|---|
run [port] |
Start development server | php ayoub run 8000 |
make:controller <Name> |
Create a controller | php ayoub make:controller UserController |
make:model <Name> |
Create a model | php ayoub make:model Product |
make:service <Name> |
Create a service | php ayoub make:service AuthService |
make:repository <Name> |
Create a repository | php ayoub make:repository UserRepository |
make:route <method> <uri> <action> |
Create a route | php ayoub make:route get /users UserController@index |
route:list |
List all routes | php ayoub route:list |
🛣️ Routing
Define your routes in routes/web.php.
Static Route:
$router->get('/about', [PageController::class, 'about']);
Dynamic Route:
// The {id} will be passed to the controller method $router->get('/user/{id}', [UserController::class, 'show']);
View Rendering:
$router->get('/', function() use ($router) { return $router->renderView('welcome'); });
📂 Structure
app/- Core logic (Controllers, Models, Services).public/- Entry point (index.php).routes/- Route definitions.views/- HTML templates.config/- Configuration files.
Built with ❤️ by Ayoub.