PHPackages                             melodicdev/framework - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. melodicdev/framework

ActiveLibrary[Framework](/categories/framework)

melodicdev/framework
====================

A modern PHP 8.2+ framework with CQRS, JWT authentication, and middleware pipeline

v1.7.4(1mo ago)044MITPHPPHP &gt;=8.2CI passing

Since Feb 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/MelodicDevelopment/melodic-php)[ Packagist](https://packagist.org/packages/melodicdev/framework)[ Docs](https://php.melodic.dev)[ RSS](/packages/melodicdev-framework/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (18)Used By (0)

Melodic PHP Framework
=====================

[](#melodic-php-framework)

A modern PHP 8.2+ framework with CQRS data patterns, JWT authentication, and a PSR-15-style middleware pipeline. Uses a layered architecture: **Controller → Service → Query/Command**.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Composer
- PDO extension (SQLite, MySQL, PostgreSQL, or any PDO driver)

Installation
------------

[](#installation)

```
composer install
```

Quick Start
-----------

[](#quick-start)

```
# Start the documentation website (runs on Melodic itself)
php -S localhost:8080 -t web/php.melodic.dev/public
```

Then visit:

- `http://localhost:8080/` — Landing page
- `http://localhost:8080/docs` — Framework documentation
- `http://localhost:8080/tutorials` — Step-by-step tutorials
- `http://localhost:8080/why-melodic` — Philosophy &amp; comparisons

Architecture
------------

[](#architecture)

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

```

The framework enforces a clean separation of concerns across layers:

LayerResponsibilityFramework NamespaceHTTPRequest/Response objects, middleware pipeline`Melodic\Http`RoutingURL pattern matching, route groups, API resources`Melodic\Routing`ControllerReceives requests, returns responses, delegates to services`Melodic\Controller`ServiceBusiness logic, orchestrates queries and commands`Melodic\Service`DataDatabase access via DbContext, CQRS query/command objects`Melodic\Data`SecurityJWT validation, authentication, authorization`Melodic\Security`DIDependency injection container with auto-wiring`Melodic\DI`ViewTemplate engine with layouts and sections`Melodic\View`CoreApplication bootstrap, configuration`Melodic\Core`Project Structure
-----------------

[](#project-structure)

```
melodic-php/
├── composer.json                            # PSR-4: Melodic\ → src/
├── src/
│   ├── Core/
│   │   ├── Application.php                  # App builder: config, middleware, routes, run()
│   │   └── Configuration.php                # JSON config loader with dot-notation access
│   ├── Http/
│   │   ├── HttpMethod.php                   # Enum: GET, POST, PUT, DELETE, PATCH, OPTIONS
│   │   ├── Request.php                      # Wraps superglobals, immutable attributes
│   │   ├── Response.php                     # Status code, headers, body, send()
│   │   ├── JsonResponse.php                 # JSON-encoded response
│   │   ├── Exception/
│   │   │   ├── HttpException.php            # Base HTTP exception with status code
│   │   │   ├── BadRequestException.php      # 400
│   │   │   ├── NotFoundException.php        # 404
│   │   │   └── MethodNotAllowedException.php # 405
│   │   └── Middleware/
│   │       ├── MiddlewareInterface.php       # process(Request, RequestHandler): Response
│   │       ├── RequestHandlerInterface.php
│   │       ├── Pipeline.php                 # Chains middleware to a final handler
│   │       ├── CorsMiddleware.php           # Configurable CORS headers
│   │       └── JsonBodyParserMiddleware.php
│   ├── Routing/
│   │   ├── Route.php                        # Method + URI pattern + controller/action
│   │   ├── Router.php                       # Registration, groups, apiResource()
│   │   └── RoutingMiddleware.php            # Resolves route, invokes controller via DI
│   ├── Controller/
│   │   ├── Controller.php                   # Abstract base with json(), created(), noContent(), etc.
│   │   ├── ApiController.php                # JSON API controller with getUserContext()
│   │   └── MvcController.php                # View rendering with layout/section support
│   ├── DI/
│   │   ├── ContainerInterface.php           # get(), has(), bind(), singleton()
│   │   ├── Container.php                    # Auto-wiring, singletons, interface bindings, factories
│   │   └── ServiceProvider.php              # Modular registration base class
│   ├── Data/
│   │   ├── DbContextInterface.php           # query(), queryFirst(), command(), scalar(), transaction()
│   │   ├── DbContext.php                    # PDO wrapper with model hydration via Reflection
│   │   ├── QueryInterface.php               # CQRS query: getSql(), execute()
│   │   ├── CommandInterface.php             # CQRS command: getSql(), execute() returns int
│   │   └── Model.php                        # Base DTO with fromArray() and toArray()
│   ├── Security/
│   │   ├── JwtValidator.php                 # Firebase JWT validation with issuer/audience checks
│   │   ├── User.php                         # User with id, username, email, entitlements
│   │   ├── UserContextInterface.php         # isAuthenticated(), getUser(), hasEntitlement()
│   │   ├── UserContext.php                  # Built from JWT claims
│   │   ├── AuthenticationMiddleware.php     # Bearer token extraction and validation
│   │   ├── AuthorizationMiddleware.php      # Entitlement-based access control
│   │   └── SecurityException.php
│   ├── Validation/
│   │   ├── Validator.php                    # Validates objects and arrays against attribute rules
│   │   ├── ValidationResult.php             # Structured result with isValid and errors
│   │   ├── ValidationException.php          # Throwable validation failure (maps to 422)
│   │   └── Rules/                           # Attribute rules
│   │       ├── Required.php
│   │       ├── Email.php
│   │       ├── MinLength.php, MaxLength.php
│   │       ├── Min.php, Max.php
│   │       ├── Pattern.php
│   │       └── In.php
│   ├── Error/
│   │   └── ExceptionHandler.php             # JSON/HTML error responses, debug mode, logging
│   ├── Event/
│   │   ├── EventDispatcherInterface.php     # listen() and dispatch()
│   │   ├── EventDispatcher.php              # Priority-based listener execution
│   │   ├── Event.php                        # Base event with stopPropagation()
│   │   └── EventServiceProvider.php
│   ├── Cache/
│   │   ├── CacheInterface.php               # PSR-16-style get/set/delete/has/clear
│   │   ├── FileCache.php                    # File-based with TTL expiration
│   │   ├── ArrayCache.php                   # In-memory for testing
│   │   └── CacheServiceProvider.php
│   ├── Session/
│   │   ├── SessionInterface.php             # start, get, set, has, remove, destroy, regenerate
│   │   ├── NativeSession.php                # Wraps PHP session functions
│   │   ├── ArraySession.php                 # In-memory for testing
│   │   └── SessionServiceProvider.php
│   ├── Log/
│   │   ├── LoggerInterface.php              # Standard log level methods
│   │   ├── LogLevel.php                     # Enum: emergency through debug
│   │   ├── FileLogger.php                   # Daily rotating log files with interpolation
│   │   ├── NullLogger.php                   # No-op for testing
│   │   └── LoggingServiceProvider.php
│   ├── Console/
│   │   ├── CommandInterface.php             # getName(), getDescription(), execute()
│   │   ├── Command.php                      # Base class with output helpers
│   │   ├── Console.php                      # Command runner with help output
│   │   ├── RouteListCommand.php             # Lists registered routes
│   │   └── CacheClearCommand.php            # Clears application cache
│   ├── Service/
│   │   └── Service.php                      # Base service holding DbContext references
│   └── View/
│       ├── ViewEngine.php                   # Renders .phtml templates with layouts/sections/caching
│       └── ViewBag.php                      # Dynamic key-value store for view data
└── web/php.melodic.dev/                     # Documentation website (dogfoods the framework)
    ├── config/config.json
    ├── public/
    │   ├── index.php                    # Entry point
    │   ├── .htaccess                    # Apache rewrite rules
    │   ├── css/site.css                 # Extracted styles
    │   └── js/site.js                   # Copy-to-clipboard, mobile nav
    ├── src/
    │   ├── Controllers/
    │   │   ├── HomeController.php       # Landing page, Why Melodic
    │   │   ├── DocsController.php       # 18 documentation pages
    │   │   └── TutorialController.php   # 5 tutorial walkthroughs
    │   └── Middleware/
    │       └── RequestTimingMiddleware.php
    └── views/
        ├── layouts/
        │   ├── marketing.phtml          # Full-width layout
        │   └── docs.phtml               # Sidebar + content layout
        ├── partials/
        │   ├── nav.phtml                # Shared navigation
        │   ├── footer.phtml             # Shared footer
        │   └── doc-sidebar.phtml        # Grouped sidebar
        ├── pages/                       # Marketing pages
        ├── docs/                        # 18 documentation pages
        └── tutorials/                   # 5 tutorial pages

```

Application Bootstrap
---------------------

[](#application-bootstrap)

Create an entry point (`public/index.php`) that configures and runs the app:

```
