Skip to content

NAF overview

NAF is a PHP microframework for HTTP applications and services. The core provides routing, controller dispatch, a dependency injection container, configuration, events, logging and error handling. Optional Composer packages add templates, forms, authentication, persistence and background jobs.

Application code uses ordinary PHP classes and explicitly imported helper functions. Route handlers return PSR-7 responses; controllers receive services through their constructors. No base controller or application-wide ORM is required.

For individual topics, start with Routing, Controllers, Views and templates, Forms and validation or Dependency injection. The navigation lists the full set of chapters.

A first route

app/routes.php
<?php

use function Naf\{json, route};

route()->add('GET', '/hello/{name}', function (string $name) {
    return json(['hello' => $name]);
}, 'hello');
curl http://127.0.0.1:8000/hello/Ada
{
    "hello": "Ada"
}

The placeholder {name} reaches the closure's $name argument, and json() returns a PSR-7 response with Content-Type: application/json; charset=UTF-8. Your first application builds this endpoint and an HTML page step by step.

Choose a starting point

You need PHP 8.3 or newer and Composer. Individual packages require additional extensions; the installation guide and package chapters name them.

  • Install the starter


    Create a project with a working welcome page, templates and forms.

    Installation

  • Build your first application


    An HTML page and a JSON endpoint, with every file and the expected results.

    Your first application

  • Pick a scenario


    Small website, JSON APIs, contact form or login: complete, tested examples.

    Application scenarios

  • Choose packages


    Find the optional package for templates, persistence, identity or jobs.

    Choosing packages

  • HTTP service without templates


    Start from the core alone for webhooks and JSON services.

    Core-only installation

  • Look something up


    Function signatures, published packages and their versions.

    Function index

If this is your first time using NAF, install the starter and follow Your first application. You can learn the core concepts as you use them; there is no need to read every reference chapter first.

Target audience

The documentation assumes familiarity with PHP classes, namespaces, Composer and basic HTTP. It explains NAF conventions as they are introduced. Start with the first application before using reference fragments, which assume an application is already bootstrapped. The small website and JSON API tutorials also provide complete setup in their own directories.

Core features

Capability Responsibility Guide
Routing and controllers Match method/path pairs and invoke handlers Routing, Controllers
HTTP messages Read requests and create responses Requests and responses
Services Construct dependencies and share registered instances Dependency injection
Configuration Load environment values and merge arrays Configuration
Events and errors Observe execution and customize failure responses Events, Errors
Plugins Discover installed packages and load their resources Plugins

The core uses PSR-7 messages, a PSR-11 container and PSR-3 logging. The optional naf/client implements PSR-18. Application lifecycle explains boot and request handling.

Design principles

NAF keeps application structure and optional capabilities separate from the HTTP core. Install the packages needed for the application, configure their services and keep business rules in application classes. Extend behavior through the container, events and plugin interfaces rather than copying framework internals.

Your application defines validation rules, access policies, schemas, tests and deployment settings. The worked examples show these responsibilities together.