NestJS + PHP = Lynx
Greetings, how are you? I hope your code and errors are plentiful. I'm back here after a long time. Let me briefly introduce myself. I'm a self-employed developer/entrepreneur who has been designing backend and system architecture with TS for 3-4 years. Everyone online knows me as Signor P. I'm here to announce that I've released my Lynx framework as open source, as I mentioned to you in the past. Lynx started as a hobby project, and then I asked myself, why not share it with other developers and develop it together? π
. Briefly, Lynx is a backend framework written in pure PHP with a NestJS architecture and syntax. It's a framework with a small CLI tool written in Rust and a database system with a small TypeORM syntax. Developers who want more technical details can check the Github repositories. So why did I write Lynx... I sometimes need to write PHP or want to write PHP. But huge frameworks like Laravel tire me out. Minimal and spacious frameworks are rare in the PHP world. As a TS developer myself, I thought, why not port a TS framework to PHP? And I decided that NestJS was the most suitable framework for this. I use Lynx myself in some hobby projects and prototypes. When I needed to write a manager for database operations, I thought, why not use the TypeORM syntax that I always use and that is compatible with NestJS? And although not exactly the same, I added a database layer in a similar TypeORM style. Entities, Repository usage, etc... Currently, Lynx works for small projects and some medium-sized projects. However, it's worth mentioning that I am not a security expert or professional software engineer. Yes, I have a few successful projects that I haven't published yet, but I should point out that I'm not that good at PHP. Let's take a brief look at the project architecture.
π your-project-root
βββ π App # πΎ LYNX CORE ENGINE (Zero dependencies, pure PHP)
β βββ π Builder # Fluent factories (e.g. ExceptionBuilder)
β βββ π Cache # Temporary runtime caching & logger.json storage
β βββ π Config # Framework system configuration
β βββ π Core # Kernel, Request, Response, Router, Autoloader, & Repositories
β βββ π Decorators # Core attributes (Module, Controller, Column, GET/POST, Inject, etc.)
β βββ π Exception # Built-in HTTP exceptions (BadRequest, NotFound, etc.)
β βββ π Helper # Console logs, secure encryption, tokenizers, & .env loaders
β βββ π Interface # LogLevels, Middleware, & ExceptionFilter contracts
β βββ π Templates # Default engine templates (e.g. default 404 page)
βββ π Src # ποΈ APPLICATION DOMAIN CODE (Write your code here)
β βββ π views # HTML template 'welcome' views & custom 404s
β βββ π AppController.php # Root application routes controller
β βββ π AppMiddleware.php # Root application middleware pipeline
β βββ π AppModule.php # Root AppModule configuration (orchestrates sub-modules)
βββ π .env # Environment Configuration (DB credentials, status, etc.)
βββ π .htaccess # Apache URL-rewriting configuration
βββ π index.php # Core application entrypoint (boots LynxApplication)
<?php
// index.php
require_once './App/Core/AutoLoader.php';
use App\Core\LynxApplication;
use Src\AppModule;
global $app;
$app = new LynxApplication(AppModule::class);
$app->run();
// Src/AppModule.php
<?php
namespace Src;
use App\Decorators\Module;
use Src\AppController;
#[Module([
'controllers' => [AppController::class]
])]
class AppModule {}
<?php
// Src/AppController.php
namespace Src;
use App\Core\Request;
use App\Core\Response;
use App\Decorators\Controller;
use App\Decorators\Get;
use App\Decorators\Post;
use App\Decorators\Middleware;
#[Controller()]
#[Middleware([AppMiddleware::class])]
class AppController
{
#[Get('/')]
public function get(Request $req, Response $res): void
{
$res->render('welcome', ['name' => 'Lynx']);
}
#[Post('/')]
public function logout(Request $req, Response $res): void
{
$res->json([
"framework" => "Lynx"
]);
}
}
<?php
// Src/AppMiddleware.php
namespace Src;
use App\Core\Request;
use App\Core\Response;
use App\Helper\Console;
use App\Interface\Middleware;
class AppMiddleware implements Middleware
{
public function use(Request $req, Response $res, mixed $next): void
{
Console::log('info', 'Run App Middleware');
$res->setHeader('X-Powered-By', 'Zexson Team');
$next($req, $res);
}
}
As you can see, you can develop PHP backend applications in the style of NestJS. I enjoy using Lynx and I like it very much. I hope this open-source project hasn't wasted your time. That's all for now. The necessary links are below. I eagerly await your feedback πΎ
π¦
Top comments (0)