DEV Community

Cover image for MonkeysLegion: Ship Production-Ready PHP in Minutes, Not Days πŸš€
Jorge Peraza
Jorge Peraza

Posted on

MonkeysLegion: Ship Production-Ready PHP in Minutes, Not Days πŸš€

TL;DR: MonkeysLegion is a lightweight, modular PHP framework that bundles everything you needβ€”blazing-fast router, DI container, CLI tools, and zero-config Dockerβ€”so you can focus on features instead of plumbing. It's MIT-licensed, open-source, and we're looking for collaborators!


Why Another PHP Framework?

Let's be honest: setting up a new PHP project can feel like assembling IKEA furniture without instructions. You need routing, dependency injection, database migrations, authentication, validation, caching... and by the time you've wired it all together, you've lost the motivation to build the actual thing.

MonkeysLegion changes that.

We built it because we were tired of the boilerplate. We wanted something that's:

  • ⚑ Fast to start β€” One composer command, and you're coding
  • 🧩 Modular β€” Use only what you need
  • πŸ”’ Production-ready β€” Built-in auth, validation, caching, and observability
  • πŸ“– Well-documented β€” Because code without docs is just legacy waiting to happen

Get Started in 60 Seconds

composer create-project monkeyscloud/monkeyslegion-skeleton my-app
cd my-app
cp .env.example .env
php ml key:generate
composer serve
Enter fullscreen mode Exit fullscreen mode

Open http://127.0.0.1:8000 β€” you're live. πŸŽ‰

What's in the Box?

MonkeysLegion isn't just another micro-framework. It's a complete ecosystem:

Category What You Get
HTTP Stack PSR-7/15 compliant, middleware pipeline
Routing Attribute-based, auto-discovery, caching
Database Query Builder, Micro-ORM, Migrations
Auth JWT, RBAC, 2FA, OAuth, API Keys
Validation DTO binding with attribute constraints
Caching File, Redis, Memcached drivers
CLI Migrations, scaffolding, Tinker REPL
Telemetry Prometheus metrics, distributed tracing

Code That Speaks for Itself

Attribute-Based Routing

No more giant route files. Define routes right where they belong:

use MonkeysLegion\Router\Attributes\Route;
use MonkeysLegion\Router\Attributes\RoutePrefix;
use MonkeysLegion\Router\Attributes\Middleware;

#[RoutePrefix('/api/users')]
#[Middleware(['cors', 'throttle'])]
class UserController
{
    #[Route('GET', '/', name: 'users.index')]
    public function index(): Response
    {
        return $this->json(User::all());
    }

    #[Route('GET', '/{id:\d+}', name: 'users.show')]
    public function show(string $id): Response
    {
        return $this->json(User::find($id));
    }

    #[Route('POST', '/', name: 'users.create')]
    #[Middleware('auth')]
    public function create(CreateUserRequest $request): Response
    {
        // Validated DTO is automatically injected
        $user = User::create($request->validated());
        return $this->json($user, 201);
    }
}
Enter fullscreen mode Exit fullscreen mode

Validation with DTOs

Type-safe request validation using PHP attributes:

use MonkeysLegion\Validation\Attributes as Assert;

final readonly class CreateUserRequest
{
    public function __construct(
        #[Assert\NotBlank]
        #[Assert\Email]
        public string $email,

        #[Assert\NotBlank]
        #[Assert\Length(min: 8, max: 64)]
        public string $password,

        #[Assert\Url]
        public ?string $website = null,
    ) {}
}
Enter fullscreen mode Exit fullscreen mode

Invalid requests automatically return structured errors:

{
  "errors": [
    { "field": "email", "message": "Value must be a valid e-mail." },
    { "field": "password", "message": "Minimum length is 8 characters." }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Fluent Query Builder

Write readable database queries without raw SQL:

$users = $qb->from('users')
    ->leftJoin('profiles', 'p', 'p.user_id', '=', 'users.id')
    ->select(['users.*', 'p.avatar'])
    ->where('status', '=', 'active')
    ->whereIn('role', ['admin', 'editor'])
    ->orderBy('created_at', 'DESC')
    ->paginate(page: 1, perPage: 20);
Enter fullscreen mode Exit fullscreen mode

Built-in Authentication

JWT auth with 2FA support, ready to use:

$result = $auth->login($email, $password, $request->ip());

if ($result->requires2FA) {
    return response()->json([
        'requires_2fa' => true,
        'challenge' => $result->challengeToken,
    ]);
}

return response()->json([
    'access_token' => $result->tokens->accessToken,
    'refresh_token' => $result->tokens->refreshToken,
]);
Enter fullscreen mode Exit fullscreen mode

Powerful CLI Tools

Scaffold your app without leaving the terminal:

php ml make:entity User          # Generate Entity
php ml make:controller User      # Generate Controller
php ml make:migration            # Generate migration from entity diff
php ml migrate                   # Run migrations
php ml tinker                    # Interactive REPL
php ml openapi:export            # Export OpenAPI spec
Enter fullscreen mode Exit fullscreen mode

The Package Ecosystem

MonkeysLegion is built as independent packages. Use the full stack or pick what you need:

  • monkeyslegion-core β€” Kernel, events, helpers
  • monkeyslegion-router β€” Full-featured routing
  • monkeyslegion-auth β€” JWT, RBAC, 2FA, OAuth
  • monkeyslegion-query β€” Query Builder & ORM
  • monkeyslegion-cache β€” PSR-16 multi-driver cache
  • monkeyslegion-files β€” File storage, chunked uploads, S3
  • monkeyslegion-mail β€” SMTP, templates, DKIM, queues
  • monkeyslegion-i18n β€” Internationalization
  • monkeyslegion-telemetry β€” Metrics & tracing
  • monkeyslegion-validation β€” DTO validation
  • monkeyslegion-template β€” MLView templating engine

Requirements

  • PHP 8.4+
  • MySQL 8.4 (recommended)
  • Composer 2.x

We Need You! 🀝

MonkeysLegion is open-source and MIT-licensed. We're actively looking for collaborators who want to:

  • πŸ› Report bugs and suggest features
  • πŸ“ Improve documentation
  • πŸ§ͺ Write tests
  • πŸ’‘ Build new packages
  • 🌍 Help with translations

No contribution is too small. Whether it's fixing a typo or implementing a new feature, we'd love to have you on board.

Join Our Community

We've set up a Slack workspace where you can:

  • Ask questions and get help
  • Discuss features and architecture
  • Share what you're building
  • Connect with other developers

πŸ‘‰ Join MonkeysLegion on Slack

Resources

Get Started Now

composer create-project monkeyscloud/monkeyslegion-skeleton my-app
Enter fullscreen mode Exit fullscreen mode

Give it a ⭐ on GitHub if you like what you see!


Built with πŸ’š by developers who believe PHP deserves better tooling.


What do you think? Have you tried MonkeysLegion? What features would you like to see? Drop a comment below or join us on Slack! πŸ‘‡

Top comments (0)