open-genetics / framework
Enterprise PHP Micro-Framework โ JWT Auth, Genetic RBAC, Query Builder, i18n, Audit Trail, Testing Framework, and Dual-Frontend SDK
Requires
- php: >=8.1
- ext-json: *
- ext-mbstring: *
- ext-pdo: *
- firebase/php-jwt: ^7.0
Requires (Dev)
- phpunit/phpunit: ^10.0
README
OpenGenetics Framework
Enterprise PHP Micro-Framework v2.2 โ Production-ready features built-in. No config bloat. Just PHP.
โจ 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.