Skip to content

ArefShojaei/Routex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Routex - PHP File-based Routing Framework

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.

About

A lightweight PHP starter framework with file-based routing inspired by Next.js

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors