arefshojaei / routex
A minimal PHP framework for base file routing
Package info
Type:project
pkg:composer/arefshojaei/routex
Requires
- php: ^8.0
- arefshojaei/php-x: ^1.6
README
A lightweight and modern PHP framework with file-based routing inspired by Next.js, designed around the MVC architecture and developer-friendly CLI tools.
Build fast PHP applications with automatic routing, controllers, models, views, and custom commands.
âĻ Features
- ðïļ File-based Routing - Create routes using the file system structure
- ⥠Dynamic Routes - Support for parameterized routes like
/products/:id - ðïļ MVC Architecture - Organized structure with Models, Controllers, and Views
- ð§Đ Controller Injection - Connect views to controllers seamlessly
- ðĨïļ Built-in Development Server - Run your application with a simple CLI command
- ð§ Custom CLI Commands - Extend your application with your own console commands
- ðĶ Composer Support - Easy installation and dependency management
- ðŠķ Lightweight & Fast - Minimal core with zero unnecessary complexity
ðĢïļ File-based Routing
Routex automatically converts your pages/ directory into application routes.
Example:
pages/
â
âââ index.php â /
âââ about.php â /about
â
âââ auth/
â âââ login.php â /auth/login
â âââ register.php â /auth/register
â
âââ products/
â âââ index.php â /products
â âââ [id].php â /products/:id
â
âââ admin/
âââ [id]/
âââ dashboard.php â /admin/:id/dashboard
ðïļ Project Structure (MVC)
Routex/ â âââ app/ â âââ Console/ â â âââ Commands/ â â â âââ Controllers/ â âââ Models/ â âââ config/ â âââ app.php â âââ database.php â âââ pages/ # Views â âââ index.php â âââ public/ â âââ assets/ â âââ index.php â âââ vendor/ âââ cli âââ composer.json âââ README.md
ðĨ Installation & Setup
Requirements
- PHP 8.0 or higher
- Composer
Install using Composer
composer create-project arefshojaei/routex my-app
Move into your project:
cd my-app
Clone from GitHub
git clone https://github.com/ArefShojaei/Routex.git
cd Routex
Install dependencies:
composer install
ð Running the Application
Routex comes with a built-in PHP development server.
Default
php cli serve
Custom Host
php cli serve --host:0.0.0.0
Custom Port
php cli serve --port:3000
Custom Host & Port
php cli serve --host:0.0.0.0 --port:3000
After running the server, open:
http://localhost:8000
ð§ MVC Usage
ðĶ Model
File: app/Models/Product.php
<?php namespace App\Models; final class Product { public string $title; public float $price; public function __construct(string $title, float $price) { $this->title = $title; $this->price = $price; } public function find() { // Find data } public function save() { // Save data } public function update() { // Update data } public function remove() { // Delete data } }
ðŪ Controller
File: app/Controllers/ProductController.php
<?php namespace App\Controllers; use Routex\Contracts\BaseController; use Routex\Http\Request; final class ProductController implements BaseController { public function __invoke(Request $request): array { return [ "id" => 1, "title" => "Book", "price" => 99 ]; } }
ðĻ View
File: pages/product.php
<?php use App\Controllers\ProductController; use Routex\View\Page; extract(Page::resolve(ProductController::class)); ?> <!DOCTYPE html> <html> <head> <title>Product Page</title> </head> <body> <span><?= $id ?></span> <h3><?= $title ?></h3> <p><?= $price ?></p> </body> </html>
ðŧ Custom CLI Commands (Optional)
Create your own commands inside:
app/Console/Commands/
Example:
<?php namespace App\Console\Commands; use PhpX\Components\Console\Command; final class ExampleCommand extends Command { public function exec(array $params): string { // Command logic return "Command executed successfully!"; } }
ðĨ Why Routex?
Routex provides a simple yet powerful development experience:
- No complex route configuration
- Familiar file-based routing system
- Clean MVC separation
- Simple CLI workflow
- Lightweight and easy to understand
- Perfect for small to medium PHP projects and learning purposes
ðĪ Contributing
Contributions are always welcome.
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m "Add amazing feature"
- Push your branch
git push origin feature/amazing-feature
- Open a Pull Request
ðĻâðŧ Author
Aref Shojaei
- ð§ Email: arefshojaei82@gmail.com
- ð GitHub: @ArefShojaei
- ðĶ Packagist: arefshojaei/routex
â Show Your Support
If Routex helps you in your projects, consider giving the repository a Star â on GitHub.
Your support motivates further development and improvements.