nanophp/framework

The core framework for NanoPHP

Installs: 0

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/nanophp/framework

dev-main 2026-02-03 15:28 UTC

This package is auto-updated.

Last update: 2026-02-03 15:31:27 UTC


README

NanoPHP Logo

NanoPHP Framework Core

The powerful engine behind NanoPHP applications

License PHP Version

๐Ÿ“ฆ About

This is the core framework package for NanoPHP. It provides the foundational components that power NanoPHP applications, including:

  • Routing Engine - Fast route matching with FastRoute
  • Dependency Injection - Powerful DI container with PHP-DI
  • Middleware Pipeline - PSR-15 compliant middleware processing
  • View Engine - Blade template compilation and rendering
  • Authentication System - Session-based authentication with guards
  • Database Integration - Eloquent ORM and query builder
  • Validation - Comprehensive request validation
  • Console Commands - 50+ built-in Artisan commands
  • Logging - Monolog-based logging system
  • Facades - Laravel-style static proxies

๐Ÿ—๏ธ Architecture

Core Components

framework/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ Application.php          # Application kernel
โ”‚   โ”œโ”€โ”€ Router.php               # Route management
โ”‚   โ”œโ”€โ”€ Facade.php               # Facade base class
โ”‚   โ”œโ”€โ”€ View.php                 # View rendering
โ”‚   โ”œโ”€โ”€ Auth.php                 # Authentication
โ”‚   โ”œโ”€โ”€ Database.php             # Database bootstrapping
โ”‚   โ”œโ”€โ”€ LogManager.php           # Logging
โ”‚   โ”œโ”€โ”€ AI.php                   # AI integration
โ”‚   โ”œโ”€โ”€ Auth/                    # Auth components
โ”‚   โ”‚   โ”œโ”€โ”€ SessionGuard.php
โ”‚   โ”‚   โ””โ”€โ”€ Gate.php
โ”‚   โ”œโ”€โ”€ Console/                 # Artisan commands
โ”‚   โ”‚   โ”œโ”€โ”€ Commands/
โ”‚   โ”‚   โ””โ”€โ”€ Kernel.php
โ”‚   โ”œโ”€โ”€ Facades/                 # Static facades
โ”‚   โ”‚   โ”œโ”€โ”€ Route.php
โ”‚   โ”‚   โ”œโ”€โ”€ View.php
โ”‚   โ”‚   โ””โ”€โ”€ Auth.php
โ”‚   โ”œโ”€โ”€ Middleware/              # Core middleware
โ”‚   โ”‚   โ”œโ”€โ”€ CsrfMiddleware.php
โ”‚   โ”‚   โ”œโ”€โ”€ TrimStrings.php
โ”‚   โ”‚   โ””โ”€โ”€ SecurityHeadersMiddleware.php
โ”‚   โ”œโ”€โ”€ Http/                    # HTTP components
โ”‚   โ”‚   โ””โ”€โ”€ Request.php
โ”‚   โ”œโ”€โ”€ Filesystem/              # Storage management
โ”‚   โ”œโ”€โ”€ Cache/                   # Caching system
โ”‚   โ”œโ”€โ”€ CoreDefinitions.php      # DI definitions
โ”‚   โ””โ”€โ”€ helpers.php              # Global helpers
โ””โ”€โ”€ composer.json

๐Ÿ”ง Installation

This package is automatically installed when you create a NanoPHP application:

composer create-project nanophp/nanophp my-project --stability=dev

Or add it to an existing project:

composer require nanophp/framework:dev-main

๐ŸŽฏ Key Features

1. Powerful Routing

use Nano\Framework\Facades\Route;

Route::get('/users/{id}', 'UserController@show');
Route::post('/users', 'UserController@store')->middleware('auth');

2. Dependency Injection

// Automatic constructor injection
class UserController
{
    public function __construct(
        private UserRepository $users,
        private Logger $log
    ) {}
}

3. Blade Templates

@extends('layouts.app')

@section('content')
    <h1>{{ $title }}</h1>
    @foreach($users as $user)
        <p>{{ $user->name }}</p>
    @endforeach
@endsection

4. Eloquent ORM

// Elegant database queries
$users = User::where('active', true)
    ->with('posts')
    ->orderBy('created_at', 'desc')
    ->get();

5. Authentication

use Nano\Framework\Facades\Auth;

// Login
Auth::attempt($credentials);

// Check authentication
if (Auth::check()) {
    $user = Auth::user();
}

// Logout
Auth::logout();

๐Ÿ› ๏ธ Console Commands

The framework provides 50+ Artisan commands:

Generators

  • make:controller - Create a new controller
  • make:model - Create a new model
  • make:middleware - Create middleware
  • make:migration - Create database migration
  • make:seeder - Create database seeder
  • make:auth - Scaffold authentication

Database

  • migrate - Run migrations
  • migrate:rollback - Rollback migrations
  • migrate:fresh - Drop all tables and re-run migrations
  • db:seed - Seed the database

Cache & Optimization

  • cache:clear - Clear application cache
  • view:clear - Clear compiled views
  • config:cache - Cache configuration

Development

  • serve - Start development server
  • tinker - Interactive REPL

๐Ÿ”Œ Integration with Illuminate

NanoPHP leverages battle-tested Laravel components:

  • illuminate/database - Eloquent ORM and Query Builder
  • illuminate/validation - Request validation
  • illuminate/view - Blade template engine
  • illuminate/filesystem - File operations
  • illuminate/translation - Localization
  • illuminate/events - Event dispatcher

๐Ÿ“š Helper Functions

The framework provides Laravel-style global helpers:

// Views
view('welcome', ['name' => 'John']);

// Routing
route('user.profile', ['id' => 1]);

// JSON responses
json(['status' => 'success']);

// Environment
env('APP_ENV', 'production');

// Paths
base_path('config/app.php');
storage_path('logs/app.log');

// String helpers
str_slug('Hello World'); // hello-world
str_random(16);

// Array helpers
array_get($array, 'key.nested', 'default');

๐Ÿ›๏ธ Design Patterns

NanoPHP implements industry-standard patterns:

  • Dependency Injection - Loose coupling, testable code
  • Facade Pattern - Clean, expressive syntax
  • Repository Pattern - Data access abstraction
  • Middleware Pattern - Request/response filtering
  • Service Container - Automatic dependency resolution
  • PSR Standards - PSR-7, PSR-11, PSR-15 compliant

๐Ÿงช Testing

The framework is designed for testability:

use PHPUnit\Framework\TestCase;

class UserTest extends TestCase
{
    public function test_user_creation()
    {
        $user = User::create([
            'name' => 'John Doe',
            'email' => 'john@example.com'
        ]);

        $this->assertEquals('John Doe', $user->name);
    }
}

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

๐Ÿ“„ License

The NanoPHP Framework is open-sourced software licensed under the MIT license.

๐Ÿ™ Acknowledgments

Built with โค๏ธ for the PHP community