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.1.2(3mo ago)071MITPHPPHP &gt;=8.2

Since Dec 28Pushed 2mo agoCompare

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

READMEChangelog (10)Dependencies (16)Versions (14)Used By (1)

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

[](#strux-framework)

Strux is a modern, lightweight, and powerful **PHP framework** designed for building robust web applications and APIs. It combines a clean architecture with a rich feature set—including an Active Record ORM, built-in queue system, event dispatcher, and flexible middleware—while maintaining a minimal core with **few external dependencies**.

Strux strictly adheres to **PSR-1, PSR-2, PSR-3, PSR-4, and PSR-7** standards for maximum interoperability.

---

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Directory Structure](#directory-structure)
- [Routing](#routing)
- [Controllers](#controllers)
- [Requests &amp; Responses](#requests--responses)
- [Middleware](#middleware)
- [Views &amp; Templating](#views--templating)
- [Database &amp; ORM](#database--orm)
- [Migrations](#migrations)
- [Query Builder](#query-builder)
- [Model Relationships](#model-relationships)
- [Event Dispatcher](#event-dispatcher)
- [Queue System](#queue-system)
- [Security](#security)
- [Command-Line Interface (CLI)](#command-line-interface-cli)
- [License](#license)

---

✨ Features
----------

[](#-features)

- PSR-compliant architecture (PSR-1, 2, 3, 4, 7)
- Zero external dependencies
- Attribute-based routing and ORM
- Active Record ORM with relationships
- Middleware dispatcher
- Event &amp; queue systems
- Built-in validation and security
- CLI tooling for rapid development
- Plates templating (Twig adapter available)

---

🧰 Requirements
--------------

[](#-requirements)

- PHP **8.2+**
- Composer
- PDO extension (for database access)

---

🚀 Installation
--------------

[](#-installation)

### Create a New Project

[](#create-a-new-project)

```
composer create-project strux/strux-app my-app
cd my-app
```

### Serve the Application

[](#serve-the-application)

```
php bin/console run
```

---

⚙️ Configuration
----------------

[](#️-configuration)

Configuration files are stored in the `etc/` directory and are automatically loaded.

### Environment Variables

[](#environment-variables)

Copy the example environment file and update it:

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

```
APP_ENV=local
APP_DEBUG=true

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=strux_db
DB_USERNAME=root
DB_PASSWORD=secret
```

---

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

[](#-directory-structure)

```
bin/        # CLI entry point
etc/        # Configuration & route files
src/        # Application source code
templates/  # Views, assets, language files
web/        # Public entry point (index.php)
var/        # Cache, logs, sessions

```

---

🛣 Routing
---------

[](#-routing)

Routes are defined in `etc/routes/web.php` or `etc/routes/api.php`.

### Fluent Routing

[](#fluent-routing)

```
$router->get('/', [HomeController::class, 'index']);
$router->get('/users/:id', [UserController::class, 'show']);
$router->post('/login', [AuthController::class, 'login'])->name('login');
```

### Attribute-Based Routing

[](#attribute-based-routing)

```
use Strux\Component\Attributes\Route;

class UserController
{
    #[Route('/users/:id', methods: ['GET'])]
    public function show(int $id) {}
}
```

---

🎮 Controllers
-------------

[](#-controllers)

Controllers live in `src/Http/Controller` and receive dependencies automatically via the service container.

```
class PageController extends Controller
{
    public function home(Request $request)
    {
        return $this->view('home', ['name' => 'Kernel']);
    }
}
```

---

📥 Requests &amp; Responses
--------------------------

[](#-requests--responses)

### Request Access

[](#request-access)

```
$request->input('name');
$request->safe()->input('name'); // Sanitized
$request->query('page');
$request->header('User-Agent');
$request->file('avatar');
```

### Responses

[](#responses)

```
return $this->view('profile');
return $this->json(['status' => 'ok']);
return $this->redirect('/login');
```

---

🛡 Middleware
------------

[](#-middleware)

Middleware intercepts requests before controllers execute.

```
class AuthMiddleware implements MiddlewareInterface
{
    public function process(
        ServerRequestInterface $request,
        RequestHandlerInterface $handler): ResponseInterface
    {
        if (!Auth::check()) {
            return $this->responseFactory->createResponse(302)
            ->withHeader('Location', '/login');
        }
        return $handler->handle($request);
    }
}
```

- Global middleware: `etc/middleware.php`
- Route-specific or attribute-based registration supported

---

🎨 Views &amp; Templating
------------------------

[](#-views--templating)

Strux uses **Plates** by default (Twig supported via adapter).

```
return $this->view('auth/login', ['error' => 'Invalid credentials']);
```

```
