arefshojaei/routex

A minimal PHP framework for base file routing

Maintainers

Package info

github.com/ArefShojaei/Routex

Type:project

pkg:composer/arefshojaei/routex

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

1.0.0 2026-06-16 13:41 UTC

This package is auto-updated.

Last update: 2026-06-17 12:33:18 UTC


README

PHP Version License GitHub

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.

Routex

âœĻ 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.

  1. Fork the repository
  2. Create a feature branch
git checkout -b feature/amazing-feature
  1. Commit your changes
git commit -m "Add amazing feature"
  1. Push your branch
git push origin feature/amazing-feature
  1. Open a Pull Request

ðŸ‘Ļ‍ðŸ’ŧ Author

Aref Shojaei

⭐ 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.