PHPackages                             spexdw/z-engine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. spexdw/z-engine

ActiveProject[Framework](/categories/framework)

spexdw/z-engine
===============

ZEngine - A modern, lightweight PHP framework with powerful service architecture

v2.0.0(4mo ago)213MITPHPPHP ^8.1CI passing

Since Nov 22Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/spexdw/z-engine)[ Packagist](https://packagist.org/packages/spexdw/z-engine)[ RSS](/packages/spexdw-z-engine/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (7)Used By (0)

ZEngine
=======

[](#zengine)

[![CI](https://github.com/spexdw/z-engine/workflows/CI/badge.svg)](https://github.com/spexdw/z-engine/actions)[![PHP Version](https://camo.githubusercontent.com/04744bae0a61d2ffe29c26f07a9612eae20445fc6feaeb77b3af1f0e9be6447c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

[![ZEngine Demo](https://camo.githubusercontent.com/ebd1ba1b802bc6ef4c106f2828d50fbe4cc0476f4738a296813a404ea99a53e3/68747470733a2f2f692e696d6775722e636f6d2f5044434a7134392e706e67)](https://camo.githubusercontent.com/ebd1ba1b802bc6ef4c106f2828d50fbe4cc0476f4738a296813a404ea99a53e3/68747470733a2f2f692e696d6775722e636f6d2f5044434a7134392e706e67)

A lightweight PHP framework. No bloat, just the essentials you actually need.

Looking for detailed readme? check [ZEngine DeepWiki](https://deepwiki.com/spexdw/z-engine) (Generated by ai expect documentation errors)

Why?
----

[](#why)

I got tired of complex frameworks with thousands of files. ZEngine is simple - you can read the entire source code in an afternoon and understand exactly what's happening.

What's Included
---------------

[](#whats-included)

- **Routing** - Map URLs to functions, add parameters, group routes
- **Middleware** - Protect routes, handle auth, whatever you need
- **Database** - Query builder that doesn't get in your way
- **Services** - Session, cookies, cache, validation, logging etc.
- **Dependency Injection** - Automatic, no XML configs
- **Error Pages** - Custom error handling with nice debug screens

Requirements
------------

[](#requirements)

- PHP 8.1+
- Composer
- That's it

Installation
------------

[](#installation)

Create a new project:

```
composer create-project spexdw/z-engine my-project
cd my-project
```

Or clone it directly:

```
git clone https://github.com/spexdw/z-engine.git my-project
cd my-project
composer install
```

Quick Start
-----------

[](#quick-start)

1. Edit `config/env.php` and set your config
2. Edit `app/routes.php` to add your routes

```
$router->get('/hello/{name}', function ($name) {
    return json(['message' => "Hello, $name!"]);
});
```

That's it. No generators, no boilerplate, just write code.

Routing
-------

[](#routing)

```
// Basic routes
$router->get('/users', function () {
    return json(['users' => []]);
});

$router->post('/users', function (Request $request) {
    $data = $request->json();
    return json(['created' => $data], 201);
});

// Other HTTP methods
$router->put('/users/{id}', function ($id, Request $request) {
    return json(['updated' => $id]);
});

$router->patch('/users/{id}', function ($id) {
    return json(['patched' => $id]);
});

$router->delete('/users/{id}', function ($id) {
    return json(['deleted' => $id]);
});

$router->any('/endpoint', function () {
    return json(['method' => 'any']);
});

// URL parameters
$router->get('/users/{id}', function ($id) {
    return json(['user_id' => $id]);
});

// Protect routes with middleware
$router->get('/admin', function () {
    return json(['secret' => 'data']);
})->middleware(AdminMiddleware::class);

// Group routes
$router->group(['prefix' => '/api'], function ($router) {
    $router->get('/users', fn() => json([]));
    $router->get('/posts', fn() => json([]));
});

// Controller usage
$router->get('/users', 'UserController@index');
$router->post('/users', [UserController::class, 'store']);
```

Controllers
-----------

[](#controllers)

Create a controller in `app/Controllers`:

```
namespace ZEngine\App\Controllers;

use ZEngine\Core\Http\Request;

class UserController
{
    public function index()
    {
        $users = db()->table('users')->get();
        return view('users.index', ['users' => $users]);
    }

    public function store(Request $request)
    {
        $data = $request->all();
        $id = db()->insert('users', $data);
        return json(['id' => $id], 201);
    }
}
```

Views
-----

[](#views)

Create views in `app/Views`:

```
// Return a view
return view('welcome'); // app/Views/welcome.php
return view('users.index', ['users' => $users]); // app/Views/users/index.php

// Using view helper
$router->get('/', function () {
    return view('welcome', ['name' => 'John']);
});
```

Request &amp; Response
----------------------

[](#request--response)

```
// Request helpers
$name = $request->input('name'); // From POST or GET
$email = $request->get('email'); // From query string
$data = $request->post('data'); // From POST
$all = $request->all(); // All input data
$json = $request->json(); // JSON payload
$token = $request->header('Authorization'); // Header
$bearer = $request->bearerToken(); // Bearer token
$file = $request->file('upload'); // Uploaded file
$ip = $request->ip(); // Client IP

// Response helpers
return json(['data' => []], 200); // JSON response
return view('page', ['key' => 'value']); // View response
return redirect('/home'); // Redirect
return Response::make('content', 200); // Plain text
```

Database
--------

[](#database)

```
// Query builder
$users = db()->table('users')
    ->where('status', 'active')
    ->orderBy('created_at', 'DESC')
    ->get();

// Get first record
$user = db()->table('users')->where('id', 1)->first();

// Count records
$count = db()->table('users')->where('status', 'active')->count();

// Pagination with limit & offset
$users = db()->table('users')->limit(10)->offset(20)->get();

// Find by ID
$user = db()->find('users', 1);

// Raw queries
$results = db()->query('SELECT * FROM users WHERE id = ?', [1]);

// Insert/Update/Delete
db()->insert('users', ['name' => 'John', 'email' => 'john@example.com']);
db()->update('users', ['status' => 'active'], ['id' => 1]);
db()->delete('users', ['id' => 1]);

// Transactions
db()->beginTransaction();
try {
    db()->insert('users', ['name' => 'John']);
    db()->commit();
} catch (Exception $e) {
    db()->rollback();
}
```

Services
--------

[](#services)

```
// Session
session()->set('user_id', 123);
$userId = session()->get('user_id');
$token = session()->token(); // CSRF token

// Cache
cache()->put('key', 'value', 300); // 5m
$value = cache()->get('key');

// Cache with callback (runs only if key doesnt exist)
$users = cache()->remember('users', 3600, function () {
    return db()->table('users')->get();
});

// Cookies
cookie()->set('theme', 'dark', time() + 3600);
$theme = cookie()->get('theme');

// Validation
$rules = ['email' => 'required|email', 'age' => 'min:18'];
$isValid = validator()->validate($data, $rules);

// Logging
logger()->error('Something broke', ['context' => 'details']);
logger()->warning('Warning message');
logger()->info('Info message');
logger()->debug('Debug data', ['user_id' => 123]);

// Events
event()->listen('user.registered', function ($userId) {
    logger()->info('User registered with ID: ' . $userId);
});

event()->dispatch('user.registered', 123);

// Hash (Password hashing)
$hash = hasher()->make('password123');
$isValid = hasher()->check('password123', $hash);

// Mail
mail()->send('user@example.com', 'Welcome!', 'Hello, welcome to our app!');

// Rate Limiting
$rateLimit = ratelimit()->check('api.endpoint', [
    '1minute' => 10,
    '1hour' => 100
]); // you can give a identifier if u want

if ($rateLimit) {
    return Response::json(['error' => $rateLimit], 429);
}
```

Middleware
----------

[](#middleware)

Create a middleware in `app/Middleware`:

```
class AuthMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        if (!$request->header('Authorization')) {
            return Response::json(['error' => 'Unauthorized'], 401);
        }
        return $next($request);
    }
}
```

Use it:

```
$router->get('/dashboard', function () {
    return json(['data' => 'secret']);
})->middleware(AuthMiddleware::class);
```

Custom Services
---------------

[](#custom-services)

Add your service to `core/Providers.php`:

```
private static function registerMyService(Container $container): void
{
    $container->singleton('myservice', function () {
        return new MyService();
    });
}
```

Then call `self::registerMyService($container);` in the `register()` method.

Use it anywhere:

```
$result = app('myservice')->doSomething();
```

Cron-Jobs (Tasks)
-----------------

[](#cron-jobs-tasks)

Add your cron to `App\Tasks\MyCron` then add your task to `/cron.php`

```
try {
    $doSomething = new DoSomething();
    $doSomething->handle();

} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
```

Note : cron.php only accessible on cli with CRON\_KEY

Error Handling
--------------

[](#error-handling)

Set `APP_DEBUG=true` in `.env` for detailed error pages with code snippets.

Set `APP_DEBUG=false` for production to show clean error pages.

Set `MAINTENANCE_MODE=1` for Maintenance mode (ip whitelist &amp; maintenance msg included)

All errors are logged to `storage/logs/error.log`.

Contributing
------------

[](#contributing)

Found a bug? Want a feature? Open an issue or PR. Keep it simple.

License
-------

[](#license)

MIT. Do whatever you want with it.

Credits
-------

[](#credits)

Built by [spexdw](https://github.com/spexdw) because existing frameworks were too complicated :p

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance78

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

6

Last Release

146d ago

Major Versions

v1.0.4 → v2.0.02025-12-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/c5ef78ec579542d155b86fc21e8a70c274af8732fcc65e00ea423ee37ed6a1c0?d=identicon)[spexdw](/maintainers/spexdw)

---

Top Contributors

[![spexdw](https://avatars.githubusercontent.com/u/174410428?v=4)](https://github.com/spexdw "spexdw (13 commits)")

---

Tags

backendframeworkliteweightmiddlewarephpphp-frameworkrouterservice-containerphpframeworkroutingservice-orientedzengine

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/spexdw-z-engine/health.svg)

```
[![Health](https://phpackages.com/badges/spexdw-z-engine/health.svg)](https://phpackages.com/packages/spexdw-z-engine)
```

###  Alternatives

[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

696214.6k17](/packages/pecee-simple-router)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
