PHPackages                             spark-php/framework - 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. spark-php/framework

ActiveLibrary[Framework](/categories/framework)

spark-php/framework
===================

Spark — a lightweight, Laravel-inspired PHP framework with routing, ORM, templating, and CLI

v1.0.8(3mo ago)0111MITPHP ^8.1

Since Apr 17Compare

[ Source](https://github.com/pawan1793/spark)[ Packagist](https://packagist.org/packages/spark-php/framework)[ Docs](https://github.com/pawan1793/spark)[ RSS](/packages/spark-php-framework/feed)WikiDiscussions Synced 3w ago

READMEChangelog (7)Dependencies (1)Versions (10)Used By (1)

Spark
=====

[](#spark)

[![Tests](https://github.com/pawan1793/spark/actions/workflows/tests.yml/badge.svg)](https://github.com/pawan1793/spark/actions/workflows/tests.yml)[![Latest Version](https://camo.githubusercontent.com/fe0791931cfa86229d97de37f990163cd7b7c756d7c523e86b7d28011b329b94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737061726b2d7068702f6672616d65776f726b2e737667)](https://packagist.org/packages/spark-php/framework)[![PHP Version](https://camo.githubusercontent.com/c51cc78601122904b2f1298cb2e0f05319ebb8e0e2179efed83476a81f0b0a3a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f737061726b2d7068702f6672616d65776f726b2e737667)](https://packagist.org/packages/spark-php/framework)[![License](https://camo.githubusercontent.com/5bdc4cdca3e8281ba6a6a86ad4a8b47a7fe89d552586fcd30e91c0eee1d50b11/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706177616e313739332f737061726b2e737667)](LICENSE)

A lightweight, Laravel-inspired PHP framework. No Symfony dependencies, no heavy abstractions — just routing, ORM, templating, middleware, DI, migrations, and a CLI in clean PHP 8.1+ code.

---

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

[](#quick-start)

```
composer create-project spark-php/skeleton my-app
cd my-app
php spark serve
```

Open .

No extra configuration needed — the app key is generated automatically and SQLite is configured out of the box.

---

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

[](#requirements)

- PHP 8.1+
- Extensions: `pdo`, `mbstring`, `json`
- No other dependencies

---

Routing
-------

[](#routing)

`routes/web.php`:

```
$router->get('/', [HomeController::class, 'index']);
$router->get('/users/{id}', [UserController::class, 'show']);
$router->get('/posts/{slug?}', [PostController::class, 'show']); // optional param

$router->post('/users', [UserController::class, 'store'])
    ->middleware(App\Middleware\Auth::class);

$router->group(['prefix' => 'admin', 'middleware' => [Auth::class]], function ($router) {
    $router->get('/dashboard', [DashboardController::class, 'index']);
});

$router->get('/ping', fn() => ['pong' => true]);

// API routes (routes/api.php) — no CSRF, prefixed /api
$router->get('/users', [UserController::class, 'index'])->name('api.users');

// Webhook — opt out of CSRF individually
$router->post('/webhook/github', [WebhookController::class, 'handle'])->withoutCsrf();
```

Route params are injected into controller methods by name.

---

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

[](#controllers)

```
namespace App\Controllers;

use Spark\Http\Request;
use Spark\Http\Response;

class UserController
{
    public function show(Request $request, string $id): Response
    {
        $user = User::find($id);
        return json($user);
    }

    public function store(Request $request): Response
    {
        $user = User::create($request->only(['name', 'email']));
        return json($user, 201);
    }
}
```

Return a `Response`, an array/object (auto-JSON), or a string (HTML).

---

Models (ORM)
------------

[](#models-orm)

```
namespace App\Models;

use Spark\Database\Model;

class User extends Model
{
    protected static array $fillable = ['name', 'email'];
    protected static bool  $timestamps = true;
}

// CRUD
$user   = User::create(['name' => 'Ada', 'email' => 'ada@x.com']);
$all    = User::all();
$one    = User::find(1);
$adults = User::where('age', '>', 18)->orderBy('name')->limit(10)->get();
$user->update(['name' => 'Ada Lovelace']);
$user->delete();
```

Relationships: `hasOne`, `hasMany`, `belongsTo`.

---

Migrations
----------

[](#migrations)

```
use Spark\Database\{Migration, Schema, Blueprint};

return new class extends Migration {
    public function up(): void {
        Schema::create('posts', function (Blueprint $t) {
            $t->id();
            $t->string('title');
            $t->text('body');
            $t->foreignId('user_id');
            $t->timestamps();
        });
    }
    public function down(): void {
        Schema::dropIfExists('posts');
    }
};
```

Supports SQLite, MySQL, and PostgreSQL.

```
php spark migrate
php spark migrate:rollback
```

---

Blade-lite Views (`.spark.php`)
-------------------------------

[](#blade-lite-views-sparkphp)

```
@extends('layout')
@section('title', 'Home')
@section('content')
  {{ $title }}
  @foreach($items as $item)
    {{ $item }}
  @endforeach
  @if($user)
    Welcome, {{ $user->name }}
  @endif
@endsection
```

Templates compile once to plain PHP in `storage/cache/views/`. Subsequent requests use the cached version.

Directives: `@extends @section @endsection @yield @include @if @elseif @else @endif @foreach @endforeach @for @while @isset @empty @unless @php @endphp`
Echo: `{{ $var }}` (HTML-escaped), `{!! $html !!}` (raw)

---

Middleware
----------

[](#middleware)

```
namespace App\Middleware;

use Closure;
use Spark\Http\Request;
use Spark\Http\Response;

class Auth
{
    public function handle(Request $request, Closure $next): Response
    {
        if (!$request->header('authorization')) {
            abort(401, 'Token required');
        }
        return $next($request);
    }
}
```

Built-in: `StartSession`, `VerifyCsrfToken`, `Cors`, `ForceHttps`.

---

Service Providers
-----------------

[](#service-providers)

```
namespace App\Providers;

use Spark\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(PaymentGateway::class, fn() => new StripeGateway(
            config('services.stripe.key')
        ));
    }

    public function boot(): void
    {
        // Runs after all providers are registered
    }
}
```

Register in `bootstrap/app.php`:

```
$app->register(\App\Providers\AppServiceProvider::class);
```

---

Dependency Injection
--------------------

[](#dependency-injection)

Constructor-inject any class; the container resolves dependencies automatically:

```
class ReportController
{
    public function __construct(private UserRepository $repo) {}

    public function index(): Response
    {
        return json($this->repo->all());
    }
}
```

---

CLI
---

[](#cli)

```
php spark serve                   # dev server (localhost:8000)
php spark make:controller Foo     # scaffold controller
php spark make:model Foo
php spark make:middleware Foo
php spark make:migration create_foo_table
php spark migrate
php spark migrate:rollback
php spark route:list
php spark key:generate
```

---

Security defaults
-----------------

[](#security-defaults)

Every response gets these headers automatically:

HeaderValue`X-Content-Type-Options``nosniff``X-Frame-Options``SAMEORIGIN``Referrer-Policy``strict-origin-when-cross-origin``Content-Security-Policy`strict + nonce for inline scripts/styles`Strict-Transport-Security`set on HTTPS`Permissions-Policy``geolocation=(), microphone=(), camera=()`CSRF tokens, secure session cookies, SQL prepared statements, mass-assignment protection, and open-redirect prevention are all on by default.

---

Logging
-------

[](#logging)

Spark includes a built-in file logger. Logs are written to `storage/logs/spark.log`.

```
// Log at info level
logger('User registered', ['user_id' => $user->id]);

// Get the Logger instance for any level
logger()->debug('Cache miss', ['key' => $cacheKey]);
logger()->warning('Slow query detected', ['ms' => 850]);
logger()->error('Payment failed', ['order' => $orderId]);
```

Log format:

```
[2026-04-17 10:30:00] INFO: User registered {"user_id":42}
[2026-04-17 10:30:01] ERROR: Payment failed {"order":99}

```

The minimum log level is controlled by `LOG_LEVEL` in your `.env` file (default: `debug`).
Valid levels: `debug`, `info`, `warning`, `error`.

You can also inject the logger via the container:

```
use Spark\Support\Logger;

class OrderController
{
    public function __construct(private Logger $logger) {}

    public function store(Request $request): Response
    {
        // ...
        $this->logger->info('Order created', ['id' => $order->id]);
        return json($order, 201);
    }
}
```

---

Helpers
-------

[](#helpers)

`app()`, `config()`, `env()`, `base_path()`, `storage_path()`, `view()`, `json()`, `response()`, `redirect()`, `abort()`, `csrf_token()`, `csrf_field()`, `bcrypt()`, `csp_nonce()`, `e()`, `dd()`, `logger()`

---

License
-------

[](#license)

[MIT](LICENSE) — Copyright (c) 2026 Pawan More

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance81

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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 ~0 days

Total

9

Last Release

99d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8011942?v=4)[Pawan More](/maintainers/pawan1793)[@pawan1793](https://github.com/pawan1793)

---

Tags

phpframeworkrouterormmvcmicro-frameworkspark

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spark-php-framework/health.svg)

```
[![Health](https://phpackages.com/badges/spark-php-framework/health.svg)](https://phpackages.com/packages/spark-php-framework)
```

###  Alternatives

[letsdrink/ouzo

Ouzo PHP MVC framework

7210.7k1](/packages/letsdrink-ouzo)[mirekmarek/php-jet

PHP Jet is modern, powerful, real-life proven, really fast and secure, small and light-weight framework for PHP8 with great clean and flexible modular architecture containing awesome developing tools. No magic, just clean software engineering.

241.3k](/packages/mirekmarek-php-jet)

PHPackages © 2026

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