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
Getting Started
Install the framework, set up a project, and bootstrap your first application.
Configuration
JSON config files, dot-notation access, environment-specific overrides.
Core
Routing
Route registration, parameters, groups, API resources, and middleware.
Controllers
API and MVC controllers, response helpers, request data, and view rendering.
Middleware
Pipeline model, built-in middleware, custom middleware, and short-circuiting.
Dependency Injection
Auto-wiring container, interface binding, singletons, and service providers.
Data & Services
Data Access & CQRS
DbContext, queries, commands, model hydration, and transactions.
Services
Business logic layer, service interfaces, read/write separation.
Validation
Declarative validation rules, custom validators, and error formatting.
Infrastructure
Error Handling
Centralized exception handler, error responses, and debug mode.
Logging
PSR-3-style logger, file-based output, and configurable log levels.
Events
Event dispatcher, listeners, and decoupled event-driven architecture.
Caching
Cache interface, file-based caching, and TTL-based expiration.
Sessions
Session management, flash messages, and session-backed state.
Console
CLI commands, task runners, and artisan-style console tools.
Frontend
Security
Security & Authentication
JWT authentication, OIDC/OAuth2/local providers, and authorization middleware.
Refresh Tokens
Secure token rotation with family-based reuse detection for long-lived sessions.
Requirements
| Dependency | Version | Purpose |
|---|---|---|
| PHP | 8.2+ | Language runtime |
| PDO extension | any | Database access |
| firebase/php-jwt | ^7.0 | JWT encoding and decoding |