A routing engine simple enough for small blogs, yet strong enough for enterprise behemoths
Go to file
Funky Waddle 83f19e5f4d
Some checks are pending
CI / build (push) Waiting to run
Update README.md
2026-02-15 12:38:56 -06:00
.github/workflows chore: add GitHub Actions CI workflow 2026-02-14 23:48:58 -06:00
src refactor: extract CLI commands to separate classes 2026-02-14 23:43:17 -06:00
tests feat: add closure support to RouteGroup::group() 2026-02-14 23:43:17 -06:00
.gitignore chore: remove .junie from git tracking 2026-02-14 23:42:17 -06:00
atlas refactor: extract CLI commands to separate classes 2026-02-14 23:43:17 -06:00
composer.json docs: finalize milestones, update documentation, and guidelines 2026-02-14 17:28:19 -06:00
LICENSE.md Initial repository setup with LICENSE, .gitignore, and composer.json 2026-02-12 13:36:48 -06:00
MILESTONES.md docs: finalize milestones, update documentation, and guidelines 2026-02-14 17:28:19 -06:00
NOTES.md docs: finalize milestones, update documentation, and guidelines 2026-02-14 17:28:19 -06:00
README.md Update README.md 2026-02-15 12:38:56 -06:00
SPECS.md Update project documentation and composer.json with explicit optional parameter logic and author details 2026-02-12 14:34:25 -06:00
test_url_generation.php feat: implement milestone 1 - foundation and core architecture 2026-02-13 15:07:59 -06:00

Atlas Routing

A high-performance, modular PHP routing engine designed for professional-grade applications. It prioritizes developer experience, architectural purity, and interoperability through PSR-7 support.

CI Packagist Total Downloads Software License

Features

  • Fluent API: Expressive and chainable route definitions.
  • Dynamic Matching: Support for {{parameters}} and {{optional?}} segments.
  • Parameter Validation: Strict validation rules (numeric, alpha, regex, etc.).
  • Route Groups: Recursive grouping with prefix and middleware inheritance.
  • Modular Routing: Automatic route discovery from modules.
  • Reverse Routing: Safe URL generation with parameter validation.
  • PSR-7 Support: Built on standard HTTP message interfaces.
  • Advanced Capabilities: Subdomain constraints, i18n support, and redirects.
  • Developer Tooling: Programmatic Inspector API and CLI tools.
  • Performance: Optimized matching engine with route caching support.

Installation

composer require getphred/atlas

Basic Usage

use Atlas\Router\Router;
use Atlas\Config\Config;
use GuzzleHttp\Psr7\ServerRequest;

// 1. Setup Configuration
$config = new Config([
    'modules_path' => __DIR__ . '/src/Modules',
]);

// 2. Initialize Router
$router = new Router($config);

// 3. Define Routes
$router->get('/users', function() {
    return 'User List';
})->name('users.index');

$router->get('/users/{{id}}', function($id) {
    return "User $id";
})->name('users.show')->valid('id', 'numeric');

// 4. Match Request
$request = ServerRequest::fromGlobals();
$route = $router->match($request);

if ($route) {
    $handler = $route->getHandler();
    // Execute handler...
} else {
    // 404 Not Found
}

Route Groups

$router->group(['prefix' => '/api', 'middleware' => ['auth']])->group(function($group) {
    $group->get('/profile', 'ProfileHandler');
    $group->get('/settings', 'SettingsHandler');
});

All group routes inherit whatever options you pass in (middleware, prefix, etc).

While the above syntax works and is completely viable, I find the double group method syntax a bit confusing.

So, here is another way you can do it (my personal preferred method) that is, in my opinion, cleaner, and more readable.

$api = $router->group(['prefix' => '/api']);

$api->get('/users', 'UserIndexHandler');
$api->post('/users', 'UserCreateHandler');

Performance & Caching

For production environments, you can cache the route collection:

if ($cache->has('routes')) {
    $routes = unserialize($cache->get('routes'));
    $router->setRoutes($routes);
} else {
    // Define your routes...
    $cache->set('routes', serialize($router->getRoutes()));
}

CLI Tools

Atlas comes with a CLI tool to help you debug your routes:

# List all routes
./atlas route:list

# Test a specific request
./atlas route:test GET /users/5

License

The MIT License (MIT). Please see License File for more information.