Project Structure
Understanding how Larafony projects are organized
Directory Structure
Larafony follows a clean, intuitive structure inspired by modern PHP frameworks. Here's what each directory contains:
my-app/
βββ bootstrap/ # Application bootstrap files
β βββ app.php # Web application bootstrap
β βββ console.php # Console application bootstrap
βββ config/ # Configuration files
β βββ database.php # Database configuration
β βββ view.php # View engine configuration
βββ database/
β βββ migrations/ # Database migrations
β βββ seeders/ # Database seeders
βββ public/
β βββ index.php # Application entry point
βββ resources/
β βββ views/ # Blade templates
βββ src/
β βββ Controllers/ # HTTP controllers
β βββ Models/ # ORM models
β βββ DTOs/ # Data Transfer Objects
β βββ Middleware/ # HTTP middleware
β βββ Console/ # Console commands
β βββ View/ # View components
βββ storage/
β βββ cache/ # Compiled views & cache
β βββ logs/ # Application logs
βββ .env # Environment variables
βββ .env.example # Example environment file
βββ composer.json # Dependencies
Bootstrap Directory
The bootstrap/ directory contains files that bootstrap your application.
bootstrap/app.php
This file creates and configures the web application instance. It registers service providers and sets up route discovery:
<?php
use Larafony\Framework\Web\Application;
$app = Application::instance(base_path: dirname(__DIR__));
// Register service providers
$app->withServiceProviders([
ErrorHandlerServiceProvider::class,
ConfigServiceProvider::class,
DatabaseServiceProvider::class,
HttpServiceProvider::class,
RouteServiceProvider::class,
ViewServiceProvider::class,
WebServiceProvider::class,
]);
// Auto-discover routes from controller attributes
$app->withRoutes(function ($router) {
$router->loadAttributeRoutes(__DIR__ . '/../src/Controllers');
});
return $app;
bootstrap/console.php
Similar to app.php, but for console commands. It bootstraps the console application
and registers command directories.
Config Directory
Configuration files live in config/. These files return arrays of configuration options.
config/database.php
Database connection settings:
<?php
return [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'larafony'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
],
],
];
Public Directory
The public/ directory contains the front controller (index.php) and assets.
This is your document rootβall requests go through index.php.
<?php
require_once __DIR__ . '/../bootstrap/app.php';
$app->run();
Src Directory
Your application code lives in src/. This follows the PSR-4 autoloading standard
with the App\ namespace.
Controllers
HTTP controllers with attribute-based routing. See the Controllers & Routing guide.
Models
ORM models with attribute-based relationships. See the Models & Relationships guide.
DTOs
Data Transfer Objects for validation. See the DTO Validation guide.
Middleware
PSR-15 middleware classes. See the Middleware guide.
Storage Directory
The storage/ directory contains compiled Blade templates, file caches, and logs.
Make sure this directory is writable.
storage/ directory must be writable by your web server.
Environment Configuration
The .env file contains environment-specific configuration. Never commit this file to version control.
APP_NAME=Larafony
APP_ENV=local
APP_DEBUG=true
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=larafony
DB_USERNAME=root
DB_PASSWORD=
VIEW_CACHE_ENABLED=true
.env.example to .env and customize it for your environment.