open-genetics/framework

Enterprise PHP Micro-Framework โ€” JWT Auth, Genetic RBAC, Query Builder, i18n, Audit Trail, Testing Framework, and Dual-Frontend SDK

Maintainers

Package info

github.com/jkstudio99/open-genetics

Homepage

Issues

Documentation

Type:project

pkg:composer/open-genetics/framework

Statistics

Installs: 36

Dependents: 0

Suggesters: 0

Stars: 1

v2.3.0 2026-02-24 13:47 UTC

This package is auto-updated.

Last update: 2026-03-24 14:48:53 UTC


README

OpenGenetics Logo

OpenGenetics Framework

Enterprise PHP Micro-Framework v2.2 โ€” Production-ready features built-in. No config bloat. Just PHP.

License: MIT PHP 8.1+ MySQL v2.3.0

โœจ What's New in v2.3

Feature Description
๐Ÿ—ƒ๏ธ Query Builder DB::table('users')->where('active',1)->paginate(20) โ€” fluent builder on PDO with prepared statements
โœ… Guard::check() Soft auth check โ€” returns bool instead of throwing, perfect for optional-auth endpoints
๐Ÿท๏ธ Cache::namespace() Isolate cache key spaces between modules โ€” Cache::namespace('shop')->get('products')
๐Ÿงช Testing: seed() $this->seed(['users' => [...]]) โ€” seed test data within transaction rollback
โฉ Pipeline::after() Post-response hooks for async side effects like audit logging
๐Ÿšซ #[SkipMiddleware] #[SkipMiddleware(CorsMiddleware::class)] โ€” exclude routes from global middleware
๐Ÿ“ LogMiddleware Built-in request/response logging middleware
๐Ÿ”Œ ErrorHandler::reporter() ErrorHandler::reporter(callable) โ€” hook for Sentry/Bugsnag integration

โœจ What's in v2.0

# Feature Description
1 โšก๏ธ Middleware Pipeline #[Middleware('auth', 'rate:10,60')] declarative middleware with Chain of Responsibility
2 ๐Ÿ—„๏ธ DB Migrations Versioned, batch-rollback migrations with migrate, migrate:rollback, migrate:status
3 ๐Ÿงช Testing Framework GeneticTestCase with HTTP client, actingAsAdmin(), assertOk(), assertPaginated()
4 ๐Ÿš€ Caching Layer File-based Cache::remember(), tag-based flush, zero dependencies
5 ๐Ÿ” Field Selector ?fields=id,name,price sparse fieldsets โ€” GraphQL-lite without the server
6 ๐Ÿ“ก Genetic Pulse Server-Sent Events real-time push โ€” no WebSocket server needed
7 ๐Ÿงฉ Genetic Modules GeneticModule plugin system with auto-discovery and lifecycle hooks
8 ๐Ÿ› ๏ธ Admin Generator make:admin <table> โ€” full CRUD admin endpoint from DB schema in seconds
9 ๐Ÿค– Endpoint AI make:endpoint-ai products "CRUD with auth and cache" โ€” NLP scaffold
10 ๐Ÿช Marketplace market:install og/notifications โ€” community packages in one command

Plus all v1.0 features: JWT Auth, RBAC, i18n, Audit Trail, Dual SDK, File-based Routing, CLI, OpenAPI

๐Ÿš€ Quick Start

# 1. Clone or create project
composer create-project open-genetics/framework my-api && cd my-api

# 2. Configure environment
cp .env.example .env
# Edit: DB_NAME, DB_USER, DB_PASS, JWT_SECRET

# 3. Bootstrap (tables + RBAC + admin user)
php genetics mutate

# 4. Start dev server
php genetics serve
# โ†’ http://127.0.0.1:8080

Default admin: admin@opengenetics.io / password (change immediately in production)

๐Ÿ’ป Building an API Endpoint

Drop a file in api/ โ€” it's instantly a route. No registration needed.

// api/products.php  โ†’  GET/POST /api/products

use OpenGenetics\Core\{Response, Cache};
use OpenGenetics\Core\DB;

#[\OpenGenetics\Core\Middleware('auth', 'rate:60,60')]
class Products
{
    public static function get(array $body): void
    {
        // Query Builder with caching
        $products = Cache::remember('products:all', 300, fn() =>
            DB::table('products')->where('active', 1)->paginate(20)
        );
        Response::success($products);
    }

    public static function post(array $body): void
    {
        // AI-assisted scaffold: php genetics make:endpoint-ai products "with auth and audit"
        Response::success(null, 'Created', 201);
    }
}

Or scaffold in seconds:

php genetics make:endpoint-ai products "CRUD with auth, search, pagination and cache"

