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

ActiveLibrary

libxa/framework
===============

LibxaFrame core framework — Foundation, Router, Atlas ORM, Blade-X, Reactive, Modules, Frontend Adapters.

v0.0.9(1mo ago)010↑2000%1MITPHPPHP ^8.3CI failing

Since Apr 8Pushed 3w agoCompare

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

READMEChangelogDependencies (12)Versions (10)Used By (1)

LibxaFrame
==========

[](#libxaframe)

The modern, elegant, and lightning-fast PHP framework for the next generation of web applications. Built around developer happiness, performance, and scalability.

Features
--------

[](#features)

- 🚀 **Blazing Fast** - Optimized for performance with minimal overhead
- 🧠 **AI Integration** - First-class AI/LLM integration out of the box
- ⚡ **Async/Fibers** - Native PHP 8.1+ Fiber concurrency without extensions
- 🔌 **WebSockets** - Real-time event-driven WebSocket ecosystem
- 🏗️ **Modular Architecture** - Package-based modular system
- 🎨 **Elegant Syntax** - Clean, expressive code following modern PHP standards
- 🛡️ **Security** - Built-in security features including LibxaSecure
- 📦 **Package System** - First-party and third-party package support
- 🗄️ **ORM &amp; Query Builder** - Powerful Atlas ORM with AI-powered queries
- 🔄 **Multi-Tenancy** - Zero-config multi-tenancy support
- 📁 **File Storage** - Consistent filesystem API
- 🧵 **Queue System** - Asynchronous job processing
- 🌐 **HTTP Client** - Connection pooling for parallel requests
- 📝 **Helpers** - Extensive utility functions

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

[](#installation)

```
composer create-project libxa/framework your-app
cd your-app
php libxa serve
```

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

[](#quick-start)

### 1. Configuration

[](#1-configuration)

Set your environment variables in `.env`:

```
APP_NAME=YourApp
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost:8000

DB_CONNECTION=sqlite
DB_DATABASE=database.sqlite

OPENAI_API_KEY=your-api-key
```

### 2. Database Setup

[](#2-database-setup)

```
php libxa migrate
```

### 3. Run Development Server

[](#3-run-development-server)

```
php libxa serve
```

Visit `http://localhost:8000` to see your application.

Framework Lifecycle
-------------------

[](#framework-lifecycle)

The LibxaFrame request lifecycle follows this flow:

```
1. HTTP Request → Public/index.php
2. HttpKernel receives request
3. Middleware Pipeline executes
4. Router matches route
5. Controller/Closure executes
6. Response generated
7. Middleware Pipeline processes response
8. Response sent to client

```

### Detailed Lifecycle

[](#detailed-lifecycle)

1. **Entry Point** - `public/index.php` boots the application
2. **Application Boot** - Service providers are registered and booted
3. **HTTP Kernel** - Handles the request through middleware
4. **Middleware Pipeline** - Global and route-specific middleware execute
5. **Router Dispatch** - Matches URL to controller action
6. **Controller Execution** - Business logic runs
7. **Response Generation** - Response object created
8. **Termination** - Middleware cleanup and final actions

Core Features
-------------

[](#core-features)

### AI Integration

[](#ai-integration)

LibxaFrame provides first-class AI integration with OpenAI and compatible services:

```
// Generate text
$response = AI::text("Write a short poem about coding.");

// Classification
$category = AI::classify("I love this framework!", ['positive', 'negative', 'neutral']);

// Embeddings
$vector = AI::embed("LibxaFrame is awesome.");

// Data extraction
$data = AI::extract("John Doe is a software engineer.", [
    'name' => 'string',
    'occupation' => 'string'
]);

// Natural language database queries
$result = DB::ask("total revenue from users in Paris last month");
```

**Configuration:**

```
OPENAI_API_KEY=your-api-key
AI_BASE_URL=https://api.openai.com/v1
ATLAS_AI_ENABLED=true
ATLAS_AI_PROVIDER=openai
ATLAS_AI_MODEL=gpt-4o-mini
```

### Async &amp; Fibers

[](#async--fibers)

True asynchronous behavior using native PHP 8.1+ Fibers:

```
use Libxa\Async\Parallel;

// Run tasks concurrently
[$users, $orders, $ads] = Parallel::run([
    'users'  => fn() => User::all(),
    'orders' => fn() => Order::recent(),
    'ads'    => fn() => Http::get('https://api.ads.com/serve'),
]);

// HTTP connection pooling
use Libxa\Http\Client;

$responses = Client::pool([
    fn() => (new Client())->get('https://api1.com/data'),
    fn() => (new Client())->get('https://api2.com/data'),
    fn() => (new Client())->get('https://api3.com/data'),
]);

// Fiber queue workers
Queue::fiber()
    ->batch($massiveArrayOfJobs)
    ->maxConcurrency(10)
    ->dispatch();
```

### WebSockets

[](#websockets)

Event-driven WebSocket ecosystem built on Workerman:

```
php libxa ws:serve
```

**WebSocket Controller:**

```
use Libxa\WebSockets\WebSocketController;

class ChatController extends WebSocketController
{
    public function onMessage($connection, $data)
    {
        $this->broadcast($data);
    }
}
```

### Modular Package System

[](#modular-package-system)

First-class package support with automatic discovery:

```
php libxa package:discover
php libxa vendor:publish --provider="Vendor\Package\ServiceProvider"
```

**Package Structure:**

```
packages/
└── my-package/
    ├── src/
    │   ├── MyServiceProvider.php
    │   ├── Routes/
    │   ├── Views/
    │   └── Database/Migrations/
    └── composer.json

```

### Atlas ORM &amp; Query Builder

[](#atlas-orm--query-builder)

Powerful database abstraction with AI capabilities:

```
// Query builder
$users = DB::table('users')
    ->where('active', true)
    ->orderBy('created_at', 'desc')
    ->get();

// Model
$user = User::find(1);
$user->name = 'John';
$user->save();

// AI-powered queries
$result = DB::ask("find all users who signed up last week");
```

### Multi-Tenancy

[](#multi-tenancy)

Zero-config multi-tenancy support:

```
TENANCY_ENABLED=true
TENANCY_DRIVER=subdomain
```

```
// Automatic tenant resolution based on subdomain
tenant()->id; // Current tenant ID
tenant()->connection; // Tenant-specific database connection
```

### File Storage

[](#file-storage)

Consistent filesystem API:

```
// Store file
Storage::put('avatars/user1.jpg', $fileContents);

// Retrieve file
$contents = Storage::get('avatars/user1.jpg');

// Check existence
if (Storage::exists('avatars/user1.jpg')) {
    // ...
}

// Delete file
Storage::delete('avatars/user1.jpg');

// File URLs
$url = Storage::url('avatars/user1.jpg');
```

### Helpers &amp; Utilities

[](#helpers--utilities)

Extensive helper functions:

```
// String helpers
str('Hello World')->slug(); // hello-world
str()->limit('Long text...', 10); // Long te...

// Array helpers
collect([1, 2, 3])->avg(); // 2
collect([1, 2, 3])->sum(); // 6

// Path helpers
app_path();
storage_path();
public_path();

// Time helpers
now()->format('Y-m-d');
now()->addDays(7);
```

### Queue System

[](#queue-system)

Asynchronous job processing:

```
// Create a job
class SendEmail implements ShouldQueue
{
    public function handle()
    {
        Mail::to($this->user)->send(new WelcomeEmail());
    }
}

// Dispatch job
SendEmail::dispatch($user);

// Process queue
php libxa queue:work
```

### HTTP Client

[](#http-client)

Powerful HTTP client with connection pooling:

```
use Libxa\Http\Client;

$client = new Client();
$response = $client->get('https://api.example.com/data');
$data = $response->json();

// POST request
$response = $client->post('https://api.example.com/users', [
    'name' => 'John Doe',
    'email' => 'john@example.com'
]);
```

Routing
-------

[](#routing)

### Basic Routes

[](#basic-routes)

```
$router->get('/', function () {
    return view('welcome');
});

$router->get('/users/{id}', function ($id) {
    return "User {$id}";
});
```

### Controller Routes

[](#controller-routes)

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

### Route Groups

[](#route-groups)

```
$router->group(['prefix' => 'admin', 'middleware' => 'auth'], function ($router) {
    $router->get('/dashboard', [AdminController::class, 'dashboard']);
    $router->get('/users', [AdminController::class, 'users']);
});
```

### Resource Routes

[](#resource-routes)

```
$router->resource('posts', PostController::class);
```

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

[](#controllers)

```
