axionphp/framework

AxionPHP - A Lightweight PHP Micro Framework with JWT API Support

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:project

pkg:composer/axionphp/framework

dev-main 2025-08-07 04:54 UTC

This package is not auto-updated.

Last update: 2026-02-23 10:19:12 UTC


README

PHP Version License Framework

AxionPHP is a lightweight, high-performance PHP micro-framework built using Symfony Components and powered by Laravel's Eloquent ORM. Inspired by Express.js and designed for modern API development, AxionPHP is fully customizable and extensible โ€” making it perfect for building RESTful APIs and web applications.

๐ŸŽฏ Key Features

โš™๏ธ Core Architecture

  • Symfony Components: Built on Symfony Routing, HTTP Foundation, Dotenv, and Event Dispatcher
  • PSR-4 Compliant: Fully Composer-based with PSR-4 autoloading
  • Modular Structure: Clean, modular, and scalable architecture

๐Ÿง  Developer Experience

  • Environment Configuration: .env based configuration for different environments
  • Debug Mode: Developer-friendly error handling with detailed stack traces
  • Simple Structure: Easy to understand and extend

๐Ÿ”„ Routing & Middleware

  • RESTful Routing: Symfony Router-based routing system
  • Middleware Pipeline: Request/response lifecycle management
  • Route Grouping: Support for route prefixes and middleware groups
  • Resource Routes: Automatic CRUD route generation

๐Ÿ›ข๏ธ ORM & Database

  • Laravel Eloquent: Elegant database interaction with Eloquent ORM
  • Multiple Databases: Support for MySQL, SQLite, PostgreSQL
  • Laravel-like Migrations: Full migration system with CLI commands
  • Schema Builder: Powerful database schema management

๐Ÿ” JWT Authentication

  • Built-in JWT: Complete JWT implementation using firebase/php-jwt
  • Secure Endpoints: Login, logout, profile, and refresh token endpoints
  • Middleware Protection: JWT middleware for protected routes
  • Token Management: Token verification, expiration, and refresh handling

๐Ÿ“ฆ API-Ready

  • JSON Responses: Consistent JSON API response format
  • Status Codes: Proper HTTP status code handling
  • CORS Support: Built-in CORS headers for API consumption

๐Ÿš€ Quick Start

Installation

  1. Clone or create your project:
git clone <your-repo> axionphp-app
cd axionphp-app
  1. Install dependencies:
composer install
  1. Configure environment:
cp .env .env.local
# Edit .env.local with your database credentials
  1. Start development server:
# Using AxionPHP CLI (recommended)
php axion start
# or
php axion start:dev

# Using Composer scripts
composer start
# or
composer serve

# Manual PHP server
php -S localhost:8000 -t public

Basic Usage

1. Define Routes

// routes/web.php
$router = app()->getRouter();

$router->get('/', 'App\Controllers\HomeController::index');
$router->post('/users', 'App\Controllers\UserController::store');

2. Create Controllers

// app/Controllers/UserController.php
<?php
namespace App\Controllers;

class UserController extends BaseController
{
    public function index()
    {
        return $this->success(['users' => User::all()]);
    }
}

3. Use Models

// app/Models/Post.php
<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $fillable = ['title', 'content', 'user_id'];
}

๐Ÿ“š API Documentation

Authentication Endpoints

Register User

POST /api/auth/register
Content-Type: application/json

{
    "name": "John Doe",
    "email": "john@example.com",
    "password": "password123"
}

Login User

POST /api/auth/login
Content-Type: application/json

{
    "email": "john@example.com",
    "password": "password123"
}

Get Profile (Protected)

GET /api/auth/profile
Authorization: Bearer <jwt-token>

Refresh Token

POST /api/auth/refresh
Authorization: Bearer <jwt-token>

Response Format

{
    "success": true,
    "message": "Success message",
    "data": {
        // Response data
    }
}

๐Ÿ—๏ธ Project Structure