๐Ÿ–ฅ๏ธ CLI โ€” 25+ Commands

Database:    mutate, seed, status, serve
Migrations:  migrate, migrate:rollback, migrate:status
Scaffold:    make:endpoint, make:middleware, make:migration,
             make:test, make:admin, make:endpoint-ai
Cache:       cache:clear, cache:stats, cache:gc
Marketplace: market:list, market:search, market:install
Modules:     modules:list
Docs:        docs:generate
Info:        help, --version, new

๐Ÿ—๏ธ Project Structure

my-api/
โ”œโ”€โ”€ api/                    # File-based routing (1 file = 1 endpoint)
โ”‚   โ””โ”€โ”€ auth/               # Auth routes (login, register, logout)
โ”œโ”€โ”€ src/Core/               # Framework core (PSR-4, PHP 8.1+)
โ”‚   โ”œโ”€โ”€ QueryBuilder.php    # Fluent Query Builder (v2.2)
โ”‚   โ”œโ”€โ”€ Cache.php           # Caching layer with namespace support (v2.2)
โ”‚   โ”œโ”€โ”€ FieldSelector.php   # GraphQL-lite sparse fieldsets
โ”‚   โ”œโ”€โ”€ Pulse.php           # Server-Sent Events
โ”‚   โ”œโ”€โ”€ ModuleLoader.php    # Plugin system
โ”‚   โ”œโ”€โ”€ AdminGenerator.php  # Admin endpoint scaffolder
โ”‚   โ”œโ”€โ”€ EndpointAI.php      # AI endpoint generator
โ”‚   โ”œโ”€โ”€ Marketplace.php     # Package registry
โ”‚   โ”œโ”€โ”€ Pipeline.php        # Middleware pipeline with Pipeline::after()
โ”‚   โ”œโ”€โ”€ Migrator.php        # DB migrations
โ”‚   โ”œโ”€โ”€ Database.php        # PDO Singleton
โ”‚   โ”œโ”€โ”€ Router.php          # File-based router
โ”‚   โ””โ”€โ”€ Response.php        # JSON response helpers
โ”œโ”€โ”€ src/Auth/               # JWT + Guard RBAC (Guard::check() v2.2)
โ”œโ”€โ”€ src/Testing/            # GeneticTestCase + TestResponse + seed()
โ”œโ”€โ”€ src/Middleware/         # Auth, CORS, RateLimit, LogMiddleware
โ”œโ”€โ”€ database/migrations/    # Versioned migration files
โ”œโ”€โ”€ modules/                # Genetic Modules (plugins)
โ”œโ”€โ”€ storage/cache/          # File cache store
โ”œโ”€โ”€ sdk/                    # Frontend SDK (React + Vanilla JS)
โ”œโ”€โ”€ locales/                # i18n dictionaries (en.json, th.json)
โ”œโ”€โ”€ genetics                # CLI tool
โ”œโ”€โ”€ public/                 # Web root (index.php)
โ””โ”€โ”€ .env                    # Environment config

๐Ÿ”ฅ Feature Highlights

Query Builder (v2.2)

$users = DB::table('users')
    ->select(['id', 'email', 'role_name'])
    ->where('is_active', 1)
    ->where('tenant_id', $tenantId)
    ->orderBy('created_at', 'DESC')
    ->paginate(20);

Middleware Pipeline

#[Middleware('auth:ADMIN', 'rate:10,60')]
class AdminProducts { ... }

Guard::check() โ€” Optional Auth (v2.2)

if (Guard::check()) {
    $user = Guard::user(); // personalized response
} else {
    // public response
}

Database Migrations

php genetics migrate            # Run pending
php genetics migrate:rollback   # Undo last batch
php genetics make:migration add_image_to_products

Testing Framework

class ProductsTest extends GeneticTestCase {
    public function testList(): void {
        $this->actingAsAdmin();
        $this->seed(['products' => [['name' => 'Test', 'active' => 1]]]);
        $this->get('/api/products')->assertOk()->assertPaginated();
    }
}

Field Selector (GraphQL-lite)

GET /api/products?fields=id,name,price,category.name

Real-time SSE

Pulse::broadcast('orders', ['id' => 123, 'status' => 'new']);
// Client: const es = new EventSource('/api/events');

Marketplace

php genetics market:search notifications
php genetics market:install og/notifications

๐Ÿ“š Documentation

Full documentation: open docs/site/overview.html or browse the 26-page docs site.

# Regenerate docs
cd docs/_tools && python3 _gen_pages.py

๐Ÿ›ก๏ธ Security

Report vulnerabilities to security@opengenetics.io โ€” do not use the issue tracker.

๐Ÿ“„ License

MIT License โ€” free and open-source. See LICENSE.