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

ActiveLibrary[Framework](/categories/framework)

strux/strux-framework
=====================

The core engine for the Strux PHP Framework

v1.4.1(1mo ago)0141MITPHPPHP &gt;=8.4

Since Dec 28Pushed 1w agoCompare

[ Source](https://github.com/strux-php/strux-framework)[ Packagist](https://packagist.org/packages/strux/strux-framework)[ RSS](/packages/strux-strux-framework/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (84)Versions (27)Used By (1)

Strux Framework
===============

[](#strux-framework)

Strux is a modern, lightweight, **attribute-driven PHP framework** for building web applications and APIs. It combines PHP 8.4+ features with a clean architecture — Active Record ORM, attribute-based routing, built-in auth, scheduler, queue, event dispatcher, and validation — while keeping a minimal core.

---

Features
--------

[](#features)

- **Attribute-driven everything** — Routes (`#[Route]`), ORM schema (`#[Entity]`, `#[Column]`), auth (`#[Authorize]`), validation (`#[Validate]`), scheduling (`#[Schedule]`)
- **Active Record ORM** with relationships (`#[OwnedBy]`, `#[OwnsMany]`, `#[OwnedByMany]`, polymorphic variants), JSON queries, pagination, soft deletes, and query caching
- **Plates templating** (default, Twig available via adapter)
- **Task Scheduler** — cron-expression and named-frequency task scheduling with mutex locking, output capture, conditional execution, and events
- **Queue system** — database-driven background job processing
- **Auth system** — Session and JWT sentinels, roles &amp; permissions, email verification, password recovery, "remember me"
- **Form system** — attribute-driven forms with auto-binding to requests, models, or arrays
- **Event dispatcher** (PSR-14)
- **CLI tooling** for rapid development (scaffolding, migrations, queue, scheduler)
- **Multi-database support** — MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, Oracle
- **Zero external dependencies** (beyond PHP extensions)

---

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

[](#requirements)

- PHP **8.4+**
- Composer
- PDO extension (for database access)
- MBString, XML extensions

---

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

[](#installation)

```
composer create-project strux/strux-app my-app
cd my-app
php bin/console run
```

---

Configuration
-------------

[](#configuration)

Configuration files live in `src/Config/`. Each config is a PHP class implementing `ConfigInterface`:

```
src/Config/
  App.php         # Application name, URL, debug mode
  Database.php    # Database connections (SQLite, MySQL, PostgreSQL, etc.)
  Auth.php        # Sentinels, password rules, email verification
  Cache.php       # Cache driver (filesystem, array, APCu)
  Queue.php       # Queue connection (sync, database)
  Scheduler.php   # Timezone, environments, maintenance mode
  Maintenance.php # Maintenance mode settings
  View.php        # View engine configuration (Plates default, Twig adapter)
  Session.php     # Session driver and options
  Cors.php        # CORS middleware configuration

```

Environment variables are loaded from `.env`:

```
cp .env.example .env
```

```
APP_ENV=local
APP_DEBUG=true
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_DATABASE=my_app
DB_USERNAME=postgres
DB_PASSWORD=secret
```

---

Directory Structure
-------------------

[](#directory-structure)

```
bin/          # CLI entry point (console)
src/          # Application source code
  App.php     # Application class
  Config/     # Configuration files
  Domain/     # Domain-driven modules (Entity, Job, Listener, Service)
  Http/
    Controllers/
      Web/    # Web controllers (HTML)
      Api/    # API controllers (JSON)
  Infrastructure/
    Database/
      Migrations/
      Seeds/
  Registry/   # Service registries
templates/    # View templates (Plates or Twig)
web/          # Public entry point (index.php)
var/          # Cache, logs, sessions
  cache/
  logs/

```

---

Routing
-------

[](#routing)

Routes are defined via PHP attributes directly on controller methods:

```
use Strux\Component\Routing\Attributes\Route;
use Strux\Component\Routing\Attributes\Prefix;
use Strux\Component\Routing\Attributes\RouteGroup;

#[Prefix('/artworks')]
class ArtworkController extends Controller
{
    #[Route('', methods: ['GET'], name: 'artworks.index')]
    public function index(): Response
    {
        return $this->view('artworks/index', ['artworks' => Artwork::all()]);
    }

    #[Route('/:id', methods: ['GET'], name: 'artworks.show')]
    public function show(string $id): Response
    {
        return $this->view('artworks/show', ['artwork' => Artwork::findOrFail($id)]);
    }
}
```

No separate route files needed.

---

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

[](#controllers)

Controllers live in `src/Http/Controllers/Web/` (HTML) or `src/Http/Controllers/Api/` (JSON). They extend `Strux\Component\Http\Controller\Web\Controller` or `Api\Controller`.

```
#[Prefix('/dashboard')]
#[Middleware([AuthorizationMiddleware::class])]
class DashboardController extends Controller
{
    public function __construct(
        private readonly ArtworkRepository $artworks
    ) {}

    #[Route('', methods: ['GET'], name: 'dashboard.index')]
    public function index(): Response
    {
        return $this->view('dashboard/index', [
            'stats' => $this->artworks->getDashboardStats()
        ]);
    }
}
```

Dependencies are injected automatically via the container.

---

Middleware
----------

[](#middleware)

Middleware classes implement `MiddlewareInterface` and are applied via the `#[Middleware]` attribute:

```
#[Middleware([AuthMiddleware::class])]
#[Route('/admin', methods: ['GET'])]
public function admin(): Response { ... }
```

Global middleware is configured in `src/Registry/MiddlewareRegistry.php`.

Built-in middleware: `AuthorizationMiddleware`, `GuestMiddleware`, `EnsureEmailIsVerified`, `CorsMiddleware`, `CsrfMiddleware`.

---

Views
-----

[](#views)

Strux uses **Plates** as its default templating engine, with **Twig** available via a built-in adapter.

```
return $this->view('pages/home', ['title' => 'Welcome']);
```

### Plates (Default)

[](#plates-default)

```
