Melodic PHP Framework

A modern PHP 8.2+ framework with CQRS, JWT authentication, dependency injection, and a middleware pipeline. Built for clarity, not magic.

Architecture

Melodic follows a layered architecture where each request flows through a predictable chain:

HTTP Request → Middleware Pipeline → Router → Controller → Service → Query/Command → Database

Every layer has a single responsibility. Controllers handle HTTP concerns, services encapsulate business logic, and queries/commands own data access. There are no facades, no mediator buses, and no hidden magic — just explicit, traceable code.

Core Principles

  • PHP 8.2+ — enums, readonly properties, constructor promotion, match expressions, and named arguments throughout
  • CQRS data access — separate Query and Command objects executed through DbContext
  • Constructor injection — auto-wiring DI container resolves dependencies from type hints
  • PSR-15-style middleware — composable pipeline for cross-cutting concerns
  • Multi-provider auth — OIDC, OAuth2, and local username/password with JWT tokens
  • MVC + API — separate controller base classes for template-rendered views and JSON APIs
  • No hidden behavior — no facades, no service locators, no global state

Quick Start

composer require melodicdev/framework

# Create your entry point
mkdir -p public config
touch public/index.php config/config.json

Then bootstrap your application:

<?php
// public/index.php
require_once __DIR__ . '/../vendor/autoload.php';

use Melodic\Core\Application;

$app = new Application(dirname(__DIR__));
$app->loadEnvironmentConfig();

$app->routes(function ($router) {
    $router->get('/', MyController::class, 'index');
});

$app->run();

Documentation

Getting Started

Core

Data & Services

Infrastructure

Frontend

Security

Requirements

DependencyVersionPurpose
PHP8.2+Language runtime
PDO extensionanyDatabase access
firebase/php-jwt^7.0JWT encoding and decoding