arefshojaei/routex

A minimal PHP framework for base file routing

Maintainers

Package info

github.com/ArefShojaei/Routex

Type:project

pkg:composer/arefshojaei/routex

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

dev-main 2026-05-16 09:16 UTC

This package is auto-updated.

Last update: 2026-05-16 09:16:39 UTC


README

PHP File based Routing

A lightweight file‑based Routing system inspired by Next.js, built with PHP and structured around the MVC architecture.

Routing patterns

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
|

Folder structure (MVC)

Project
|
├── app/
│   ├── Controllers/
│   └── Models/
|
├── config/
│   └── app.php
│   └── database.php
│
├── pages/        (Views)
│   └── index.php
│
├── public/
│   ├── assets/
│   └── index.php
│
├── vendor/
├── .gitignore
├── composer.json
└── README.md

Installation

Composer

composer create-project arefshojaei/routex my-app

Github

git clone https://github.com/ArefShojaei/Routex/Routex.git

Setup

Move to the folder

cd my-app

Install dependencies

composer install

How to run the App?

You can use two ways for running such as:

Built-in PHP web-server

php -S [host]:[port] -t public/

Apache web-server

Soon...

How to use the MVC?

Model

app/Models/Post.php

<?php

namespace App\Models;

final class Product {
    public string $title;
    public float $price;

    public function __construct(string $title, float $price) {}

    public function find() {...}
    public function save() {...}
    public function update() {...}
    public function remove() {...}
}

Controller

app/Controllers/PostController.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

app/pages/post.php

<?php

use App\Controllers\ProductController;
use Routex\View\Page;

extract(Page::resolve(ProductController::class));
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Product page</title>
</head>
<body>
    <div>
        <span><?= $id ?></span> 
        <h3><?= $title ?></h3>
        <p><?= $price ?></p>
    </div>
</body>
</html>