Skip to main content

Directory structure

my-api/
├── omnitrix the command line: php omnitrix <command>
├── bootstrap.php builds and returns the Application
├── config/ one file per configuration section
│ ├── app.php name, environment, debug, log level
│ ├── server.php host, port, workers
│ ├── http.php body size limit, request timeout
│ ├── database.php MySQL/MariaDB connection and pool
│ ├── redis.php Redis connection and pool
│ ├── cache.php cache prefix and default TTL
│ ├── http_client.php outbound HTTP defaults
│ └── queue.php queue name, concurrency, job classes
├── routes/
│ └── api.php route definitions
├── src/ your code, namespace App\
│ ├── Controllers/
│ ├── Models/
│ ├── Middleware/
│ └── Jobs/
├── database/
│ ├── migrations/ schema changes, run in filename order
│ └── seeds/ seeders, namespace Database\Seeds\
├── storage/
│ └── logs/ OpenSwoole's server log
├── tests/ PHPUnit tests (Unit/, Feature/)
├── .env local settings and secrets (not committed)
├── .env.example template for .env (committed)
└── composer.json

How a request reaches your code​

  1. php omnitrix serve requires bootstrap.php, which loads .env, reads config/, registers global middleware and loads routes/api.php.
  2. The server starts its worker processes. Each worker builds its own services (database pool, Redis client, HTTP client) and binds them to the facades.
  3. Each request runs in a coroutine: routing, middleware, your controller, then the response.

bootstrap.php is plain PHP. Add global middleware, extra route files, metrics or the CPU pool there:

$app->middleware(new SecurityHeaders(), new AccessLog($app->logger()));
$app->routes(__DIR__ . '/routes/admin.php');
$app->enableMetrics('/metrics', [$metricsAuth]);

Naming​

KindLocationNamespaceGenerator
Controllersrc/ControllersApp\Controllersmake:controller
Modelsrc/ModelsApp\Modelsmake:model
Middlewaresrc/MiddlewareApp\Middlewaremake:middleware
Jobsrc/JobsApp\Jobsmake:job
Migrationdatabase/migrationsnone (returns an object)make:migration
Seederdatabase/seedsDatabase\Seedsmake:seeder

Add more folders under src/ freely (services, repositories, DTOs); everything in src/ is autoloaded under App\.