mhvefgh/microlite

A modern, lightweight, PSR-15 compliant PHP microframework with zero bloat.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:project

pkg:composer/mhvefgh/microlite

v1.0.3 2025-11-16 16:12 UTC

This package is auto-updated.

Last update: 2025-12-16 16:27:25 UTC


README

Microlite Logo

Microlite

A fast, lightweight, modern PHP microframework inspired by Laravel β€” fully PSR-15 compliant.

Build APIs, microservices, or small apps with zero bloat. Simple, speedy, and scalable.

About

Microlite is a modern, ultra-lightweight PHP microframework built for developers who want simplicity, speed, and complete control over their application architecture. Designed for projects where a full-stack framework is unnecessary or too heavy, Microlite provides the essential tools you need β€” and nothing you don’t.

Inspired by the elegance and developer-friendly structure of Laravel, Microlite offers a familiar and intuitive workflow without requiring you to learn a new ecosystem. If you enjoy the Laravel style but need something significantly smaller and faster, Microlite is the perfect fit.

Fully PSR-15 compliant, minimal by design, and highly flexible, Microlite allows you to extend or customize every layer. Whether you're building micro-services, APIs, or small high-performance applications, Microlite keeps your stack clean and efficient.

Contributions are welcome β€” feel free to star the project, open issues, or submit PRs! πŸš€

PHP >= 8.1 License: MIT Packagist Tests Downloads

Why Microlite?

Feature Microlite Laravel Slim
Size ~50KB ~10MB+ ~100KB
Speed Ultra-fast Medium Fast
Learning Curve Laravel-like High Low
Dependencies Zero bloat Many Minimal
Best For APIs & Microservices Full apps APIs

Perfect when you love Laravel's style but hate the overhead.

Features

  • Zero Bloat β€” Only what you need
  • FastRoute β€” Blazing fast routing
  • Medoo ORM β€” Lightweight database layer
  • PSR-15 Middleware β€” Full stack support
  • .env Config β€” Simple environment management
  • CLI Tools β€” Symfony Console commands
  • PHP Views β€” With helpers (view(), e(), auth())
  • Session Auth β€” Built-in authentication helper
  • Testing Ready β€” PHPUnit + examples

Installation

composer create-project mhvefgh/microlite my-app
cd my-app
cp .env.example .env
php -S localhost:8000 -t public

Open β†’ http://localhost:8000

Quick Start

1. Routes (routes/web.php)

<?php
return function ($app) {
    $router = $app->router();

    $router->get('/', 'HomeController@index');
    $router->get('/hello/{name}', 'HomeController@hello');
    $router->get('/dashboard', 'DashboardController@index')->middleware('auth');
};

2. Controller (app/Controllers/HomeController.php)

<?php
namespace App\Controllers;

use Src\Core\Controller;
use Src\Core\Request;

class HomeController extends Controller
{
    public function index(Request $req): string
    {
        return view('home', [
            'title' => 'Welcome to Microlite',
            'user'  => auth()
        ], 'layouts.main');
    }

    public function hello(Request $req, string $name): string
    {
        return "<h1>Hello, " . e($name) . "!</h1>";
    }
}

3. View (resources/views/home.php)

<h1 class="text-4xl font-bold"><?= $title ?></h1>
<p>Welcome to Microlite! <?= auth() ? 'Logged in as ' . e(auth()->name) : 'Guest' ?></p>
<a href="/hello/World" class="text-blue-600 underline">Say Hello β†’</a>

Database & Model Example

// app/Models/User.php
<?php
namespace App\Models;

use Src\Core\Model;

class User extends Model
{
    protected string $table = 'users';
    protected array $fillable = ['name', 'email', 'password'];

    public function save(): bool
    {
        if ($this->password) {
            $this->password = password_hash($this->password, PASSWORD_DEFAULT);
        }
        return parent::save();
    }
}

// In controller
$user = new User([
    'name' => 'Ali',
    'email' => 'ali@example.com',
    'password' => '123456'
]);
$user->save();

Middleware Example

// app/Middleware/AuthMiddleware.php
<?php
namespace App\Middleware;

use Src\Core\Middleware;
use Src\Core\Request;

class AuthMiddleware extends Middleware
{
    public function handle(Request $request, callable $next)
    {
        if (!auth()) redirect('/login');
        return $next($request);
    }
}

Project Structure

my-app/
β”œβ”€β”€ app/              # Controllers, Models, Middleware
β”œβ”€β”€ public/           # index.php (entry point)
β”œβ”€β”€ resources/views/  # PHP templates
β”œβ”€β”€ routes/           # web.php
β”œβ”€β”€ src/              # Framework core
β”œβ”€β”€ tests/            # PHPUnit tests
β”œβ”€β”€ .env.example
└── composer.json

CLI Commands

# Show Microlite information (default command)
php microlite
php microlite about

# Start the development server (like php artisan serve)
php microlite serve
php microlite serve --host=0.0.0.0 --port=8080

# Generate a new controller
php microlite make:controller UserController
php microlite make:controller Admin/PostController

# Generate a new model
php microlite make:model Post
php microlite make:model ProductCategory

# Clear application cache
php microlite cache:clear

# Get help for any command
php microlite --help
php microlite serve --help

Available Commands

Command Description
about Display Microlite version and environment info
serve Start the built-in PHP development server
make:controller <name> Create a new controller class
make:model <name> Create a new model class
cache:clear Remove all cached files (views, config, routes, etc.)

Tip: Just run php microlite with no arguments to see the beautiful welcome screen!

Testing

composer test

Contributing

We love contributions!

Fork β†’ Create branch β†’ Commit β†’ Push β†’ Pull Request

Author

Mohammad Hossein Vefgh
Full-Stack PHP Developer | Open Source Enthusiast

License

Released under the MIT License.

Copyright Β© 2025 Mohammad Hossein Vefgh

If you like Microlite, give it a ⭐

Microlite β€” Laravel-style, but microlite.