Zero Framework
Zero routing. Zero configuration. Zero bloat. The framework stays out of your way so you can write your application.
Create a PHP class in modules/, give it a method, and it's an endpoint. That's it.
Installation
A site is a folder with core at core/. One script lays out everything around it:
git init mysite && cd mysite git submodule add git@github.com:rmvanda/zero.core core git submodule update --init --recursive # core's own entity/ submodule core/skeleton/zero-init.sh mysite.com # no composer install. no npm install. no bundler. no build.
core/skeleton/zero-init.sh clones nothing, needs no root, and never overwrites a file that exists. It builds app/, an empty modules/ and entity/, storage/cache/ and etc/ around the clone. Getting Started walks through it and what to do next.
The core/ directory of this site is that repository plus one local addition — a #[PageMeta] attribute, with its design note, that is not upstream yet. Every tracked file is the repository as published, so “read the source” is a literal invitation rather than a slogan. The bootstrap finds everything by path, so the shape of the directory is the configuration:
That bootstrap is the whole of the framework's setup. It is core/skeleton/frontend/www/index.php, reproduced here in full, because there is no more of it to show:
<?php
// Zero Framework Bootstrap
// ZERO_ROOT is the folder three levels above www/ (app/frontend/www inside the
// zero root), whatever the site folder is called.
define("ZERO_ROOT", dirname(__DIR__, 3) . "/");
define("ROOT_PATH", dirname(ZERO_ROOT) . "/");
define("VIEW_PATH", ZERO_ROOT . "app/frontend/frame/");
define("MODULE_PATH", ZERO_ROOT . "modules/");
require ZERO_ROOT . "core/Application.php";
$app = new Zero\Core\Application();
$app->registerAutoloaders();
$app->parseRequest();
$app->defineConstants();
$app->run(
\Zero\Core\Request::$module,
\Zero\Core\Request::$endpoint,
\Zero\Core\Request::$args
);
Four constants and four calls. Note the order: parseRequest() runs before defineConstants(), which is what lets a module carry its own config.ini — those constants are defined only on requests routed to that module, and they are defined before the module class is loaded.
WEB_ROOT must be set in app/config/config.ini, and the web server must be able to write its assets/ folder. It is the directory a module symlinks its own assets/ into on the first request to it (Module::linkAssets()). Without it, a module's CSS and JS have nowhere to be published.
What is Zero Framework?
Zero is a minimal PHP MVC framework that maps URLs directly to PHP classes. There's no routing table to maintain, no YAML configuration to write, no dependency injection container to wire up. You create a module class, give it public methods, and the framework handles everything else.
The front controller — Application, Request, Response and Module — is four files and 2,176 lines that you can read in an afternoon. When something breaks, you'll know where to look — because there's nowhere to hide.
Both halves of that are checkable in under a minute, which is the point of stating them. Search the tree for a route file: there is no routes/web.php, no routes.yaml, no route cache and no #[Route] attribute anywhere in the framework. Then look for a dependency. Core does carry a composer.json, and its own description says what it is for: it “documents the packages a site installs; nothing reads this file at runtime.” It names one package, minishlink/web-push, which only the Push module uses, and suggests google/apiclient for Google sign-in. There is no composer.lock, no vendor/, no package.json and no node_modules/. Composer is supported, not required — registerAutoloaders() pulls in vendor/autoload.php only if that file happens to exist, and nothing notices when it doesn't. This site has no vendor/ at all.
What comes with it
Core is no longer only a front controller. The same clone brings, switched on or off per site in app/modules.ini:
| In core | What it is |
|---|---|
core/modules/ |
Nine bundled modules: Index, Auth, User, Admin, Push and Entity are on by default; Module, HelloWorld and Test are examples and off. A site can turn any of them off, or override one with a module of the same name. |
core/attribute/ |
The attribute gates that run before an endpoint: login, permission, method, parameters, IP, token, audit. |
core/Session.php, core/access/ |
Sessions, users, groups and permissions. |
core/lib/ |
Libraries any site can use: Mail, Http, Crypto, Net, CloudFlare. |
core/entity/ |
The optional Entity Framework, as a submodule of core. |
core/skeleton/ |
The template for a new site and the defaults core falls back to: frame pieces, config, wording. |
A site that wants none of it still gets none of it in its way. This one has no database and no sign-in: its app/modules.ini turns Auth, User, Admin, Push and Entity off, and every page you can reach from the navigation is one of the site's own six modules.
How It Works
A URL like /user-profile/edit/42 automatically resolves to UserProfile::edit('42'). Kebab-case URLs map to camelCase class names and methods. Arguments in the URL path become method parameters.
The middle box is the whole trick. Application::run() asks Zero\Core\Modules whether the first URL segment names a module — a folder in the site's modules/ or in core/modules/ that is switched on — requires its controller if, and only if, it does, then calls the second segment as a method on the instance. The filesystem is the lookup table. That is why there is nothing to register when you add a page, and nothing to re-cache when you deploy one.
It is also the security boundary. Application::classFile() only returns a file that lies inside the module's own folder, so a URL cannot reach a class outside it. Core says so in its own comment on isModule(): “Doing this ensures the controller can't call things outside of the module path.” And only a public method is an endpoint: every helper in Response and Module is protected, so no URL reaches one.
Every row below is a live URL on this site, resolved by that mechanism and nothing else. Click one and check:
| URL | Resolves to |
|---|---|
| /zero | Zero::index() — no endpoint segment, so index is the default |
| /zero/routing | Zero::routing() |
| /examples/hello-world | Examples::helloWorld() — kebab-case converted to camelCase |
| /shadow/gallery | Shadow::gallery() |
Everything after /module/endpoint/ is sliced into an array and splatted into the method, so PHP's own signature is the request contract. Required, optional and defaulted segments are declared where the code lives instead of in a route pattern — and a URL that omits a required parameter raises ArgumentCountError, which run() converts into a 400 before your method body executes. You never write if (!isset($args[0])) return 400;.
Core Features
rocket_launch Getting Started
Core as a submodule, zero-init.sh, and what a site may leave out.
route Routing
Automatic URL-to-class mapping with kebab-case conversion, argument unpacking, and standalone pages.
widgets Modules
Self-contained application units with controllers, views, models, and assets.
account_tree Submodules
Infinitely nestable modules with frame and asset inheritance.
web Views & Responses
Dual HTML/JSON endpoints, frame templates, and flexible response methods.
error Error Handling
HTTPError exceptions with custom error views and JSON error bodies.
verified_user Attributes
PHP 8 attributes for authentication, authorization, validation, and auditing.
key Sessions & Permissions
Session, users and groups, capabilities, and per-item sharing.
shield Security & Logging
Banned requests, allowed-ips.lst, trusted proxies, and Console.
tune Configuration & Wording
Constants from .ini files, skeleton defaults, and strings/.
inventory_2 Bundled Modules
The nine modules in core/modules/, their tiers, and app/modules.ini.
admin_panel_settings Admin Screens
How a module offers an admin screen, and the screens Admin ships.
folder_open Asset Management
CSS, JS, and components auto-loaded by naming convention.
manage_search Class Loading
One rule maps a Zero\ namespace to a folder, for requests and scripts alike.
database Models & Database
No ORM and no migrations. A lazy PDO connection that never opens until something asks — this site never does.
library_books Libraries
Mail, Http, Crypto, Net and CloudFlare in core/lib/.
extension Plugins
Five lifecycle hooks, dispatched by core/PluginLoader.php and called from core/Application.php.
upgrade Upgrading
What was removed or replaced, and what to use instead.
Minimal Example
<?php
namespace Zero\Module;
class Hello extends \Zero\Core\Module {
public function index() {
$this->respond($this->viewPath . 'index.php');
}
// The signature is the request contract. Drop the default from $name and
// /hello/greet becomes a 400 before this method body ever runs.
public function greet(string $name = 'world', int $times = 1) {
// respond() reports whatever $status holds. Leave it unset and the
// JSON envelope says "unknown" -- see the next section.
$this->status = 'success';
$this->data = ['name' => $name, 'times' => $times];
$this->respond($this->viewPath . 'greet.php');
}
}
That's a complete module. Visit /hello to see the index, or /hello/greet/claude to greet someone. Send an Accept: application/json header and the same endpoint returns JSON.
This page is a Zero module
The framework describing itself here is the one that rendered the sentence you are reading. This page is Zero::index() in modules/Zero/Zero.php; its view is modules/Zero/view/index.php. Nineteen public methods, nineteen pages — the eighteen cards above, plus this one.
So the dual-response claim does not need a diagram. Point curl at a sibling page and watch one method produce three different documents. Every command and every response below is real output from this site:
curl https://stave.dev/zero/routing
The full framed page: head, header, the view, sideNav, footer. Its <title> comes back as Routing — Zero Framework — stave.dev, composed by a #[PageMeta] attribute on the method and another on the class. Nothing in the view writes it.
curl -H "X-Requested-With: XMLHttpRequest" https://stave.dev/zero/routing
<div class="doc-header">
<h1>Routing</h1>
... the rest of the view, and nothing else.
The same method, with every frame piece suppressed. Response::add(), which includes each frame piece, returns early whenever the request carried that header, so you get the view and nothing else — no separate partial, no second route.
curl -H "Accept: application/json" https://stave.dev/zero/routing
{"data":[],"status":"unknown","code":200}
data is empty because this endpoint sets no $this->data, and status reads "unknown" because it never assigned $this->status. respond() reports what it was handed, not what you hoped for. Name it in your endpoint and it shows up.
One method, three shapes. There is no /api/* twin, no second controller, no if ($request->ajax()) branch in the view and no serializer layer. respond() is the only response primitive in the framework, and it branches on the request headers.
The same is true when nothing is found. Ask for a page that does not exist and the 404 is rendered through the module that was already running, so it keeps that module's own frame, view path and assets — and a JSON client gets a JSON error body from the identical throw:
curl -i https://stave.dev/zero/nothing-here
HTTP/1.1 404 Not Found
# rendered inside Zero's own layout, not a generic framework page
curl -H "Accept: application/json" https://stave.dev/zero/nothing-here
{"status":"error","message":"Not Found","detail":"nothingHere","code":404}
And that 404 is the last resort, not the first. When the requested method does not exist, Module::__call() looks for a submodule of that name, and then Response::__call() takes the first of three things: a view file in the module's own view/ folder, a public method of Index named after the first URL segment, or a view file in Index's view/ folder of that name. A content page can cost one file and no class; you add a controller method later, only when the page needs logic. Routing has the full order.