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.
- ๐๏ธ 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
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/dashboardRoutex/
โ
โโโ app/
โ โโโ Console/
โ โ โโโ Commands/
โ โ
โ โโโ Controllers/
โ โโโ Models/
โ
โโโ config/
โ โโโ app.php
โ โโโ database.php
โ
โโโ pages/ # Views
โ โโโ index.php
โ
โโโ public/
โ โโโ assets/
โ โโโ index.php
โ
โโโ vendor/
โโโ cli
โโโ composer.json
โโโ README.md- PHP 8.0 or higher
- Composer
composer create-project arefshojaei/routex my-appMove into your project:
cd my-appgit clone https://github.com/ArefShojaei/Routex.git
cd RoutexInstall dependencies:
composer installRoutex comes with a built-in PHP development server.
php cli servephp cli serve --host:0.0.0.0php cli serve --port:3000php cli serve --host:0.0.0.0 --port:3000After running the server, open:
http://localhost:8000File: 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
}
}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
];
}
}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>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!";
}
}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
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
Aref Shojaei
- ๐ง Email: arefshojaei82@gmail.com
- ๐ GitHub: @ArefShojaei
- ๐ฆ Packagist: arefshojaei/routex
If Routex helps you in your projects, consider giving the repository a Star โญ on GitHub.
Your support motivates further development and improvements.