luminearisa/luminous

Luminous - Lightweight PHP Framework for RESTful APIs

Maintainers

Package info

github.com/luminearisa/luminous

Type:project

pkg:composer/luminearisa/luminous

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.3 2026-01-08 06:16 UTC

This package is auto-updated.

Last update: 2026-04-08 06:51:46 UTC


README

Lightweight PHP Framework for RESTful APIs

PHP Version License

๐ŸŒŸ Features

  • โœ… PHP Native - No heavy framework dependencies
  • โœ… MVC Architecture - Clean separation of concerns
  • โœ… RESTful API - Built for modern API development
  • โœ… JWT Authentication - Secure token-based auth
  • โœ… Database Support - MySQL & SQLite out of the box
  • โœ… CLI Tool - Powerful lumi command-line interface
  • โœ… Shared Hosting Ready - Deploy to Hostinger, cPanel easily
  • โœ… Clean Configuration - .lumi config system + .env

๐Ÿ“‹ Requirements

  • PHP >= 8.1
  • Composer
  • MySQL or SQLite

๐Ÿš€ Quick Start

1. Installation

# Clone or download the framework
cd luminous

# Install dependencies
composer install

# Copy environment file
cp .env.example .env

# Configure your .env file
nano .env

2. Configuration

Edit .env file:

APP_ENV=production
APP_DEBUG=false

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_NAME=your_database
DB_USER=your_username
DB_PASS=your_password

JWT_SECRET=your-super-secret-key-change-this

3. Make CLI Executable

chmod +x lumi

4. Run Development Server

php -S localhost:8000

Visit: http://localhost:8000

๐Ÿ› ๏ธ CLI Commands

Luminous provides a powerful CLI tool called lumi:

# List all commands
php lumi list

# Create a controller
php lumi make:controller UserController

# Create a model
php lumi make:model User

# Create a migration
php lumi make:migration create_users_table

# Create a middleware
php lumi make:middleware CheckRole

# Run migrations
php lumi migrate

๐Ÿ“ Directory Structure

/
โ”œโ”€โ”€ index.php                 # Entry point (root)
โ”œโ”€โ”€ lumi                      # CLI tool
โ”œโ”€โ”€ composer.json             # Dependencies
โ”œโ”€โ”€ .env                      # Environment config
โ”œโ”€โ”€ /app
โ”‚   โ”œโ”€โ”€ /Core                 # Framework core
โ”‚   โ”‚   โ”œโ”€โ”€ Router.php
โ”‚   โ”‚   โ”œโ”€โ”€ Request.php
โ”‚   โ”‚   โ”œโ”€โ”€ Response.php
โ”‚   โ”‚   โ”œโ”€โ”€ Controller.php
โ”‚   โ”‚   โ”œโ”€โ”€ Database.php
โ”‚   โ”‚   โ”œโ”€โ”€ JWT.php
โ”‚   โ”‚   โ””โ”€โ”€ Env.php
โ”‚   โ”œโ”€โ”€ /Controllers          # Your controllers
โ”‚   โ”œโ”€โ”€ /Models               # Your models
โ”‚   โ”œโ”€โ”€ /Middlewares          # Middleware classes
โ”‚   โ”œโ”€โ”€ /Helpers              # Helper classes
โ”‚   โ””โ”€โ”€ /Console              # CLI commands
โ”œโ”€โ”€ /routes
โ”‚   โ””โ”€โ”€ api.php               # API routes
โ”œโ”€โ”€ /config
โ”‚   โ””โ”€โ”€ config.lumi           # Framework config
โ”œโ”€โ”€ /database
โ”‚   โ””โ”€โ”€ /migrations           # Database migrations
โ””โ”€โ”€ /storage
    โ”œโ”€โ”€ /logs                 # Log files
    โ””โ”€โ”€ /cache                # Cache files

๐Ÿ”ง Configuration System

Luminous uses two configuration files:

.env - Environment Variables

Used for credentials and environment-specific values:

DB_HOST=localhost
DB_NAME=mydb
JWT_SECRET=secret

config.lumi - Framework Configuration

Used for framework settings (JSON format):

{
  "jwt": {
    "secret": "env:JWT_SECRET",
    "algo": "HS256",
    "expire": 3600
  }
}

Values prefixed with env: reference .env variables.

