PHPackages                             zh-innovation/mini-backend - 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. zh-innovation/mini-backend

ActiveProject[Framework](/categories/framework)

zh-innovation/mini-backend
==========================

A lightweight and high-performance PHP Backend Framework Engine.

v1.2.0(2w ago)17↓100%[5 issues](https://github.com/AbdalrhmanAbdoAlhade/ZH-Zephyr/issues)MITPHPPHP &gt;=8.2

Since May 20Pushed 2w agoCompare

[ Source](https://github.com/AbdalrhmanAbdoAlhade/ZH-Zephyr)[ Packagist](https://packagist.org/packages/zh-innovation/mini-backend)[ RSS](/packages/zh-innovation-mini-backend/feed)WikiDiscussions main Synced 1w ago

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

```
███████╗██╗  ██╗    ███╗   ███╗██╗███╗   ██╗██╗
╚════██║██║  ██║    ████╗ ████║██║████╗  ██║██║
    ██╔╝███████║    ██╔████╔██║██║██╔██╗ ██║██║
   ██╔╝ ██╔══██║    ██║╚██╔╝██║██║██║╚██╗██║██║
   ██║  ██║  ██║    ██║ ╚═╝ ██║██║██║ ╚████║██║
   ╚═╝  ╚═╝  ╚═╝    ╚═╝     ╚═╝╚═╝╚═╝  ╚═══╝╚═╝

```

⚡ ZH Mini-Backend Engine v2.0
=============================

[](#-zh-mini-backend-engine-v20)

**A high-performance, ultra-lightweight PHP Micro-Framework**
*Built from scratch. Zero dependencies. Production-ready security.*

[![PHP](https://camo.githubusercontent.com/6caa15003495643be73f70c6033009042189b7d38acf492a3d5fd04ffbb45059/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://php.net)[![License](https://camo.githubusercontent.com/b1b93040a2b81ff24e28460bc7f3bbbb08b7ead45385da36cae48c656cd2310f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d3030443946463f7374796c653d666c61742d737175617265)](LICENSE)[![Architecture](https://camo.githubusercontent.com/74e24112c6a068d98d11f74b05531a765756d0628755e8219b4f37395800328b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4172636869746563747572652d4d56432532302532422532305053522d2d342d3030464639463f7374796c653d666c61742d737175617265)](composer.json)[![Security](https://camo.githubusercontent.com/57120e497c3704b4d1b5f0e93f3ab1fbb13a668fe841d2758b2c092de7a8db9f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53656375726974792d456e746572707269736525323047726164652d4646364233353f7374796c653d666c61742d737175617265)](#-security-first)[![Validation](https://camo.githubusercontent.com/2c06fac7f741b5e701dfa176394d783fbe3b3d573159d21a69e155d9f8bd7bb9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56616c69646174696f6e2d313025324225323052756c65732d4646443730303f7374796c653d666c61742d737175617265)](#-input-validation)[![Database](https://camo.githubusercontent.com/caa9cb990633efba73bff00feee85b17090945ce21d76c4ca36b08d9b6d4ea0f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f44617461626173652d536f667425323044656c657465732d4444413044443f7374796c653d666c61742d737175617265)](#-advanced-queries)

> **"Architecture Over Size"** — Pure PHP engineered for maximum speed on minimal resources.
> Ideal for **PWA Backends**, **REST APIs**, **Egyptian Market Integrations**, and **Shared Hosting** with strict CPU/RAM limits.

---

🎯 Why ZH Mini-Backend v2.0?
---------------------------

[](#-why-zh-mini-backend-v20)

**ZH Mini-Backend** is the foundation for production-grade APIs without the bloat. Version 2.0 now includes **enterprise-level security**, **comprehensive validation**, and **data integrity features** — all while maintaining a **2MB footprint**.

FeatureZH v2.0ZH v1.0Laravel**SQL Injection Protection**✅ Automatic⚠️ Manual✅**Input Validation**✅ 10+ Rules❌✅**Soft Deletes**✅ Built-in❌✅**Secure CORS**✅ Whitelist⚠️ Permissive✅**JWT Authentication**✅ Native✅ Native✅ Package**RAM on Boot****~2 MB**~2 MB~40–60 MB**Database Migrations**✅ SQL-based✅ SQL-based✅ PHP-based**Shared Hosting Ready**✅ YES✅ YES⚠️ Heavy---

🚀 What's New in v2.0
--------------------

[](#-whats-new-in-v20)

### ✨ **Security Enhancements**

[](#-security-enhancements)

- 🔒 **Column Validation** - Prevent SQL injection in dynamic queries
- 🔒 **CORS Whitelisting** - Origin validation instead of wildcard
- 🔒 **Input Sanitization** - Strip tags and normalize data
- 🔒 **Typed Interfaces** - All middleware must implement contracts

### ✨ **Validation Framework**

[](#-validation-framework)

- ✅ **Required, Email, Numeric, Integer, String** rules
- ✅ **Min/Max Length** - String &amp; numeric constraints
- ✅ **Unique Validation** - Database-level uniqueness checks
- ✅ **Regex Patterns** - Custom format matching
- ✅ **Confirmed Fields** - Password confirmation support
- ✅ **In List** - Enum-style validation

### ✨ **Advanced Queries**

[](#-advanced-queries)

- 📊 **Soft Deletes** - `softDelete()`, `notDeleted()`, `restore()`
- 📊 **Timestamps** - `created_at`, `updated_at`, `deleted_at`
- 📊 **Foreign Keys** - Proper relational integrity
- 📊 **Indexes** - Performance-optimized table schemas

### ✨ **CLI Enhancements**

[](#-cli-enhancements)

- 🖥️ **Fixed Middleware Generator** - Now implements `Middleware` interface
- 🖥️ **All Scaffolding** - Controllers, Models, Middleware

---

📂 Directory Structure
---------------------

[](#-directory-structure)

```
ZH-Zephyr-main/
│
├── app/
│   ├── Controllers/        # 🎯 Business logic — REST endpoints
│   │   ├── AuthController.php
│   │   ├── ProductController.php
│   │   ├── CategoryController.php
│   │   └── Controller.php (base class)
│   │
│   ├── Middleware/         # 🔐 Security filters
│   │   ├── AuthMiddleware.php (JWT validation)
│   │   ├── CorsMiddleware.php (origin validation)
│   │   └── [YourMiddleware.php]
│   │
│   └── Models/             # 📦 Data layer
│       ├── Product.php
│       ├── Category.php
│       ├── User.php
│       └── Model.php (base class with security)
│
├── config/
│   └── database.php        # Database connection config
│
├── core/                   # ⚙️ Framework Engine
│   ├── Router.php          # Route registration & dispatch
│   ├── Request.php         # HTTP input abstraction
│   ├── Response.php        # JSON response helpers
│   ├── Validator.php       # ✨ NEW - Input validation rules
│   ├── DB.php              # PDO Singleton with security
│   ├── JwtAuth.php         # JWT token handling
│   ├── Middleware.php      # Interface contract
│   ├── ErrorHandler.php    # Exception & error handling
│   ├── DotEnv.php          # Environment parser
│   └── helpers.php         # Utility functions
│
├── database/
│   └── migrations/
│       ├── 001_create_products_table.sql
│       ├── 002_create_users_table.sql
│       └── 2026_05_20_201651_create_categories_table.sql
│
├── public/                 # 🌐 Web root
│   ├── index.php           # Front controller
│   ├── index.html          # Landing page
│   ├── manifest.json       # PWA manifest
│   └── sw.js               # Service worker
│
├── routes/
│   └── api.php             # All API route definitions
│
├── .env.example            # Environment template
├── .env                    # Environment config (git-ignored)
├── zh.php                  # 🖥️ CLI management tool
├── composer.json           # PSR-4 autoloading
├── CHANGES_SUMMARY.md      # 📋 Detailed changelog
├── README.md               # This file
└── LICENSE                 # MIT License

```

---

⚡ Quick Start
-------------

[](#-quick-start)

### 1. Clone &amp; Setup

[](#1-clone--setup)

```
git clone https://github.com/AbdalrhmanAbdoAlhade/ZH-Zephyr-main.git
cd ZH-Zephyr-main
composer install
cp .env.example .env
```

### 2. Configure Database

[](#2-configure-database)

Edit `.env`:

```
DB_HOST=localhost
DB_NAME=your_database_name
DB_USER=root
DB_PASS=your_password
```

### 3. Initialize Database

[](#3-initialize-database)

```
# Create database
php zh.php db:create

# Run migrations
php zh.php db:migrate
```

### 4. Start Development Server

[](#4-start-development-server)

```
php -S localhost:8000 -t public
```

Visit `http://localhost:8000` — you should see the landing page. ✅

---

🖥️ CLI Commands
---------------

[](#️-cli-commands)

The `zh.php` tool is your control center for the entire application lifecycle.

### Database Commands

[](#database-commands)

```
# Create database from .env configuration
php zh.php db:create

# Run all SQL migration files in order
php zh.php db:migrate
```

### Scaffolding Commands

[](#scaffolding-commands)

```
# Create a new RESTful controller
php zh.php make:controller ProductController

# Create a new model with table mapping
php zh.php make:model Product

# Create a new middleware (implements Middleware interface)
php zh.php make:middleware RateLimitMiddleware
```

### Package Commands

[](#package-commands)

```
# Publish package assets (if using packages)
php zh.php vendor:publish App/MyPackage
```

### Help

[](#help)

```
# Show all available commands
php zh.php

# Example output:
# ┌─ ZH Mini-Backend CLI ─────────────────────────┐
# │                                               │
# │ Database:                                     │
# │   php zh.php db:create                        │
# │   php zh.php db:migrate                       │
# │                                               │
# │ Scaffolding:                                  │
# │   php zh.php make:controller            │
# │   php zh.php make:model                 │
# │   php zh.php make:middleware            │
# │                                               │
# │ Packages:                                     │
# │   php zh.php vendor:publish         │
# └─────────────────────────────────────────────┘
```

---

🛣️ Routing &amp; Middleware
---------------------------

[](#️-routing--middleware)

### Basic Routing

[](#basic-routing)

```