axionphp/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ Controllers/          # Application controllers
โ”‚   โ”‚   โ”œโ”€โ”€ BaseController.php
โ”‚   โ”‚   โ”œโ”€โ”€ AuthController.php
โ”‚   โ”‚   โ””โ”€โ”€ HomeController.php
โ”‚   โ”œโ”€โ”€ Models/              # Eloquent models
โ”‚   โ”‚   โ””โ”€โ”€ User.php
โ”‚   โ””โ”€โ”€ Middleware/          # Custom middleware
โ”œโ”€โ”€ bootstrap/               # Framework bootstrap
โ”‚   โ”œโ”€โ”€ app.php             # Application setup
โ”‚   โ””โ”€โ”€ database.php        # Database configuration
โ”œโ”€โ”€ core/                   # Framework core
โ”‚   โ”œโ”€โ”€ Router.php          # Routing system
โ”‚   โ”œโ”€โ”€ JwtHelper.php       # JWT utilities
โ”‚   โ””โ”€โ”€ JwtMiddleware.php   # JWT middleware
โ”œโ”€โ”€ routes/                 # Route definitions
โ”‚   โ”œโ”€โ”€ web.php            # Web routes
โ”‚   โ””โ”€โ”€ api.php            # API routes
โ”œโ”€โ”€ public/                # Public directory
โ”‚   โ””โ”€โ”€ index.php          # Entry point
โ”œโ”€โ”€ .env                   # Environment configuration
โ”œโ”€โ”€ composer.json          # Dependencies
โ””โ”€โ”€ README.md             # Documentation

๐Ÿ”ง Configuration

Environment Variables

# Application
APP_NAME=AxionPHP
APP_ENV=development
APP_DEBUG=true
APP_URL=http://localhost:8000

# Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=axionphp
DB_USERNAME=root
DB_PASSWORD=

# JWT
JWT_SECRET=your-super-secret-jwt-key
JWT_ALGORITHM=HS256
JWT_EXPIRATION=3600

๐Ÿ—„๏ธ Database Migrations

AxionPHP includes a powerful Laravel-like migration system for managing your database schema.

Creating Migrations

# Create a new table migration
php axion make:migration create_users_table --create=users

# Create a table modification migration
php axion make:migration add_avatar_to_users_table --table=users

# Create a blank migration
php axion make:migration update_user_permissions

Running Migrations

# Run all pending migrations
php axion migrate

# Check migration status
php axion migrate:status

# Rollback the last batch of migrations
php axion migrate:rollback

# Rollback multiple batches
php axion migrate:rollback --step=3

Migration Examples

Creating a Table

<?php

use Core\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateUsersTable extends Migration
{
    public function up(): void
    {
        $this->schema->create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->timestamps();
        });
    }

    public function down(): void
    {
        $this->schema->dropIfExists('users');
    }
}

Modifying a Table

<?php

use Core\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;

class AddAvatarToUsersTable extends Migration
{
    public function up(): void
    {
        $this->schema->table('users', function (Blueprint $table) {
            $table->string('avatar')->nullable()->after('email');
            $table->text('bio')->nullable();
        });
    }

    public function down(): void
    {
        $this->schema->table('users', function (Blueprint $table) {
            $table->dropColumn(['avatar', 'bio']);
        });
    }
}

Available Schema Methods

The migration system supports all Laravel schema builder methods:

  • Column Types: string(), text(), integer(), bigInteger(), boolean(), date(), datetime(), timestamp(), json(), etc.
  • Column Modifiers: nullable(), default(), unique(), index(), after(), first(), etc.
  • Foreign Keys: foreignId(), constrained(), onDelete(), onUpdate()
  • Indexes: index(), unique(), primary(), foreign()

Composer Scripts

You can also use Composer scripts for convenience:

# Server commands
composer start                # Start development server
composer start:dev            # Start development server (alias)
composer serve                # Start server (legacy)

# Migration commands
composer migrate              # Run migrations
composer migrate:rollback     # Rollback migrations
composer migrate:status       # Check migration status
composer make:migration       # Create new migration (requires name argument)

๐Ÿงช Testing

Run the built-in development server:

composer serve

Test the API endpoints:

# Test framework info
curl http://localhost:8000/

# Test health check
curl http://localhost:8000/health

# Test user registration (demo - in-memory)
curl -X POST http://localhost:8000/api/demo/register \
  -H "Content-Type: application/json" \
  -d '{"name":"Test User","email":"test@example.com","password":"password123"}'

๐Ÿ“ License

This project is licensed under the MIT License.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“ž Support

For support and questions, please open an issue on GitHub.

AxionPHP - Built with โค๏ธ for modern PHP development