๐Ÿ›ฃ๏ธ Routing

Define routes in routes/api.php:

// Simple route
$router->get('/users', 'UserController@index');

// Route with parameter
$router->get('/users/{id}', 'UserController@show');

// Route with middleware
$router->post('/posts', 'PostController@store', [AuthMiddleware::class]);

// Route group
$router->group(['prefix' => '/api', 'middleware' => AuthMiddleware::class], function ($router) {
    $router->get('/profile', 'UserController@profile');
    $router->put('/profile', 'UserController@update');
});

๐ŸŽฎ Controllers

Create controller using CLI or manually:

<?php

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Request;
use App\Core\Response;

class UserController extends Controller
{
    public function index(Request $request, Response $response): void
    {
        $response->success(['users' => []]);
    }

    public function show(Request $request, Response $response, array $params): void
    {
        $id = $params['id'];
        $response->success(['id' => $id, 'name' => 'John Doe']);
    }
}

๐Ÿ’พ Models & Database

Create model using CLI:

php lumi make:model User

Use the model:

use App\Models\User;

// Get all users
$users = User::all();

// Find by ID
$user = User::find(1);

// Find by condition
$user = User::firstWhere('email', 'user@example.com');

// Create
User::create([
    'name' => 'John Doe',
    'email' => 'john@example.com'
]);

// Update
User::update(1, ['name' => 'Jane Doe']);

// Delete
User::delete(1);

๐Ÿ”’ Authentication

Luminous includes JWT authentication:

Generate Token

use App\Core\JWT;

$token = JWT::generate([
    'user_id' => 1,
    'email' => 'user@example.com'
]);

Verify Token

$payload = JWT::verify($token);
if ($payload) {
    // Token is valid
}

Protected Routes

use App\Middlewares\AuthMiddleware;

$router->get('/profile', 'UserController@profile', [AuthMiddleware::class]);

๐Ÿ“ฆ Database Migrations

Create migration:

php lumi make:migration create_users_table

Edit migration file in database/migrations/:

public function up(): void
{
    $sql = "
        CREATE TABLE IF NOT EXISTS users (
            id INTEGER PRIMARY KEY AUTO_INCREMENT,
            name VARCHAR(255) NOT NULL,
            email VARCHAR(255) NOT NULL UNIQUE,
            password VARCHAR(255) NOT NULL,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        )
    ";
    Database::query($sql);
}

Run migrations:

php lumi migrate

๐ŸŒ Deploying to Shared Hosting

1. Upload Files

Upload all files to your hosting via FTP/cPanel File Manager.

2. Set Document Root

Point your domain to the root directory (where index.php is located).

3. Create .htaccess

Create .htaccess in root:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

4. Set Permissions

chmod -R 755 storage/
chmod 644 .env

5. Configure .env

Update database credentials in .env for your hosting environment.

๐Ÿ“ API Response Format

All API responses follow this format:

Success Response

{
  "status": "success",
  "message": "Operation successful",
  "data": {
    "id": 1,
    "name": "Item"
  }
}

Error Response

{
  "status": "error",
  "message": "Validation failed",
  "errors": {
    "email": ["Email is required"]
  }
}

๐Ÿ” Security Features

  • Password hashing with password_hash()
  • JWT token authentication
  • Request validation
  • SQL injection prevention (PDO prepared statements)
  • CORS middleware

๐Ÿ“š Helpers

Hash Helper

use App\Helpers\Hash;

$hashed = Hash::make('password123');
$verified = Hash::verify('password123', $hashed);

String Helper

use App\Helpers\Str;

$random = Str::random(16);
$slug = Str::slug('Hello World'); // hello-world

๐Ÿงช Example Application Flow

  1. Request hits index.php
  2. Environment & config loaded
  3. Router matches the request to a route
  4. Middleware executed (if any)
  5. Controller method called
  6. Response sent as JSON

๐Ÿ“– Documentation

For more detailed documentation, please visit the /docs folder or check individual class files.

๐Ÿค Contributing

Contributions are welcome! Feel free to submit pull requests or open issues.

๐Ÿ“„ License

This framework is open-sourced software licensed under the MIT license.

๐Ÿ™ Credits

Built with โค๏ธ using:

Luminous Framework - Build APIs the simple way! โœจ